Skip to content

Commit a566b34

Browse files
committed
Add roundtrip test for source location conversions.
1 parent 22d9217 commit a566b34

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package engineering.swat.rascal.lsp.util;
2+
3+
import static org.junit.Assert.assertEquals;
4+
5+
import org.junit.Test;
6+
import org.rascalmpl.values.IRascalValueFactory;
7+
import org.rascalmpl.vscode.lsp.util.locations.ColumnMaps;
8+
import org.rascalmpl.vscode.lsp.util.locations.Locations;
9+
10+
public class LocationsTest {
11+
12+
@Test
13+
public void roundtrip() {
14+
var VF = IRascalValueFactory.getInstance();
15+
var fileName = "PNG.bird";
16+
var contents = "module images::PNG\r\n" + //
17+
"\r\n" + //
18+
"struct Signature {\r\n" + //
19+
" u8 _ ?(== 0x89)\r\n" + //
20+
" byte[] _[3] ?(== \"PNG\")\r\n" + //
21+
" byte[] _[4] ?(== <0x0d, 0x0a, 0x1a, 0x0a>)\r\n" + //
22+
"}\r\n" + //
23+
"";
24+
var columns = new ColumnMaps(f -> contents);
25+
var in = VF.sourceLocation(fileName, 22, 119, 3, 7, 0, 1); // the structure
26+
var range = Locations.toRange(in, columns);
27+
var out = Locations.setRange(in, range, columns);
28+
assertEquals(in, out);
29+
}
30+
}

0 commit comments

Comments
 (0)