Search in sources :

Example 66 with StringReader

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);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) StringReader(java.io.StringReader) StreamTokenizer(java.io.StreamTokenizer)

Example 67 with StringReader

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));
}
Also used : StringReader(java.io.StringReader)

Example 68 with StringReader

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"));
}
Also used : StringReader(java.io.StringReader) Properties(java.util.Properties)

Example 69 with StringReader

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"));
}
Also used : StringReader(java.io.StringReader) Properties(java.util.Properties)

Example 70 with StringReader

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());
}
Also used : BufferedReader(java.io.BufferedReader) Support_StringReader(tests.support.Support_StringReader) StringReader(java.io.StringReader)

Aggregations

StringReader (java.io.StringReader)4150 Test (org.junit.Test)1003 IOException (java.io.IOException)589 Reader (java.io.Reader)445 InputSource (org.xml.sax.InputSource)408 BufferedReader (java.io.BufferedReader)342 TokenStream (org.apache.lucene.analysis.TokenStream)302 ArrayList (java.util.ArrayList)273 StringWriter (java.io.StringWriter)251 Tokenizer (org.apache.lucene.analysis.Tokenizer)241 Document (org.w3c.dom.Document)232 JSONReader (com.alibaba.fastjson.JSONReader)195 DocumentBuilder (javax.xml.parsers.DocumentBuilder)180 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)157 Map (java.util.Map)144 HashMap (java.util.HashMap)136 Element (org.w3c.dom.Element)134 StreamSource (javax.xml.transform.stream.StreamSource)132 ParserResult (org.jabref.logic.importer.ParserResult)130 MockTokenizer (org.apache.lucene.analysis.MockTokenizer)120