3535
3636public class LocationsTest {
3737
38+ private static IRascalValueFactory VF = IRascalValueFactory .getInstance ();
39+ private String fileName = "PNG.bird" ;
40+
41+ private static ColumnMaps columns (String contents ) {
42+ return new ColumnMaps (f -> contents );
43+ }
44+
3845 @ Test
39- public void roundtrip () {
40- var VF = IRascalValueFactory .getInstance ();
41- var fileName = "PNG.bird" ;
46+ public void roundtripWindowsEmptyLine () {
4247 var contents = "module images::PNG\r \n " + //
4348 "\r \n " + //
4449 "struct Signature {\r \n " + //
@@ -47,10 +52,55 @@ public void roundtrip() {
4752 " byte[] _[4] ?(== <0x0d, 0x0a, 0x1a, 0x0a>)\r \n " + //
4853 "}\r \n " + //
4954 "" ;
50- var columns = new ColumnMaps ( f -> contents );
55+ var columns = columns ( contents );
5156 var in = VF .sourceLocation (fileName , 22 , 119 , 3 , 7 , 0 , 1 ); // the structure
52- var range = Locations .toRange (in , columns );
53- var out = Locations .setRange (in , range , columns );
57+ var out = Locations .setRange (in , Locations .toRange (in , columns ), columns );
58+ assertEquals (in , out );
59+ }
60+
61+ @ Test
62+ public void roundtripWindows () {
63+ var contents = "module images::PNG\r \n " + //
64+ "struct Signature {\r \n " + //
65+ " u8 _ ?(== 0x89)\r \n " + //
66+ " byte[] _[3] ?(== \" PNG\" )\r \n " + //
67+ " byte[] _[4] ?(== <0x0d, 0x0a, 0x1a, 0x0a>)\r \n " + //
68+ "}\r \n " + //
69+ "" ;
70+ var columns = columns (contents );
71+ var in = VF .sourceLocation (fileName , 20 , 119 , 2 , 6 , 0 , 1 ); // the structure
72+ var out = Locations .setRange (in , Locations .toRange (in , columns ), columns );
73+ assertEquals (in , out );
74+ }
75+
76+ @ Test
77+ public void roundtripUnixEmptyLine () {
78+ var contents = "module images::PNG\n " + //
79+ "\n " + //
80+ "struct Signature {\n " + //
81+ " u8 _ ?(== 0x89)\n " + //
82+ " byte[] _[3] ?(== \" PNG\" )\n " + //
83+ " byte[] _[4] ?(== <0x0d, 0x0a, 0x1a, 0x0a>)\n " + //
84+ "}\n " + //
85+ "" ;
86+ var columns = columns (contents );
87+ var in = VF .sourceLocation (fileName , 20 , 115 , 3 , 7 , 0 , 1 ); // the structure
88+ var out = Locations .setRange (in , Locations .toRange (in , columns ), columns );
89+ assertEquals (in , out );
90+ }
91+
92+ @ Test
93+ public void roundtripUnix () {
94+ var contents = "module images::PNG\n " + //
95+ "struct Signature {\n " + //
96+ " u8 _ ?(== 0x89)\n " + //
97+ " byte[] _[3] ?(== \" PNG\" )\n " + //
98+ " byte[] _[4] ?(== <0x0d, 0x0a, 0x1a, 0x0a>)\n " + //
99+ "}\n " + //
100+ "" ;
101+ var columns = columns (contents );
102+ var in = VF .sourceLocation (fileName , 19 , 115 , 2 , 6 , 0 , 1 ); // the structure
103+ var out = Locations .setRange (in , Locations .toRange (in , columns ), columns );
54104 assertEquals (in , out );
55105 }
56106}
0 commit comments