@Test public void fileWithOneCommand_script() { Scriptum scriptum1 = Scriptum.of(ScriptumBasicTest.class, "FileWithOneCommand"); SqlScript script = scriptum1.script("TheCommand"); assertThat(script).isNotNull(); assertThat(script.count()).isEqualTo(1); List<? extends SqlStatement> statements = script.getStatements(); SqlStatement statement = statements.get(0); assertThat(statement.getSourceText()).contains("select something", "from some_table"); }
@Test public void parse_multiLineComment_3() { String text = "/* \n" + " * a multi-line comment \n" + " */ \n" + "do something \n"; final SqlScript script = build(text); assertThat(script.count()).isEqualTo(1); assertThat(script.getStatements().get(0).getSourceText()).isEqualTo("do something"); }
@Test public void parse_multiLineComment_1() { String text = "/* a multi-line comment*/\n" + "do something"; final SqlScript script = build(text); assertThat(script.count()).isEqualTo(1); assertThat(script.getStatements().get(0).getSourceText()).isEqualTo("do something"); }
@Test public void parse_singleLineComment() { String text = "-- a single line comment \n" + "do something"; final SqlScript script = build(text); assertThat(script.count()).isEqualTo(1); assertThat(script.getStatements().get(0).getSourceText()).isEqualTo("do something"); }
@Test public void parse_multiLineComment_preserveOracleHint() { String text = "select /*+index(i)*/ * \n" + "from table \n"; final SqlScript script = build(text); assertThat(script.count()).isEqualTo(1); final String queryText = script.getStatements().get(0).getSourceText(); assertThat(queryText).contains("/*+index(i)*/"); }
@Test public void parse_2_in_2_lines() { String text = "create table X;\n drop table X"; final SqlScript script = build(text); assertThat(script.count()).isEqualTo(2); assertThat(script.getStatements().get(0).getSourceText()).isEqualTo("create table X"); assertThat(script.getStatements().get(1).getSourceText()).isEqualTo("drop table X"); }
@Test public void parse_singleLineComment_preserveOracleHint() { String text = "select --+index(i) \n" + " all fields \n" + "from my_table \n"; final SqlScript script = build(text); assertThat(script.hasStatements()).isTrue(); assertThat(script.count()).isEqualTo(1); final String queryText = script.getStatements().get(0).getSourceText(); assertThat(queryText).contains("--+index(i)"); }