1 /** 2 * Copyright (c) 2008, http://www.snakeyaml.org 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package org.pyyaml; 17 18 import org.yaml.snakeyaml.error.Mark; 19 20 /** 21 * imported from PyYAML 22 */ 23 public class PyMarkTest extends PyImportTest { 24 testMarks()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 } 58