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