Skip to content

Commit d79029c

Browse files
unhappychoiceclaude
andcommitted
feat: add comprehensive Scala test suite
- Add Scala language support tests for code extraction functionality - Include unit tests for Scala file extension mapping - Add integration tests for Scala parser (functions, classes, objects, traits, enums) - Add Scala comment processing tests with special characters - Add comprehensive typing core tests with snapshot validation - Create dedicated test structure in tests/integration/languages/scala/ - Add helper function for consistent test extraction options Tests cover various Scala constructs: - Functions (def statements) - Classes and case classes - Objects and case objects - Traits and sealed traits - Enums with pattern matching - Higher-order functions and for comprehensions - Comment handling for both // and /* */ styles 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 8dc6b40 commit d79029c

17 files changed

+1127
-0
lines changed

tests/integration/comment_processing_tests.rs

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,4 +443,79 @@ functionB();"#;
443443
);
444444
}
445445
}
446+
447+
#[test]
448+
fn test_scala_comment_processing() {
449+
let scala_code = r#"// Scala object definition with comments
450+
object Calculator {
451+
/* Multi-line comment
452+
with calculations */
453+
def add(x: Int, y: Int): Int = x + y
454+
455+
// Single line comment for multiplication
456+
def multiply(x: Int, y: Int): Int = {
457+
/* Another block comment */
458+
x * y
459+
}
460+
}
461+
462+
class MathUtils {
463+
// Comment with special symbols: → ← ↑ ↓
464+
def factorial(n: Int): Int = {
465+
if (n <= 1) 1 else n * factorial(n - 1)
466+
}
467+
}"#;
468+
469+
// Find all comment ranges manually for testing
470+
let comment_ranges = vec![
471+
// First single-line comment
472+
(0, "// Scala object definition with comments".len()),
473+
// Multi-line comment
474+
(scala_code.find("/* Multi-line comment").unwrap(),
475+
scala_code.find("calculations */").unwrap() + "calculations */".len()),
476+
// Single line comment for multiplication
477+
(scala_code.find("// Single line comment").unwrap(),
478+
scala_code.find("multiplication").unwrap() + "multiplication".len()),
479+
// Another block comment
480+
(scala_code.find("/* Another block comment").unwrap(),
481+
scala_code.find("comment */").unwrap() + "comment */".len()),
482+
// Comment with special symbols
483+
(scala_code.find("// Comment with special").unwrap(),
484+
scala_code.find("↑ ↓").unwrap() + "↑ ↓".len()),
485+
];
486+
487+
println!("=== Scala Comment Processing Test ===");
488+
println!("Code: {}", scala_code);
489+
println!("Comment ranges: {:?}", comment_ranges);
490+
491+
let typing_core = TypingCore::new(scala_code, &comment_ranges, Default::default());
492+
let display_ranges = typing_core.display_comment_ranges();
493+
494+
println!("Display text: {}", typing_core.text_to_display());
495+
println!("Display ranges: {:?}", display_ranges);
496+
497+
// Should find all comment ranges
498+
assert_eq!(
499+
display_ranges.len(),
500+
comment_ranges.len(),
501+
"Should find all Scala comments"
502+
);
503+
504+
for (i, &(start, end)) in display_ranges.iter().enumerate() {
505+
let display_text = typing_core.text_to_display();
506+
let comment = &display_text[start..end];
507+
println!("Comment {}: {:?}", i, comment);
508+
509+
// Verify comments contain expected content
510+
match i {
511+
0 => assert!(comment.contains("Scala object"), "Should contain 'Scala object'"),
512+
1 => assert!(comment.contains("Multi-line") && comment.contains("calculations"),
513+
"Should contain multi-line comment content"),
514+
2 => assert!(comment.contains("multiplication"), "Should contain 'multiplication'"),
515+
3 => assert!(comment.contains("Another block"), "Should contain 'Another block'"),
516+
4 => assert!(comment.contains("→ ← ↑ ↓"), "Should contain special symbols"),
517+
_ => {}
518+
}
519+
}
520+
}
446521
}

tests/integration/languages/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pub mod php;
1111
pub mod python;
1212
pub mod ruby;
1313
pub mod rust;
14+
pub mod scala;
1415
pub mod swift;
1516
pub mod typescript;
1617

0 commit comments

Comments
 (0)