Verifies: SYS-REQ-112 (container length accessor). reqproof:proptest:skip targeted witness/regression test; not a property-test subject SYS-REQ-112:nominal:nominal SYS-REQ-112:boundary:nominal SYS-REQ-112:malformed_input:nominal SYS-REQ-112:malformed_input:negative
(t *testing.T)
| 96 | // SYS-REQ-112:malformed_input:nominal |
| 97 | // SYS-REQ-112:malformed_input:negative |
| 98 | func TestGetObjectLen(t *testing.T) { |
| 99 | tests := []struct { |
| 100 | name string |
| 101 | data string |
| 102 | keys []string |
| 103 | want int |
| 104 | wantErr error |
| 105 | }{ |
| 106 | { |
| 107 | name: "empty object", |
| 108 | data: `{}`, |
| 109 | want: 0, |
| 110 | }, |
| 111 | { |
| 112 | name: "one key", |
| 113 | data: `{"one":1}`, |
| 114 | want: 1, |
| 115 | }, |
| 116 | { |
| 117 | name: "five keys", |
| 118 | data: `{"one":1,"two":2,"three":3,"four":4,"five":5}`, |
| 119 | want: 5, |
| 120 | }, |
| 121 | { |
| 122 | name: "nested object", |
| 123 | data: `{"outer":{"one":1,"two":{"nested":true},"three":3}}`, |
| 124 | keys: []string{"outer"}, |
| 125 | want: 3, |
| 126 | }, |
| 127 | { |
| 128 | name: "string values containing commas", |
| 129 | data: `{"one":"a,b,c","two":"d,e","three":"no comma"}`, |
| 130 | want: 3, |
| 131 | }, |
| 132 | { |
| 133 | name: "addressed value is not an object", |
| 134 | data: `{"value":[]}`, |
| 135 | keys: []string{"value"}, |
| 136 | wantErr: KeyPathNotFoundError, |
| 137 | }, |
| 138 | { |
| 139 | name: "missing path", |
| 140 | data: `{"value":{}}`, |
| 141 | keys: []string{"missing"}, |
| 142 | wantErr: KeyPathNotFoundError, |
| 143 | }, |
| 144 | } |
| 145 | |
| 146 | for _, test := range tests { |
| 147 | t.Run(test.name, func(t *testing.T) { |
| 148 | got, err := GetObjectLen([]byte(test.data), test.keys...) |
| 149 | if test.wantErr != nil { |
| 150 | if !errors.Is(err, test.wantErr) { |
| 151 | t.Fatalf("GetObjectLen() error = %v, want %v", err, test.wantErr) |
| 152 | } |
| 153 | return |
| 154 | } |
| 155 | if err != nil { |
nothing calls this directly
no test coverage detected