Path: blob/master/test/jdk/java/io/StreamTokenizer/QuoteTest.java
41149 views
/*1* Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/* @test24* @bug 421887925* @summary On encountering a quoted string in the stream, nextToken() must26* return '\"' and StreamTokenizer.toString() must return the actual quoted27* string.28*/293031import java.io.*;3233public class QuoteTest {3435static String testStr = "token1 token2 \"The test string\" token4";36public static void main(String[] args) throws Exception {3738System.err.println("Parsing String: " + testStr);39StreamTokenizer st = new StreamTokenizer(new StringReader(testStr));40boolean foundToken = false;41String matchStr = null;42while(st.nextToken() != StreamTokenizer.TT_EOF)43{44switch (st.ttype) {45case '\"':46foundToken = true;47matchStr = st.toString();48System.err.println("Found token " + matchStr);49break;50default:51System.err.println("Found token " + st);52break;53}54}55if (!foundToken)56throw new RuntimeException("Test failed to recognize Quote type");57if (!matchStr.equals("Token[The test string], line 1"))58throw new RuntimeException("Test failed parse quoted string");59}60}616263