How to use containsKeywordsAtOffset method of org.testcontainers.ext.ScriptUtils class

Best Testcontainers-java code snippet using org.testcontainers.ext.ScriptUtils.containsKeywordsAtOffset

Source:ScriptUtils.java Github

copy

Full Screen

...144 if (!inLiteral && inBlockComment && containsSubstringAtOffset(lowerCaseScriptContent, blockCommentEndDelimiter, i)) {145 inBlockComment = false;146 }147 final boolean inComment = inLineComment || inBlockComment;148 if (!inLiteral && !inComment && containsKeywordsAtOffset(lowerCaseScriptContent, "BEGIN", i, separator, commentPrefix, blockCommentStartDelimiter)) {149 compoundStatementDepth++;150 }151 if (!inLiteral && !inComment && containsKeywordsAtOffset(lowerCaseScriptContent, "END", i, separator, commentPrefix, blockCommentStartDelimiter)) {152 compoundStatementDepth--;153 }154 final boolean inCompoundStatement = compoundStatementDepth != 0;155 if (!inLiteral && !inCompoundStatement) {156 if (script.startsWith(separator, i)) {157 // we've reached the end of the current statement158 sb = flushStringBuilder(sb, statements);159 i += separator.length() - 1;160 continue;161 }162 else if (script.startsWith(commentPrefix, i)) {163 // skip over any content from the start of the comment to the EOL164 int indexOfNextNewline = script.indexOf("\n", i);165 if (indexOfNextNewline > i) {166 i = indexOfNextNewline;167 continue;168 }169 else {170 // if there's no EOL, we must be at the end171 // of the script, so stop here.172 break;173 }174 }175 else if (script.startsWith(blockCommentStartDelimiter, i)) {176 // skip over any block comments177 int indexOfCommentEnd = script.indexOf(blockCommentEndDelimiter, i);178 if (indexOfCommentEnd > i) {179 i = indexOfCommentEnd + blockCommentEndDelimiter.length() - 1;180 inBlockComment = false;181 continue;182 }183 else {184 throw new ScriptParseException(String.format("Missing block comment end delimiter [%s].",185 blockCommentEndDelimiter), resource);186 }187 }188 else if (c == ' ' || c == '\n' || c == '\t' || c == '\r') {189 // avoid multiple adjacent whitespace characters190 if (sb.length() > 0 && sb.charAt(sb.length() - 1) != ' ') {191 c = ' ';192 }193 else {194 continue;195 }196 }197 }198 sb.append(c);199 }200 flushStringBuilder(sb, statements);201 }202 private static StringBuilder flushStringBuilder(StringBuilder sb, List<String> statements) {203 if (sb.length() == 0) {204 return sb;205 }206 final String s = sb.toString().trim();207 if (StringUtils.isNotEmpty(s)) {208 statements.add(s);209 }210 return new StringBuilder();211 }212 private static boolean isSeperator(char c, String separator, String commentPrefix,213 String blockCommentStartDelimiter) {214 return c == ' ' || c == '\r' || c == '\n' || c == '\t' ||215 c == separator.charAt(0) || c == separator.charAt(separator.length() - 1) ||216 c == commentPrefix.charAt(0) || c == blockCommentStartDelimiter.charAt(0) ||217 c == blockCommentStartDelimiter.charAt(blockCommentStartDelimiter.length() - 1);218 }219 private static boolean containsSubstringAtOffset(String lowercaseString, String substring, int offset) {220 String lowercaseSubstring = substring.toLowerCase();221 return lowercaseString.startsWith(lowercaseSubstring, offset);222 }223 private static boolean containsKeywordsAtOffset(String lowercaseString, String keywords, int offset,224 String separator, String commentPrefix,225 String blockCommentStartDelimiter) {226 String lowercaseKeywords = keywords.toLowerCase();227 boolean backSeperated = (offset == 0) || isSeperator(lowercaseString.charAt(offset - 1),228 separator, commentPrefix, blockCommentStartDelimiter);229 boolean frontSeperated = (offset >= (lowercaseString.length() - keywords.length())) ||230 isSeperator(lowercaseString.charAt(offset + keywords.length()),231 separator, commentPrefix, blockCommentStartDelimiter);232 return backSeperated && frontSeperated && lowercaseString.startsWith(lowercaseKeywords, offset);233 }234 private static void checkArgument(boolean expression, String errorMessage) {235 if (!expression) {236 throw new IllegalArgumentException(errorMessage);237 }...

Full Screen

Full Screen

containsKeywordsAtOffset

Using AI Code Generation

copy

Full Screen

1import org.testcontainers.ext.ScriptUtils2assert ScriptUtils.containsKeywordsAtOffset(sql, "SELECT", 0)3assert ScriptUtils.containsKeywordsAtOffset(sql, "FROM", 13)4assert ScriptUtils.containsKeywordsAtOffset(sql, "WHERE", 22)5assert !ScriptUtils.containsKeywordsAtOffset(sql, "WHERE", 21)6assert ScriptUtils.containsKeywordsAtOffset(sql, "SELECT", 0)7assert ScriptUtils.containsKeywordsAtOffset(sql, "SELECT", 1)8assert ScriptUtils.containsKeywordsAtOffset(sql, "SELECT", 2)9assert ScriptUtils.containsKeywordsAtOffset(sql, "SELECT", 3)10assert ScriptUtils.containsKeywordsAtOffset(sql, "SELECT", 4)11assert !ScriptUtils.containsKeywordsAtOffset(sql, "SELECT", 5)12assert !ScriptUtils.containsKeywordsAtOffset(sql, "SELECT", 6)13assert ScriptUtils.containsKeywordsAtOffset(sql, "FROM", 12)14assert ScriptUtils.containsKeywordsAtOffset(sql, "FROM", 13)15assert ScriptUtils.containsKeywordsAtOffset(sql, "FROM", 14)16assert ScriptUtils.containsKeywordsAtOffset(sql, "FROM", 15)17assert ScriptUtils.containsKeywordsAtOffset(sql, "FROM", 16)18assert !ScriptUtils.containsKeywordsAtOffset(sql, "FROM", 17)19assert !ScriptUtils.containsKeywordsAtOffset(sql, "FROM", 18)20assert ScriptUtils.containsKeywordsAtOffset(sql, "WHERE", 21)21assert ScriptUtils.containsKeywordsAtOffset(sql, "WHERE", 22)22assert ScriptUtils.containsKeywordsAtOffset(sql, "WHERE", 23)23assert ScriptUtils.containsKeywordsAtOffset(sql, "WHERE", 24)24assert ScriptUtils.containsKeywordsAtOffset(sql, "WHERE", 25)25assert !ScriptUtils.containsKeywordsAtOffset(sql, "WHERE", 26)26assert !ScriptUtils.containsKeywordsAtOffset(sql, "WHERE", 27)27assert ScriptUtils.containsKeywordsAtOffset(sql, "John", 23)28assert ScriptUtils.containsKeywordsAtOffset(sql, "John", 24)29assert ScriptUtils.containsKeywordsAtOffset(sql, "John", 25)30assert ScriptUtils.containsKeywordsAtOffset(sql, "John", 26)31assert !ScriptUtils.containsKeywordsAtOffset(sql, "John", 27)32assert !ScriptUtils.containsKeywordsAtOffset(sql, "John", 28)

Full Screen

Full Screen

containsKeywordsAtOffset

Using AI Code Generation

copy

Full Screen

1import org.testcontainers.containers.PostgreSQLContainer2import org.testcontainers.ext.ScriptUtils3def db = new PostgreSQLContainer()4db.start()5def script = "create table foo (bar text);"6assert ScriptUtils.containsKeywordsAtOffset(script, "create".length(), 0, "create")7assert !ScriptUtils.containsKeywordsAtOffset(script, "create".length(), 0, "table")8assert ScriptUtils.containsKeywordsAtOffset(scriptWithComment, "create".length(), 0, "create")9assert !ScriptUtils.containsKeywordsAtOffset(scriptWithComment, "create".length(), 0, "table")10assert ScriptUtils.containsKeywordsAtOffset(scriptWithComment, "create".length(), "/* this is a comment */\n".length(), "create")11assert !ScriptUtils.containsKeywordsAtOffset(scriptWithComment, "create".length(), "/* this is a comment */\n".length(), "table")12db.stop()13assert ScriptUtils.containsKeywordsAtOffset(script, "create".length(), 0, "create")14assert ScriptUtils.containsKeywordsAtOffset(script, "create".length(), 0, "create")15assert ScriptUtils.containsKeywordsAtOffset(script, "create".length(), 0, "create")16assert ScriptUtils.containsKeywordsAtOffset(script, "create".length(),

Full Screen

Full Screen

containsKeywordsAtOffset

Using AI Code Generation

copy

Full Screen

1import org.testcontainers.ext.ScriptUtils2if (ScriptUtils.containsKeywordsAtOffset(sql, offset, keywords)) {3 def newSql = ScriptUtils.replaceKeywordsAtOffset(sql, offset, keywords, values)4}5else {6}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful