Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Sources/SwiftExtract/SwiftTypes/SwiftKnownModules.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ private let foundationEssentialsSourceFile: SourceFileSyntax = """
public init(timeIntervalSince1970: Double)
}

public typealias TimeInterval = Double

public struct UUID {}

public struct URL {
Expand Down
126 changes: 126 additions & 0 deletions Tests/JExtractSwiftTests/TimeIntervalTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2026 Apple Inc. and the Swift.org project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of Swift.org project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//

import JExtractSwiftLib
import SwiftJavaConfigurationShared
import Testing

struct TimeIntervalTests {
@Test(
"Import: accept TimeInterval (resolves to Double)",
arguments: [
(
JExtractGenerationMode.jni,
/* expected Java chunks */
[
"""
public static void delay(double seconds) {
SwiftModule.$delay(seconds);
}
"""
],
/* expected Swift chunks */
[
"""
@_cdecl("Java_com_example_swift_SwiftModule__00024delay__D")
public func Java_com_example_swift_SwiftModule__00024delay__D(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass, seconds: jdouble) {
SwiftModule.delay(seconds: Double(fromJNI: seconds, in: environment))
}
"""
],
)
]
)
func func_accept_timeInterval(
mode: JExtractGenerationMode,
expectedJavaChunks: [String],
expectedSwiftChunks: [String]
) throws {
let text =
"""
import Foundation

public func delay(seconds: TimeInterval)
"""

try assertOutput(
input: text,
mode,
.java,
detectChunkByInitialLines: 1,
expectedChunks: expectedJavaChunks
)

try assertOutput(
input: text,
mode,
.swift,
detectChunkByInitialLines: 1,
expectedChunks: expectedSwiftChunks
)
}

@Test(
"Import: return TimeInterval (resolves to Double)",
arguments: [
(
JExtractGenerationMode.jni,
/* expected Java chunks */
[
"""
public static double now() {
return SwiftModule.$now();
}
"""
],
/* expected Swift chunks */
[
"""
@_cdecl("Java_com_example_swift_SwiftModule__00024now__")
public func Java_com_example_swift_SwiftModule__00024now__(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass) -> jdouble {
return SwiftModule.now()
}
"""
]
)
]
)
func func_return_timeInterval(
mode: JExtractGenerationMode,
expectedJavaChunks: [String],
expectedSwiftChunks: [String]
) throws {
let text =
"""
import Foundation
public func now() -> TimeInterval
"""

try assertOutput(
input: text,
mode,
.java,
detectChunkByInitialLines: 1,
expectedChunks: expectedJavaChunks
)

try assertOutput(
input: text,
mode,
.swift,
detectChunkByInitialLines: 1,
expectedChunks: expectedSwiftChunks
)
}
}
Loading