Simulates exact strings Go receives on different Windows shells.
(t *testing.T)
| 286 | |
| 287 | // Simulates exact strings Go receives on different Windows shells. |
| 288 | func TestParseJSONMap_WindowsShellScenarios(t *testing.T) { |
| 289 | tests := []struct { |
| 290 | name string |
| 291 | input string |
| 292 | wantLen int |
| 293 | wantErr bool |
| 294 | }{ |
| 295 | {"bash: normal JSON", `{"a":"1","b":"2"}`, 2, false}, |
| 296 | {"cmd.exe: single-quoted", `'{"a":"1","b":"2"}'`, 2, false}, // strip ' fix |
| 297 | {"PS 5.x: mangled", `{a:1,b:2}`, 0, true}, // unrecoverable |
| 298 | {"PS 5.x: empty JSON OK", `{}`, 0, false}, // no inner " |
| 299 | {"PS 7.3+: normal JSON", `{"a":"1"}`, 1, false}, // already fixed |
| 300 | {"PS escaped: correct", `{"a":"1"}`, 1, false}, // after CommandLineToArgvW |
| 301 | } |
| 302 | for _, tt := range tests { |
| 303 | t.Run(tt.name, func(t *testing.T) { |
| 304 | got, err := ParseJSONMap(tt.input, "--params", nil, nil) |
| 305 | if (err != nil) != tt.wantErr { |
| 306 | t.Errorf("error = %v, wantErr %v", err, tt.wantErr) |
| 307 | return |
| 308 | } |
| 309 | if !tt.wantErr && len(got) != tt.wantLen { |
| 310 | t.Errorf("got %d keys, want %d", len(got), tt.wantLen) |
| 311 | } |
| 312 | }) |
| 313 | } |
| 314 | } |
nothing calls this directly
no test coverage detected