diff options
author | fzaiser <fzaiser@google.com> | 2017-08-14 12:00:51 +0200 |
---|---|---|
committer | Irina Iancu <elenairina@google.com> | 2017-08-14 14:16:22 +0200 |
commit | e0f1333de8e1ecd43bdb39992f97b916f00d49ee (patch) | |
tree | d768b73aee78b4c0f3aed0424c8a31a325aeae51 /src/test/java | |
parent | 05418b33dd87d63e2653e594d462b2aedb0e22e5 (diff) |
Fix Skylark parsing of call expressions.
This allows more complex expressions to be called, not just identifiers.
For example, "x[0]()" is not a syntax error anymore.
RELNOTES: None
PiperOrigin-RevId: 165157981
Diffstat (limited to 'src/test/java')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/syntax/EvaluationTest.java | 6 | ||||
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/syntax/ParserTest.java | 9 |
2 files changed, 12 insertions, 3 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 becaab2ac8..fb438a6e70 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 @@ -142,6 +142,12 @@ public class EvaluationTest extends EvaluationTestCase { } @Test + public void testComplexFunctionCall() throws Exception { + newTest().setUp("functions = [min, max]", "l = [1,2]") + .testEval("(functions[0](l), functions[1](l))", "(1, 2)"); + } + + @Test public void testKeywordArgs() throws Exception { // This function returns the map of keyword arguments passed to it. diff --git a/src/test/java/com/google/devtools/build/lib/syntax/ParserTest.java b/src/test/java/com/google/devtools/build/lib/syntax/ParserTest.java index c616b2ad78..a9a9e4cc7b 100644 --- a/src/test/java/com/google/devtools/build/lib/syntax/ParserTest.java +++ b/src/test/java/com/google/devtools/build/lib/syntax/ParserTest.java @@ -174,10 +174,13 @@ public class ParserTest extends EvaluationTestCase { @Test public void testFuncallExpr() throws Exception { - FuncallExpression e = (FuncallExpression) parseExpression("foo(1, 2, bar=wiz)"); + FuncallExpression e = (FuncallExpression) parseExpression("foo[0](1, 2, bar=wiz)"); - Identifier ident = (Identifier) e.getFunction(); - assertThat(ident.getName()).isEqualTo("foo"); + IndexExpression function = (IndexExpression) e.getFunction(); + Identifier functionList = (Identifier) function.getObject(); + assertThat(functionList.getName()).isEqualTo("foo"); + IntegerLiteral listIndex = (IntegerLiteral) function.getKey(); + assertThat(listIndex.getValue()).isEqualTo(0); assertThat(e.getArguments()).hasSize(3); assertThat(e.getNumPositionalArguments()).isEqualTo(2); |