11module Test.SrcLoc where
22
3- import Test.Tasty
4- import Test.Tasty.HUnit
5- import Data.List (sort )
63import Agda.Position
7- import Data.Text (Text )
84import qualified Data.IntMap as IntMap
5+ import Data.List (sort )
6+ import Data.Text (Text )
7+ import Test.Tasty
8+ import Test.Tasty.HUnit
99
1010tests :: TestTree
1111tests = testGroup " Source Location" [positionToOffsetTests, offsetToPositionTests]
@@ -16,41 +16,40 @@ positionToOffsetTests :: TestTree
1616positionToOffsetTests =
1717 testGroup
1818 " Position => Offset"
19- [ testCase " cached table" $ IntMap. toList (unToOffset table) @?= [(1 , 4 ), (2 , 9 ), (3 , 12 )]
20- , testCase " line 0" $ run [(0 , 0 ), (0 , 1 ), (0 , 2 ), (0 , 3 )] @?= [0 , 1 , 2 , 3 ]
21- , testCase " line 1" $ run [(1 , 0 ), (1 , 1 ), (1 , 2 ), (1 , 3 ), (1 , 4 )] @?= [4 , 5 , 6 , 7 , 8 ]
22- , testCase " line 2" $ run [(2 , 0 ), (2 , 1 )] @?= [9 , 10 ]
23- , testCase " line 3" $ run [(3 , 0 ), (3 , 1 )] @?= [12 , 13 ]
19+ [ testCase " cached table" $ IntMap. toList (unToOffset table) @?= [(1 , 4 ), (2 , 9 ), (3 , 12 )],
20+ testCase " line 0" $ run [(0 , 0 ), (0 , 1 ), (0 , 2 ), (0 , 3 )] @?= [0 , 1 , 2 , 3 ],
21+ testCase " line 1" $ run [(1 , 0 ), (1 , 1 ), (1 , 2 ), (1 , 3 ), (1 , 4 )] @?= [4 , 5 , 6 , 7 , 8 ],
22+ testCase " line 2" $ run [(2 , 0 ), (2 , 1 )] @?= [9 , 10 ],
23+ testCase " line 3" $ run [(3 , 0 ), (3 , 1 )] @?= [12 , 13 ]
2424 ]
2525 where
26- text :: Text
26+ text :: Text
2727 text = " 012\n 456\r\n 90\r 23"
2828
2929 table :: ToOffset
3030 table = makeToOffset text
3131
3232 run :: [(Int , Int )] -> [Int ]
3333 run = map (toOffset table)
34-
34+
3535--------------------------------------------------------------------------------
3636
3737offsetToPositionTests :: TestTree
3838offsetToPositionTests =
3939 testGroup
4040 " Offset => Position"
41- [ testCase " cached table" $ IntMap. toList (unFromOffset table) @?= [(4 , 1 ), (9 , 2 ), (12 , 3 )]
42- , testCase " line 0" $ run [0 , 1 , 2 , 3 ] @?= [(0 , 0 ), (0 , 1 ), (0 , 2 ), (0 , 3 )]
43- , testCase " line 1" $ run [4 , 5 , 6 , 7 , 8 ] @?= [(1 , 0 ), (1 , 1 ), (1 , 2 ), (1 , 3 ), (1 , 4 )]
44- , testCase " line 2" $ run [9 , 10 ] @?= [(2 , 0 ), (2 , 1 )]
45- , testCase " line 3" $ run [12 , 13 ] @?= [(3 , 0 ), (3 , 1 )]
41+ [ testCase " cached table" $ IntMap. toList (unFromOffset table) @?= [(4 , 1 ), (9 , 2 ), (12 , 3 )],
42+ testCase " line 0" $ run [0 , 1 , 2 , 3 ] @?= [(0 , 0 ), (0 , 1 ), (0 , 2 ), (0 , 3 )],
43+ testCase " line 1" $ run [4 , 5 , 6 , 7 , 8 ] @?= [(1 , 0 ), (1 , 1 ), (1 , 2 ), (1 , 3 ), (1 , 4 )],
44+ testCase " line 2" $ run [9 , 10 ] @?= [(2 , 0 ), (2 , 1 )],
45+ testCase " line 3" $ run [12 , 13 ] @?= [(3 , 0 ), (3 , 1 )]
4646 ]
4747 where
48- text :: Text
48+ text :: Text
4949 text = " 012\n 456\r\n 90\r 23"
5050
5151 table :: FromOffset
5252 table = makeFromOffset text
5353
5454 run :: [Int ] -> [(Int , Int )]
5555 run = map (fromOffset table)
56-
0 commit comments