Verifies: SYS-REQ-102 MCDC SYS-REQ-102: mutation_input_has_unicode_keys=T, mutation_handles_unicode_keys_safely=T => TRUE
(t *testing.T)
| 758 | // Verifies: SYS-REQ-102 |
| 759 | // MCDC SYS-REQ-102: mutation_input_has_unicode_keys=T, mutation_handles_unicode_keys_safely=T => TRUE |
| 760 | func 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 |