Skip to content

Commit 41b6dab

Browse files
committed
add tests
1 parent 628b223 commit 41b6dab

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2025 Apple Inc. and the Swift.org project authors
6+
// Licensed under Apache License v2.0
7+
//
8+
// See LICENSE.txt for license information
9+
// See CONTRIBUTORS.txt for the list of Swift.org project authors
10+
//
11+
// SPDX-License-Identifier: Apache-2.0
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
import JExtractSwiftLib
16+
import JavaKitConfigurationShared
17+
import Testing
18+
19+
@Suite
20+
struct MemoryManagementModeTests {
21+
let text =
22+
"""
23+
class MyClass {}
24+
25+
public func f() -> MyClass
26+
"""
27+
28+
@Test
29+
func explicit() throws {
30+
var config = Configuration()
31+
config.memoryManagementMode = .explicit
32+
33+
try assertOutput(
34+
input: text,
35+
config: config,
36+
.jni, .java,
37+
expectedChunks: [
38+
"""
39+
/**
40+
* Downcall to Swift:
41+
* {@snippet lang=swift :
42+
* public func f() -> MyClass
43+
* }
44+
*/
45+
public static MyClass f(SwiftArena swiftArena$) {
46+
return new MyClass(SwiftModule.$f(), swiftArena$);
47+
}
48+
""",
49+
]
50+
)
51+
}
52+
53+
@Test
54+
func allowGlobalAutomatic() throws {
55+
var config = Configuration()
56+
config.memoryManagementMode = .allowGlobalAutomatic
57+
58+
try assertOutput(
59+
input: text,
60+
config: config,
61+
.jni, .java,
62+
detectChunkByInitialLines: 1,
63+
expectedChunks: [
64+
"""
65+
public static MyClass f() {
66+
return f(SwiftMemoryManagement.GLOBAL_SWIFT_JAVA_ARENA);
67+
}
68+
""",
69+
"""
70+
public static MyClass f(SwiftArena swiftArena$) {
71+
return new MyClass(SwiftModule.$f(), swiftArena$);
72+
}
73+
""",
74+
]
75+
)
76+
}
77+
}

0 commit comments

Comments
 (0)