1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.pyyaml;
17
18 import java.io.File;
19 import java.io.FileInputStream;
20 import java.io.IOException;
21 import java.io.InputStream;
22
23 import org.yaml.snakeyaml.error.YAMLException;
24 import org.yaml.snakeyaml.reader.ReaderException;
25 import org.yaml.snakeyaml.reader.StreamReader;
26 import org.yaml.snakeyaml.reader.UnicodeReader;
27
28
29
30
31 public class PyReaderTest extends PyImportTest {
32
33 public void testReaderUnicodeErrors() throws IOException {
34 File[] inputs = getStreamsByExtension(".stream-error");
35 for (int i = 0; i < inputs.length; i++) {
36 InputStream input = new FileInputStream(inputs[i]);
37 StreamReader stream = new StreamReader(new UnicodeReader(input));
38 try {
39 while (stream.peek() != '\u0000') {
40 stream.forward();
41 }
42 fail("Invalid stream must not be accepted: " + inputs[i].getAbsolutePath()
43 + "; encoding=" + stream.getEncoding());
44 } catch (ReaderException e) {
45 assertTrue(e.toString(),
46 e.toString().contains(" special characters are not allowed"));
47 } catch (YAMLException e) {
48 assertTrue(e.toString(), e.toString().contains("MalformedInputException"));
49 } finally {
50 input.close();
51 }
52 }
53 }
54 }