-
Notifications
You must be signed in to change notification settings - Fork 24.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simpler regex constants in painless #68486
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,9 +59,9 @@ public void testPatternAfterUnaryNotBoolean() { | |
|
||
public void testInTernaryCondition() { | ||
assertEquals(true, exec("return /foo/.matcher('foo').matches() ? true : false")); | ||
assertEquals(1, exec("def i = 0; i += /foo/.matcher('foo').matches() ? 1 : 1; return i")); | ||
assertEquals(1, exec("def i = 0; i += /foo/.matcher('foo').matches() ? 1 : 0; return i")); | ||
assertEquals(true, exec("return 'foo' ==~ /foo/ ? true : false")); | ||
assertEquals(1, exec("def i = 0; i += 'foo' ==~ /foo/ ? 1 : 1; return i")); | ||
assertEquals(1, exec("def i = 0; i += 'foo' ==~ /foo/ ? 1 : 0; return i")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like a mistake. |
||
} | ||
|
||
public void testInTernaryTrueArm() { | ||
|
@@ -232,6 +232,30 @@ public void testReplaceFirstQuoteReplacement() { | |
exec("'the quick brown fox'.replaceFirst(/[aeiou]/, m -> '$' + m.group().toUpperCase(Locale.ROOT))")); | ||
} | ||
|
||
public void testStoreInMap() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it might be useful to have similar tests in the constant folding tests that verify that we fold constants in these positions. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could use the bytecode assertion for that kind of test. |
||
assertEquals(true, exec("Map m = [:]; m.a = /foo/; m.a.matcher('foo').matches()")); | ||
} | ||
|
||
public void testStoreInMapDef() { | ||
assertEquals(true, exec("def m = [:]; m.a = /foo/; m.a.matcher('foo').matches()")); | ||
} | ||
|
||
public void testStoreInList() { | ||
assertEquals(true, exec("List l = [null]; l.0 = /foo/; l.0.matcher('foo').matches()")); | ||
} | ||
|
||
public void testStoreInListDef() { | ||
assertEquals(true, exec("def l = [null]; l.0 = /foo/; l.0.matcher('foo').matches()")); | ||
} | ||
|
||
public void testStoreInArray() { | ||
assertEquals(true, exec("Pattern[] a = new Pattern[1]; a[0] = /foo/; a[0].matcher('foo').matches()")); | ||
} | ||
|
||
public void testStoreInArrayDef() { | ||
assertEquals(true, exec("def a = new Pattern[1]; a[0] = /foo/; a[0].matcher('foo').matches()")); | ||
} | ||
|
||
public void testCantUsePatternCompile() { | ||
IllegalArgumentException e = expectScriptThrows(IllegalArgumentException.class, () -> { | ||
exec("Pattern.compile('aa')"); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it correct to say this should never happen outside of bugs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct. I just wanted to get a better error message for my debugging. Is ok? Should I throw the exception in another way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's good. I just wanted to make sure I wasn't missing something user related.