From c440e46152f89f1d7cf95e8eacf16dd7f182e27c Mon Sep 17 00:00:00 2001 From: Miel Vander Sande Date: Wed, 13 May 2026 09:23:59 +0200 Subject: [PATCH] Add tests for skip expansion without initial context --- tests/test_jsonld.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tests/test_jsonld.py b/tests/test_jsonld.py index 6f9699d6..5331438d 100644 --- a/tests/test_jsonld.py +++ b/tests/test_jsonld.py @@ -931,3 +931,41 @@ def test_empty_context(self): input = {'http://schema.org/codeRepository': {'@id': 'http:'}} compacted = jsonld.compact(input, {}) assert compacted == input + + # Issue 82 + def test_no_initial_context_drops_property(self): + """ + Compacting without initial context should drop the original input. + """ + + input = {'name': 'Bob'} + + compacted = jsonld.compact(input, {"@vocab": "http://example.org#"}) + expected = {"@context": {"@vocab": "http://example.org#"}} + + assert compacted == expected + + @pytest.mark.xfail + def test_no_initial_context_and_with_skip_expand_does_not_drop_property_whe_not_array(self): + """ + Compacting document with singular value and without initial context should + output the original input when skipExpansion is enabled. + """ + + input = {'name': 'Bob'} + + compacted = jsonld.compact(input, {"@vocab": "http://example.org#"}, {"skipExpansion": True}) + expected = {"@context": {"@vocab": "http://example.org#"}, "name": "Bob"} + assert compacted == expected + + def test_no_initial_context_and_with_skip_expand_does_not_drop_property_when_array(self): + """ + Compacting document with array value and without initial context should + output the original input when skipExpansion is enabled. + """ + + input = {'name': ['Bob']} + + compacted = jsonld.compact(input, {"@vocab": "http://example.org#"}, {"skipExpansion": True}) + expected = {"@context": {"@vocab": "http://example.org#"}, "name": "Bob"} + assert compacted == expected