From 5e8752b64acf3b5d5ae0a8929f20119e1281628a Mon Sep 17 00:00:00 2001 From: Florian Weikert Date: Fri, 11 Dec 2015 21:54:43 +0000 Subject: Skylark: implemented min() and max(). -- MOS_MIGRATED_REVID=110025690 --- .../build/lib/syntax/MethodLibraryTest.java | 106 +++++++++++++++++++++ 1 file changed, 106 insertions(+) (limited to 'src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java') 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 @@ -39,6 +39,112 @@ public class MethodLibraryTest extends EvaluationTestCase { setFailFast(true); } + @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()", "['']"); -- cgit v1.2.3