Complete StaticVec implementation.

This commit is contained in:
Stephen Chung
2020-05-17 22:19:49 +08:00
parent a2c50879fe
commit 8b5550eeb6
11 changed files with 373 additions and 169 deletions

View File

@@ -84,28 +84,39 @@ fn test_module_resolver() -> Result<(), Box<EvalAltResult>> {
assert!(matches!(
*engine
.eval::<()>(
.eval::<INT>(
r#"
let x = 0;
for x in range(0, 10) {
import "hello" as h;
x += h::answer;
}
x
"#
)
.expect_err("should error"),
EvalAltResult::ErrorTooManyModules(_)
));
#[cfg(not(feature = "no_function"))]
assert!(matches!(
*engine
.eval::<()>(
.eval::<INT>(
r#"
let x = 0;
fn foo() {
import "hello" as h;
x += h::answer;
}
for x in range(0, 10) {
foo();
}
x
"#
)
.expect_err("should error"),
@@ -114,6 +125,7 @@ fn test_module_resolver() -> Result<(), Box<EvalAltResult>> {
engine.set_max_modules(0);
#[cfg(not(feature = "no_function"))]
engine.eval::<()>(
r#"
fn foo() {

View File

@@ -43,20 +43,40 @@ fn test_max_operations_functions() -> Result<(), Box<EvalAltResult>> {
engine.eval::<()>(
r#"
print("Test1");
let x = 0;
while x < 28 {
print(x);
x += 1;
}
"#,
)?;
#[cfg(not(feature = "no_function"))]
engine.eval::<()>(
r#"
print("Test2");
fn inc(x) { x + 1 }
let x = 0;
while x < 20 { x = inc(x); }
"#,
)?;
#[cfg(not(feature = "no_function"))]
assert!(matches!(
*engine
.eval::<()>(
r#"
print("Test3");
fn inc(x) { x + 1 }
let x = 0;
while x < 1000 { x = inc(x); }
"#
while x < 28 {
print(x);
x = inc(x);
}
"#,
)
.expect_err("should error"),
EvalAltResult::ErrorTooManyOperations(_)