Skip to content

Testing Guide

Guide to testing USL compiler and generated code.

Compiler Tests

Unit Tests

#[test]
fn test_lexer() {
    let source = "entity User { }";
    let tokens = lex(source);
    assert_eq!(tokens.len(), 5);
}

Integration Tests

Located in tests/:

#[test]
fn test_compile_simple() {
    let result = compile_file("tests/simple.usl");
    assert!(result.is_ok());
}

Snapshot Tests

For testing generated code:

#[test]
fn test_codegen_typescript() {
    let generated = generate_typescript("test.usl");
    insta::assert_snapshot!(generated);
}

Running Tests

# All tests
cargo test

# Specific test
cargo test test_lexer

# With output
cargo test -- --nocapital

# Update snapshots
cargo insta review

Coverage

cargo tarpaulin --out Html

Back to Contributing