-
Notifications
You must be signed in to change notification settings - Fork 1.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
GROOVY-9848: in
operator: key set membership for isCase(Map,Object)
#1904
base: master
Are you sure you want to change the base?
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 |
---|---|---|
|
@@ -19,11 +19,11 @@ | |
package groovy | ||
|
||
import groovy.test.GroovyTestCase | ||
import org.codehaus.groovy.util.StringUtil | ||
|
||
import java.awt.Dimension | ||
import java.nio.CharBuffer | ||
import java.util.concurrent.LinkedBlockingQueue | ||
import org.codehaus.groovy.util.StringUtil | ||
|
||
/** | ||
* Tests various GDK methods | ||
|
@@ -445,12 +445,6 @@ class GroovyMethodsTest extends GroovyTestCase { | |
assert map.size() == 2 | ||
} | ||
|
||
void testInForLists() { | ||
def list = ['a', 'b', 'c'] | ||
assert 'b' in list | ||
assert !('d' in list) | ||
} | ||
|
||
void testFirstLastHeadTailInitForLists() { | ||
def list = ['a', 'b', 'c'] | ||
assert 'a' == list.first() | ||
|
@@ -548,10 +542,71 @@ class GroovyMethodsTest extends GroovyTestCase { | |
assert list.size() == 3 | ||
} | ||
|
||
// GROOVY-9848 | ||
void testInForMaps() { | ||
assert 'foo' in [foo:true] | ||
assert 'foo' in [foo:null] | ||
assert 'bar' !in [foo:true] | ||
assert 'bar' !in [:].withDefault{ true } | ||
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. Again here I would use false as default to be more clear about the keys being used |
||
} | ||
|
||
void testInForSets() { | ||
def set = ['a', 'b', 'c'] as Set | ||
assert 'a' in set | ||
assert 'b' in set | ||
assert 'c' in set | ||
assert 'd' !in set | ||
assert !('d' in set) | ||
assert !(null in set) | ||
assert !(true in set) | ||
} | ||
|
||
void testInForLists() { | ||
def list = ['a', 'b', 'c'] | ||
assert 'a' in list | ||
assert 'b' in list | ||
assert 'c' in list | ||
assert 'd' !in list | ||
assert !('d' in list) | ||
assert !(null in list) | ||
assert !(true in list) | ||
} | ||
|
||
void testInForArrays() { | ||
String[] array = ['a', 'b', 'c'] | ||
def array = new String[]{'a', 'b', 'c'} | ||
assert 'a' in array | ||
assert 'b' in array | ||
assert 'c' in array | ||
assert 'd' !in array | ||
assert !('d' in array) | ||
assert !(null in array) | ||
assert !(true in array) | ||
} | ||
|
||
// GROOVY-2456 | ||
void testInForStrings() { | ||
def string = 'abc' | ||
shouldFail { assert 'a' in string } | ||
shouldFail { assert 'b' in string } | ||
shouldFail { assert 'c' in string } | ||
shouldFail { assert 'ab' in string } | ||
shouldFail { assert 'bc' in string } | ||
assert 'abc' in string | ||
assert !('d' in string) | ||
assert !(null in string) | ||
assert !(true in string) | ||
} | ||
|
||
// GROOVY-7919 | ||
void testInForIterables() { | ||
Iterable iter = { -> ['a','b','c'].iterator() } | ||
assert 'a' in iter | ||
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. actually it would be nice to do assert 'a' in iter twice to show that the second time it fails |
||
assert 'b' in iter | ||
assert 'c' in iter | ||
assert 'd' !in iter | ||
assert !('d' in iter) | ||
assert !(null in iter) | ||
assert !(true in iter) | ||
} | ||
|
||
void testMaxForIterable() { | ||
|
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.
To make it really clear I would go one step further and change [foo:true] to [foo:false]