Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

42
LINES

< > BotCompany Repo | #1034324 // test_compiledLeftArrowScript - test left-arrow script compiled to byte code. only a few cases so far (OK)

JavaX fragment (include) [tags: use-pretranspiled]

Transpiled version (32993L) is out of date.

1  
!include once #1034831 // Gazelle 22 Function Include for Testing
2  
3  
svoid test_compiledLeftArrowScript() {
4  
  embedded S countLoop(int n) {
5  
    ret [[ i <- 0; while lessThan i ]] + n + [[ { i <- plus i 1 }; i ]];
6  
  }
7  
  
8  
  embedded void testScript(S script, O expectedValue) {
9  
    var makeIF0 = leftArrowScriptToEvaluable(leftArrowParse(script));
10  
    makeIF0.printDisassembly(true);
11  
    print(+script);
12  
    assertEqualsVerbose(expectedValue, makeIF0!!);
13  
  }
14  
  
15  
  // int primitive
16  
  testScript([[ 5 ]], 5);
17  
  testScript([[ -5 ]], -5);
18  
19  
  // double primitive
20  
  testScript([[ str 1.5e2 ]], "150.0");
21  
    
22  
  // new object with constructor arguments
23  
  testScript([[ new Pair "hello" "world" ]], pair("hello", "world"));
24  
  
25  
  // assign & get variable
26  
  testScript([[ i <- 23; i ]], 23);
27  
  
28  
  // while loop
29  
  testScript(countLoop(5), 5);
30  
  
31  
  // conditional return
32  
  testScript([[
33  
    if true { return "so true" }
34  
    return "oops"
35  
  ]], "so true");
36  
  
37  
  testScript([[
38  
    if false { return "not true" }
39  
    return "but this"
40  
  ]], "but this");
41  
    
42  
}

Author comment

Began life as a copy of #1033988

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1034324
Snippet name: test_compiledLeftArrowScript - test left-arrow script compiled to byte code. only a few cases so far (OK)
Eternal ID of this version: #1034324/10
Text MD5: 4d5720ac72a9e69c9948dc49a4df561b
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-03-11 02:26:12
Source code size: 1082 bytes / 42 lines
Pitched / IR pitched: No / No
Views / Downloads: 142 / 321
Version history: 9 change(s)
Referenced in: [show references]