@@ -469,6 +469,65 @@ test "Verify tokens have locations that are in order", ->
469
469
ok token[2 ].first_column >= lastToken[2 ].last_column
470
470
lastToken = token
471
471
472
+ test " Verify OUTDENT tokens are located at the end of the previous token" , ->
473
+ source = '''
474
+ SomeArr = [ ->
475
+ if something
476
+ lol =
477
+ count: 500
478
+ ]
479
+ '''
480
+ tokens = CoffeeScript .tokens source
481
+ [... , number , curly , outdent1 , outdent2 , outdent3 , bracket , terminator ] = tokens
482
+ eq number[0 ], ' NUMBER'
483
+ for outdent in [outdent1, outdent2, outdent3]
484
+ eq outdent[0 ], ' OUTDENT'
485
+ eq outdent[2 ].first_line , number[2 ].last_line
486
+ eq outdent[2 ].first_column , number[2 ].last_column
487
+ eq outdent[2 ].last_line , number[2 ].last_line
488
+ eq outdent[2 ].last_column , number[2 ].last_column
489
+
490
+ test " Verify OUTDENT and CALL_END tokens are located at the end of the previous token" , ->
491
+ source = '''
492
+ a = b {
493
+ c: ->
494
+ d e,
495
+ if f
496
+ g {},
497
+ if h
498
+ i {}
499
+ }
500
+ '''
501
+ tokens = CoffeeScript .tokens source
502
+ [... , closeCurly1, callEnd1, outdent1, outdent2, callEnd2, outdent3, outdent4,
503
+ callEnd3, outdent5, outdent6, closeCurly2, callEnd4, terminator] = tokens
504
+ eq closeCurly1[0 ], ' }'
505
+ assertAtCloseCurly = (token ) ->
506
+ eq token[2 ].first_line , closeCurly1[2 ].last_line
507
+ eq token[2 ].first_column , closeCurly1[2 ].last_column
508
+ eq token[2 ].last_line , closeCurly1[2 ].last_line
509
+ eq token[2 ].last_column , closeCurly1[2 ].last_column
510
+
511
+ for token in [outdent1, outdent2, outdent3, outdent4, outdent5, outdent6]
512
+ eq token[0 ], ' OUTDENT'
513
+ assertAtCloseCurly (token)
514
+ for token in [callEnd1, callEnd2, callEnd3]
515
+ eq token[0 ], ' CALL_END'
516
+ assertAtCloseCurly (token)
517
+
518
+ test " Verify real CALL_END tokens have the right position" , ->
519
+ source = '''
520
+ a()
521
+ '''
522
+ tokens = CoffeeScript .tokens source
523
+ [identifier , callStart , callEnd , terminator ] = tokens
524
+ startIndex = identifier[2 ].first_column
525
+ eq identifier[2 ].last_column , startIndex
526
+ eq callStart[2 ].first_column , startIndex + 1
527
+ eq callStart[2 ].last_column , startIndex + 1
528
+ eq callEnd[2 ].first_column , startIndex + 2
529
+ eq callEnd[2 ].last_column , startIndex + 2
530
+
472
531
test " Verify all tokens get a location" , ->
473
532
doesNotThrow ->
474
533
tokens = CoffeeScript .tokens testScript
0 commit comments