Skip to content

Commit 2e9a89e

Browse files
[#204]: Add nested type-scoped context regression test
1 parent 7a9150f commit 2e9a89e

1 file changed

Lines changed: 60 additions & 0 deletions

File tree

tests/test_jsonld.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,66 @@ def test_scoped_context_on_nest_term_expands_nested_properties(self):
344344

345345
assert result == expected
346346

347+
# Issue 204
348+
def test_scoped_context_on_nest_term_expands_nested_type_scoped_context(self):
349+
"""
350+
A scoped context on a @nest term should be in effect when expanding the
351+
nested node, including when processing any type-scoped contexts found on
352+
that node.
353+
354+
JSON-LD 1.1 defines property nesting as semantically transparent: nested
355+
properties are removed during expansion and treated as if their contents
356+
were declared directly on the containing node object. It also defines
357+
scoped contexts as property-scoped when the term is used as a property
358+
and type-scoped when the term is used as a type. This test combines both
359+
rules deliberately:
360+
361+
* p1 is an @nest term with a property-scoped context.
362+
* That context defines Type and gives Type its own type-scoped context.
363+
* The nested node uses Type and then uses p2 from Type's scoped context.
364+
365+
If nested values are expanded by directly walking their keys instead of
366+
running the normal expansion setup for the nested node, Type and p2 fall
367+
back to the outer @vocab. The expected result proves that the @nest term
368+
context is active before @type is expanded and before Type's scoped
369+
context is applied.
370+
"""
371+
input = {
372+
"@context": {
373+
"@vocab": "http://example.org/outer#",
374+
"p1": {
375+
"@id": "@nest",
376+
"@context": {
377+
"Type": {
378+
"@id": "http://example.org/ns#Type",
379+
"@context": {
380+
"p2": "http://example.org/ns#P2",
381+
},
382+
},
383+
},
384+
},
385+
},
386+
"p1": {
387+
"@type": "Type",
388+
"p2": "foo",
389+
},
390+
}
391+
392+
expected = [
393+
{
394+
"@type": ["http://example.org/ns#Type"],
395+
"http://example.org/ns#P2": [
396+
{
397+
"@value": "foo",
398+
}
399+
],
400+
}
401+
]
402+
403+
result = jsonld.expand(input)
404+
405+
assert result == expected
406+
347407

348408
def test_mixed_plain_and_vocab_terms(self):
349409
"""Contexts with both plain and @type:@vocab terms should work correctly."""

0 commit comments

Comments
 (0)