diff options
author | Florian Weikert <fwe@google.com> | 2015-12-16 12:38:38 +0000 |
---|---|---|
committer | Damien Martin-Guillerez <dmarting@google.com> | 2015-12-16 12:56:06 +0000 |
commit | 233a46e905f9d1fab490fd4ffebf0959d9e94bec (patch) | |
tree | a5424d8313bd4986fce6b5d30acd47e1ee833103 /src/test | |
parent | 3e08d11ba6c3368a5687f609cb9040cf2a11bd6e (diff) |
Skylark: implemented all() and any()
--
MOS_MIGRATED_REVID=110348607
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/syntax/EvalUtilsTest.java | 10 | ||||
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java | 87 |
2 files changed, 96 insertions, 1 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/EvalUtilsTest.java b/src/test/java/com/google/devtools/build/lib/syntax/EvalUtilsTest.java index 6a6bf70a7b..f5cb497f67 100644 --- a/src/test/java/com/google/devtools/build/lib/syntax/EvalUtilsTest.java +++ b/src/test/java/com/google/devtools/build/lib/syntax/EvalUtilsTest.java @@ -49,6 +49,16 @@ public class EvalUtilsTest { } @Test + public void testEmptyStringToIterable() throws Exception { + assertThat(EvalUtils.toIterable("", null)).isEmpty(); + } + + @Test + public void testStringToIterable() throws Exception { + assertThat(EvalUtils.toIterable("abc", null)).hasSize(3); + } + + @Test public void testDataTypeNames() throws Exception { assertEquals("string", EvalUtils.getDataTypeName("foo")); assertEquals("int", EvalUtils.getDataTypeName(3)); diff --git a/src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java b/src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java index de20fc2f7e..f649ce2ab1 100644 --- a/src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java +++ b/src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java @@ -266,6 +266,91 @@ public class MethodLibraryTest extends EvaluationTestCase { } @Test + public void testAllWithEmptyValue() throws Exception { + new SkylarkTest() + .testStatement("all('')", true) + .testStatement("all([])", true) + .testIfExactError("type 'NoneType' is not iterable", "any(None)"); + } + + @Test + public void testAllWithPrimitiveType() throws Exception { + new SkylarkTest() + .testStatement("all('test')", true) + .testIfErrorContains("", "all(1)"); + } + + @Test + public void testAllWithList() throws Exception { + new SkylarkTest() + .testStatement("all([False])", false) + .testStatement("all([True, False])", false) + .testStatement("all([False, False])", false) + .testStatement("all([False, True])", false) + .testStatement("all(['', True])", false) + .testStatement("all([0, True])", false) + .testStatement("all([[], True])", false) + .testStatement("all([True, 't', 1])", true); + } + + @Test + public void testAllWithSet() throws Exception { + new SkylarkTest() + .testStatement("all(set([0]))", false) + .testStatement("all(set([1, 0]))", false) + .testStatement("all(set([1]))", true); + } + + @Test + public void testAllWithDict() throws Exception { + new SkylarkTest() + .testStatement("all({1 : None})", true) + .testStatement("all({None : 1})", false); + } + + @Test + public void testAnyWithEmptyValue() throws Exception { + new SkylarkTest() + .testStatement("any('')", false) + .testStatement("any([])", false) + .testIfExactError("type 'NoneType' is not iterable", "any(None)"); + } + + @Test + public void testAnyWithPrimitiveType() throws Exception { + new SkylarkTest() + .testStatement("any('test')", true) + .testIfErrorContains("", "any(1)"); + } + + @Test + public void testAnyWithList() throws Exception { + new SkylarkTest() + .testStatement("any([False])", false) + .testStatement("any([0])", false) + .testStatement("any([''])", false) + .testStatement("any([[]])", false) + .testStatement("any([True, False])", true) + .testStatement("any([False, False])", false) + .testStatement("any([False, '', 0])", false) + .testStatement("any([False, '', 42])", true); + } + + @Test + public void testAnyWithSet() throws Exception { + new SkylarkTest() + .testStatement("any(set([0]))", false) + .testStatement("any(set([1, 0]))", true); + } + + @Test + public void testAnyWithDict() throws Exception { + new SkylarkTest() + .testStatement("any({1 : None, '' : None})", true) + .testStatement("any({None : 1, '' : 2})", false); + } + + @Test public void testStackTraceLocation() throws Exception { new SkylarkTest().testIfErrorContains( "Traceback (most recent call last):\n\t" @@ -867,7 +952,7 @@ public class MethodLibraryTest extends EvaluationTestCase { @Test public void testReversedWithStrings() throws Exception { new BothModesTest() - .testEval("reversed('')", "['']") + .testEval("reversed('')", "[]") .testEval("reversed('a')", "['a']") .testEval("reversed('abc')", "['c', 'b', 'a']") .testEval("reversed('__test ')", "[' ', ' ', 't', 's', 'e', 't', '_', '_']") |