001: package liquibase.util;
002:
003: import static org.junit.Assert.*;
004: import org.junit.Test;
005:
006: public class StringUtilsTest {
007:
008: @Test
009: public void noComments() {
010: String noComments = " Some text but no comments";
011: String result = StringUtils.stripComments(noComments);
012: assertEquals(noComments, result);
013: }
014:
015: @Test
016: public void singleLineNoNewLine() {
017: String sql = "Some text";
018: String comment = " -- with comment";
019: String totalLine = sql + comment;
020: String result = StringUtils.stripComments(totalLine);
021:
022: assertEquals(sql, result);
023: }
024:
025: @Test
026: public void singleLineNoFollowOnLine() {
027: String sql = "Some text";
028: String comment = " -- with comment\n";
029: String totalLine = sql + comment;
030: String result = StringUtils.stripComments(totalLine);
031:
032: assertEquals(sql + "\n", result);
033: }
034:
035: @Test
036: public void singleLineMultipleComments() {
037: String sql = "Some text";
038: String comment = " -- with comment";
039: String totalLine = sql + comment + "\n" + sql + comment;
040: String result = StringUtils.stripComments(totalLine);
041:
042: assertEquals(sql + "\n" + sql, result);
043: }
044:
045: @Test
046: public void singleLineWithFollowupLine() {
047: String sql = "Some text";
048: String comment = " -- with comment";
049: String totalLine = sql + comment + "\n" + sql;
050: String result = StringUtils.stripComments(totalLine);
051:
052: assertEquals(sql + "\n" + sql, result);
053: }
054:
055: @Test
056: public void multiLineOnOwnLine() {
057: String sql = "/*Some text\nmore text*/";
058:
059: String result = StringUtils.stripComments(sql);
060: assertEquals("\n", result);
061: }
062:
063: @Test
064: public void multiLineAfterSQL() {
065: String sql = "some sql";
066: String comment = "/*Some text\nmore text*/";
067: String total = sql + comment;
068: String result = StringUtils.stripComments(total);
069: assertEquals(sql + "\n", result);
070: }
071:
072: @Test
073: public void multiLineFinishesWithTextOnLine() {
074: String sql = "some sql";
075: String comment = "/*Some text\nmore text*/";
076: String total = comment + sql;
077: String result = StringUtils.stripComments(total);
078: assertEquals("\n" + sql, result);
079: }
080:
081: @Test
082: public void multiLineStartAndFinishWithSQL() {
083: String sql = "some sql";
084: String comment = "/*Some text\nmore text*/";
085: String total = sql + comment + sql;
086: String result = StringUtils.stripComments(total);
087: assertEquals(sql + "\n" + sql, result);
088: }
089:
090: @Test
091: public void shouldStripComments() {
092: String sql = "some sql";
093: String comment = "/*Some text\nmore text*/";
094: String total = sql + comment + sql;
095: String[] result = StringUtils.processMutliLineSQL(total, true);
096: assertEquals(1, result.length);
097: assertEquals(sql + "\n" + sql, result[0]);
098: }
099:
100: @Test
101: public void shouldNotStripComments() {
102: String sql = "some sql";
103: String comment = "/*Some text\nmore text*/";
104: String total = sql + comment + sql;
105: String[] result = StringUtils.processMutliLineSQL(total, false);
106: assertEquals(1, result.length);
107: assertEquals(total, result[0]);
108: }
109:
110: @Test
111: public void splitOngo() {
112: String sql = "some sql\ngo\nmore sql";
113: String[] result = StringUtils.splitSQL(sql);
114: assertEquals(2, result.length);
115: assertEquals("some sql", result[0]);
116: assertEquals("more sql", result[1]);
117: }
118:
119: @Test
120: public void splitOnGO() {
121: String sql = "some sql\nGO\nmore sql";
122: String[] result = StringUtils.splitSQL(sql);
123: assertEquals(2, result.length);
124: assertEquals("some sql", result[0]);
125: assertEquals("more sql", result[1]);
126: }
127: }
|