Skip to content

Commit 917d1af

Browse files
committed
Add tests for valid binary <, >, <=, >=
Also fixed the test title ('<==|>==' -> '<=|>=')
1 parent 415f943 commit 917d1af

File tree

2 files changed

+47
-29
lines changed

2 files changed

+47
-29
lines changed

src/slang/utils/__tests__/__snapshots__/rttc.ts.snap

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,60 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`Invalid binary type combinations for (<|>|<==|>==) return TypeError 1`] = `"Expected string or number on left hand side of operation, got boolean."`;
3+
exports[`Invalid binary type combinations for (<|>|<=|>=) return TypeError 1`] = `"Expected string or number on left hand side of operation, got boolean."`;
44

5-
exports[`Invalid binary type combinations for (<|>|<==|>==) return TypeError 2`] = `"Expected string on right hand side of operation, got number."`;
5+
exports[`Invalid binary type combinations for (<|>|<=|>=) return TypeError 2`] = `"Expected string on right hand side of operation, got number."`;
66

7-
exports[`Invalid binary type combinations for (<|>|<==|>==) return TypeError 3`] = `"Expected string on right hand side of operation, got function."`;
7+
exports[`Invalid binary type combinations for (<|>|<=|>=) return TypeError 3`] = `"Expected string on right hand side of operation, got function."`;
88

9-
exports[`Invalid binary type combinations for (<|>|<==|>==) return TypeError 4`] = `"Expected number on right hand side of operation, got string."`;
9+
exports[`Invalid binary type combinations for (<|>|<=|>=) return TypeError 4`] = `"Expected number on right hand side of operation, got string."`;
1010

11-
exports[`Invalid binary type combinations for (<|>|<==|>==) return TypeError 5`] = `"Expected string or number on left hand side of operation, got function."`;
11+
exports[`Invalid binary type combinations for (<|>|<=|>=) return TypeError 5`] = `"Expected string or number on left hand side of operation, got function."`;
1212

13-
exports[`Invalid binary type combinations for (<|>|<==|>==) return TypeError 6`] = `"Expected string or number on left hand side of operation, got boolean."`;
13+
exports[`Invalid binary type combinations for (<|>|<=|>=) return TypeError 6`] = `"Expected string or number on left hand side of operation, got boolean."`;
1414

15-
exports[`Invalid binary type combinations for (<|>|<==|>==) return TypeError 7`] = `"Expected string or number on left hand side of operation, got function."`;
15+
exports[`Invalid binary type combinations for (<|>|<=|>=) return TypeError 7`] = `"Expected string or number on left hand side of operation, got function."`;
1616

17-
exports[`Invalid binary type combinations for (<|>|<==|>==) return TypeError 8`] = `"Expected string on right hand side of operation, got function."`;
17+
exports[`Invalid binary type combinations for (<|>|<=|>=) return TypeError 8`] = `"Expected string on right hand side of operation, got function."`;
1818

19-
exports[`Invalid binary type combinations for (<|>|<==|>==) return TypeError 9`] = `"Expected string on right hand side of operation, got number."`;
19+
exports[`Invalid binary type combinations for (<|>|<=|>=) return TypeError 9`] = `"Expected string on right hand side of operation, got number."`;
2020

21-
exports[`Invalid binary type combinations for (<|>|<==|>==) return TypeError 10`] = `"Expected string or number on left hand side of operation, got function."`;
21+
exports[`Invalid binary type combinations for (<|>|<=|>=) return TypeError 10`] = `"Expected string or number on left hand side of operation, got function."`;
2222

23-
exports[`Invalid binary type combinations for (<|>|<==|>==) return TypeError 11`] = `"Expected number on right hand side of operation, got string."`;
23+
exports[`Invalid binary type combinations for (<|>|<=|>=) return TypeError 11`] = `"Expected number on right hand side of operation, got string."`;
2424

25-
exports[`Invalid binary type combinations for (<|>|<==|>==) return TypeError 12`] = `"Expected string or number on left hand side of operation, got boolean."`;
25+
exports[`Invalid binary type combinations for (<|>|<=|>=) return TypeError 12`] = `"Expected string or number on left hand side of operation, got boolean."`;
2626

27-
exports[`Invalid binary type combinations for (<|>|<==|>==) return TypeError 13`] = `"Expected string or number on left hand side of operation, got function."`;
27+
exports[`Invalid binary type combinations for (<|>|<=|>=) return TypeError 13`] = `"Expected string or number on left hand side of operation, got function."`;
2828

29-
exports[`Invalid binary type combinations for (<|>|<==|>==) return TypeError 14`] = `"Expected string on right hand side of operation, got function."`;
29+
exports[`Invalid binary type combinations for (<|>|<=|>=) return TypeError 14`] = `"Expected string on right hand side of operation, got function."`;
3030

31-
exports[`Invalid binary type combinations for (<|>|<==|>==) return TypeError 15`] = `"Expected string or number on left hand side of operation, got boolean."`;
31+
exports[`Invalid binary type combinations for (<|>|<=|>=) return TypeError 15`] = `"Expected string or number on left hand side of operation, got boolean."`;
3232

33-
exports[`Invalid binary type combinations for (<|>|<==|>==) return TypeError 16`] = `"Expected string on right hand side of operation, got number."`;
33+
exports[`Invalid binary type combinations for (<|>|<=|>=) return TypeError 16`] = `"Expected string on right hand side of operation, got number."`;
3434

35-
exports[`Invalid binary type combinations for (<|>|<==|>==) return TypeError 17`] = `"Expected string on right hand side of operation, got function."`;
35+
exports[`Invalid binary type combinations for (<|>|<=|>=) return TypeError 17`] = `"Expected string on right hand side of operation, got function."`;
3636

37-
exports[`Invalid binary type combinations for (<|>|<==|>==) return TypeError 18`] = `"Expected number on right hand side of operation, got string."`;
37+
exports[`Invalid binary type combinations for (<|>|<=|>=) return TypeError 18`] = `"Expected number on right hand side of operation, got string."`;
3838

39-
exports[`Invalid binary type combinations for (<|>|<==|>==) return TypeError 19`] = `"Expected string or number on left hand side of operation, got function."`;
39+
exports[`Invalid binary type combinations for (<|>|<=|>=) return TypeError 19`] = `"Expected string or number on left hand side of operation, got function."`;
4040

41-
exports[`Invalid binary type combinations for (<|>|<==|>==) return TypeError 20`] = `"Expected string or number on left hand side of operation, got boolean."`;
41+
exports[`Invalid binary type combinations for (<|>|<=|>=) return TypeError 20`] = `"Expected string or number on left hand side of operation, got boolean."`;
4242

43-
exports[`Invalid binary type combinations for (<|>|<==|>==) return TypeError 21`] = `"Expected string or number on left hand side of operation, got function."`;
43+
exports[`Invalid binary type combinations for (<|>|<=|>=) return TypeError 21`] = `"Expected string or number on left hand side of operation, got function."`;
4444

45-
exports[`Invalid binary type combinations for (<|>|<==|>==) return TypeError 22`] = `"Expected string on right hand side of operation, got function."`;
45+
exports[`Invalid binary type combinations for (<|>|<=|>=) return TypeError 22`] = `"Expected string on right hand side of operation, got function."`;
4646

47-
exports[`Invalid binary type combinations for (<|>|<==|>==) return TypeError 23`] = `"Expected string on right hand side of operation, got number."`;
47+
exports[`Invalid binary type combinations for (<|>|<=|>=) return TypeError 23`] = `"Expected string on right hand side of operation, got number."`;
4848

49-
exports[`Invalid binary type combinations for (<|>|<==|>==) return TypeError 24`] = `"Expected string or number on left hand side of operation, got function."`;
49+
exports[`Invalid binary type combinations for (<|>|<=|>=) return TypeError 24`] = `"Expected string or number on left hand side of operation, got function."`;
5050

51-
exports[`Invalid binary type combinations for (<|>|<==|>==) return TypeError 25`] = `"Expected number on right hand side of operation, got string."`;
51+
exports[`Invalid binary type combinations for (<|>|<=|>=) return TypeError 25`] = `"Expected number on right hand side of operation, got string."`;
5252

53-
exports[`Invalid binary type combinations for (<|>|<==|>==) return TypeError 26`] = `"Expected string or number on left hand side of operation, got boolean."`;
53+
exports[`Invalid binary type combinations for (<|>|<=|>=) return TypeError 26`] = `"Expected string or number on left hand side of operation, got boolean."`;
5454

55-
exports[`Invalid binary type combinations for (<|>|<==|>==) return TypeError 27`] = `"Expected string or number on left hand side of operation, got function."`;
55+
exports[`Invalid binary type combinations for (<|>|<=|>=) return TypeError 27`] = `"Expected string or number on left hand side of operation, got function."`;
5656

57-
exports[`Invalid binary type combinations for (<|>|<==|>==) return TypeError 28`] = `"Expected string on right hand side of operation, got function."`;
57+
exports[`Invalid binary type combinations for (<|>|<=|>=) return TypeError 28`] = `"Expected string on right hand side of operation, got function."`;
5858

5959
exports[`Invalid binary type combinations for (-|*|/|%) return TypeError 1`] = `"Expected number on right hand side of operation, got boolean."`;
6060

src/slang/utils/__tests__/rttc.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,25 @@ test('Valid binary type combinations are OK for (===|!==)', () => {
155155
errors.map(error => expect(error).toBeUndefined())
156156
})
157157

158-
test('Invalid binary type combinations for (<|>|<==|>==) return TypeError', () => {
158+
test('Valid binary type combinations are OK for (<|>|<=|>=)', () => {
159+
const operatorValues = [
160+
['<', num, num],
161+
['<', str, str],
162+
['>', num, num],
163+
['>', str, str],
164+
['<=', num, num],
165+
['<=', str, str],
166+
['>=', num, num],
167+
['>=', str, str]
168+
]
169+
const context = mockRuntimeContext()
170+
const errors = operatorValues.map(opVals => {
171+
return rttc.checkBinaryExpression(context, opVals[0] as BinaryOperator, opVals[1], opVals[2])
172+
})
173+
errors.map(error => expect(error).toBeUndefined())
174+
})
175+
176+
test('Invalid binary type combinations for (<|>|<=|>=) return TypeError', () => {
159177
const operatorValues = [
160178
['<', bool, num],
161179
['<', str, num],

0 commit comments

Comments
 (0)