use of java.io.StringReader in project j2objc by google.
the class OldAndroidStreamTokenizerTest method testStreamTokenizer.
public void testStreamTokenizer() throws Exception {
String str = "Testing 12345 \n alpha \r\n omega";
String strb = "-3.8 'BLIND mice' \r sEe /* how */ they run";
StringReader aa = new StringReader(str);
StringReader ba = new StringReader(strb);
StreamTokenizer a = new StreamTokenizer(aa);
StreamTokenizer b = new StreamTokenizer(ba);
assertEquals(1, a.lineno());
assertEquals(StreamTokenizer.TT_WORD, a.nextToken());
assertEquals("Token[Testing], line 1", a.toString());
assertEquals(StreamTokenizer.TT_NUMBER, a.nextToken());
assertEquals("Token[n=12345.0], line 1", a.toString());
assertEquals(StreamTokenizer.TT_WORD, a.nextToken());
assertEquals("Token[alpha], line 2", a.toString());
assertEquals(StreamTokenizer.TT_WORD, a.nextToken());
assertEquals("Token[omega], line 3", a.toString());
assertEquals(StreamTokenizer.TT_EOF, a.nextToken());
assertEquals("Token[EOF], line 3", a.toString());
b.commentChar('u');
b.eolIsSignificant(true);
b.lowerCaseMode(true);
b.ordinaryChar('y');
b.slashStarComments(true);
assertEquals(StreamTokenizer.TT_NUMBER, b.nextToken());
assertEquals(-3.8, b.nval);
assertEquals("Token[n=-3.8], line 1", b.toString());
// '
assertEquals(39, b.nextToken());
assertEquals("Token[BLIND mice], line 1", b.toString());
// \n
assertEquals(10, b.nextToken());
assertEquals("Token[EOL], line 2", b.toString());
assertEquals(StreamTokenizer.TT_WORD, b.nextToken());
assertEquals("Token[see], line 2", b.toString());
assertEquals(StreamTokenizer.TT_WORD, b.nextToken());
assertEquals("Token[the], line 2", b.toString());
// y
assertEquals(121, b.nextToken());
assertEquals("Token['y'], line 2", b.toString());
assertEquals(StreamTokenizer.TT_WORD, b.nextToken());
assertEquals("Token[r], line 2", b.toString());
assertEquals(StreamTokenizer.TT_EOF, b.nextToken());
assertEquals("Token[EOF], line 2", b.toString());
// A harmony regression test
byte[] data = new byte[] { (byte) '-' };
StreamTokenizer tokenizer = new StreamTokenizer(new ByteArrayInputStream(data));
tokenizer.nextToken();
String result = tokenizer.toString();
assertEquals("Token['-'], line 1", result);
// another harmony regression test
byte[] data2 = new byte[] { (byte) '"', (byte) 'H', (byte) 'e', (byte) 'l', (byte) 'l', (byte) 'o', (byte) '"' };
StreamTokenizer tokenizer2 = new StreamTokenizer(new ByteArrayInputStream(data2));
tokenizer2.nextToken();
result = tokenizer2.toString();
assertEquals("Token[Hello], line 1", result);
}
use of java.io.StringReader in project j2objc by google.
the class OldAndroidStringReaderTest method testStringReader.
public void testStringReader() throws Exception {
String str = "AbCdEfGhIjKlMnOpQrStUvWxYz";
StringReader a = new StringReader(str);
StringReader b = new StringReader(str);
StringReader c = new StringReader(str);
StringReader d = new StringReader(str);
Assert.assertEquals(str, read(a));
Assert.assertEquals("AbCdEfGhIj", read(b, 10));
Assert.assertEquals("bdfhjlnprtvxz", skipRead(c));
Assert.assertEquals("AbCdEfGdEfGhIjKlMnOpQrStUvWxYz", markRead(d, 3, 4));
}
use of java.io.StringReader in project j2objc by google.
the class PackagePrefixesTest method testPackagePrefixesFile.
public void testPackagePrefixesFile() throws IOException {
String prefixes = "# Prefix mappings\n" + "java.lang: JL\n" + "foo.bar: FB\n";
StringReader reader = new StringReader(prefixes);
Properties properties = new Properties();
properties.load(reader);
PackagePrefixes prefixMap = options.getPackagePrefixes();
assertNull(prefixMap.getPrefix("java.lang"));
assertNull(prefixMap.getPrefix("foo.bar"));
prefixMap.addPrefixProperties(properties);
assertEquals("JL", prefixMap.getPrefix("java.lang"));
assertEquals("FB", prefixMap.getPrefix("foo.bar"));
}
use of java.io.StringReader in project j2objc by google.
the class PackagePrefixesTest method testPackagePrefixesWithTrailingSpace.
/**
* Regression test for http://code.google.com/p/j2objc/issues/detail?id=100.
*/
public void testPackagePrefixesWithTrailingSpace() throws IOException {
String prefixes = "# Prefix mappings\n" + "java.lang: JL\n" + // Trailing space should be ignored.
"foo.bar: FB \n";
StringReader reader = new StringReader(prefixes);
Properties properties = new Properties();
properties.load(reader);
PackagePrefixes prefixMap = options.getPackagePrefixes();
prefixMap.addPrefixProperties(properties);
assertEquals("JL", prefixMap.getPrefix("java.lang"));
assertEquals("FB", prefixMap.getPrefix("foo.bar"));
}
use of java.io.StringReader in project j2objc by google.
the class OldBufferedReaderTest method test_readLine_interaction_with_mark_and_reset.
public void test_readLine_interaction_with_mark_and_reset() throws Exception {
BufferedReader r = new BufferedReader(new StringReader("1\r\n2\n3"));
assertEquals("1", r.readLine());
r.mark(256);
// This read skips the '\n'.
assertEquals('2', r.read());
assertEquals("", r.readLine());
// Now we're back half-way through the "\r\n".
r.reset();
assertEquals("2", r.readLine());
assertEquals("3", r.readLine());
assertNull(r.readLine());
}
Aggregations