public void Declare_variable_with_array_initializer_17() { // Assert.Inconclusive("Array initializers has not been implemented yet"); var rt = Load(@"// variable names starting with $ // are variables grabbed from an external source let console = $console fn print_hello_world() -> void { console.log(""Hello World"".length * 3 + 5 / 12 - 10.4) let cc = [""asd"",""pasd""] let i = 0 foreach(var j in cc) { console.log(j + i) i++ } } print_hello_world()"); var cw = new ConsoleWrapperTest(rt); rt.RegisterGlobalVariable("console", cw); rt.Run(); Assert.AreEqual("23,0166666666667\r\nasd0\r\npasd1\r\n", cw.Output); }
public void Invoke_combination_of_strcat_usages() { var rt = Load(@"let console = $0 fn favoColor() -> string { return ""green"" } fn main() -> void { let zerratar = ""Karl"" let anders = ""Anders"" console.log(""Hey there "" + anders + ""!"") console.log(""My name is "" + zerratar + ""."") console.log(""My favorite color is "" + favoColor()) } main()"); var console = new ConsoleWrapperTest(rt); rt.Invoke(console); Assert.AreEqual(@"Hey there Anders! My name is Karl. My favorite color is green ", console.Output); }
public void Invoke_managed_speed_test_3() { // Assert.Inconclusive("Array initializers has not been implemented yet"); var rt = Load(@"let console = $console fn test(any arr) -> void { console.log(arr[1]) } let apa = ""hello"" let names = [] names = [123,apa, 521] test(names) "); var cw = new ConsoleWrapperTest(rt); rt.RegisterGlobalVariable("console", cw); Stopwatch sw = new Stopwatch(); sw.Start(); for (var i = 0; i < 10000; i++) { cw.Output = ""; rt.Run(); Assert.AreEqual("hello\r\n", cw.Output); } sw.Stop(); var elapsedTime = sw.ElapsedMilliseconds; Assert.IsTrue(elapsedTime < 1000, "We were unable to run this code 10000 times under a second :(.. Elasped: " + elapsedTime); System.Diagnostics.Trace.WriteLine(elapsedTime + "ms for 10k runs."); }
public void Console_log_constant_expr() { var rt = Load("fn test(any console) { console.log(\"Hello World\".length) }"); var console = new ConsoleWrapperTest(rt); var result = rt.Invoke <string>("test", console); Assert.AreEqual("11\r\n", console.Output); }
public void Declare_variable_with_array_initializer_12() { // Assert.Inconclusive("Array initializers has not been implemented yet"); var rt = Load(@"let console = $console console.log([123, 55, 521].length) "); var cw = new ConsoleWrapperTest(rt); rt.RegisterGlobalVariable("console", cw); rt.Run(); Assert.AreEqual("3\r\n", cw.Output); }
public void Declare_variable_with_array_initializer_15() { // Assert.Inconclusive("Array initializers has not been implemented yet"); var rt = Load(@"let console = $console let names = [123, 55, ""asd""] let res = names.indexof(""asd"") console.log(res) "); var cw = new ConsoleWrapperTest(rt); rt.RegisterGlobalVariable("console", cw); rt.Run(); Assert.AreEqual("2\r\n", cw.Output); }
public void Declare_variable_with_array_initializer_5() { // Assert.Inconclusive("Array initializers has not been implemented yet"); var rt = Load(@"let console = $console let apa = ""hello"" let names = [123,apa, 521] console.log(names[1]) "); var cw = new ConsoleWrapperTest(rt); rt.RegisterGlobalVariable("console", cw); rt.Run(); Assert.AreEqual("hello\r\n", cw.Output); }
public void Push_array_return_item_value_8() { // Assert.Inconclusive("This feature has not yet been implemented."); var rt = Load(@"let console = $console let names = [""Daisy"",""Friday""] console.log(names[1][0])"); var cw = new ConsoleWrapperTest(rt); rt.RegisterGlobalVariable("$console", cw); rt.Run(); Assert.AreEqual("F\r\n", cw.Output); }
public void Push_array_return_item_value_1() { var rt = Load(@"let console = $console let names = [] names.push(""Daisy"") console.log(names[0])"); var cw = new ConsoleWrapperTest(rt); rt.RegisterGlobalVariable("$console", cw); rt.Run(); Assert.AreEqual("Daisy\r\n", cw.Output); }
public void Declare_variable_with_array_initializer_8() { // Assert.Inconclusive("Array initializers has not been implemented yet"); var rt = Load(@"let console = $console fn test(any arr) -> void { console.log(arr[0]) } let apa = ""hello"" test([123,apa, 521]) "); var cw = new ConsoleWrapperTest(rt); rt.RegisterGlobalVariable("console", cw); rt.Run(); Assert.AreEqual("123\r\n", cw.Output); }
public void Push_array_return_item_value_5() { var rt = Load(@"let console = $console let names = [] names.push(""Daisy"") let len = names.length for(let j = 0; j < len; j++) { console.log(names[j]) }"); var cw = new ConsoleWrapperTest(rt); rt.RegisterGlobalVariable("console", cw); rt.Run(); Assert.AreEqual("Daisy\r\n", cw.Output); }
public void Declare_variable_with_increment_assignment_4() { // Assert.Inconclusive("Array initializers has not been implemented yet"); var rt = Load(@"let console = $console fn print_hello_world() -> void { let a = 0 a += 2 console.log(a) } print_hello_world()"); var cw = new ConsoleWrapperTest(rt); rt.RegisterGlobalVariable("console", cw); rt.Run(); Assert.AreEqual("2\r\n", cw.Output); }
public void IF_else_then_1() { var rt = Load(@"let console = $console let account = 500 fn bet(number betsum) -> void { if(betsum > account) { console.log(""sluta tro på lyyx"") console.log(""försök igen"") } else { console.log(""du har bettat "" + betsum) } } bet(498) "); var cw = new ConsoleWrapperTest(rt); rt.RegisterGlobalVariable("console", cw); rt.Run(); Assert.AreEqual("du har bettat 498\r\n", cw.Output); }
public void Invoke_managed_speed_test() { // Assert.Inconclusive("Array initializers has not been implemented yet"); var rt = Load(@"$console.log(""hello"")"); Stopwatch sw = new Stopwatch(); var cw2 = new ConsoleWrapperTest(rt); sw.Start(); for (var i = 0; i < 10000; i++) { cw2.Output = ""; cw2.log("hello"); Assert.AreEqual("hello\r\n", cw2.Output); } sw.Stop(); var managedElapsed = (double)sw.ElapsedMilliseconds; var cw = new ConsoleWrapperTest(rt); rt.RegisterGlobalVariable("console", cw); sw.Restart(); sw.Start(); for (var i = 0; i < 10000; i++) { cw.Output = ""; rt.Run(); Assert.AreEqual("hello\r\n", cw.Output); } sw.Stop(); var elapsedTime = (double)sw.ElapsedMilliseconds; // Assert.IsTrue(elapsedTime < 1000, "We were unable to run this code 10000 times under a second :(.. Elasped: " + elapsedTime); var proc = elapsedTime / managedElapsed; // Assert.IsTrue(proc < 100, "Seem like we are running " + proc + "x slower than managed code."); System.Diagnostics.Trace.WriteLine(proc + "x slower than managed code."); }