-
Notifications
You must be signed in to change notification settings - Fork 89
Expand file tree
/
Copy pathOrgAndrejsJsonTests.swift
More file actions
51 lines (39 loc) · 1.47 KB
/
OrgAndrejsJsonTests.swift
File metadata and controls
51 lines (39 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2024 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 Foundation
import SwiftJava
// Import the json library wrapper:
import OrgAndrejsJson
enum OrgAndrejsJsonTests {
static func run() async throws {
print("Now testing Json library...")
let json = Json(#"{"host": "localhost", "port": 80}"#)
precondition(json.hasOwnProperty("port"))
let port: JavaInteger = json.get("port")!
precondition(port.toString() == "80")
precondition(port.intValue() == 80)
print("Reading swift-java.config inside OrgAndrejsJson folder...")
let configPath = String.currentWorkingDirectory.appending("/Sources/OrgAndrejsJson/swift-java.config")
let config = try JavaClass<Json>().of.url("file://" + configPath)!
precondition(config.hasOwnProperty("repositories"))
print(config.toString())
}
}
private extension String {
static var currentWorkingDirectory: Self {
let path = getcwd(nil, 0)!
defer { free(path) }
return String(cString: path)
}
}