diff --git a/scripts/for1.rhai b/scripts/for1.rhai index 8fc6c95e..345d17a7 100644 --- a/scripts/for1.rhai +++ b/scripts/for1.rhai @@ -12,6 +12,6 @@ for a in arr { //print(a); // <- if you uncomment this line, the script will fail to run // 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); } diff --git a/scripts/string.rhai b/scripts/string.rhai index 835b2556..38dc52e9 100644 --- a/scripts/string.rhai +++ b/scripts/string.rhai @@ -10,8 +10,8 @@ print("foo" < "bar"); // string comparison print("foo" >= "bar"); // string comparison print("the answer is " + 42); // string building using non-string types -let s = "hello, world!"; // string variable -print("length=" + s.len); // should be 13 +let s = "\u2764" hello, world! \U0001F603"; // string variable +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?' diff --git a/tests/modules.rs b/tests/modules.rs index e6d604b6..6f1deb92 100644 --- a/tests/modules.rs +++ b/tests/modules.rs @@ -81,7 +81,7 @@ fn test_module_resolver() -> Result<(), Box> { import "hello" as h1; import "hello" as h2; h1::sum(h2::answer, -10, 3, 7) - "# + "# )?, 42 ); @@ -102,7 +102,7 @@ fn test_module_resolver() -> Result<(), Box> { } sum - "# + "# ) .expect_err("should error"), EvalAltResult::ErrorTooManyModules(_) @@ -125,7 +125,7 @@ fn test_module_resolver() -> Result<(), Box> { } sum - "# + "# ) .expect_err("should error"), EvalAltResult::ErrorInFunctionCall(fn_name, _, _) if fn_name == "foo" @@ -143,7 +143,7 @@ fn test_module_resolver() -> Result<(), Box> { for x in range(0, 10) { foo(); } - "#, + "#, )?; } @@ -164,35 +164,35 @@ fn test_module_from_ast() -> Result<(), Box> { let ast = engine.compile( r#" - // Functions become module functions - fn calc(x) { - x + 1 - } - fn add_len(x, y) { - x + len(y) - } - private fn hidden() { - throw "you shouldn't see me!"; - } - - // Imported modules become sub-modules - import "another module" as extra; - - // Variables defined at global level become module variables - const x = 123; - let foo = 41; - let hello; - - // Final variable values become constant module variable values - foo = calc(foo); - hello = "hello, " + foo + " worlds!"; + // Functions become module functions + fn calc(x) { + x + 1 + } + fn add_len(x, y) { + x + len(y) + } + private fn hidden() { + throw "you shouldn't see me!"; + } + + // Imported modules become sub-modules + import "another module" as extra; + + // Variables defined at global level become module variables + const x = 123; + let foo = 41; + let hello; + + // Final variable values become constant module variable values + foo = calc(foo); + hello = "hello, " + foo + " worlds!"; - export - x as abc, - foo, - hello, - extra as foobar; - "#, + export + x as abc, + foo, + hello, + extra as foobar; + "#, )?; let module = Module::eval_ast_as_new(Scope::new(), &ast, &engine)?;