Skip to content

Commit 597c14e

Browse files
authored
Merge pull request #1510 from NativeScript/vmutafov/kotlin-extension-functions
Add Kotlin extension functions support
2 parents eb632a6 + e77c820 commit 597c14e

33 files changed

+900
-192
lines changed

test-app/app/src/main/assets/app/mainpage.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,5 @@ require("./tests/kotlin/companions/testCompanionObjectsSupport");
5959
require("./tests/kotlin/properties/testPropertiesSupport");
6060
require("./tests/kotlin/delegation/testDelegationSupport");
6161
require("./tests/kotlin/objects/testObjectsSupport");
62-
require("./tests/kotlin/functions/testTopLevelFunctionsSupport");
62+
require("./tests/kotlin/functions/testTopLevelFunctionsSupport");
63+
require("./tests/kotlin/extensions/testExtensionFunctionsSupport")
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
describe("Tests Kotlin extension functions support", function () {
2+
3+
it("Test Kotlin extension functions with no arguments and no return value should work", function () {
4+
var obj = new java.lang.Object();
5+
var hasException = false;
6+
7+
try {
8+
obj.extensionFunctionWithNoArgumentsAndNoReturnValue();
9+
} catch (error) {
10+
hasException = true;
11+
}
12+
13+
expect(hasException).toBe(false);
14+
});
15+
16+
it("Test Kotlin extension functions with no arguments should work", function () {
17+
var obj = new java.lang.Object();
18+
var hasException = false;
19+
20+
try {
21+
var res = obj.extensionFunctionWithNoArgumentsAndStringReturnValue();
22+
expect(res).toBe("some data");
23+
} catch (error) {
24+
hasException = true;
25+
}
26+
27+
expect(hasException).toBe(false);
28+
});
29+
30+
it("Test Kotlin extension functions with one primitive argument and no return value should work", function () {
31+
var obj = new java.lang.Object();
32+
var hasException = false;
33+
34+
try {
35+
obj.extensionFunctionWithOnePrimitiveArgumentAndNoReturnValue(42);
36+
} catch (error) {
37+
hasException = true;
38+
}
39+
40+
expect(hasException).toBe(false);
41+
});
42+
43+
it("Test Kotlin extension functions with one primitive argument should work", function () {
44+
var obj = new java.lang.Object();
45+
var hasException = false;
46+
47+
try {
48+
var res = obj.extensionFunctionWithOnePrimitiveArgumentAndStringReturnValue(42);
49+
expect(res).toBe("some data 42");
50+
} catch (error) {
51+
hasException = true;
52+
}
53+
54+
expect(hasException).toBe(false);
55+
});
56+
57+
it("Test Kotlin extension functions with one object type argument and no return value should work", function () {
58+
var obj = new java.lang.Object();
59+
var arg = new java.lang.Object();
60+
var hasException = false;
61+
62+
try {
63+
obj.extensionFunctionWithOneObjectTypeArgumentAndNoReturnValue(arg);
64+
} catch (error) {
65+
hasException = true;
66+
}
67+
68+
expect(hasException).toBe(false);
69+
});
70+
71+
it("Test Kotlin extension functions with one object type argument should work", function () {
72+
var obj = new java.lang.Object();
73+
var arg = new java.lang.Object();
74+
var argAsString = arg.toString();
75+
var hasException = false;
76+
77+
try {
78+
var res = obj.extensionFunctionWithOneObjectTypeArgumentAndStringReturnValue(arg);
79+
expect(res).toBe("some data " + argAsString);
80+
} catch (error) {
81+
hasException = true;
82+
}
83+
84+
expect(hasException).toBe(false);
85+
});
86+
87+
it("Test Kotlin extension functions with multiple object type arguments and no return value should work", function () {
88+
var obj = new java.lang.Object();
89+
var arg1 = new java.lang.Object();
90+
var arg2 = "test";
91+
var hasException = false;
92+
93+
try {
94+
obj.extensionFunctionWithMultipleObjectTypeArgumentsAndNoReturnValue(arg1, arg2);
95+
} catch (error) {
96+
hasException = true;
97+
}
98+
99+
expect(hasException).toBe(false);
100+
});
101+
102+
it("Test Kotlin extension functions with multiple object type arguments should work", function () {
103+
var obj = new java.lang.Object();
104+
var arg1 = new java.lang.Object();
105+
var arg1AsString = arg1.toString();
106+
var arg2 = "test";
107+
var hasException = false;
108+
109+
try {
110+
var res = obj.extensionFunctionWithMultipleObjectTypeArgumentsAndStringReturnValue(arg1, arg2);
111+
expect(res).toBe("some data " + arg1AsString + " test");
112+
} catch (error) {
113+
hasException = true;
114+
}
115+
116+
expect(hasException).toBe(false);
117+
});
118+
119+
});

0 commit comments

Comments
 (0)