Skip to content

Commit 9153dd9

Browse files
committed
Add more tests
1 parent 07b76cd commit 9153dd9

7 files changed

+63
-3
lines changed

test/Interop/Cxx/members/Inputs/constructor-calls-method.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#ifndef TEST_INTEROP_CXX_MEMBERS_INPUTS_CONSTRUCTOR_CALLS_METHOD_H
22
#define TEST_INTEROP_CXX_MEMBERS_INPUTS_CONSTRUCTOR_CALLS_METHOD_H
33

4-
struct Increment {
4+
struct Incrementor {
55
int increment(int t) { return t + 1; }
66
};
77

88
struct IncrementUser {
99
int incrementee;
10-
IncrementUser(int value) { incrementee = Increment().increment(value); }
10+
IncrementUser(int value) { incrementee = Incrementor().increment(value); }
1111
};
1212

1313
inline int callConstructor(int value) { return IncrementUser(value).incrementee; }
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#ifndef TEST_INTEROP_CXX_MEMBERS_INPUTS_METHOD_CALLS_METHOD_FROM_NESTED_STRUCT_H
2+
#define TEST_INTEROP_CXX_MEMBERS_INPUTS_METHOD_CALLS_METHOD_FROM_NESTED_STRUCT_H
3+
4+
struct IncrementUser {
5+
struct Incrementor {
6+
int increment(int t) { return t + 1; }
7+
};
8+
int callIncrement(int value) { return Incrementor().increment(value); }
9+
};
10+
11+
inline int callMethod(int value) {
12+
return IncrementUser().callIncrement(value);
13+
}
14+
15+
#endif // TEST_INTEROP_CXX_MEMBERS_INPUTS_METHOD_CALLS_METHOD_FROM_NESTED_STRUCT_H

test/Interop/Cxx/members/Inputs/module.modulemap

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module ConstructorCallsFunction {
22
header "constructor-calls-function.h"
33
}
44

5-
module ConstructorCalls {
5+
module ConstructorCallsMethod {
66
header "constructor-calls-method.h"
77
}
88

@@ -13,3 +13,7 @@ module MethodCallsFunction {
1313
module MethodCallsMethod {
1414
header "method-calls-method.h"
1515
}
16+
17+
module MethodCallsMethodFromNestedStruct {
18+
header "method-calls-method-from-nested-struct.h"
19+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: %target-swift-emit-ir %s -I %S/Inputs -enable-cxx-interop | %FileCheck %s
2+
3+
import MethodCallsMethodFromNestedStruct
4+
5+
public func getValueFromMethod() -> CInt {
6+
return callMethod(41)
7+
}
8+
9+
// CHECK: define linkonce_odr i32 @_ZN13IncrementUser11Incrementor9incrementEi(%"struct.IncrementUser::Incrementor"* %this, i32 %t)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: %target-run-simple-swift(-I %S/Inputs -Xfrontend -enable-cxx-interop)
2+
//
3+
// REQUIRES: executable_test
4+
5+
import MethodCallsMethodFromNestedStruct
6+
import StdlibUnittest
7+
8+
var MembersTestSuite = TestSuite("MembersTestSuite")
9+
10+
MembersTestSuite.test("emit-method-from-nested-struct") {
11+
expectEqual(42, callMethod(41))
12+
}
13+
14+
runAllTests()
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: %target-swift-emit-ir %s -I %S/Inputs -enable-cxx-interop | %FileCheck %s
2+
3+
import ConstructorCallsMethod
4+
5+
public func getIncrementorValue() -> CInt {
6+
return callConstructor(41)
7+
}
8+
9+
// CHECK: define linkonce_odr i32 @_ZN11Incrementor9incrementEi(%struct.Incrementor* %this, i32 %t)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: %target-swift-emit-ir %s -I %S/Inputs -enable-cxx-interop | %FileCheck %s
2+
3+
import MethodCallsMethod
4+
5+
public func getValueFromMethod() -> CInt {
6+
return callMethod(41)
7+
}
8+
9+
// CHECK: define linkonce_odr i32 @_ZN11Incrementor9incrementEi(%struct.Incrementor* %this, i32 %t)

0 commit comments

Comments
 (0)