#![cfg(all(feature = "compile", feature = "verify"))]
extern crate alloc;
use keleusma::compiler::compile;
use keleusma::lexer::tokenize;
use keleusma::parser::parse;
fn compiles(src: &str) -> bool {
let tokens = tokenize(src).expect("lex");
let program = parse(&tokens).expect("parse");
compile(&program).is_ok()
}
#[cfg(not(any(
feature = "narrow-word-8",
feature = "narrow-word-16",
feature = "narrow-word-32"
)))]
#[test]
fn yielding_struct_with_text_field_compiles() {
let src = "struct Greeting { msg: Text, n: Word }\n\
loop main(seed: Word) -> Greeting { \
yield Greeting { msg: \"hi\", n: seed } \
}";
assert!(
compiles(src),
"yielding a struct with a flat Text field must now compile (read-before-resume)"
);
}
#[cfg(not(any(
feature = "narrow-word-8",
feature = "narrow-word-16",
feature = "narrow-word-32"
)))]
#[test]
fn yielding_enum_with_text_payload_compiles() {
let src = "enum Msg { Quiet, Loud(Text) }\n\
loop main(seed: Word) -> Msg { yield Msg::Loud(\"hi\") }";
assert!(
compiles(src),
"yielding an enum with a flat Text payload must now compile"
);
}
#[cfg(not(any(
feature = "narrow-word-8",
feature = "narrow-word-16",
feature = "narrow-word-32"
)))]
#[test]
fn yielding_struct_holding_text_struct_compiles() {
let src = "struct Inner { t: Text }\n\
struct Outer { inner: Inner, n: Word }\n\
loop main(seed: Word) -> Outer { \
yield Outer { inner: Inner { t: \"hi\" }, n: seed } \
}";
assert!(
compiles(src),
"yielding a struct transitively containing a flat Text field must now compile"
);
}
#[cfg(not(any(
feature = "narrow-word-8",
feature = "narrow-word-16",
feature = "narrow-word-32"
)))]
#[test]
fn yielding_text_tuple_compiles() {
let src = "loop main(seed: Word) -> (Word, Text) { yield (seed, \"hi\") }";
assert!(
compiles(src),
"yielding a tuple with a flat Text element must now compile"
);
}
#[cfg(not(any(
feature = "narrow-word-8",
feature = "narrow-word-16",
feature = "narrow-word-32"
)))]
#[test]
fn yielding_text_array_compiles() {
let src = "loop main(seed: Word) -> [Text; 2] { yield [\"a\", \"b\"] }";
assert!(
compiles(src),
"yielding an array of flat Text must now compile"
);
}
#[test]
fn yielding_bare_static_string_still_compiles() {
let src = "loop main(seed: Word) -> Text { yield \"hello\" }";
assert!(
compiles(src),
"yielding a bare static string must remain allowed"
);
}
#[test]
fn yielding_struct_without_text_still_compiles() {
let src = "struct Point { x: Word, y: Word }\n\
loop main(seed: Word) -> Point { yield Point { x: seed, y: 2 } }";
assert!(
compiles(src),
"yielding a struct with no Text field must remain allowed"
);
}