1+ //===----------------------------------------------------------------------===//
2+ //
3+ // This source file is part of the Swift.org open source project
4+ //
5+ // Copyright (c) 2024 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 JavaKitExample
16+
17+ import SwiftJava
18+ import JavaUtilFunction
19+ import Testing
20+
21+ @Suite
22+ struct ManglingTests {
23+
24+ @Test
25+ func methodMangling( ) throws {
26+ let jvm = try ! JavaVirtualMachine . shared (
27+ classpath: [
28+ " .build/plugins/outputs/javakitsampleapp/JavaKitExample/destination/JavaCompilerPlugin/Java "
29+ ]
30+ )
31+ let env = try ! jvm. environment ( )
32+
33+ let helper = ThreadSafeHelperClass ( environment: env)
34+
35+ let text : JavaString ? = helper. textOptional
36+ #expect( #"Optional("cool string")"# == String ( describing: Optional ( " cool string " ) ) )
37+ #expect( #"Optional("cool string")"# == String ( describing: text) )
38+
39+ // let defaultValue: String? = helper.getOrElse(JavaOptional<JavaString>.empty())
40+ // #expect(#"Optional("or else value")"# == String(describing: defaultValue))
41+
42+ let noneValue : JavaOptional < JavaString > = helper. getNil ( ) !
43+ #expect( noneValue. isPresent ( ) == false )
44+ #expect( " \( noneValue) " == " SwiftJava.JavaOptional<SwiftJava.JavaString> " )
45+
46+ let textFunc : JavaString ? = helper. getTextOptional ( )
47+ #expect( #"Optional("cool string")"# == String ( describing: textFunc) )
48+
49+ let doubleOpt : Double ? = helper. valOptional
50+ #expect( #"Optional(2.0)"# == String ( describing: doubleOpt) )
51+
52+ let longOpt : Int64 ? = helper. fromOptional ( 21 as Int32 ? )
53+ #expect( #"Optional(21)"# == String ( describing: longOpt) )
54+ }
55+
56+ }
0 commit comments