-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTypeCheckVisitorTest.java
More file actions
106 lines (91 loc) · 3.27 KB
/
Copy pathTypeCheckVisitorTest.java
File metadata and controls
106 lines (91 loc) · 3.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/** Important to test the error cases in case the
* AST is not being completely traversed.
*
* Only need to test syntactically correct programs, or
* program fragments.
*/
package cop5556sp17;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import cop5556sp17.AST.ASTNode;
public class TypeCheckVisitorTest {
@Rule
public ExpectedException thrown = ExpectedException.none();
@Test
public void testAssignmentBoolLit0() throws Exception{
String input = "p {\nboolean y \ny <- false;}";
Scanner scanner = new Scanner(input);
scanner.scan();
Parser parser = new Parser(scanner);
ASTNode program = parser.parse();
TypeCheckVisitor v = new TypeCheckVisitor();
program.visit(v, null);
}
@Test
public void testAssignmentBoolLitError0() throws Exception{
String input = "p { boolean y \ny <- 3;}";
Scanner scanner = new Scanner(input);
scanner.scan();
Parser parser = new Parser(scanner);
ASTNode program = parser.parse();
TypeCheckVisitor v = new TypeCheckVisitor();
thrown.expect(TypeCheckVisitor.TypeCheckException.class);
program.visit(v, null);
}
@Test
public void testProgram0() throws Exception {
String input = "$jffd { integer x boolean y image z frame a x <- 10; sleep 99; }";
Scanner scanner = new Scanner(input);
scanner.scan();
Parser parser = new Parser(scanner);
ASTNode program = parser.parse();
TypeCheckVisitor v = new TypeCheckVisitor();
//thrown.expect(TypeCheckVisitor.TypeCheckException.class);
program.visit(v, null);
}
@Test
public void testProgram1() throws Exception {
String input = "$jffd { integer x boolean y x <- y; }";
Scanner scanner = new Scanner(input);
scanner.scan();
Parser parser = new Parser(scanner);
ASTNode program = parser.parse();
TypeCheckVisitor v = new TypeCheckVisitor();
thrown.expect(TypeCheckVisitor.TypeCheckException.class);
program.visit(v, null);
}
@Test
public void testProgram2() throws Exception {
String input = "abc integer x, integer x {}";
Scanner scanner = new Scanner(input);
scanner.scan();
Parser parser = new Parser(scanner);
ASTNode program = parser.parse();
TypeCheckVisitor v = new TypeCheckVisitor();
thrown.expect(TypeCheckVisitor.TypeCheckException.class);
program.visit(v, null);
}
@Test
public void testBinaryExpression() throws Exception {
String input = "p integer a, integer b { integer a image img1 image img2 if(img1 != img2) {image a a <- img1; } if(a != b) {boolean a a <- img1 != img2; }}";
Scanner scanner = new Scanner(input);
scanner.scan();
Parser parser = new Parser(scanner);
ASTNode program = parser.parse();
TypeCheckVisitor v = new TypeCheckVisitor();
//thrown.expect(TypeCheckVisitor.TypeCheckException.class);
program.visit(v, null);
}
@Test
public void testBinaryChainTypeError15() throws Exception{
String input = "p {\nimage ident_img frame ident_frame ident_img -> ident_frame -> move(false,7) \n;}";
Scanner scanner = new Scanner(input);
scanner.scan();
Parser parser = new Parser(scanner);
ASTNode program = parser.parse();
TypeCheckVisitor v = new TypeCheckVisitor();
thrown.expect(TypeCheckVisitor.TypeCheckException.class);
program.visit(v, null);
}
}