This commit is contained in:
Stephen Chung
2022-11-30 14:11:09 +08:00
parent c509cc896d
commit fc4c8731f0
6 changed files with 166 additions and 119 deletions

View File

@@ -21,6 +21,7 @@ fn test_arrays() -> Result<(), Box<EvalAltResult>> {
assert_eq!(engine.eval::<INT>("let y = [1, 2, 3]; y[-1]")?, 3);
assert_eq!(engine.eval::<INT>("let y = [1, 2, 3]; y[-3]")?, 1);
assert!(engine.eval::<bool>("let y = [1, 2, 3]; 2 in y")?);
assert!(engine.eval::<bool>("let y = [1, 2, 3]; 42 !in y")?);
assert_eq!(engine.eval::<INT>("let y = [1, 2, 3]; y += 4; y[3]")?, 4);
assert_eq!(
engine.eval::<INT>("let y = [1, 2, 3]; pad(y, 5, 42); len(y)")?,

View File

@@ -17,7 +17,7 @@ fn test_max_string_size() -> Result<(), Box<EvalAltResult>> {
.compile(r#"let x = "hello, world!";"#)
.expect_err("should error")
.err_type(),
ParseErrorType::LiteralTooLarge("Length of string literal".to_string(), 10)
ParseErrorType::LiteralTooLarge("Length of string".to_string(), 10)
);
assert_eq!(
@@ -25,7 +25,7 @@ fn test_max_string_size() -> Result<(), Box<EvalAltResult>> {
.compile(r#"let x = "朝に紅顔、暮に白骨";"#)
.expect_err("should error")
.err_type(),
ParseErrorType::LiteralTooLarge("Length of string literal".to_string(), 10)
ParseErrorType::LiteralTooLarge("Length of string".to_string(), 10)
);
assert!(matches!(

View File

@@ -34,6 +34,15 @@ fn test_loop() -> Result<(), Box<EvalAltResult>> {
ParseErrorType::LoopBreak
);
#[cfg(not(feature = "no_function"))]
assert_eq!(
*engine
.compile("loop { let f = || { break; } }")
.expect_err("should error")
.err_type(),
ParseErrorType::LoopBreak
);
assert_eq!(
*engine
.compile("let x = 0; if x > 0 { continue; }")