aa
com.cliffc.aa.TestREPL Class Reference
Collaboration diagram for com.cliffc.aa.TestREPL:
[legend]

Public Member Functions

void close_repl ()
 
void open_repl ()
 
void testREPL00 ()
 
void testREPL01 ()
 
void testREPL02 ()
 
void testREPL03 ()
 
void testREPL04 () throws IOException
 

Public Attributes

final SystemErrRule sysErr = new SystemErrRule().enableLog().muteForSuccessfulTests()
 
final SystemOutRule sysOut = new SystemOutRule().enableLog().muteForSuccessfulTests()
 

Private Member Functions

void test (String partial, String expected)
 
void testerr (String partial, String parerr, String expected, int line, int cur_off)
 

Private Attributes

String _prog
 

Detailed Description

Definition at line 16 of file TestREPL.java.

Member Function Documentation

◆ close_repl()

void com.cliffc.aa.TestREPL.close_repl ( )

Definition at line 33 of file TestREPL.java.

33  {
34  }

◆ open_repl()

void com.cliffc.aa.TestREPL.open_repl ( )

Definition at line 22 of file TestREPL.java.

22  {
23  REPL.init();
24  _prog = "";
25  // Drain the initial prompt string so tests do not expect one
26  String actual = sysOut.getLog();
27  String expected = REPL.prompt;
28  assertEquals(expected,actual);
29  sysOut.clearLog();
30  assertTrue(sysErr.getLog().isEmpty());
31  }

References com.cliffc.aa.TestREPL._prog, com.cliffc.aa.REPL.init(), com.cliffc.aa.REPL.prompt, com.cliffc.aa.TestREPL.sysErr, and com.cliffc.aa.TestREPL.sysOut.

Here is the call graph for this function:

◆ test()

void com.cliffc.aa.TestREPL.test ( String  partial,
String  expected 
)
private

Definition at line 80 of file TestREPL.java.

80  {
81  _prog = REPL.go_one(_prog,partial);
82  String actual = sysOut.getLog();
83  String exp = expected+System.lineSeparator()+REPL.prompt;
84  assertEquals(exp,actual);
85  sysOut.clearLog();
86  assertTrue(sysErr.getLog().isEmpty());
87  }

References com.cliffc.aa.TestREPL._prog, com.cliffc.aa.REPL.go_one(), com.cliffc.aa.REPL.prompt, com.cliffc.aa.TestREPL.sysErr, and com.cliffc.aa.TestREPL.sysOut.

Referenced by com.cliffc.aa.TestREPL.testREPL00(), com.cliffc.aa.TestREPL.testREPL01(), com.cliffc.aa.TestREPL.testREPL02(), com.cliffc.aa.TestREPL.testREPL03(), and com.cliffc.aa.TestREPL.testREPL04().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ testerr()

void com.cliffc.aa.TestREPL.testerr ( String  partial,
String  parerr,
String  expected,
int  line,
int  cur_off 
)
private

Definition at line 90 of file TestREPL.java.

90  {
91  _prog = REPL.go_one(_prog,partial);
92  String actual = sysOut.getLog();
93  String cursor = new String(new char[cur_off]).replace('\0', ' ');
94  String exp = new SB().p("stdin:").p(line).p(":").p(expected).nl().p(parerr).p(';').nl().p(cursor).p('^').nl().p(REPL.prompt).toString();
95  assertEquals(exp,actual);
96  sysOut.clearLog();
97  assertTrue(sysErr.getLog().isEmpty());
98  }

References com.cliffc.aa.TestREPL._prog, com.cliffc.aa.REPL.go_one(), com.cliffc.aa.util.SB.nl(), com.cliffc.aa.util.SB.p(), com.cliffc.aa.REPL.prompt, com.cliffc.aa.TestREPL.sysErr, com.cliffc.aa.TestREPL.sysOut, and com.cliffc.aa.util.SB.toString().

Referenced by com.cliffc.aa.TestREPL.testREPL01(), and com.cliffc.aa.TestREPL.testREPL03().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ testREPL00()

void com.cliffc.aa.TestREPL.testREPL00 ( )

Definition at line 37 of file TestREPL.java.

37  {
38  test("2", "2");
39  }

References com.cliffc.aa.TestREPL.test().

Here is the call graph for this function:

◆ testREPL01()

void com.cliffc.aa.TestREPL.testREPL01 ( )

Definition at line 42 of file TestREPL.java.

42  {
43  test("2+3", "5");
44  test("x=3", "3");
45  test("x*x", "9");
46  testerr("y*y", "y*y", "Unknown ref 'y'",4,0);
47  test("x=4", "4");
48  testerr("x+x", "x=4", "Cannot re-assign final val 'x'",4,0);
49  test("3+2", "5");
50  test("sq={x->x*x}", "[sq=*{x -> }]");
51  test("sq 5","25");
52  testerr("sq \"abc\"", "sq={x->x*x}", "*\"abc\" is none of (flt64,int64)", 6,7);
53  testerr("x", "x=4", "Cannot re-assign final val 'x'",4,0);
54  }

References com.cliffc.aa.TestREPL.test(), and com.cliffc.aa.TestREPL.testerr().

Here is the call graph for this function:

◆ testREPL02()

void com.cliffc.aa.TestREPL.testREPL02 ( )

Definition at line 57 of file TestREPL.java.

57  {
58  test("do={pred->{body->pred()?body():^; do pred body}}","[do=*{pred -> }]");
59  test("sum:=0; i:=0; do {i++ < 100} {sum:=sum+i}; sum","int64");
60  }

References com.cliffc.aa.TestREPL.test().

Here is the call graph for this function:

◆ testREPL03()

void com.cliffc.aa.TestREPL.testREPL03 ( )

Definition at line 63 of file TestREPL.java.

63  {
64  test ("hash := {@{ tab = [3]; get = { key -> idx = key.hash(); tab[idx] } } }","[hash=*{ -> }]");
65  testerr("junk := hash:int","junk := hash:int","[hash=*{ -> }] is not a int64",2,12);
66  testerr("hash.tab","hash.tab","Unknown field '.tab'",2,5);
67  test ("x := hash()","@{tab==*[3]0/obj?; get==[get=*{key -> }]}");
68  testerr("x.#tab","x.#tab","Unknown ref 'tab'",3,3);
69  test ("#x.tab","3");
70  }

References com.cliffc.aa.TestREPL.test(), and com.cliffc.aa.TestREPL.testerr().

Here is the call graph for this function:

◆ testREPL04()

void com.cliffc.aa.TestREPL.testREPL04 ( ) throws IOException

Definition at line 72 of file TestREPL.java.

72  {
73  String hash_src = new String(Files.readAllBytes( Paths.get("test/java/com/cliffc/aa","HashTable.aa")));
74  test(hash_src,"[HashTable=*{ -> }]");
75  test("htab = HashTable()","@{_tab=*[7]0/obj; get=[get=*{key -> }]; put=[put=*{key val -> }]}");
76  test("htab.put(\"Monday\",1)","0");
77  }

References com.cliffc.aa.TestREPL.test().

Here is the call graph for this function:

Member Data Documentation

◆ _prog

String com.cliffc.aa.TestREPL._prog
private

◆ sysErr

final SystemErrRule com.cliffc.aa.TestREPL.sysErr = new SystemErrRule().enableLog().muteForSuccessfulTests()

◆ sysOut

final SystemOutRule com.cliffc.aa.TestREPL.sysOut = new SystemOutRule().enableLog().muteForSuccessfulTests()

The documentation for this class was generated from the following file:
com.cliffc.aa.TestREPL._prog
String _prog
Definition: TestREPL.java:21
com.cliffc.aa.TestREPL.testerr
void testerr(String partial, String parerr, String expected, int line, int cur_off)
Definition: TestREPL.java:90
com.cliffc.aa.TestREPL.sysOut
final SystemOutRule sysOut
Definition: TestREPL.java:18
com.cliffc.aa.TestREPL.test
void test(String partial, String expected)
Definition: TestREPL.java:80
com.cliffc.aa.TestREPL.sysErr
final SystemErrRule sysErr
Definition: TestREPL.java:19