diff options
author | Laurent Le Brun <laurentlb@google.com> | 2015-05-18 13:11:05 +0000 |
---|---|---|
committer | Damien Martin-Guillerez <dmarting@google.com> | 2015-05-18 20:00:03 +0000 |
commit | b4c5474cec6f92df0c9e8b2a789d67f5ae6a56b6 (patch) | |
tree | a7cf4058783025fd682e8271326bbbceed1ef797 /src/test | |
parent | 717a5590bfc71890dfdd57e5390492beeef22561 (diff) |
Allow if filtering in list comprehensions
--
MOS_MIGRATED_REVID=93881507
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/syntax/EvaluationTest.java | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/EvaluationTest.java b/src/test/java/com/google/devtools/build/lib/syntax/EvaluationTest.java index b410fa03da..b3e5bcff48 100644 --- a/src/test/java/com/google/devtools/build/lib/syntax/EvaluationTest.java +++ b/src/test/java/com/google/devtools/build/lib/syntax/EvaluationTest.java @@ -394,6 +394,29 @@ public class EvaluationTest extends EvaluationTestCase { } @Test + public void testListComprehensionsWithFiltering() throws Exception { + eval("range3 = [0, 1, 2]"); // used below + + assertThat(eval("[a for a in (4, None, 2, None, 1) if a != None]").toString()) + .isEqualTo("[4, 2, 1]"); + assertThat(eval("[b+c for b in [0, 1, 2] for c in [0, 1, 2] if b + c > 2]").toString()) + .isEqualTo("[3, 3, 4]"); + assertThat(eval("[d+e for d in range3 if d % 2 == 1 for e in range3]").toString()) + .isEqualTo("[1, 2, 3]"); + assertThat(eval( + "[[f,g] for f in [0, 1, 2, 3, 4] if f for g in [5, 6, 7, 8] if f * g % 12 == 0 ]") + .toString()).isEqualTo("[[2, 6], [3, 8], [4, 6]]"); + assertThat(eval("[h for h in [4, 2, 0, 1] if h]").toString()) + .isEqualTo("[4, 2, 1]"); + } + + @Test + public void testListComprehensionDefinitionOrder() throws Exception { + checkEvalErrorContains("name 'y' is not defined", + "[x for x in (1, 2) if y for y in (3, 4)]"); + } + + @Test public void testTupleDestructuring() throws Exception { eval("a, b = 1, 2"); assertThat(lookup("a")).isEqualTo(1); |