diff --git a/tests/test_jsonld.py b/tests/test_jsonld.py index 5331438d..0e0906fd 100644 --- a/tests/test_jsonld.py +++ b/tests/test_jsonld.py @@ -969,3 +969,38 @@ def test_no_initial_context_and_with_skip_expand_does_not_drop_property_when_arr compacted = jsonld.compact(input, {"@vocab": "http://example.org#"}, {"skipExpansion": True}) expected = {"@context": {"@vocab": "http://example.org#"}, "name": "Bob"} assert compacted == expected + + # Issue 83 + def test_with_vocab_no_id(self): + """ + Compacting with @vocab should not compact a plain string value + """ + ctx = {'@vocab': 'http://ex.org/#', 'path': {'@type': '@id'}} + input = { + 'http://ex.org/#path': 'http://ex.org/#shortname', + } + expected = { + "@context": {"@vocab": "http://ex.org/#", "path": {"@type": "@id"}}, + "http://ex.org/#path": "http://ex.org/#shortname", + } + + compacted = jsonld.compact(input, ctx) + + assert compacted == expected + + def test_with_vocab_with_id(self): + """ + Compacting with @vocab should compact an @id value + """ + ctx = {'@vocab': 'http://ex.org/#', 'path': {'@type': '@id'}} + input = { + 'http://ex.org/#path': {'@id': 'http://ex.org/#shortname'}, + } + expected = { + "@context": {"@vocab": "http://ex.org/#", "path": {"@type": "@id"}}, + "path": "http://ex.org/#shortname", + } + + compacted = jsonld.compact(input, ctx) + + assert compacted == expected