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 java.io.File; 17 import java.io.FileInputStream; 18 import java.io.IOException; 19 import java.io.InputStream; 20 import org.yaml.snakeyaml.error.YAMLException; 21 import org.yaml.snakeyaml.reader.ReaderException; 22 import org.yaml.snakeyaml.reader.StreamReader; 23 import org.yaml.snakeyaml.reader.UnicodeReader; 24 25 /** 26 * imported from PyYAML 27 */ 28 public class PyReaderTest extends PyImportTest { 29 testReaderUnicodeErrors()30 public void testReaderUnicodeErrors() throws IOException { 31 File[] inputs = getStreamsByExtension(".stream-error"); 32 for (int i = 0; i < inputs.length; i++) { 33 InputStream input = new FileInputStream(inputs[i]); 34 UnicodeReader unicodeReader = new UnicodeReader(input); 35 StreamReader stream = new StreamReader(unicodeReader); 36 try { 37 while (stream.peek() != '\u0000') { 38 stream.forward(); 39 } 40 fail("Invalid stream must not be accepted: " + inputs[i].getAbsolutePath() + "; encoding=" 41 + unicodeReader.getEncoding()); 42 } catch (ReaderException e) { 43 assertTrue(e.toString(), e.toString().contains(" special characters are not allowed")); 44 } catch (YAMLException e) { 45 assertTrue(e.toString(), e.toString().contains("MalformedInputException")); 46 } finally { 47 input.close(); 48 } 49 } 50 } 51 } 52