-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathValueBoxingTests.swift
109 lines (94 loc) · 3.46 KB
/
ValueBoxingTests.swift
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import WinSDK
import XCTest
import test_component
import Foundation
struct Person : Equatable
{
var firstName: String
var lastName: String
var age: Int
}
class ValueBoxingTests : XCTestCase {
public func testInInt() {
let value: Int = 2
let classy = Class()
let result = try! classy.inObject(value)
XCTAssertEqual("\(value)", result)
}
public func testInString() {
let words = "hello world"
let classy = Class()
let result = try! classy.inObject(words)
XCTAssertEqual(words, result)
}
/*
https://linear.app/the-browser-company/issue/WIN-650/some-unicode-conversions-dont-work
public func testInChar() {
let classy = Class()
// regionalIndicatorForUS is 🇺🇸
let regionalIndicatorForUS: Character = "\u{1F1FA}\u{1F1F8}"
let result = try! classy.inObject(regionalIndicatorForUS)
XCTAssertEqual(String(regionalIndicatorForUS), result)
}
*/
public func testInWinRTClass() {
// Verify that we return the class name of the swift type
let derived = Derived()
let classy = Class()
let result = try! classy.inObject(derived)
XCTAssertEqual(NSStringFromClass(Derived.self), result)
}
public func testInSwiftStruct() {
// Swift structs are wrapped and boxed by the runtime in a __SwiftValue class:
// https://github.com/apple/swift-corelibs-foundation/blob/4eacf8848d0a5a6bfb7a6fd52ad4ba0405dea5b2/Sources/Foundation/Bridging.swift#L73
let classy = Class()
let person = Person(firstName: "John", lastName: "Doe", age: 32)
let result = try! classy.inObject(person)
XCTAssertEqual("Foundation.__SwiftValue", result)
}
public func testOutInterface() {
var anyObj: Any?
let classy = Class()
try! classy.outObject(&anyObj)
let obj = anyObj as! test_component.IStringable
XCTAssertEqual("123", try! obj.toString())
}
public func testInAppImplemented() {
let classy = Class()
let delegate = MySimpleDelegate()
let result = try! classy.inObject(delegate)
XCTAssertEqual("simple", result)
}
public func testInAppImplementedMultipleInterfaces() {
let classy = Class()
let doubleDelegate = DoubleDelegate()
let result = try! classy.inObject(doubleDelegate)
XCTAssertEqual("simply basic", result)
}
public func testRoundTripping() {
// Add a swift implementation so this will test the roundtripping of swift
// objects
let impl = MyImplementableDelegate()
let classy = Class("with delegate", .orange, impl)
let person = Person(firstName: "John", lastName: "Doe", age: 32)
let result = try! classy.inObject(person)
XCTAssertEqual(result, String(describing: person))
var anyObj: Any?
try! classy.outObject(&anyObj)
XCTAssertEqual(anyObj as! Person, person)
anyObj = try! classy.returnObject()
XCTAssertEqual(anyObj as! Person, person)
}
}
var valueBoxingTests: [XCTestCaseEntry] = [
testCase([
("InInt", ValueBoxingTests.testInInt),
("InString", ValueBoxingTests.testInString),
("InWinRTClass", ValueBoxingTests.testInWinRTClass),
("InSwiftStruct", ValueBoxingTests.testInSwiftStruct),
("OutInterface", ValueBoxingTests.testOutInterface),
("testInAppImplemented", ValueBoxingTests.testInAppImplemented),
("testInAppImplementedMultipleInterfaces", ValueBoxingTests.testInAppImplementedMultipleInterfaces),
("RoundTripping", ValueBoxingTests.testRoundTripping)
])
]