Verifies: SYS-REQ-115 (lenient traversal and deletion) SYS-REQ-115:nominal:nominal reqproof:proptest:skip targeted witness/regression test; not a property-test subject
(t *testing.T)
| 142 | // SYS-REQ-115:nominal:nominal |
| 143 | // reqproof:proptest:skip targeted witness/regression test; not a property-test subject |
| 144 | func TestConfigTraversalAndDelete(t *testing.T) { |
| 145 | data := []byte(`{'items':['one','two'],'object':{'a':'A','b':'B'}}`) |
| 146 | |
| 147 | var items []string |
| 148 | if _, err := Lenient.ArrayEach(data, func(value []byte, _ ValueType, _ int, err error) { |
| 149 | if err != nil { |
| 150 | t.Errorf("Lenient.ArrayEach callback error: %v", err) |
| 151 | return |
| 152 | } |
| 153 | items = append(items, string(value)) |
| 154 | }, "items"); err != nil { |
| 155 | t.Fatalf("Lenient.ArrayEach returned error: %v", err) |
| 156 | } |
| 157 | if want := []string{"one", "two"}; !reflect.DeepEqual(items, want) { |
| 158 | t.Fatalf("Lenient.ArrayEach values = %v, want %v", items, want) |
| 159 | } |
| 160 | |
| 161 | entries := make(map[string]string) |
| 162 | err := Lenient.ObjectEach(data, func(key, value []byte, _ ValueType, _ int) error { |
| 163 | if _, duplicate := entries[string(key)]; duplicate { |
| 164 | return errors.New("duplicate key") |
| 165 | } |
| 166 | entries[string(key)] = string(value) |
| 167 | return nil |
| 168 | }, "object") |
| 169 | if err != nil { |
| 170 | t.Fatalf("Lenient.ObjectEach returned error: %v", err) |
| 171 | } |
| 172 | if want := map[string]string{"a": "A", "b": "B"}; !reflect.DeepEqual(entries, want) { |
| 173 | t.Fatalf("Lenient.ObjectEach entries = %v, want %v", entries, want) |
| 174 | } |
| 175 | |
| 176 | deleted := Lenient.Delete(data, "object", "a") |
| 177 | if got, want := string(deleted), `{'items':['one','two'],'object':{'b':'B'}}`; got != want { |
| 178 | t.Fatalf("Lenient.Delete = %s, want %s", got, want) |
| 179 | } |
| 180 | } |
nothing calls this directly
no test coverage detected