Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit 246bfea

Browse files
committed
Add tests for different positions within ternary expressions
1 parent 2538ed3 commit 246bfea

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

spec/javascript-spec.coffee

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,16 @@ describe "Javascript grammar", ->
7070
expect(tokens[0]).toEqual value: keyword, scopes: ['source.js']
7171
expect(tokens[1]).toEqual value: ':', scopes: ['source.js', 'keyword.operator.js']
7272

73-
it "tokenizes `#{keyword}` in ternary expressions", ->
73+
it "tokenizes `#{keyword}` in the middle of ternary expressions", ->
7474
{tokens} = grammar.tokenizeLine("a ? #{keyword} : b")
7575
expect(tokens[2]).toEqual value: ' ', scopes: ['source.js']
7676
expect(tokens[3]).toEqual value: keyword, scopes: ['source.js', scope]
7777

78+
it "tokenizes `#{keyword}` at the end of ternary expressions", ->
79+
{tokens} = grammar.tokenizeLine("a ? b : #{keyword}")
80+
expect(tokens[4]).toEqual value: ' ', scopes: ['source.js']
81+
expect(tokens[5]).toEqual value: keyword, scopes: ['source.js', scope]
82+
7883
describe "built-in globals", ->
7984
it "tokenizes them as support classes", ->
8085
{tokens} = grammar.tokenizeLine('window')
@@ -363,10 +368,14 @@ describe "Javascript grammar", ->
363368
expect(tokens[0]).toEqual value: 'FOO', scopes: ['source.js']
364369
expect(tokens[1]).toEqual value: ':', scopes: ['source.js', 'keyword.operator.js']
365370

366-
it "tokenizes constants in ternary expressions", ->
371+
it "tokenizes constants in the middle of ternary expressions", ->
367372
{tokens} = grammar.tokenizeLine('a ? FOO : b')
368373
expect(tokens[3]).toEqual value: 'FOO', scopes: ['source.js', 'constant.other.js']
369374

375+
it "tokenizes constants at the end of ternary expressions", ->
376+
{tokens} = grammar.tokenizeLine('a ? b : FOO')
377+
expect(tokens[5]).toEqual value: 'FOO', scopes: ['source.js', 'constant.other.js']
378+
370379
describe "ES6 string templates", ->
371380
it "tokenizes them as strings", ->
372381
{tokens} = grammar.tokenizeLine('`hey ${name}`')
@@ -435,10 +444,14 @@ describe "Javascript grammar", ->
435444
expect(tokens[0]).toEqual value: 'yield', scopes: ['source.js']
436445
expect(tokens[1]).toEqual value: ':', scopes: ['source.js', 'keyword.operator.js']
437446

438-
it "tokenizes yield in ternary expressions", ->
447+
it "tokenizes yield in the middle of ternary expressions", ->
439448
{tokens} = grammar.tokenizeLine('a ? yield : b')
440449
expect(tokens[3]).toEqual value: 'yield', scopes: ['source.js', 'meta.control.yield.js', 'keyword.control.js']
441450

451+
it "tokenizes yield at the end of ternary expressions", ->
452+
{tokens} = grammar.tokenizeLine('a ? b : yield')
453+
expect(tokens[5]).toEqual value: 'yield', scopes: ['source.js', 'meta.control.yield.js', 'keyword.control.js']
454+
442455
describe "default: in a switch statement", ->
443456
it "tokenizes it as a keyword", ->
444457
{tokens} = grammar.tokenizeLine('default: ')

0 commit comments

Comments
 (0)