mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-25 22:36:20 +00:00
painless: Improve string concat tests; add state machine check after MethodWriter
This commit is contained in:
parent
b27b0483d5
commit
b418d01117
@ -488,4 +488,12 @@ public final class MethodWriter extends GeneratorAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitEnd() {
|
||||
if (stringConcatArgs != null && !stringConcatArgs.isEmpty()) {
|
||||
throw new IllegalStateException("String concat bytecode not completed.");
|
||||
}
|
||||
super.visitEnd();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,6 +19,8 @@
|
||||
|
||||
package org.elasticsearch.painless;
|
||||
|
||||
import static org.elasticsearch.painless.WriterConstants.MAX_INDY_STRING_CONCAT_ARGS;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class StringTests extends ScriptTestCase {
|
||||
@ -70,15 +72,27 @@ public class StringTests extends ScriptTestCase {
|
||||
}
|
||||
|
||||
public void testAppendMany() {
|
||||
for (int i = MAX_INDY_STRING_CONCAT_ARGS - 5; i < MAX_INDY_STRING_CONCAT_ARGS + 5; i++) {
|
||||
doTestAppendMany(i);
|
||||
}
|
||||
}
|
||||
|
||||
private void doTestAppendMany(int count) {
|
||||
StringBuilder script = new StringBuilder("String s = \"cat\"; return s");
|
||||
StringBuilder result = new StringBuilder("cat");
|
||||
for (int i = 0; i < WriterConstants.MAX_INDY_STRING_CONCAT_ARGS + 10; i++) {
|
||||
final String s = String.format(Locale.ROOT, "%03d", i);
|
||||
for (int i = 1; i < count; i++) {
|
||||
final String s = String.format(Locale.ROOT, "%03d", i);
|
||||
script.append(" + '").append(s).append("'.toString()");
|
||||
result.append(s);
|
||||
}
|
||||
//System.out.println(Debugger.toString(script.toString()));
|
||||
assertEquals(result.toString(), exec(script.toString()));
|
||||
final String s = script.toString();
|
||||
assertTrue("every string part should be separatly pushed to stack.",
|
||||
Debugger.toString(s).contains(String.format(Locale.ROOT, "LDC \"%03d\"", count/2)));
|
||||
assertEquals(result.toString(), exec(s));
|
||||
}
|
||||
|
||||
public void testNestedConcats() {
|
||||
assertEquals("foo1010foo", exec("String s = 'foo'; String x = '10'; return s + Integer.parseInt(x + x) + s;"));
|
||||
}
|
||||
|
||||
public void testStringAPI() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user