diff options
author | 2018-04-04 13:59:27 -0700 | |
---|---|---|
committer | 2018-04-04 14:01:20 -0700 | |
commit | 7520dcce42217c8076b06ed88c0e4e04ed99a0f4 (patch) | |
tree | f3c8156e096114dabddba39e8ae7ea21d00e2560 /src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java | |
parent | 16e188b99a5b0d07a0976ba5eb6013b3de8befb9 (diff) |
Migrate SkylarkNativeModule methods to use @SkylarkCallable instead of @SkylarkSignature
Most notably, this involves introduction of a new function abstraction, BuiltinMethod, which can wrap a {objc, SkylarkCallable} pair into a BaseFunction for later calling. (This is required due to the current layer of indirection on the end "native" module)
RELNOTES: None.
PiperOrigin-RevId: 191642467
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java | 24 |
1 files changed, 24 insertions, 0 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 ed8fb91906..ee6fc425bb 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 @@ -163,6 +163,7 @@ public class SkylarkEvaluationTest extends EvaluationTest { return ImmutableMap.of("a", ImmutableList.of("b", "c")); } + @SkylarkCallable( name = "with_params", documented = false, @@ -352,6 +353,18 @@ public class SkylarkEvaluationTest extends EvaluationTest { + ")"; } + @SkylarkCallable(name = "proxy_methods_object", + doc = "Returns a struct containing all callable method objects of this mock", + allowReturnNones = true) + public ClassObject proxyMethodsObject() { + ImmutableMap.Builder<String, Object> builder = new ImmutableMap.Builder<>(); + for (String nativeFunction : FuncallExpression.getMethodNames(Mock.class)) { + builder.put(nativeFunction, + FuncallExpression.getBuiltinCallable(this, nativeFunction)); + } + return NativeProvider.STRUCT.create(builder.build(), "no native callable '%s'"); + } + @Override public String toString() { return "<mock>"; @@ -921,6 +934,16 @@ public class SkylarkEvaluationTest extends EvaluationTest { } @Test + public void testProxyMethodsObject() throws Exception { + new SkylarkTest() + .update("mock", new Mock()) + .setUp( + "m = mock.proxy_methods_object()", + "b = m.with_params(1, True, named=True)") + .testLookup("b", "with_params(1, true, false, true, false, a)"); + } + + @Test public void testJavaCallWithPositionalAndKwargs() throws Exception { new SkylarkTest() .update("mock", new Mock()) @@ -1527,6 +1550,7 @@ public class SkylarkEvaluationTest extends EvaluationTest { "is_empty", "nullfunc_failing", "nullfunc_working", + "proxy_methods_object", "return_bad", "string", "string_list", |