• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2008, SnakeYAML
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5  * in compliance with the License. You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software distributed under the License
10  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11  * or implied. See the License for the specific language governing permissions and limitations under
12  * the License.
13  */
14 package org.pyyaml;
15 
16 import org.yaml.snakeyaml.error.Mark;
17 
18 /**
19  * imported from PyYAML
20  */
21 public class PyMarkTest extends PyImportTest {
22 
testMarks()23   public void testMarks() {
24     String content = getResource("test_mark.marks");
25     String[] inputs = content.split("---\n");
26     for (int i = 1; i < inputs.length; i++) {
27       String input = inputs[i];
28       int index = 0;
29       int line = 0;
30       int column = 0;
31       while (input.charAt(index) != '*') {
32         if (input.charAt(index) != '\n') {
33           line += 1;
34           column = 0;
35         } else {
36           column += 1;
37         }
38         index += 1;
39       }
40       Mark mark = new Mark("testMarks", index, line, column, input.toCharArray(), index);
41       String snippet = mark.get_snippet(2, 79);
42       assertTrue("Must only have one '\n'.", snippet.indexOf("\n") > -1);
43       assertEquals("Must only have only one '\n'.", snippet.indexOf("\n"),
44           snippet.lastIndexOf("\n"));
45       String[] lines = snippet.split("\n");
46       String data = lines[0];
47       String pointer = lines[1];
48       assertTrue("Mark must be restricted: " + data, data.length() < 82);
49       int dataPosition = data.indexOf("*");
50       int pointerPosition = pointer.indexOf("^");
51       assertEquals("Pointer should coincide with '*':\n " + snippet, dataPosition, pointerPosition);
52     }
53   }
54 }
55