@@ -839,21 +839,46 @@ def test_non_empty_values_with_non_existing_template_value(self):
839839 compiled = self .handler .compile (template , expected )
840840 self .assertEqual (compiled , expected_compilation )
841841
842+ def test_sync_template_all_structured_deleted_dict_root (self ):
843+ # Dict root with only structured entries
844+ s1 = generate_random_string ()
845+ s2 = generate_random_string ()
846+ source = '{"a": {"string": "%s"}, "b": {"string": "%s"}}' % (s1 , s2 )
847+
848+ template , _ = self .handler .parse (source )
849+
850+ # Empty stringset -> all structured entries should be removed
851+ updated = self .handler .sync_template (template , [])
852+
853+ data = json .loads (updated )
854+ # Dict root should become an empty object
855+ self .assertEqual (data , {})
856+
857+ def test_sync_template_all_structured_deleted_list_root (self ):
858+ s1 = generate_random_string ()
859+ s2 = generate_random_string ()
860+ source = '[{"a": {"string": "%s"}, "b": {"string": "%s"}}]' % (s1 , s2 )
861+
862+ template , _ = self .handler .parse (source )
863+
864+ updated = self .handler .sync_template (template , [])
865+
866+ data = json .loads (updated )
867+ self .assertEqual (data , [])
868+
869+
842870 def test_sync_template_keeps_all_when_strings_match (self ):
843- # Template with two strings
844871 s1 = generate_random_string ()
845872 s2 = generate_random_string ()
846873 source = '{"a": {"string": "%s"}, "b": {"string": "%s"}}' % (s1 , s2 )
847874
848875 template , stringset = self .handler .parse (source )
849876
850- # Sanity: template now has hashes
851877 hash1 = stringset [0 ].template_replacement
852878 hash2 = stringset [1 ].template_replacement
853879 self .assertIn (hash1 , template )
854880 self .assertIn (hash2 , template )
855881
856- # If we pass back the same stringset, sync_template should be a no-op
857882 updated = self .handler .sync_template (template , stringset )
858883
859884 self .assertEqual (updated , template )
0 commit comments