forked from testcontainers/testcontainers-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix bugs introduced by testcontainers#7646
- Loading branch information
1 parent
d80ce60
commit 46f03d2
Showing
3 changed files
with
99 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
modules/database-commons/src/main/java/org/testcontainers/ext/Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.testcontainers.ext; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.ArrayList; | ||
import java.util.stream.Collectors; | ||
|
||
public class Test { | ||
public static void main(String[] args) throws IOException { | ||
Path p = Paths.get("C:\\ideaspace\\synthesized\\testing-suite\\engine\\executor\\src\\e2e\\resources\\testspecs\\mysql\\prepare_test_data.sql"); | ||
|
||
String s = Files.lines(p).collect(Collectors.joining("\n")); | ||
ArrayList<String> l = new ArrayList<>(); | ||
ScriptUtils.splitSqlScript("a", s, ";", | ||
ScriptUtils.DEFAULT_COMMENT_PREFIX, ScriptUtils.DEFAULT_BLOCK_COMMENT_START_DELIMITER, | ||
ScriptUtils.DEFAULT_BLOCK_COMMENT_END_DELIMITER, l); | ||
l.forEach(line -> { | ||
System.out.println(line); | ||
System.out.println("----"); | ||
}); | ||
|
||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
modules/database-commons/src/test/java/org/testcontainers/ext/ScriptScannerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package org.testcontainers.ext; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.junit.Test; | ||
|
||
import java.util.regex.Pattern; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class ScriptScannerTest { | ||
@Test | ||
public void testHugeStringLiteral() { | ||
String script = "/* a comment */ \"" + StringUtils.repeat('~', 10000) + "\";"; | ||
ScriptScanner scanner = scanner(script); | ||
assertThat(scanner.next()).isEqualTo(ScriptScanner.Lexem.COMMENT); | ||
assertThat(scanner.next()).isEqualTo(ScriptScanner.Lexem.WHITESPACE); | ||
assertThat(scanner.next()).isEqualTo(ScriptScanner.Lexem.QUOTED_STRING); | ||
assertThat(scanner.getCurrentMatch()).matches(Pattern.compile("\"~+\"")); | ||
} | ||
|
||
@Test | ||
public void testPgIdentifierWithDollarSigns() { | ||
ScriptScanner scanner = scanner("this$is$a$valid$postgreSQL$identifier " + | ||
"$a$While this is a quoted string$a$$ --just followed by a dollar sign"); | ||
assertThat(scanner.next()).isEqualTo(ScriptScanner.Lexem.IDENTIFIER); | ||
assertThat(scanner.next()).isEqualTo(ScriptScanner.Lexem.WHITESPACE); | ||
assertThat(scanner.next()).isEqualTo(ScriptScanner.Lexem.QUOTED_STRING); | ||
assertThat(scanner.next()).isEqualTo(ScriptScanner.Lexem.OTHER); | ||
} | ||
|
||
@Test | ||
public void testQuotedLiterals(){ | ||
ScriptScanner scanner = scanner("'this \\'is a literal' \"this \\\" is a literal\""); | ||
assertThat(scanner.next()).isEqualTo(ScriptScanner.Lexem.QUOTED_STRING); | ||
assertThat(scanner.getCurrentMatch()).isEqualTo("'this \\'is a literal'"); | ||
assertThat(scanner.next()).isEqualTo(ScriptScanner.Lexem.WHITESPACE); | ||
assertThat(scanner.next()).isEqualTo(ScriptScanner.Lexem.QUOTED_STRING); | ||
assertThat(scanner.getCurrentMatch()).isEqualTo("\"this \\\" is a literal\""); | ||
} | ||
|
||
private static ScriptScanner scanner(String script) { | ||
return new ScriptScanner("dummy", | ||
script, | ||
ScriptUtils.DEFAULT_STATEMENT_SEPARATOR, | ||
ScriptUtils.DEFAULT_COMMENT_PREFIX, | ||
ScriptUtils.DEFAULT_BLOCK_COMMENT_START_DELIMITER, | ||
ScriptUtils.DEFAULT_BLOCK_COMMENT_END_DELIMITER); | ||
} | ||
} |