Skip to content

Latest commit

 

History

History
103 lines (80 loc) · 2.75 KB

File metadata and controls

103 lines (80 loc) · 2.75 KB

Test Coverage for String Interpolation

Unit Tests (14 tests in print.rs)

Basic Interpolation Tests

  • test_interpolate_string_simple - Single variable interpolation
  • test_interpolate_string_number - Number interpolation
  • test_interpolate_string_boolean - Boolean interpolation
  • test_interpolate_string_multiple - Multiple variables in one string

Edge Cases

  • test_interpolate_string_no_variables - String without any variables
  • test_interpolate_string_escaped_braces - Escaped {{ braces
  • test_interpolate_string_escaped_closing - Escaped }} braces

Error Cases

  • test_interpolate_string_undefined_variable - Undefined variable error
  • test_interpolate_string_empty_variable - Empty {} error
  • test_interpolate_string_unclosed_brace - Missing closing } error

Integration Tests (6 tests in interpreter/mod.rs)

End-to-End Tests

  • test_string_interpolation_basic - Basic interpolation with string variable
  • test_string_interpolation_number - Interpolation with number variable
  • test_string_interpolation_boolean - Interpolation with boolean variable
  • test_string_interpolation_multiple - Multiple variables in statement
  • test_string_interpolation_undefined_variable - Error handling for undefined vars
  • test_string_without_interpolation - Plain text without variables

Test Coverage Summary

Total Tests: 27 (increased from 11)

  • Frontend (Lexer/Parser): 4 tests
  • Runtime (Interpreter): 9 tests
  • Builtins (Print): 14 tests
  • Utils (Integration): 4 tests

String Interpolation Coverage: 20 tests

  • Unit tests: 14
  • Integration tests: 6

What's Tested

Positive Cases

  • Single variable interpolation
  • Multiple variables in one string
  • Different data types (string, number, boolean)
  • Text without interpolation
  • Escaped braces ({{ and }})

Error Cases

  • Undefined variables
  • Empty variable names {}
  • Unclosed braces {name
  • Invalid characters in variable names

Implementation Details

  • Proper error messages
  • Correct string concatenation
  • Type-to-string conversion
  • Variable lookup in scope

Running the Tests

# Run all tests
cargo test

# Run only interpolation tests
cargo test interpolate

# Run with output
cargo test -- --nocapture

# Run specific test
cargo test test_interpolate_string_simple

Test Examples

Basic Interpolation

let name = "Alice"
print("Hello {name}")  // Output: Hello Alice

Multiple Variables

let name = "Bob"
let age = 30
print("{name} is {age}")  // Output: Bob is 30

Error Handling

print("Hello {undefined}")  // Error: Undefined variable: undefined

Escaped Braces

print("Literal {{braces}}")  // Output: Literal {braces}