/**
 * Copyright (c) 2008-2011, http://www.snakeyaml.org
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.yaml.snakeyaml.reader;

import java.util.regex.Matcher;

import junit.framework.TestCase;

public class ReaderStringTest extends TestCase {

    public void testCheckPrintable() {
        StreamReader reader = new StreamReader("test");
        reader.checkPrintable("test");
        Matcher matcher = StreamReader.NON_PRINTABLE.matcher("test");
        assertFalse(matcher.find());

        try {
            reader.checkPrintable("test".toCharArray(), 0, 4);
        } catch (ReaderException e) {
            fail();
        }

    }

    public void testCheckNonPrintable() {
        Matcher matcher = StreamReader.NON_PRINTABLE.matcher("test\u0005 fail");
        assertTrue(matcher.find());
        try {
            new StreamReader("test\u0005 fail");
            fail("Non printable Unicode characters must not be accepted.");
        } catch (ReaderException e) {
            assertEquals(
                    "unacceptable character '' (0x5) special characters are not allowed\nin \"<string>\", position 4",
                    e.toString());
        }
    }

    public void testForward() {
        StreamReader reader = new StreamReader("test");
        while (reader.peek() != '\u0000') {
            reader.forward(1);
        }
        reader = new StreamReader("test");
        assertEquals('t', reader.peek());
        reader.forward(1);
        assertEquals('e', reader.peek());
        reader.forward(1);
        assertEquals('s', reader.peek());
        reader.forward(1);
        assertEquals('t', reader.peek());
        reader.forward(1);
        assertEquals('\u0000', reader.peek());
    }

    public void testPeekInt() {
        StreamReader reader = new StreamReader("test");
        assertEquals('t', reader.peek(0));
        assertEquals('e', reader.peek(1));
        assertEquals('s', reader.peek(2));
        assertEquals('t', reader.peek(3));
        reader.forward(1);
        assertEquals('e', reader.peek(0));
        assertEquals('s', reader.peek(1));
        assertEquals('t', reader.peek(2));
    }

}

@@ -1738,32 +1738,1108 @@
     %7D%0D%0A    %7D%0D%0A%0D%0A
+    /**%0D%0A     * test that regular expression and array check work the same%0D%0A     */%0D%0A    public void testCheckAll() %7B%0D%0A        StreamReader streamReader = new StreamReader(%22%22);%0D%0A        for (char i = 0; i %3C 256 * 256 - 1; i++) %7B%0D%0A            char%5B%5D chars = new char%5B1%5D;%0D%0A            chars%5B0%5D = i;%0D%0A            String str = new String(chars);%0D%0A            Matcher matcher = StreamReader.NON_PRINTABLE.matcher(str);%0D%0A            boolean regularExpressionResult = !matcher.find();%0D%0A%0D%0A            boolean charsArrayResult = true;%0D%0A            try %7B%0D%0A                streamReader.checkPrintable(chars, 0, 1);%0D%0A            %7D catch (Exception e) %7B%0D%0A                String error = e.getMessage();%0D%0A                assertTrue(%0D%0A                        error,%0D%0A                        error.startsWith(%22unacceptable character%22)%0D%0A                                %7C%7C error.equals(%22special characters are not allowed%22));%0D%0A                charsArrayResult = false;%0D%0A            %7D%0D%0A            assertEquals(%22Failed for #%22 + i, regularExpressionResult, charsArrayResult);%0D%0A        %7D%0D%0A    %7D%0D%0A%0D%0A
     public void 

add test to see if non-printable check on char[] gives the same result as regexp on String. thx py4fun