(t *testing.T)
| 404 | } |
| 405 | |
| 406 | func TestExtractJSON(t *testing.T) { |
| 407 | tests := []struct { |
| 408 | name string |
| 409 | input string |
| 410 | expected string |
| 411 | }{ |
| 412 | { |
| 413 | name: "plain JSON", |
| 414 | input: `{"key": "value"}`, |
| 415 | expected: `{"key": "value"}`, |
| 416 | }, |
| 417 | { |
| 418 | name: "JSON in code block", |
| 419 | input: "```json\n{\"key\": \"value\"}\n```", |
| 420 | expected: `{"key": "value"}`, |
| 421 | }, |
| 422 | { |
| 423 | name: "JSON with text before", |
| 424 | input: "Here is the JSON:\n{\"key\": \"value\"}", |
| 425 | expected: `{"key": "value"}`, |
| 426 | }, |
| 427 | { |
| 428 | name: "JSON with text after", |
| 429 | input: "{\"key\": \"value\"}\nThat's it!", |
| 430 | expected: `{"key": "value"}`, |
| 431 | }, |
| 432 | { |
| 433 | name: "nested JSON", |
| 434 | input: `{"outer": {"inner": "value"}}`, |
| 435 | expected: `{"outer": {"inner": "value"}}`, |
| 436 | }, |
| 437 | { |
| 438 | name: "JSON with string containing braces", |
| 439 | input: `{"message": "This is a {test} string"}`, |
| 440 | expected: `{"message": "This is a {test} string"}`, |
| 441 | }, |
| 442 | { |
| 443 | name: "JSON with escaped quotes", |
| 444 | input: `{"message": "She said \"hello\""}`, |
| 445 | expected: `{"message": "She said \"hello\""}`, |
| 446 | }, |
| 447 | { |
| 448 | name: "JSON with multiple objects (should extract first)", |
| 449 | input: `{"first": "object"} {"second": "object"}`, |
| 450 | expected: `{"first": "object"}`, |
| 451 | }, |
| 452 | { |
| 453 | name: "complex nested JSON", |
| 454 | input: `{"summary": "test", "data": {"nested": {"deep": "value"}}, "array": [1, 2, 3]}`, |
| 455 | expected: `{"summary": "test", "data": {"nested": {"deep": "value"}}, "array": [1, 2, 3]}`, |
| 456 | }, |
| 457 | } |
| 458 | |
| 459 | for _, tt := range tests { |
| 460 | t.Run(tt.name, func(t *testing.T) { |
| 461 | result := extractJSON(tt.input) |
| 462 | if result != tt.expected { |
| 463 | t.Errorf("Expected %s, got %s", tt.expected, result) |
nothing calls this directly
no test coverage detected