-
Notifications
You must be signed in to change notification settings - Fork 0
/
TokenParserTest.java
136 lines (112 loc) · 5 KB
/
TokenParserTest.java
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import static org.junit.Assert.*;
import org.junit.*;
public class TokenParserTest {
private TokenParser parser = new TokenParser();
@Test
public void isNumberShouldReturnTrueWhenANumber() {
assertTrue("5 is a number", parser.isNumber("5"));
assertTrue("5.0 is a number", parser.isNumber("5.0"));
assertTrue(".5 is a number", parser.isNumber(".5"));
assertTrue("1234.5 is a number", parser.isNumber("1234.5"));
assertTrue("0.9 is a number", parser.isNumber("0.9"));
}
@Test
public void isNumberShouldReturnFalseWhenNotANumber() {
assertFalse("asdf is not a number", parser.isNumber("asdf"));
assertFalse("5f is not a number", parser.isNumber("5f"));
assertFalse(". is not a number", parser.isNumber("."));
assertFalse("\"\" is not a number", parser.isNumber(""));
assertFalse("+1 is not a number", parser.isNumber("+1"));
assertFalse("11.123e is not a number", parser.isNumber("11.123e"));
}
@Test
public void isDigitShouldReturnTrueWhenADigit() {
assertTrue("1 is a digit", parser.isDigit("1"));
assertTrue("0 is a digit", parser.isDigit("0"));
assertTrue("9 is a digit", parser.isDigit("9"));
}
@Test
public void isDigitShouldReturnFalseWhenNotADigit() {
assertFalse("a is not a digit", parser.isDigit("a"));
assertFalse(". is not a digit", parser.isDigit("."));
assertFalse("< is not a digit", parser.isDigit("<"));
}
@Test
public void isDecimalShouldReturnTrueWhenADecimal() {
assertTrue("1. is a decimal", parser.isDecimal("1", "."));
}
@Test
public void isDecimalShouldReturnFalseWhenNotADecimal() {
assertFalse("1z is not a decimal point", parser.isDecimal("1", "z"));
assertFalse("1.12. is not another decimal point", parser.isDecimal("1.12", "."));
}
@Test
public void isSpaceShouldReturnTrueWhenASpace() {
assertTrue("' ' is a space", parser.isSpace(" "));
}
@Test
public void isSpaceShouldReturnFalseWhenNotASpace() {
assertFalse("p is not a space", parser.isSpace("p"));
assertFalse("\n is not a space", parser.isSpace("\n"));
}
@Test
public void isEOLShouldReturnTrueWhenAnEOL() {
assertTrue("\n is an EOL", parser.isEOL("\n"));
}
@Test
public void isEOLShouldReturnFalseWhenNotAnEOL() {
assertFalse("q is not an EOL", parser.isEOL("q"));
assertFalse("' ' is not an EOL", parser.isEOL(" "));
}
@Test
public void isStringCharacterShouldReturnTrueIfIsStringCharacter() {
assertTrue("' is true", parser.isStringCharacter("'"));
assertTrue("\" is true", parser.isStringCharacter("\""));
}
@Test
public void isStringCharacterShouldReturnFalseIfIsNotStringCharacter() {
assertFalse("a is not a string char", parser.isStringCharacter("a"));
assertFalse("7 is not a string char", parser.isStringCharacter("7"));
assertFalse("'' is not a string char", parser.isStringCharacter(""));
}
@Test
public void isDelimiterShouldReturnTrueWhenADelimiter() {
assertTrue("' ' is a delimiter", parser.isDelimiter(" "));
assertTrue("'\n' is a delimiter", parser.isDelimiter("\n"));
assertTrue("'<' is a delimiter", parser.isDelimiter("<"));
assertTrue("'IF' is a delimiter", parser.isDelimiter("IF"));
assertTrue("')' is a delimiter", parser.isDelimiter(")"));
}
@Test
public void isDelimiterShouldReturnFalseWhenNotADelimiter() {
assertFalse("6.23 is not a delimiter", parser.isDelimiter("6.23"));
assertFalse("ABCD is not a delimiter", parser.isDelimiter("ABCD"));
assertFalse(": is not a delimiter", parser.isDelimiter(":"));
}
@Test
public void isAssignmentShouldReturnTrueWhenAssignmentToken() {
assertTrue(":= is an assignmet opperator", parser.isAssignment(":", "="));
}
@Test
public void isAssignmentShouldReturnFalseWhenNotAssignment() {
assertFalse(":1 is not an assignmet opperator", parser.isAssignment(":", "1"));
}
@Test
public void isSubstringShouldReturnTrueWhenContainsSubString() {
assertTrue("'Hello' Contains a substring", parser.isSubString("'Hello'"));
assertTrue("\"Hello\" Contains a substring", parser.isSubString("\"Hello\""));
}
@Test
public void isSubStringShouldReturnFalseWhenDoesNotContainsSubString() {
assertFalse("ARGS does not contain a substring", parser.isSubString("ARGS"));
}
@Test
public void isLogicalShouldReturnTrueWhenLogicalALogicalOperator() {
assertTrue("< is a logical operator", parser.isLogical("<"));
assertTrue("= is a logical operator", parser.isLogical("="));
assertTrue("> is a logical operator", parser.isLogical(">"));
assertTrue("<> is a logical operator", parser.isLogical("<>"));
assertTrue("<= is a logical operator", parser.isLogical("<="));
assertTrue(">= is a logical operator", parser.isLogical(">="));
}
}