// Path: streamflyer-core/src/main/java/com/github/rwitzel/streamflyer/xml/XmlVersionReader.java
// public class XmlVersionReader extends BufferedReader {
// 
//     private String xmlVersion;
// 
//     //
//     // constructors
//     //
// 
//     public XmlVersionReader(Reader in) throws IOException {
//         super(in);
// 
//         String prolog = prolog();
//         xmlVersion = xmlVersion(prolog);
//     }
// 
//     //
//     // private methods
//     //
// 
//     private String xmlVersion(String prolog) {
// 
//         // (Should we do aware of BOMs here? No. I consider it the
//         // responsibility of the caller to provide characters without BOM.)
// 
//         Matcher matcher = Pattern.compile("<\\?xml[^>]*version\\s*=\\s*['\"]((1.0)|(1.1))['\"].*").matcher(prolog);
//         if (matcher.matches()) {
//             return matcher.group(1);
//         } else {
//             // the default, see class comment.
//             return "1.0";
//         }
//     }
// 
//     private String prolog() throws IOException {
// 
//         // the prolog may contain many, many whitespace characters -> 4096
//         final int MAX_SNIFFED_CHARACTERS = 4096;
// 
//         mark(MAX_SNIFFED_CHARACTERS);
//         try {
// 
//             char[] cbuf = new char[MAX_SNIFFED_CHARACTERS];
//             int read = read(cbuf);
//             if (read == -1) {
//                 return "";
//             } else {
//                 return new String(cbuf, 0, read);
//             }
//         } finally {
//             reset();
//         }
//     }
// 
//     //
//     // public methods
//     //
// 
//     /**
//      * @return Returns the XML version read from the character stream. If there is XML prolog given, then version "1.0"
//      *         is assumed and returned.
//      */
//     public String getXmlVersion() {
//         return xmlVersion;
//     }
// }


import org.junit.Test;
import com.github.rwitzel.streamflyer.xml.XmlVersionReader;
import static org.junit.Assert.*;
import java.io.StringReader;
import junit.framework.TestCase;
/**
 * Copyright (C) 2011 rwitzel75@googlemail.com
 *
 * 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 com.github.rwitzel.streamflyer.xml;






/**
 * Tests {@link XmlVersionReader}.
 * 
 * @author rwoo
 * @since 27.06.2011
 */
public class XmlVersionReaderTest {

    @Test
    public void testNoXmlVersionInProlog() throws Exception {
        assertXmlVersion("1.0", "<html>");
        assertXmlVersion("1.0", "<html version='1.1'>");
        assertXmlVersion("1.1", "<?xml version='1.1'><html version='1.0'>");
        assertXmlVersion("1.0", "");
    }

    @Test
    public void testXmlVersion10InProlog() throws Exception {
        assertXmlVersion("1.0", "<?xml encoding='hossa' version='1.0' standalone='true'");
        assertXmlVersion("1.0", "<?xml encoding=\"hossa\" version=\"1.0\" standalone=\"true\"");

        assertXmlVersion("1.0", "<?xml encoding='hossa' version = '1.0' standalone='true'");
        assertXmlVersion("1.0", "<?xml encoding=\"hossa\" version  =  \"1.0\" standalone=\"true\"");

    }

    @Test
    public void testXmlVersion11InProlog() throws Exception {
        assertXmlVersion("1.1", "<?xml encoding='hossa' version='1.1' standalone='true'");
        assertXmlVersion("1.1", "<?xml encoding=\"hossa\" version=\"1.1\" standalone=\"true\"");

        assertXmlVersion("1.1", "<?xml encoding='hossa' version = '1.1' standalone='true'");
        assertXmlVersion("1.1", "<?xml encoding=\"hossa\" version  =  \"1.1\" standalone=\"true\"");
    }

    private void assertXmlVersion(String expectedXmlVersion, String xml) throws Exception {
// Path: streamflyer-core/src/main/java/com/github/rwitzel/streamflyer/xml/XmlVersionReader.java
// public class XmlVersionReader extends BufferedReader {
// 
//     private String xmlVersion;
// 
//     //
//     // constructors
//     //
// 
//     public XmlVersionReader(Reader in) throws IOException {
//         super(in);
// 
//         String prolog = prolog();
//         xmlVersion = xmlVersion(prolog);
//     }
// 
//     //
//     // private methods
//     //
// 
//     private String xmlVersion(String prolog) {
// 
//         // (Should we do aware of BOMs here? No. I consider it the
//         // responsibility of the caller to provide characters without BOM.)
// 
//         Matcher matcher = Pattern.compile("<\\?xml[^>]*version\\s*=\\s*['\"]((1.0)|(1.1))['\"].*").matcher(prolog);
//         if (matcher.matches()) {
//             return matcher.group(1);
//         } else {
//             // the default, see class comment.
//             return "1.0";
//         }
//     }
// 
//     private String prolog() throws IOException {
// 
//         // the prolog may contain many, many whitespace characters -> 4096
//         final int MAX_SNIFFED_CHARACTERS = 4096;
// 
//         mark(MAX_SNIFFED_CHARACTERS);
//         try {
// 
//             char[] cbuf = new char[MAX_SNIFFED_CHARACTERS];
//             int read = read(cbuf);
//             if (read == -1) {
//                 return "";
//             } else {
//                 return new String(cbuf, 0, read);
//             }
//         } finally {
//             reset();
//         }
//     }
// 
//     //
//     // public methods
//     //
// 
//     /**
//      * @return Returns the XML version read from the character stream. If there is XML prolog given, then version "1.0"
//      *         is assumed and returned.
//      */
//     public String getXmlVersion() {
//         return xmlVersion;
//     }
// }


// Path: streamflyer-core/src/test/java/com/github/rwitzel/streamflyer/xml/XmlVersionReaderTest.java
import org.junit.Test;
import com.github.rwitzel.streamflyer.xml.XmlVersionReader;
import static org.junit.Assert.*;
import java.io.StringReader;
import junit.framework.TestCase;

/**
 * Copyright (C) 2011 rwitzel75@googlemail.com
 *
 * 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 com.github.rwitzel.streamflyer.xml;






/**
 * Tests {@link XmlVersionReader}.
 * 
 * @author rwoo
 * @since 27.06.2011
 */
public class XmlVersionReaderTest {

    @Test
    public void testNoXmlVersionInProlog() throws Exception {
        assertXmlVersion("1.0", "<html>");
        assertXmlVersion("1.0", "<html version='1.1'>");
        assertXmlVersion("1.1", "<?xml version='1.1'><html version='1.0'>");
        assertXmlVersion("1.0", "");
    }

    @Test
    public void testXmlVersion10InProlog() throws Exception {
        assertXmlVersion("1.0", "<?xml encoding='hossa' version='1.0' standalone='true'");
        assertXmlVersion("1.0", "<?xml encoding=\"hossa\" version=\"1.0\" standalone=\"true\"");

        assertXmlVersion("1.0", "<?xml encoding='hossa' version = '1.0' standalone='true'");
        assertXmlVersion("1.0", "<?xml encoding=\"hossa\" version  =  \"1.0\" standalone=\"true\"");

    }

    @Test
    public void testXmlVersion11InProlog() throws Exception {
        assertXmlVersion("1.1", "<?xml encoding='hossa' version='1.1' standalone='true'");
        assertXmlVersion("1.1", "<?xml encoding=\"hossa\" version=\"1.1\" standalone=\"true\"");

        assertXmlVersion("1.1", "<?xml encoding='hossa' version = '1.1' standalone='true'");
        assertXmlVersion("1.1", "<?xml encoding=\"hossa\" version  =  \"1.1\" standalone=\"true\"");
    }

    private void assertXmlVersion(String expectedXmlVersion, String xml) throws Exception {
        XmlVersionReader reader = new XmlVersionReader(new StringReader(xml));