Code example for StreamTokenizer

Methods: nextToken, whitespaceChars

0
	/** 
	 * @tests java.io.StreamTokenizer#whitespaceChars(int, int) 
	 */ 
	public void test_whitespaceCharsII() throws IOException { 
		setTest("azbc iof z 893"); 
		st.whitespaceChars('a', 'z');
		assertTrue("OrdinaryChar failed.",
			   st.nextToken() == StreamTokenizer.TT_NUMBER);
	} 
 
	/** 
	 * @tests java.io.StreamTokenizer#wordChars(int, int) 
	 */ 
	public void test_wordCharsII() throws IOException { 
		setTest("A893 -9B87"); 
		st.wordChars('0', '9');
		assertTrue("WordChar failed1.",
			   st.nextToken() == StreamTokenizer.TT_WORD);
		assertEquals("WordChar failed2.", "A893", st.sval);
		assertTrue("WordChar failed3.",
			   st.nextToken() == StreamTokenizer.TT_NUMBER);
		st.nextToken();
		assertEquals("WordChar failed4.", "B87", st.sval);
		 
		setTest("    Hello World"); 
		st.wordChars(' ', ' ');
		st.nextToken();
		assertEquals("WordChars failed for whitespace.", "Hello World", st.sval
			     ); 
		 
		setTest("    Hello World\r\n  \'Hello World\' Hello\' World"); 
		st.wordChars(' ', ' ');
		st.wordChars('\'', '\'');
		st.nextToken();
		assertTrue("WordChars failed for whitespace: " + st.sval, st.sval
			   .equals("Hello World"));
		st.nextToken();
		assertTrue("WordChars failed for quote1: " + st.sval, st.sval
			   .equals("\'Hello World\' Hello\' World"));
	} 
 
	private void setTest(String s) {
		testString = s;
		r = new Support_StringReader(testString);
		st = new StreamTokenizer(r);
	} 
 
	protected void setUp() { 
	}