|
52 | 52 | import java.util.Arrays;
|
53 | 53 | import java.util.List;
|
54 | 54 |
|
| 55 | +import com.oracle.graal.python.runtime.interop.InteropArray; |
| 56 | +import com.oracle.graal.python.test.PythonTests; |
| 57 | +import com.oracle.truffle.api.interop.ArityException; |
| 58 | +import com.oracle.truffle.api.interop.InteropLibrary; |
| 59 | +import com.oracle.truffle.api.interop.TruffleObject; |
| 60 | +import com.oracle.truffle.api.interop.UnknownIdentifierException; |
| 61 | +import com.oracle.truffle.api.library.ExportLibrary; |
| 62 | +import com.oracle.truffle.api.library.ExportMessage; |
| 63 | + |
55 | 64 | import org.graalvm.polyglot.Context;
|
56 | 65 | import org.graalvm.polyglot.Context.Builder;
|
57 | 66 | import org.graalvm.polyglot.Engine;
|
|
67 | 76 | import org.junit.runners.Parameterized.Parameter;
|
68 | 77 | import org.junit.runners.Parameterized.Parameters;
|
69 | 78 |
|
70 |
| -import com.oracle.graal.python.runtime.interop.InteropArray; |
71 |
| -import com.oracle.graal.python.test.PythonTests; |
72 |
| -import com.oracle.truffle.api.interop.ArityException; |
73 |
| -import com.oracle.truffle.api.interop.InteropLibrary; |
74 |
| -import com.oracle.truffle.api.interop.TruffleObject; |
75 |
| -import com.oracle.truffle.api.interop.UnknownIdentifierException; |
76 |
| -import com.oracle.truffle.api.library.ExportLibrary; |
77 |
| -import com.oracle.truffle.api.library.ExportMessage; |
78 |
| - |
79 | 79 | @RunWith(Enclosed.class)
|
80 | 80 | public class JavaInteropTest {
|
81 | 81 | public static class GeneralInterop extends PythonTests {
|
@@ -509,6 +509,54 @@ public void writableBindings() {
|
509 | 509 | assertTrue(javaObj.isNumber());
|
510 | 510 | assertEquals(javaObj.asInt(), 42);
|
511 | 511 | }
|
| 512 | + |
| 513 | + @ExportLibrary(InteropLibrary.class) |
| 514 | + static final class WrapString implements TruffleObject { |
| 515 | + private final String str; |
| 516 | + |
| 517 | + WrapString(String str) { |
| 518 | + this.str = str; |
| 519 | + } |
| 520 | + |
| 521 | + @ExportMessage |
| 522 | + @SuppressWarnings("static-method") |
| 523 | + boolean isString() { |
| 524 | + return true; |
| 525 | + } |
| 526 | + |
| 527 | + @ExportMessage |
| 528 | + String asString() { |
| 529 | + return str; |
| 530 | + } |
| 531 | + } |
| 532 | + |
| 533 | + @ExportLibrary(InteropLibrary.class) |
| 534 | + static final class WrapBoolean implements TruffleObject { |
| 535 | + private final boolean flag; |
| 536 | + |
| 537 | + WrapBoolean(boolean flag) { |
| 538 | + this.flag = flag; |
| 539 | + } |
| 540 | + |
| 541 | + @ExportMessage |
| 542 | + @SuppressWarnings("static-method") |
| 543 | + boolean isBoolean() { |
| 544 | + return true; |
| 545 | + } |
| 546 | + |
| 547 | + @ExportMessage |
| 548 | + boolean asBoolean() { |
| 549 | + return flag; |
| 550 | + } |
| 551 | + } |
| 552 | + |
| 553 | + @Test |
| 554 | + public void multiplyStrBool() { |
| 555 | + context.getBindings("python").putMember("javaBool", new WrapBoolean(true)); |
| 556 | + context.getBindings("python").putMember("javaStr", new WrapString("test")); |
| 557 | + assertEquals(context.eval("python", "javaStr * javaBool").asString(), "test"); |
| 558 | + assertEquals(context.eval("python", "javaBool * javaStr").asString(), "test"); |
| 559 | + } |
512 | 560 | }
|
513 | 561 |
|
514 | 562 | @RunWith(Parameterized.class)
|
|
0 commit comments