|
325 | 325 | expect($writtenContent)->toContain('arg1'); // Existing args preserved |
326 | 326 | }); |
327 | 327 |
|
328 | | -test('detectIndentation works correctly with various patterns', function (string $content, int $position, string $expected, string $description) { |
| 328 | +test('detectIndentation works correctly with various patterns', function (string $content, int $position, int $expected, string $description) { |
329 | 329 | $writer = new FileWriter('/tmp/test.json'); |
330 | 330 |
|
331 | 331 | $result = $writer->detectIndentation($content, $position); |
@@ -513,61 +513,49 @@ function indentationDetectionCases(): array |
513 | 513 | 'mcp.json5 servers indentation' => [ |
514 | 514 | 'content' => "{\n // Here are comments within my JSON\n \"servers\": {\n \"mysql\": {\n \"command\": \"npx\"\n },\n \"laravel-boost\": {\n \"command\": \"php\"\n }\n },\n \"inputs\": []\n}", |
515 | 515 | 'position' => 200, // Position near end of servers block |
516 | | - 'expected' => ' ', // 8 spaces for server-level items |
| 516 | + 'expected' => 8, |
517 | 517 | 'description' => 'Should detect 8 spaces for server definitions in mcp.json5', |
518 | 518 | ], |
519 | 519 | 'nested object with 4-space base indent' => [ |
520 | 520 | 'content' => "{\n \"config\": {\n \"server1\": {\n \"command\": \"test\"\n }\n }\n}", |
521 | 521 | 'position' => 80, |
522 | | - 'expected' => ' ', // 8 spaces for server-level |
| 522 | + 'expected' => 8, |
523 | 523 | 'description' => 'Should detect 8 spaces for nested server definitions', |
524 | 524 | ], |
525 | 525 | 'no previous server definitions' => [ |
526 | 526 | 'content' => "{\n \"inputs\": []\n}", |
527 | 527 | 'position' => 20, |
528 | | - 'expected' => ' ', // Fallback to 8 spaces |
| 528 | + 'expected' => 8, |
529 | 529 | 'description' => 'Should fallback to 8 spaces when no server definitions found', |
530 | 530 | ], |
531 | | - 'tab-indented servers' => [ |
532 | | - 'content' => "{\n\t\"servers\": {\n\t\t\"mysql\": {\n\t\t\t\"command\": \"npx\"\n\t\t}\n\t}\n}", |
533 | | - 'position' => 50, |
534 | | - 'expected' => "\t\t", // 2 tabs for server-level |
535 | | - 'description' => 'Should detect tab indentation for server definitions', |
536 | | - ], |
537 | | - 'mixed indentation with tabs and spaces' => [ |
538 | | - 'content' => "{\n \t\"servers\": {\n \t \"mysql\": {\n \t \"command\": \"npx\"\n \t }\n \t}\n}", |
539 | | - 'position' => 70, |
540 | | - 'expected' => " \t ", // Mixed indentation preserved |
541 | | - 'description' => 'Should preserve mixed tab/space indentation', |
542 | | - ], |
543 | 531 | 'deeper nesting with 2-space indent' => [ |
544 | 532 | 'content' => "{\n \"config\": {\n \"servers\": {\n \"mysql\": {\n \"command\": \"test\"\n }\n }\n }\n}", |
545 | 533 | 'position' => 80, |
546 | | - 'expected' => ' ', // 6 spaces for server-level in deeper nesting |
| 534 | + 'expected' => 6, |
547 | 535 | 'description' => 'Should detect correct indentation in deeply nested structures', |
548 | 536 | ], |
549 | 537 | 'single server definition at root level' => [ |
550 | 538 | 'content' => "{\n\"mysql\": {\n \"command\": \"npx\"\n}\n}", |
551 | 539 | 'position' => 30, |
552 | | - 'expected' => '', // No indentation at root level |
| 540 | + 'expected' => 0, |
553 | 541 | 'description' => 'Should detect no indentation for root-level server definitions', |
554 | 542 | ], |
555 | 543 | 'multiple server definitions with consistent indentation' => [ |
556 | 544 | 'content' => "{\n \"servers\": {\n \"mysql\": {\n \"command\": \"npx\"\n },\n \"postgres\": {\n \"command\": \"pg\"\n }\n }\n}", |
557 | 545 | 'position' => 150, |
558 | | - 'expected' => ' ', // 8 spaces |
| 546 | + 'expected' => 8, |
559 | 547 | 'description' => 'Should consistently detect indentation across multiple servers', |
560 | 548 | ], |
561 | 549 | 'server definition with comments' => [ |
562 | 550 | 'content' => "{\n // Comment here\n \"servers\": {\n \"mysql\": { // inline comment\n \"command\": \"npx\"\n }\n }\n}", |
563 | 551 | 'position' => 120, |
564 | | - 'expected' => ' ', // 8 spaces |
| 552 | + 'expected' => 8, |
565 | 553 | 'description' => 'Should detect indentation correctly when comments are present', |
566 | 554 | ], |
567 | 555 | 'empty content' => [ |
568 | 556 | 'content' => '', |
569 | 557 | 'position' => 0, |
570 | | - 'expected' => ' ', // Fallback |
| 558 | + 'expected' => 8, |
571 | 559 | 'description' => 'Should fallback to 8 spaces for empty content', |
572 | 560 | ], |
573 | 561 | ]; |
|
0 commit comments