aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/build/lib/syntax
diff options
context:
space:
mode:
authorGravatar cparsons <cparsons@google.com>2018-03-07 11:01:17 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2018-03-07 11:03:38 -0800
commit5d446a7b8f784e9fc41e82a1b1fa941fe52cea31 (patch)
tree017273e8eb73558576f88f33c910bad9ad56e9f0 /src/test/java/com/google/devtools/build/lib/syntax
parentf1013485d41efd8503f9d4f937e17d1b4bc91ed3 (diff)
Allow passing location, ast, and environment to @SkylarkCallable methods
RELNOTES: None. PiperOrigin-RevId: 188201686
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/syntax')
-rw-r--r--src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java128
1 files changed, 126 insertions, 2 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java b/src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java
index 9711dea3f5..8bb82f1279 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java
@@ -233,12 +233,118 @@ public class SkylarkEvaluationTest extends EvaluationTest {
+ ", "
+ optionalNamed
+ ", "
- + nonNoneable.toString()
+ + nonNoneable
+ (noneable != Runtime.NONE ? ", " + noneable : "")
+ (multi != Runtime.NONE ? ", " + multi : "")
+ ")";
}
+ @SkylarkCallable(
+ name = "with_extra",
+ doc = "",
+ useLocation = true,
+ useAst = true,
+ useEnvironment = true
+ )
+ public String withExtraInterpreterParams(
+ Location location, FuncallExpression func, Environment env) {
+ return "with_extra("
+ + location.getStartLine()
+ + ", "
+ + func.getArguments().size()
+ + ", "
+ + env.isGlobal()
+ + ")";
+ }
+
+ @SkylarkCallable(
+ name = "with_params_and_extra",
+ doc = "",
+ mandatoryPositionals = 1,
+ parameters = {
+ @Param(name = "pos2", defaultValue = "False", type = Boolean.class),
+ @Param(
+ name = "posOrNamed",
+ defaultValue = "False",
+ type = Boolean.class,
+ positional = true,
+ named = true
+ ),
+ @Param(name = "named", type = Boolean.class, positional = false, named = true),
+ @Param(
+ name = "optionalNamed",
+ type = Boolean.class,
+ defaultValue = "False",
+ positional = false,
+ named = true
+ ),
+ @Param(
+ name = "nonNoneable",
+ type = Object.class,
+ defaultValue = "\"a\"",
+ positional = false,
+ named = true
+ ),
+ @Param(
+ name = "noneable",
+ type = Integer.class,
+ defaultValue = "None",
+ noneable = true,
+ positional = false,
+ named = true
+ ),
+ @Param(
+ name = "multi",
+ allowedTypes = {
+ @ParamType(type = String.class),
+ @ParamType(type = Integer.class),
+ @ParamType(type = SkylarkList.class, generic1 = Integer.class),
+ },
+ defaultValue = "None",
+ noneable = true,
+ positional = false,
+ named = true
+ )
+ },
+ useAst = true,
+ useLocation = true,
+ useEnvironment = true
+ )
+ public String withParamsAndExtraInterpreterParams(
+ Integer pos1,
+ boolean pos2,
+ boolean posOrNamed,
+ boolean named,
+ boolean optionalNamed,
+ Object nonNoneable,
+ Object noneable,
+ Object multi,
+ Location location,
+ FuncallExpression func,
+ Environment env) {
+ return "with_params_and_extra("
+ + pos1
+ + ", "
+ + pos2
+ + ", "
+ + posOrNamed
+ + ", "
+ + named
+ + ", "
+ + optionalNamed
+ + ", "
+ + nonNoneable
+ + (noneable != Runtime.NONE ? ", " + noneable : "")
+ + (multi != Runtime.NONE ? ", " + multi : "")
+ + ", "
+ + location.getStartLine()
+ + ", "
+ + func.getArguments().size()
+ + ", "
+ + env.isGlobal()
+ + ")";
+ }
+
@Override
public String toString() {
return "<mock>";
@@ -922,6 +1028,22 @@ public class SkylarkEvaluationTest extends EvaluationTest {
}
@Test
+ public void testJavaFunctionWithExtraInterpreterParams() throws Exception {
+ new SkylarkTest()
+ .update("mock", new Mock())
+ .setUp("v = mock.with_extra()")
+ .testLookup("v", "with_extra(1, 0, true)");
+ }
+
+ @Test
+ public void testJavaFunctionWithParamsAndExtraInterpreterParams() throws Exception {
+ new SkylarkTest()
+ .update("mock", new Mock())
+ .setUp("b = mock.with_params_and_extra(1, True, named=True)")
+ .testLookup("b", "with_params_and_extra(1, true, false, true, false, a, 1, 3, true)");
+ }
+
+ @Test
public void testStructAccessOfMethod() throws Exception {
new SkylarkTest()
.update("mock", new Mock())
@@ -1404,7 +1526,9 @@ public class SkylarkEvaluationTest extends EvaluationTest {
"struct_field_callable",
"value_of",
"voidfunc",
- "with_params");
+ "with_extra",
+ "with_params",
+ "with_params_and_extra");
}
@Test