diff --git a/autotest/EscTest/EscTest.cpp b/autotest/EscTest/EscTest.cpp index 2f1f77a66..719a200c9 100644 --- a/autotest/EscTest/EscTest.cpp +++ b/autotest/EscTest/EscTest.cpp @@ -67,8 +67,22 @@ CHK(a, |, b); \ LOG(#val << " = " << v << ", ref: " << ref); \ ASSERT(v == ref); } +void SIC_Print(EscEscape& e) +{ + if(e[0].IsArray()) + LOG((String) e[0]); + else + if(e[0].IsNumber()) + LOG(e[0].GetNumber()); + else + if(!e[0].IsVoid()) + e.ThrowError("invalid argument to 'Print'"); +} + CONSOLE_APP_MAIN { + StdLogSetup(LOG_FILE|LOG_COUT); + CHKDBL(3.1, 2.1); CHKDBL(3.0, 2.0); CHKDBL(3.0, (int64)2); @@ -96,4 +110,22 @@ CONSOLE_APP_MAIN CHKV(global.Get("a").GetNumber(), 3); CHKV(Evaluate("--a", global).GetNumber(), 2); CHKV(global.Get("a").GetNumber(), 2); + + LOG("----"); + global.GetAdd("s", "Test"); + CHKV((WString)Evaluate("s", global), "Test"); + + LOG("----"); + Escape(global, "Print(x)", SIC_Print); + try { + Scan(global, LoadFile(GetDataFile("script.esc"))); + Execute(global, "main", INT_MAX); + } + catch(CParser::Error e) { + Cout() << "ERROR: " << e << "\n"; + } + + DDUMP(global.Get("out")); + DDUMP(global.Get("out2")); + DDUMP(global.Get("out3")); } diff --git a/autotest/EscTest/script.esc b/autotest/EscTest/script.esc index 9903768b6..a75a7fa9c 100644 --- a/autotest/EscTest/script.esc +++ b/autotest/EscTest/script.esc @@ -1,17 +1,17 @@ -check(a, b) -{ -// Print("// ========================"); -// Print("// a: " + to_string(a) ", b: " + to_string(b)); - Check("a", a, ""); - Check("b", b, ""); - Check("a + b", a + b, ""); - Check("a - b", a - b, ""); - Check("a * b", a * b, ""); - Check("a / b", a / b, ""); -} - main() { - check(0, 1); - check(1.1, 1.2); - check(0xfffffffffffffff0, 1); + Print("Hello world!"); + x = {}; + x.a = 123; + x.b = "Hello!"; + + :out = x; + + x.foo = @(x) { .a = x; }; + + x.foo("test"); + :out2 = x.a; + + :out3 = []; + for(i = 0; i < 10; i++) + :out3[] = i; } diff --git a/autotest/StringUtil/StringUtil.cpp b/autotest/StringUtil/StringUtil.cpp index 15b9fafe0..4076a6a89 100644 --- a/autotest/StringUtil/StringUtil.cpp +++ b/autotest/StringUtil/StringUtil.cpp @@ -24,6 +24,15 @@ void TestTrimRight(String what, String s, String r) } } +void TestMultiReplace() +{ + VectorMap r; + r("hell", "hello")("hello", "hell"); + String h = Replace(String("TEXT: hell hello!"), r); + DDUMP(h); + ASSERT(h == "TEXT: hello hell!"); +} + CONSOLE_APP_MAIN { String h = "http://www.website.org"; @@ -34,4 +43,6 @@ CONSOLE_APP_MAIN TestTrimLeft("http://", "http://www.website.org", "www.website.org"); TestTrimRight(".org", "www.website.org", "www.website"); + + TestMultiReplace(); }