View Javadoc

    1   /**
    2    * Copyright (c) 2008-2011, 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
    17  package org.pyyaml;
    18
    19  import java.io.File;
    20  import java.io.FileInputStream;
    21  import java.io.IOException;
    22  import java.io.InputStream;
    23
    24  import org.yaml.snakeyaml.reader.ReaderException;
    25  import org.yaml.snakeyaml.reader.StreamReader;
    26  import org.yaml.snakeyaml.reader.UnicodeReader;
    27
    28  /**
    29   * @see imported from PyYAML
    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              } finally {
    48                  input.close();
    49              }
    50          }
    51      }
    52  }