Android Open Source - SQLiteMigrationManager S Q L Parser Tests






From Project

Back to project page SQLiteMigrationManager.

License

The source code is released under:

Apache License

If you think the Android project SQLiteMigrationManager listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.layer.sqlite;
//  www . j a v a2s.co m
import android.test.AndroidTestCase;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.List;

import static org.fest.assertions.api.Assertions.assertThat;

public class SQLParserTests extends AndroidTestCase {
    public void testParseSingleNoComments() throws Exception {
        String statement = "statement1;\ncontinued;";
        InputStream in = new ByteArrayInputStream(statement.getBytes("UTF-8"));

        List<String> parsed = SQLParser.Statements.fromStream(in);
        assertThat(parsed).hasSize(1);
        assertThat(parsed.get(0)).isEqualTo("statement1;\ncontinued;");
    }

    public void testParseMultipleNoComments() throws Exception {
        String statement = "statement1;\n\nstatement2;";
        InputStream in = new ByteArrayInputStream(statement.getBytes("UTF-8"));

        List<String> parsed = SQLParser.Statements.fromStream(in);
        assertThat(parsed).hasSize(2);
        assertThat(parsed.get(0)).isEqualTo("statement1;");
        assertThat(parsed.get(1)).isEqualTo("statement2;");
    }

    public void testParseLineComment() throws Exception {
        String statement = "statement1;\n  --comment1 \n statement2;";
        InputStream in = new ByteArrayInputStream(statement.getBytes("UTF-8"));

        List<String> parsed = SQLParser.Statements.fromStream(in);
        assertThat(parsed).hasSize(2);
        assertThat(parsed.get(0)).isEqualTo("statement1;");
        assertThat(parsed.get(1)).isEqualTo("statement2;");
    }

    public void testParseBlockComment() throws Exception {
        String statement
                = "statement1;\n/* comment1 */ /* comment2\n ** continued */\n statement2; /*comment3 /* */continued";
        InputStream in = new ByteArrayInputStream(statement.getBytes("UTF-8"));

        List<String> parsed = SQLParser.Statements.fromStream(in);
        assertThat(parsed).hasSize(2);
        assertThat(parsed.get(0)).isEqualTo("statement1;");
        assertThat(parsed.get(1)).isEqualTo("statement2; continued");
    }
}




Java Source Code List

com.layer.sqlite.Fixtures.java
com.layer.sqlite.ResourceDataSourceTests.java
com.layer.sqlite.SQLParserTests.java
com.layer.sqlite.SQLParser.java
com.layer.sqlite.SQLiteMigrationManagerTests.java
com.layer.sqlite.SQLiteMigrationManager.java
com.layer.sqlite.datasource.DataSource.java
com.layer.sqlite.datasource.ResourceDataSource.java
com.layer.sqlite.migrations.Migration.java
com.layer.sqlite.migrations.ResourceMigration.java
com.layer.sqlite.schema.ResourceSchema.java
com.layer.sqlite.schema.Schema.java