Skip to content

Commit 6a3a423

Browse files
committed
test: add tests for ternary expressions (issue #43)
- Add test cases for nested ternary expressions - Add test case for ternary with method calls - Tests verify correct highlighting in these scenarios - Tests currently pass, indicating issue may already be resolved Closes #43
1 parent e132a78 commit 6a3a423

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

test/expressions.tests.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,48 @@ Object newPoint = new Vector(point.x * z, 0);`);
191191
Token.Punctuation.Semicolon,
192192
]);
193193
});
194+
195+
it('nested ternary expression (issue #43)', async () => {
196+
const input = Input.InMethod(`Integer result = x ? y ? 1 : 2 : 3;`);
197+
const tokens = await tokenize(input);
198+
199+
tokens.should.deep.equal([
200+
Token.PrimitiveType.Integer,
201+
Token.Identifiers.LocalName('result'),
202+
Token.Operators.Assignment,
203+
Token.Variables.ReadWrite('x'),
204+
Token.Operators.Conditional.QuestionMark,
205+
Token.Variables.ReadWrite('y'),
206+
Token.Operators.Conditional.QuestionMark,
207+
Token.Literals.Numeric.Decimal('1'),
208+
Token.Operators.Conditional.Colon,
209+
Token.Literals.Numeric.Decimal('2'),
210+
Token.Operators.Conditional.Colon,
211+
Token.Literals.Numeric.Decimal('3'),
212+
Token.Punctuation.Semicolon,
213+
]);
214+
});
215+
216+
it('ternary with method call (issue #43)', async () => {
217+
const input = Input.InMethod(`String s = x ? getValue() : getDefault();`);
218+
const tokens = await tokenize(input);
219+
220+
tokens.should.deep.equal([
221+
Token.PrimitiveType.String,
222+
Token.Identifiers.LocalName('s'),
223+
Token.Operators.Assignment,
224+
Token.Variables.ReadWrite('x'),
225+
Token.Operators.Conditional.QuestionMark,
226+
Token.Identifiers.MethodName('getValue'),
227+
Token.Punctuation.OpenParen,
228+
Token.Punctuation.CloseParen,
229+
Token.Operators.Conditional.Colon,
230+
Token.Identifiers.MethodName('getDefault'),
231+
Token.Punctuation.OpenParen,
232+
Token.Punctuation.CloseParen,
233+
Token.Punctuation.Semicolon,
234+
]);
235+
});
194236
});
195237

196238
describe('Element Access', () => {

0 commit comments

Comments
 (0)