1 19 20 package org.netbeans.modules.db.sql.execute; 21 22 import org.netbeans.junit.NbTestCase; 23 24 28 public class SQLExecuteHelperTest extends NbTestCase { 29 30 public SQLExecuteHelperTest(String testName) { 31 super(testName); 32 } 33 34 public void testSplit() { 35 assertSplit("select --line\n from dual", "select from dual"); 37 assertSplit("select ----line\n from dual", "select from dual"); 38 assertSplit("select --line from dual", "select"); 39 40 assertSplit("select /* block */ from dual", "select from dual"); 42 assertSplit("select ///* block */ from dual", "select // from dual"); 43 assertSplit("select /* block * block ***/ from dual", "select from dual"); 44 assertSplit("select /* block from dual", "select"); 45 assertSplit("select a - b / c from dual", "select a - b / c from dual"); 46 assertSplit("select 'foo /* bar */ -- baz' from dual", "select 'foo /* bar */ -- baz' from dual"); 47 48 assertSplit("select --comment; \n foo", "select foo"); 50 assertSplit("select /* ; */ foo", "select foo"); 51 52 assertSplit(" ;; ; ", new String [0]); 54 assertSplit("/* comment */ select foo; /* comment */ select bar -- comment", new String [] { "select foo", "select bar" }); 55 56 String test = " select foo ; select /* comment */bar;\n select baz -- comment"; 58 assertSplit(test, new StatementInfo[] { 60 new StatementInfo("select foo", 2, 0, 2, 12), 61 new StatementInfo("select bar", 18, 0, 18, 41), 62 new StatementInfo("select baz", 46, 1, 3, 56), 63 }); 64 } 65 66 private static void assertSplit(String script, String expected) { 67 assertSplit(script, new String [] { expected }); 68 } 69 70 private static void assertSplit(String script, String [] expected) { 71 StatementInfo[] stmts = (StatementInfo[])SQLExecuteHelper.split(script).toArray(new StatementInfo[0]); 72 assertEquals(expected.length, stmts.length); 73 for (int i = 0; i < expected.length; i++) { 74 assertEquals(expected[i], stmts[i].getSQL()); 75 } 76 } 77 78 private static void assertSplit(String script, StatementInfo[] expected) { 79 StatementInfo[] stmts = (StatementInfo[])SQLExecuteHelper.split(script).toArray(new StatementInfo[0]); 80 assertEquals(expected.length, stmts.length); 81 for (int i = 0; i < expected.length; i++) { 82 assertEquals(expected[i].getSQL(), stmts[i].getSQL()); 83 assertEquals(expected[i].getStartOffset(), stmts[i].getStartOffset()); 84 assertEquals(expected[i].getStartLine(), stmts[i].getStartLine()); 85 assertEquals(expected[i].getStartColumn(), stmts[i].getStartColumn()); 86 assertEquals(expected[i].getEndOffset(), stmts[i].getEndOffset()); 87 } 88 } 89 } 90 | Popular Tags |