Archived
a42429012e
- crates/ → engrams/ (Rust engrams live here)
- el-compiler/ added: el self-hosting compiler as an el package
- src/{compiler,lexer,parser,codegen}.el
- bootstrap/el-compiler.elc (114KB, Rust-compiled seed)
- el.toml Cargo.toml workspace paths updated
- neuron-rs cross-repo path deps fixed (were pointing to products/ instead of foundation/)
132 lines
2.9 KiB
Rust
132 lines
2.9 KiB
Rust
//! Tests that el `test { ... }` blocks parse and type-check correctly.
|
|
|
|
use crate::{parse_ok, pipeline_ok};
|
|
|
|
// ── Parse tests ───────────────────────────────────────────────────────────────
|
|
|
|
#[test]
|
|
fn test_parse_simple_test_block() {
|
|
let src = r#"
|
|
test "addition works" {
|
|
assert 1 + 1 == 2
|
|
}
|
|
"#;
|
|
assert!(parse_ok(src).is_ok(), "simple test block should parse");
|
|
}
|
|
|
|
#[test]
|
|
fn test_parse_test_with_unit_target() {
|
|
let src = r#"
|
|
test "unit test" target: unit {
|
|
assert true
|
|
}
|
|
"#;
|
|
assert!(parse_ok(src).is_ok(), "test with unit target should parse");
|
|
}
|
|
|
|
#[test]
|
|
fn test_parse_test_with_e2e_target() {
|
|
let src = r#"
|
|
test "e2e test" target: e2e {
|
|
assert true
|
|
}
|
|
"#;
|
|
assert!(parse_ok(src).is_ok(), "test with e2e target should parse");
|
|
}
|
|
|
|
#[test]
|
|
fn test_parse_test_with_both_target() {
|
|
let src = r#"
|
|
test "both targets" target: both {
|
|
assert true
|
|
}
|
|
"#;
|
|
assert!(parse_ok(src).is_ok(), "test with both target should parse");
|
|
}
|
|
|
|
#[test]
|
|
fn test_parse_test_with_let_binding() {
|
|
let src = r#"
|
|
test "arithmetic" {
|
|
let x: Int = 3 + 4
|
|
assert x == 7
|
|
}
|
|
"#;
|
|
assert!(parse_ok(src).is_ok(), "test with let binding should parse");
|
|
}
|
|
|
|
#[test]
|
|
fn test_parse_test_with_fn_call() {
|
|
let src = r#"
|
|
fn double(n: Int) -> Int {
|
|
return n * 2
|
|
}
|
|
test "double function" {
|
|
let result: Int = double(5)
|
|
assert result == 10
|
|
}
|
|
"#;
|
|
assert!(parse_ok(src).is_ok(), "test calling fn should parse");
|
|
}
|
|
|
|
#[test]
|
|
fn test_parse_multiple_asserts() {
|
|
let src = r#"
|
|
test "multiple assertions" {
|
|
assert 1 < 2
|
|
assert 2 < 3
|
|
assert 3 > 0
|
|
}
|
|
"#;
|
|
assert!(parse_ok(src).is_ok(), "test with multiple asserts should parse");
|
|
}
|
|
|
|
#[test]
|
|
fn test_parse_test_with_seed_node() {
|
|
let src = r#"
|
|
test "with seed data" target: unit {
|
|
seed Node { node_type: "User", content: "Alice", importance: 0.9 }
|
|
assert true
|
|
}
|
|
"#;
|
|
assert!(parse_ok(src).is_ok(), "test with seed node should parse");
|
|
}
|
|
|
|
// ── Pipeline tests ────────────────────────────────────────────────────────────
|
|
|
|
#[test]
|
|
fn test_pipeline_test_block_typechecks() {
|
|
let src = r#"
|
|
test "type-checks ok" {
|
|
let x: Int = 42
|
|
assert x > 0
|
|
}
|
|
"#;
|
|
assert!(pipeline_ok(src).is_ok(), "test block should type-check");
|
|
}
|
|
|
|
#[test]
|
|
fn test_pipeline_test_with_string_typechecks() {
|
|
let src = r#"
|
|
test "string test" {
|
|
let s: String = "hello"
|
|
let n: Int = string_len(s)
|
|
assert n > 0
|
|
}
|
|
"#;
|
|
assert!(pipeline_ok(src).is_ok(), "test using stdlib should type-check");
|
|
}
|
|
|
|
#[test]
|
|
fn test_pipeline_multiple_test_blocks() {
|
|
let src = r#"
|
|
test "first" {
|
|
assert true
|
|
}
|
|
test "second" {
|
|
assert 1 == 1
|
|
}
|
|
"#;
|
|
assert!(pipeline_ok(src).is_ok(), "multiple test blocks should type-check");
|
|
}
|