Package com.asakusafw.runtime.value

Examples of com.asakusafw.runtime.value.StringOption


     * test for text values.
     * @throws Exception if failed
     */
    @Test
    public void text_values() throws Exception {
        assertRestorable(new StringOption("Hello"));
        assertRestorable(new StringOption("\u3042\u3044\u3046\u3048\u304a"));
        assertRestorable(new StringOption("\",\r\n\t "));
        assertRestorable(new StringOption());
    }
View Full Code Here


     * @throws Exception if failed
     */
    @Test
    public void multi_cells() throws Exception {
        CsvEmitter emitter = createEmitter();
        emitter.emit(new StringOption("a"));
        emitter.emit(new StringOption("b"));
        emitter.emit(new StringOption("c"));
        emitter.endRecord();
        emitter.close();

        CsvParser parser = createParser();
        assertThat(parser.next(), is(true));
        assertThat(fill(parser, new StringOption()), is(new StringOption("a")));
        assertThat(fill(parser, new StringOption()), is(new StringOption("b")));
        assertThat(fill(parser, new StringOption()), is(new StringOption("c")));
        parser.endRecord();

        assertThat(parser.next(), is(false));
        parser.close();
    }
View Full Code Here

     * @throws Exception if failed
     */
    @Test
    public void multi_records() throws Exception {
        CsvEmitter emitter = createEmitter();
        emitter.emit(new StringOption("a"));
        emitter.endRecord();
        emitter.emit(new StringOption("b"));
        emitter.endRecord();
        emitter.emit(new StringOption("c"));
        emitter.endRecord();
        emitter.close();

        CsvParser parser = createParser();
        assertThat(parser.next(), is(true));
        assertThat(fill(parser, new StringOption()), is(new StringOption("a")));
        parser.endRecord();
        assertThat(parser.next(), is(true));
        assertThat(fill(parser, new StringOption()), is(new StringOption("b")));
        parser.endRecord();
        assertThat(parser.next(), is(true));
        assertThat(fill(parser, new StringOption()), is(new StringOption("c")));
        parser.endRecord();

        assertThat(parser.next(), is(false));
        parser.close();
    }
View Full Code Here

    public void string_values() throws Exception {
        CsvParser parser = create(
                "Hello,"
                + "\u3042\u3044\u3046\u3048\u304a,"
                + "\",\"\"\r\n\", ,");
        StringOption option = new StringOption();

        assertThat(parser.next(), is(true));

        parser.fill(option);
        assertThat(option.getAsString(), is("Hello"));

        parser.fill(option);
        assertThat(option.getAsString(), is("\u3042\u3044\u3046\u3048\u304a"));

        parser.fill(option);
        assertThat(option.getAsString(), is(",\"\r\n"));

        parser.fill(option);
        assertThat(option.getAsString(), is(" "));

        parser.fill(option);
        assertThat(option.isNull(), is(true));

        parser.endRecord();
        assertThat(parser.next(), is(false));
    }
View Full Code Here

        headers = Arrays.asList("key", "value");

        CsvParser parser = create(
                "key,value\r\n" +
                "hello,world\r\n");
        StringOption key = new StringOption();
        StringOption value = new StringOption();

        assertThat(parser.next(), is(true));
        assertThat(parser.getCurrentLineNumber(), is(2));
        assertThat(parser.getCurrentRecordNumber(), is(1));
        parser.fill(key);
        parser.fill(value);
        parser.endRecord();
        assertThat(parser.next(), is(false));

        assertThat(key.getAsString(), is("hello"));
        assertThat(value.getAsString(), is("world"));
    }
View Full Code Here

        headers = Arrays.asList("key", "data");

        CsvParser parser = create(
                "key,value\r\n" +
                "hello,world\r\n");
        StringOption key = new StringOption();
        StringOption value = new StringOption();

        assertThat(parser.next(), is(true));
        assertThat(parser.getCurrentLineNumber(), is(1));
        assertThat(parser.getCurrentRecordNumber(), is(1));
        parser.fill(key);
        parser.fill(value);
        parser.endRecord();
        assertThat(key.getAsString(), is("key"));
        assertThat(value.getAsString(), is("value"));

        assertThat(parser.next(), is(true));
        assertThat(parser.getCurrentLineNumber(), is(2));
        assertThat(parser.getCurrentRecordNumber(), is(2));
        parser.fill(key);
        parser.fill(value);
        parser.endRecord();
        assertThat(key.getAsString(), is("hello"));
        assertThat(value.getAsString(), is("world"));

        assertThat(parser.next(), is(false));
    }
View Full Code Here

        assertFill(parser, "x");
        parser.endRecord();

        try {
            assertThat(parser.next(), is(true));
            parser.fill(new StringOption());
            parser.endRecord();
            fail();
        } catch (CsvFormatException e) {
            assertThat(e.getStatus().getReason(), is(Reason.UNEXPECTED_EOF));
        }
View Full Code Here

        assertFill(parser, "\rx");
        parser.endRecord();

        try {
            assertThat(parser.next(), is(true));
            parser.fill(new StringOption("\r"));
            parser.endRecord();
            fail();
        } catch (CsvFormatException e) {
            assertThat(e.getStatus().getReason(), is(Reason.UNEXPECTED_EOF));
        }
View Full Code Here

        }

        CsvParser parser = create(buf.toString());

        assertThat(parser.next(), is(true));
        StringOption option = new StringOption();
        parser.fill(option);
        assertThat(option.getAsString().length(), is(characters));
        parser.endRecord();

        assertThat(parser.next(), is(false));
    }
View Full Code Here

     * 文字列を出力するテスト。
     * @throws Exception 例外が発生した場合
     */
    @Test
    public void emitString() throws Exception {
        StringOption value = new StringOption();

        value.modify("");
        emitter.emit(value);
        value.modify("Hello, world!");
        emitter.emit(value);
        value.modify("こんにちは、世界!");
        emitter.emit(value);
        emitter.endRecord();

        value.setNull();
        emitter.emit(value);
        value.modify("\n\t\\");
        emitter.emit(value);
        value.modify(LONG_STRING);
        emitter.emit(value);
        emitter.endRecord();

        emitter.close();

        RecordParser parser = parser();
        assertThat(parser.next(), is(true));
        parser.fill(value);
        assertThat(value.getAsString(), is(""));
        parser.fill(value);
        assertThat(value.getAsString(), is("Hello, world!"));
        parser.fill(value);
        assertThat(value.getAsString(), is("こんにちは、世界!"));

        assertThat(parser.next(), is(true));
        parser.fill(value);
        assertThat(value.isNull(), is(true));
        parser.fill(value);
        assertThat(value.getAsString(), is("\n\t\\"));
        parser.fill(value);
        assertThat(value.getAsString(), is(LONG_STRING));

        assertThat(parser.next(), is(false));
    }
View Full Code Here

TOP

Related Classes of com.asakusafw.runtime.value.StringOption

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.