@@ -10,6 +10,113 @@ class StORMTests: XCTestCase {
10
10
override func setUp( ) {
11
11
super. setUp ( )
12
12
}
13
+
14
+ func testKeyTypeIntegerNil( ) {
15
+
16
+ let val : Int ? = nil
17
+
18
+ // Grab the type of value:
19
+ let type = type ( of: val)
20
+ // Check if we are nil, we would then of course have an empty primary key.
21
+
22
+ switch type {
23
+ case is Int . Type , is Int ? . Type:
24
+ guard String ( describing: val) != " nil " else {
25
+ XCTAssert ( true )
26
+ return
27
+ }
28
+ XCTFail ( " Value was supposed to be nil. " )
29
+ // return (val as! Int == 0)
30
+ case is String . Type , is String ? . Type:
31
+ // return (val as! String).isEmpty
32
+ XCTFail ( " Type was supposed to be an integer. " )
33
+ default :
34
+ XCTFail ( " Type should either be a String or Integer. " )
35
+ print ( " [StORM] WARNING: Unexpected type for PRIMARY KEY in function: \( #function) . TYPE: \( type) " )
36
+ // return false
37
+ }
38
+
39
+ }
40
+
41
+ func testKeyTypeOptionalInteger( ) {
42
+
43
+
44
+ let val : Int ? = 1
45
+
46
+ let anyVal : Any = val
47
+
48
+ // Grab the type of value:
49
+ let type = type ( of: val)
50
+ // Check if we are nil, we would then of course have an empty primary key.
51
+ guard String ( describing: anyVal) != " nil " else {
52
+ XCTFail ( " Value was not supposed to be nil. " )
53
+ return
54
+ }
55
+
56
+ switch type {
57
+ case is Int . Type , is Int ? . Type:
58
+ XCTAssert ( ( anyVal as? Int ) != nil , " Failed to cast optional Integer as Any to Int " )
59
+ // return (val as! Int == 0)
60
+ case is String . Type , is String ? . Type:
61
+ // return (val as! String).isEmpty
62
+ XCTFail ( " Type was supposed to be an integer. " )
63
+ default :
64
+ XCTFail ( " Type should either be a String or Integer. " )
65
+ print ( " [StORM] WARNING: Unexpected type for PRIMARY KEY in function: \( #function) . TYPE: \( type) " )
66
+ // return false
67
+ }
68
+
69
+ }
70
+
71
+ func testKeyTypeStringNil( ) {
72
+
73
+ let val : String ? = nil
74
+
75
+ // Grab the type of value:
76
+ let type = type ( of: val)
77
+
78
+ switch type {
79
+ case is Int . Type , is Int ? . Type:
80
+ XCTFail ( " Type was supposed to be a string. " )
81
+ case is String . Type , is String ? . Type:
82
+ guard String ( describing: val) != " nil " else {
83
+ XCTAssert ( true )
84
+ return
85
+ }
86
+ XCTFail ( " Value was supposed to be nil. " )
87
+ default :
88
+ XCTFail ( " Type should either be a String or Integer. " )
89
+ print ( " [StORM] WARNING: Unexpected type for PRIMARY KEY in function: \( #function) . TYPE: \( type) " )
90
+ }
91
+
92
+ }
93
+
94
+ func testKeyTypeOptionalString( ) {
95
+
96
+
97
+ let val : String ? = " "
98
+
99
+ let anyVal : Any = val
100
+
101
+ // Grab the type of value:
102
+ let type = type ( of: val)
103
+ // Check if we are nil, we would then of course have an empty primary key.
104
+ guard String ( describing: anyVal) != " nil " else {
105
+ XCTFail ( " Value was not supposed to be nil. " )
106
+ return
107
+ }
108
+
109
+ switch type {
110
+ case is Int . Type , is Int ? . Type:
111
+ XCTFail ( " Type was supposed to be a string. " )
112
+ case is String . Type , is String ? . Type:
113
+ XCTAssert ( ( anyVal as? String ) != nil , " Failed to cast optional string as Any to String " )
114
+ default :
115
+ XCTFail ( " Type should either be a String or Integer. " )
116
+ print ( " [StORM] WARNING: Unexpected type for PRIMARY KEY in function: \( #function) . TYPE: \( type) " )
117
+ }
118
+
119
+ }
13
120
14
121
static var allTests : [ ( String , ( StORMTests ) -> ( ) throws -> Void ) ] {
15
122
return [
0 commit comments