aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java
diff options
context:
space:
mode:
authorGravatar Florian Weikert <fwe@google.com>2015-12-11 21:54:43 +0000
committerGravatar David Chen <dzc@google.com>2015-12-13 18:27:40 +0000
commit5e8752b64acf3b5d5ae0a8929f20119e1281628a (patch)
tree3984fb9e7129606ea5090b8bb2dd7aeb8572bc02 /src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java
parent1812967ba20266cae559bf117f0efc8e32d43fcf (diff)
Skylark: implemented min() and max().
-- MOS_MIGRATED_REVID=110025690
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java')
-rw-r--r--src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java106
1 files changed, 106 insertions, 0 deletions
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 76f46bfa35..e76471cf6d 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
@@ -40,6 +40,112 @@ public class MethodLibraryTest extends EvaluationTestCase {
}
@Test
+ public void testMinWithInvalidArgs() throws Exception {
+ new SkylarkTest()
+ .testIfExactError("type 'int' is not iterable", "min(1)")
+ .testIfExactError("Expected at least one argument", "min([])");
+ }
+
+ @Test
+ public void testMinWithString() throws Exception {
+ new SkylarkTest()
+ .testStatement("min('abcdefxyz')", "a")
+ .testStatement("min('test', 'xyz')", "test");
+ }
+
+ @Test
+ public void testMinWithList() throws Exception {
+ new SkylarkTest()
+ .testEval("min([4, 5], [1])", "[1]")
+ .testEval("min([1, 2], [3])", "[1, 2]")
+ .testEval("min([1, 5], [1, 6], [2, 4], [0, 6])", "[0, 6]")
+ .testStatement("min([-1])", -1)
+ .testStatement("min([5, 2, 3])", 2);
+ }
+
+ @Test
+ public void testMinWithDict() throws Exception {
+ new SkylarkTest().testStatement("min({1: 2, -1 : 3})", -1).testStatement("min({2: None})", 2);
+ }
+
+ @Test
+ public void testMinWithSet() throws Exception {
+ new SkylarkTest().testStatement("min(set([-1]))", -1).testStatement("min(set([5, 2, 3]))", 2);
+ }
+
+ @Test
+ public void testMinWithPositionalArguments() throws Exception {
+ new SkylarkTest().testStatement("min(-1, 2)", -1).testStatement("min(5, 2, 3)", 2);
+ }
+
+ @Test
+ public void testMinWithSameValues() throws Exception {
+ new SkylarkTest()
+ .testStatement("min(1, 1, 1, 1, 1, 1)", 1)
+ .testStatement("min([1, 1, 1, 1, 1, 1])", 1);
+ }
+
+ @Test
+ public void testMinWithDifferentTypes() throws Exception {
+ new SkylarkTest()
+ .testStatement("min(1, '2', True)", true)
+ .testStatement("min([1, '2', True])", true)
+ .testStatement("min(None, 1, 'test')", Runtime.NONE);
+ }
+
+ @Test
+ public void testMaxWithInvalidArgs() throws Exception {
+ new SkylarkTest()
+ .testIfExactError("type 'int' is not iterable", "max(1)")
+ .testIfExactError("Expected at least one argument", "max([])");
+ }
+
+ @Test
+ public void testMaxWithString() throws Exception {
+ new SkylarkTest()
+ .testStatement("max('abcdefxyz')", "z")
+ .testStatement("max('test', 'xyz')", "xyz");
+ }
+
+ @Test
+ public void testMaxWithList() throws Exception {
+ new SkylarkTest()
+ .testEval("max([1, 2], [5])", "[5]")
+ .testStatement("max([-1])", -1)
+ .testStatement("max([5, 2, 3])", 5);
+ }
+
+ @Test
+ public void testMaxWithDict() throws Exception {
+ new SkylarkTest().testStatement("max({1: 2, -1 : 3})", 1).testStatement("max({2: None})", 2);
+ }
+
+ @Test
+ public void testMaxWithSet() throws Exception {
+ new SkylarkTest().testStatement("max(set([-1]))", -1).testStatement("max(set([5, 2, 3]))", 5);
+ }
+
+ @Test
+ public void testMaxWithPositionalArguments() throws Exception {
+ new SkylarkTest().testStatement("max(-1, 2)", 2).testStatement("max(5, 2, 3)", 5);
+ }
+
+ @Test
+ public void testMaxWithSameValues() throws Exception {
+ new SkylarkTest()
+ .testStatement("max(1, 1, 1, 1, 1, 1)", 1)
+ .testStatement("max([1, 1, 1, 1, 1, 1])", 1);
+ }
+
+ @Test
+ public void testMaxWithDifferentTypes() throws Exception {
+ new SkylarkTest()
+ .testStatement("max(1, '2', True)", "2")
+ .testStatement("max([1, '2', True])", "2")
+ .testStatement("max(None, 1, 'test')", "test");
+ }
+
+ @Test
public void testSplitLines_EmptyLine() throws Exception {
new SkylarkTest().testEval("''.splitlines()", "[]").testEval("'\\n'.splitlines()", "['']");
}