Verifies: SYS-REQ-008 [boundary] MCDC SYS-REQ-008: N/A
(t *testing.T)
| 110 | // Verifies: SYS-REQ-008 [boundary] |
| 111 | // MCDC SYS-REQ-008: N/A |
| 112 | func TestEachKeySupplementalCoverage(t *testing.T) { |
| 113 | t.Run("supports more than stack sized path sets", func(t *testing.T) { |
| 114 | var doc strings.Builder |
| 115 | var paths [][]string |
| 116 | doc.WriteByte('{') |
| 117 | for i := 0; i < 129; i++ { |
| 118 | if i > 0 { |
| 119 | doc.WriteByte(',') |
| 120 | } |
| 121 | fmt.Fprintf(&doc, `"k%d":%d`, i, i) |
| 122 | paths = append(paths, []string{fmt.Sprintf("k%d", i)}) |
| 123 | } |
| 124 | doc.WriteByte('}') |
| 125 | |
| 126 | var count int |
| 127 | EachKey([]byte(doc.String()), func(idx int, value []byte, vt ValueType, err error) { |
| 128 | if err != nil { |
| 129 | t.Fatalf("EachKey large path set callback error: %v", err) |
| 130 | } |
| 131 | count++ |
| 132 | }, paths...) |
| 133 | if count != 129 { |
| 134 | t.Fatalf("EachKey large path set count = %d, want 129", count) |
| 135 | } |
| 136 | }) |
| 137 | |
| 138 | t.Run("supports deeper than stack sized paths", func(t *testing.T) { |
| 139 | var doc strings.Builder |
| 140 | var path []string |
| 141 | for i := 0; i < 129; i++ { |
| 142 | key := fmt.Sprintf("k%d", i) |
| 143 | path = append(path, key) |
| 144 | fmt.Fprintf(&doc, `{"%s":`, key) |
| 145 | } |
| 146 | doc.WriteString(`1`) |
| 147 | for i := 0; i < 129; i++ { |
| 148 | doc.WriteByte('}') |
| 149 | } |
| 150 | |
| 151 | var got string |
| 152 | EachKey([]byte(doc.String()), func(idx int, value []byte, vt ValueType, err error) { |
| 153 | if err != nil { |
| 154 | t.Fatalf("EachKey deep path callback error: %v", err) |
| 155 | } |
| 156 | got = string(value) |
| 157 | }, path) |
| 158 | if got != "1" { |
| 159 | t.Fatalf("EachKey deep path value = %q, want %q", got, "1") |
| 160 | } |
| 161 | }) |
| 162 | |
| 163 | t.Run("supports more than stack sized indexed array requests", func(t *testing.T) { |
| 164 | var doc strings.Builder |
| 165 | var paths [][]string |
| 166 | doc.WriteByte('[') |
| 167 | for i := 0; i < 129; i++ { |
| 168 | if i > 0 { |
| 169 | doc.WriteByte(',') |