@@ -3,6 +3,20 @@ local fs = require("@lute/fs")
33
44local parser = require ("@batteries/syntax/parser" )
55local printer = require ("@batteries/syntax/printer" )
6+ local T = require ("@batteries/syntax/ast_types" )
7+
8+ local function assertEqualsLocation (
9+ actual : T .Location ,
10+ startLine : number ,
11+ startColumn : number ,
12+ endLine : number ,
13+ endColumn : number
14+ )
15+ assert (actual .begin .line == startLine )
16+ assert (actual .begin .column == startColumn )
17+ assert (actual ["end" ].line == endLine )
18+ assert (actual ["end" ].column == endColumn )
19+ end
620
721local function test_tokenContainsLeadingSpaces ()
822 local block = luau .parse (" local x = 1" ).root
@@ -15,6 +29,7 @@ local function test_tokenContainsLeadingSpaces()
1529 assert (# token .leadingTrivia == 1 )
1630 assert (token .leadingTrivia [1 ].tag == "whitespace" )
1731 assert (token .leadingTrivia [1 ].text == " " )
32+ assertEqualsLocation (token .leadingTrivia [1 ].location , 0 , 0 , 0 , 2 )
1833end
1934
2035local function test_tokenContainsLeadingNewline ()
@@ -28,6 +43,7 @@ local function test_tokenContainsLeadingNewline()
2843 assert (# token .leadingTrivia == 1 )
2944 assert (token .leadingTrivia [1 ].tag == "whitespace" )
3045 assert (token .leadingTrivia [1 ].text == "\n " )
46+ assertEqualsLocation (token .leadingTrivia [1 ].location , 0 , 0 , 1 , 0 )
3147end
3248
3349local function test_tokenContainsLeadingSingleLineComment ()
@@ -41,8 +57,10 @@ local function test_tokenContainsLeadingSingleLineComment()
4157 assert (# token .leadingTrivia == 2 )
4258 assert (token .leadingTrivia [1 ].tag == "comment" )
4359 assert (token .leadingTrivia [1 ].text == "-- comment" )
60+ assertEqualsLocation (token .leadingTrivia [1 ].location , 0 , 0 , 0 , 10 )
4461 assert (token .leadingTrivia [2 ].tag == "whitespace" )
4562 assert (token .leadingTrivia [2 ].text == "\n " )
63+ assertEqualsLocation (token .leadingTrivia [2 ].location , 0 , 10 , 1 , 0 )
4664end
4765
4866local function test_tokenContainsLeadingBlockComment ()
@@ -56,8 +74,10 @@ local function test_tokenContainsLeadingBlockComment()
5674 assert (# token .leadingTrivia == 2 )
5775 assert (token .leadingTrivia [1 ].tag == "blockcomment" )
5876 assert (token .leadingTrivia [1 ].text == "--[[ comment ]]" )
77+ assertEqualsLocation (token .leadingTrivia [1 ].location , 0 , 0 , 0 , 15 )
5978 assert (token .leadingTrivia [2 ].tag == "whitespace" )
6079 assert (token .leadingTrivia [2 ].text == " " )
80+ assertEqualsLocation (token .leadingTrivia [2 ].location , 0 , 15 , 0 , 16 )
6181end
6282
6383local function test_tokenizeWhitespace ()
0 commit comments