MCPcopy
hub / github.com/buger/jsonparser / TestMutationUnicodeKeys

Function TestMutationUnicodeKeys

obligation_property_test.go:760–800  ·  view source on GitHub ↗

Verifies: SYS-REQ-102 MCDC SYS-REQ-102: mutation_input_has_unicode_keys=T, mutation_handles_unicode_keys_safely=T => TRUE

(t *testing.T)

Source from the content-addressed store, hash-verified

758// Verifies: SYS-REQ-102
759// MCDC SYS-REQ-102: mutation_input_has_unicode_keys=T, mutation_handles_unicode_keys_safely=T => TRUE
760func TestMutationUnicodeKeys(t *testing.T) {
761 t.Run("Set_unicode_key", func(t *testing.T) {
762 defer func() {
763 if r := recover(); r != nil {
764 t.Fatalf("Set with unicode key panicked: %v", r)
765 }
766 }()
767
768 data := []byte(`{"caf\u00e9":"latte","normal":"value"}`)
769 // Try to set a value using a Unicode key
770 result, err := Set(data, []byte(`"espresso"`), "normal")
771 if err != nil {
772 t.Fatalf("Set returned error: %v", err)
773 }
774 // Verify the mutation was applied
775 val, err := GetString(result, "normal")
776 if err != nil {
777 t.Fatalf("GetString after Set returned error: %v", err)
778 }
779 if val != "espresso" {
780 t.Fatalf("Expected 'espresso', got %q", val)
781 }
782 })
783
784 t.Run("Delete_unicode_key", func(t *testing.T) {
785 defer func() {
786 if r := recover(); r != nil {
787 t.Fatalf("Delete with unicode key panicked: %v", r)
788 }
789 }()
790
791 // Test Delete on document with a raw UTF-8 key
792 data := []byte("{\"caf\xc3\xa9\":\"latte\",\"tea\":\"green\"}")
793 result := Delete(data, "tea")
794 // Verify tea was removed and the document is still parseable
795 _, _, _, err := Get(result, "tea")
796 if !errors.Is(err, KeyPathNotFoundError) {
797 t.Fatalf("Expected KeyPathNotFoundError after Delete, got: %v", err)
798 }
799 })
800}
801
802// Verifies: SYS-REQ-105
803// MCDC SYS-REQ-105: getunsafestring_input_has_unicode_edge_cases=T, getunsafestring_handles_unicode_edges_safely=T => TRUE

Callers

nothing calls this directly

Calls 4

SetFunction · 0.85
GetStringFunction · 0.85
DeleteFunction · 0.85
GetFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…