Fix scripts and tests.
This commit is contained in:
parent
549ef6bf7f
commit
f3bde843cb
@ -12,6 +12,6 @@ for a in arr {
|
|||||||
//print(a); // <- if you uncomment this line, the script will fail to run
|
//print(a); // <- if you uncomment this line, the script will fail to run
|
||||||
// because 'a' is not defined here
|
// because 'a' is not defined here
|
||||||
|
|
||||||
for i in range(0, 5) { // runs through a range from 1 to 5 exclusive
|
for i in range(0, 5) { // runs through a range from 0 to 4
|
||||||
print(i);
|
print(i);
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,8 @@ print("foo" < "bar"); // string comparison
|
|||||||
print("foo" >= "bar"); // string comparison
|
print("foo" >= "bar"); // string comparison
|
||||||
print("the answer is " + 42); // string building using non-string types
|
print("the answer is " + 42); // string building using non-string types
|
||||||
|
|
||||||
let s = "hello, world!"; // string variable
|
let s = "\u2764" hello, world! \U0001F603"; // string variable
|
||||||
print("length=" + s.len); // should be 13
|
print("length=" + s.len); // should be 17
|
||||||
|
|
||||||
s[s.len-1] = '?'; // change the string
|
s[s.len-3] = '?'; // change the string
|
||||||
print("Question: " + s); // should print 'Question: hello, world?'
|
print("Question: " + s); // should print 'Question: hello, world?'
|
||||||
|
@ -81,7 +81,7 @@ fn test_module_resolver() -> Result<(), Box<EvalAltResult>> {
|
|||||||
import "hello" as h1;
|
import "hello" as h1;
|
||||||
import "hello" as h2;
|
import "hello" as h2;
|
||||||
h1::sum(h2::answer, -10, 3, 7)
|
h1::sum(h2::answer, -10, 3, 7)
|
||||||
"#
|
"#
|
||||||
)?,
|
)?,
|
||||||
42
|
42
|
||||||
);
|
);
|
||||||
@ -102,7 +102,7 @@ fn test_module_resolver() -> Result<(), Box<EvalAltResult>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sum
|
sum
|
||||||
"#
|
"#
|
||||||
)
|
)
|
||||||
.expect_err("should error"),
|
.expect_err("should error"),
|
||||||
EvalAltResult::ErrorTooManyModules(_)
|
EvalAltResult::ErrorTooManyModules(_)
|
||||||
@ -125,7 +125,7 @@ fn test_module_resolver() -> Result<(), Box<EvalAltResult>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sum
|
sum
|
||||||
"#
|
"#
|
||||||
)
|
)
|
||||||
.expect_err("should error"),
|
.expect_err("should error"),
|
||||||
EvalAltResult::ErrorInFunctionCall(fn_name, _, _) if fn_name == "foo"
|
EvalAltResult::ErrorInFunctionCall(fn_name, _, _) if fn_name == "foo"
|
||||||
@ -143,7 +143,7 @@ fn test_module_resolver() -> Result<(), Box<EvalAltResult>> {
|
|||||||
for x in range(0, 10) {
|
for x in range(0, 10) {
|
||||||
foo();
|
foo();
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,35 +164,35 @@ fn test_module_from_ast() -> Result<(), Box<EvalAltResult>> {
|
|||||||
|
|
||||||
let ast = engine.compile(
|
let ast = engine.compile(
|
||||||
r#"
|
r#"
|
||||||
// Functions become module functions
|
// Functions become module functions
|
||||||
fn calc(x) {
|
fn calc(x) {
|
||||||
x + 1
|
x + 1
|
||||||
}
|
}
|
||||||
fn add_len(x, y) {
|
fn add_len(x, y) {
|
||||||
x + len(y)
|
x + len(y)
|
||||||
}
|
}
|
||||||
private fn hidden() {
|
private fn hidden() {
|
||||||
throw "you shouldn't see me!";
|
throw "you shouldn't see me!";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Imported modules become sub-modules
|
// Imported modules become sub-modules
|
||||||
import "another module" as extra;
|
import "another module" as extra;
|
||||||
|
|
||||||
// Variables defined at global level become module variables
|
// Variables defined at global level become module variables
|
||||||
const x = 123;
|
const x = 123;
|
||||||
let foo = 41;
|
let foo = 41;
|
||||||
let hello;
|
let hello;
|
||||||
|
|
||||||
// Final variable values become constant module variable values
|
// Final variable values become constant module variable values
|
||||||
foo = calc(foo);
|
foo = calc(foo);
|
||||||
hello = "hello, " + foo + " worlds!";
|
hello = "hello, " + foo + " worlds!";
|
||||||
|
|
||||||
export
|
export
|
||||||
x as abc,
|
x as abc,
|
||||||
foo,
|
foo,
|
||||||
hello,
|
hello,
|
||||||
extra as foobar;
|
extra as foobar;
|
||||||
"#,
|
"#,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let module = Module::eval_ast_as_new(Scope::new(), &ast, &engine)?;
|
let module = Module::eval_ast_as_new(Scope::new(), &ast, &engine)?;
|
||||||
|
Loading…
Reference in New Issue
Block a user