This repository has been archived by the owner on May 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 512
METRON-656: Make Stellar 'in' closer to functioning like python #416
Closed
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
98d9b94
METRON-656: Add String Contains to Stellar
cestella 931589e
METRON-656: Make Stellar 'in' closer to functioning like python
cestella 23c1988
Merge branch 'master' into METRON-656
cestella 36505e3
Better testing
cestella 0aa056f
Removed extraneous added newline
cestella ca08079
Updated tests.
cestella e88b5d4
Updating to handle default cases
cestella 80081c7
Updating docs.
cestella d929c37
updating
cestella File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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 |
---|---|---|
|
@@ -402,19 +402,58 @@ public void testBooleanOps() throws Exception { | |
} | ||
|
||
@Test | ||
public void testList() throws Exception { | ||
public void testInCollection() throws Exception { | ||
final Map<String, String> variableMap = new HashMap<String, String>() {{ | ||
put("foo", "casey"); | ||
put("empty", ""); | ||
put("spaced", "metron is great"); | ||
}}; | ||
Assert.assertTrue(runPredicate("foo in [ 'casey', 'david' ]", v -> variableMap.get(v))); | ||
Assert.assertFalse(runPredicate("foo in [ ]", v -> variableMap.get(v))); | ||
Assert.assertTrue(runPredicate("foo in [ foo, 'david' ]", v -> variableMap.get(v))); | ||
Assert.assertTrue(runPredicate("foo in [ 'casey', 'david' ] and 'casey' == foo", v -> variableMap.get(v))); | ||
Assert.assertTrue(runPredicate("foo in [ 'casey', 'david' ] and foo == 'casey'", v -> variableMap.get(v))); | ||
Assert.assertTrue(runPredicate("foo in [ 'casey' ]", v -> variableMap.get(v))); | ||
Assert.assertFalse(runPredicate("foo not in [ 'casey', 'david' ]", v -> variableMap.get(v))); | ||
Assert.assertFalse(runPredicate("foo not in [ 'casey', 'david' ] and 'casey' == foo", v -> variableMap.get(v))); | ||
Assert.assertTrue(runPredicate("null in [ null, 'something' ]", v -> variableMap.get(v))); | ||
Assert.assertFalse(runPredicate("null not in [ null, 'something' ]", v -> variableMap.get(v))); | ||
} | ||
|
||
@Test | ||
public void testInMap() throws Exception { | ||
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. Can we add a couple test cases for String values?
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. Sure thing. Done, let me know what you think about them. 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. Looks great! +1 |
||
final Map<String, String> variableMap = new HashMap<String, String>() {{ | ||
put("foo", "casey"); | ||
put("empty", ""); | ||
}}; | ||
Assert.assertTrue(runPredicate("'casey' in { foo : 5 }", v -> variableMap.get(v))); | ||
Assert.assertFalse(runPredicate("'casey' not in { foo : 5 }", v -> variableMap.get(v))); | ||
Assert.assertTrue(runPredicate("foo in { foo : 5 }", v -> variableMap.get(v))); | ||
Assert.assertFalse(runPredicate("foo not in { foo : 5 }", v -> variableMap.get(v))); | ||
Assert.assertTrue(runPredicate("'foo' in { 'foo' : 5 }", v -> variableMap.get(v))); | ||
Assert.assertFalse(runPredicate("'foo' not in { 'foo' : 5 }", v -> variableMap.get(v))); | ||
Assert.assertTrue(runPredicate("foo in { 'casey' : 5 }", v -> variableMap.get(v))); | ||
Assert.assertFalse(runPredicate("foo not in { 'casey' : 5 }", v -> variableMap.get(v))); | ||
Assert.assertFalse(runPredicate("empty in { foo : 5 }", v -> variableMap.get(v))); | ||
Assert.assertTrue(runPredicate("empty not in { foo : 5 }", v -> variableMap.get(v))); | ||
Assert.assertFalse(runPredicate("'foo' in { }", v -> variableMap.get(v))); | ||
Assert.assertFalse(runPredicate("null in { 'foo' : 5 }", v -> variableMap.get(v))); | ||
Assert.assertTrue(runPredicate("null not in { 'foo' : 5 }", v -> variableMap.get(v))); | ||
} | ||
|
||
@Test | ||
public void testInString() throws Exception { | ||
final Map<String, String> variableMap = new HashMap<String, String>() {{ | ||
put("foo", "casey"); | ||
put("empty", ""); | ||
}}; | ||
Assert.assertTrue(runPredicate("'case' in foo", v -> variableMap.get(v))); | ||
Assert.assertFalse(runPredicate("'case' not in foo", v -> variableMap.get(v))); | ||
Assert.assertFalse(runPredicate("'case' in empty", v -> variableMap.get(v))); | ||
Assert.assertTrue(runPredicate("'case' not in empty", v -> variableMap.get(v))); | ||
Assert.assertFalse(runPredicate("'case' in [ foo ]", v -> variableMap.get(v))); | ||
Assert.assertTrue(runPredicate("'case' not in [ foo ]", v -> variableMap.get(v))); | ||
Assert.assertFalse(runPredicate("null in foo", v -> variableMap.get(v))); | ||
Assert.assertTrue(runPredicate("null not in foo", v -> variableMap.get(v))); | ||
} | ||
|
||
@Test | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Sorry, one last comment. I was a bit curious as to how the expression
'grok' not in 'foobar' == true
would be evaluated by Stellar. I wasn't sure if it would be'(grok' not in 'foobar') == true
or'grok' not in ('foobar' == true)
. Unfortunately when I tried to run a test it said it is not a valid expression. I think this may be an issue in the Stellar grammar. It is probably outside the scope of this ticket, but I thought I should mention it here.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.
Yeah, that's a stellar language bug.
('grok' not in 'foobar') == true
should work.