1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.pyyaml;
17
18 import org.yaml.snakeyaml.error.Mark;
19
20
21
22
23 public class PyMarkTest extends PyImportTest {
24
25 public void testMarks() {
26 String content = getResource("test_mark.marks");
27 String[] inputs = content.split("---\n");
28 for (int i = 1; i < inputs.length; i++) {
29 String input = inputs[i];
30 int index = 0;
31 int line = 0;
32 int column = 0;
33 while (input.charAt(index) != '*') {
34 if (input.charAt(index) != '\n') {
35 line += 1;
36 column = 0;
37 } else {
38 column += 1;
39 }
40 index += 1;
41 }
42 Mark mark = new Mark("testMarks", index, line, column, input, index);
43 String snippet = mark.get_snippet(2, 79);
44 assertTrue("Must only have one '\n'.", snippet.indexOf("\n") > -1);
45 assertEquals("Must only have only one '\n'.", snippet.indexOf("\n"),
46 snippet.lastIndexOf("\n"));
47 String[] lines = snippet.split("\n");
48 String data = lines[0];
49 String pointer = lines[1];
50 assertTrue("Mark must be restricted: " + data, data.length() < 82);
51 int dataPosition = data.indexOf("*");
52 int pointerPosition = pointer.indexOf("^");
53 assertEquals("Pointer should coincide with '*':\n " + snippet, dataPosition,
54 pointerPosition);
55 }
56 }
57 }