!include once #1034034 // Gazelle 22 Function Include for Scripts set flag PingV3. scope test_leftArrowScript sclass #Tester { O value = "123"; } svoid test_leftArrowScript() { embedded S countLoop(int n) { ret [[ i <- 0; while lessThan i ]] + n + [[ { i <- plus i 1 }; i ]]; } testFunctionValues(script -> leftArrowVerbose((S) script), // int primitive [[ 5 ]], 5, [[ -5 ]], -5, // function definition & call [[ def double x { Math multiplyExact x 2 } double 10 ]], 20, // new object with constructor arguments [[ new Pair "hello" "world" ]], pair("hello", "world"), // double primitive [[ str 1.5e2 ]], "150.0", // [not implemented, too complicated] // last = result of last statement // [[ plus 1 2; Math addExact 5 last ]], 8, // get static field [[ Color black ]], Color.black, // get instance field, [[ tester <- new test_leftArrowScript_Tester; tester value ]], "123", // while loop countLoop(5), 5, // if statement [[ if lessThan 0 1 { "ok" } ]], "ok", [[ if lessThan 1 0 { "ok" } ]], null, // for each [[ l <- ll 2 3 sum <- 0 for number in l { sum <- plus sum number } sum ]], 5, ); // Test that ping is called at least once per loop iteration var script1 = leftArrowParse(countLoop(5)); var script2 = leftArrowParse(countLoop(6)); long pingCount1 = countPingCalls(-> script1!); long pingCount2 = countPingCalls(-> script2!); printVars(+pingCount1, +pingCount2); assertTrue(pingCount2 > pingCount1); print("Left-arrow script tested OK"); }