Skip to content

Commit 4b5ba42

Browse files
authored
Merge pull request #20 from apocolipse/unit-tests
Added unit tests
2 parents 756b902 + 847c2ed commit 4b5ba42

File tree

2 files changed

+70
-3
lines changed

2 files changed

+70
-3
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ dependencies: [
5151

5252
You can compile IDL sources for Swift 3 with the following command:
5353

54-
thrift --gen swift_3 thrift_file
54+
thrift --gen swift thrift_file
5555

5656
## Client Example
5757
```swift
@@ -90,10 +90,11 @@ func write(_ val: String) throws
9090
#### Generator Flags
9191
| Flag | Description |
9292
| ------------- |:-------------:|
93-
| async_clients | Generate clients which invoke asynchronously via block syntax.Asynchronous classes are appended with `_Async` |
93+
| async_clients | Generate clients which invoke asynchronously via block syntax. Asynchronous classes are appended with `_Async` |
9494
| no_strict* | Generates non-strict structs |
9595
| debug_descriptions | Allow use of debugDescription so the app can add description via a cateogory/extension |
9696
| log_unexpected | Log every time an unexpected field ID or type is encountered. |
97+
| safe_enums | Generate enum types with an unknown case to handle unspecified values rather than throw a serialization error |
9798

9899

99100

Tests/ThriftTests/TCompactProtocolTests.swift

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,70 @@ class TCompactProtocolTests: XCTestCase {
128128
}
129129
}
130130

131+
func testInt32ZigZag() {
132+
let zero: Int32 = 0
133+
let one: Int32 = 1
134+
let nOne: Int32 = -1
135+
let two: Int32 = 2
136+
let nTwo: Int32 = -2
137+
let max = Int32.max
138+
let min = Int32.min
139+
140+
XCTAssertEqual(proto.i32ToZigZag(zero), UInt32(0), "Error 32bit zigzag on \(zero)")
141+
XCTAssertEqual(proto.zigZagToi32(0), zero, "Error 32bit zigzag on \(zero)")
142+
143+
XCTAssertEqual(proto.i32ToZigZag(nOne), UInt32(1), "Error 32bit zigzag on \(nOne)")
144+
XCTAssertEqual(proto.zigZagToi32(1), nOne, "Error 32bit zigzag on \(nOne)")
145+
146+
XCTAssertEqual(proto.i32ToZigZag(one), UInt32(2), "Error 32bit zigzag on \(one)")
147+
XCTAssertEqual(proto.zigZagToi32(2), one, "Error 32bit zigzag on \(one)")
148+
149+
XCTAssertEqual(proto.i32ToZigZag(nTwo), UInt32(3), "Error 32bit zigzag on \(nTwo)")
150+
XCTAssertEqual(proto.zigZagToi32(3), nTwo, "Error 32bit zigzag on \(nTwo)")
151+
152+
XCTAssertEqual(proto.i32ToZigZag(two), UInt32(4), "Error 32bit zigzag on \(two)")
153+
XCTAssertEqual(proto.zigZagToi32(4), two, "Error 32bit zigzag on \(two)")
154+
155+
let uMaxMinusOne: UInt32 = UInt32.max - 1
156+
XCTAssertEqual(proto.i32ToZigZag(max), uMaxMinusOne, "Error 32bit zigzag on \(max)")
157+
XCTAssertEqual(proto.zigZagToi32(uMaxMinusOne), max, "Error 32bit zigzag on \(max)")
158+
159+
XCTAssertEqual(proto.i32ToZigZag(min), UInt32.max, "Error 32bit zigzag on \(min)")
160+
XCTAssertEqual(proto.zigZagToi32(UInt32.max), min, "Error 32bit zigzag on \(min)")
161+
}
162+
163+
func testInt64ZigZag() {
164+
let zero: Int64 = 0
165+
let one: Int64 = 1
166+
let nOne: Int64 = -1
167+
let two: Int64 = 2
168+
let nTwo: Int64 = -2
169+
let max = Int64.max
170+
let min = Int64.min
171+
172+
XCTAssertEqual(proto.i64ToZigZag(zero), UInt64(0), "Error 64bit zigzag on \(zero)")
173+
XCTAssertEqual(proto.zigZagToi64(0), zero, "Error 64bit zigzag on \(zero)")
174+
175+
XCTAssertEqual(proto.i64ToZigZag(nOne), UInt64(1), "Error 64bit zigzag on \(nOne)")
176+
XCTAssertEqual(proto.zigZagToi64(1), nOne, "Error 64bit zigzag on \(nOne)")
177+
178+
XCTAssertEqual(proto.i64ToZigZag(one), UInt64(2), "Error 64bit zigzag on \(one)")
179+
XCTAssertEqual(proto.zigZagToi64(2), one, "Error 64bit zigzag on \(one)")
180+
181+
XCTAssertEqual(proto.i64ToZigZag(nTwo), UInt64(3), "Error 64bit zigzag on \(nTwo)")
182+
XCTAssertEqual(proto.zigZagToi64(3), nTwo, "Error 64bit zigzag on \(nTwo)")
183+
184+
XCTAssertEqual(proto.i64ToZigZag(two), UInt64(4), "Error 64bit zigzag on \(two)")
185+
XCTAssertEqual(proto.zigZagToi64(4), two, "Error 64bit zigzag on \(two)")
186+
187+
let uMaxMinusOne: UInt64 = UInt64.max - 1
188+
XCTAssertEqual(proto.i64ToZigZag(max), uMaxMinusOne, "Error 64bit zigzag on \(max)")
189+
XCTAssertEqual(proto.zigZagToi64(uMaxMinusOne), max, "Error 64bit zigzag on \(max)")
190+
191+
XCTAssertEqual(proto.i64ToZigZag(min), UInt64.max, "Error 64bit zigzag on \(min)")
192+
XCTAssertEqual(proto.zigZagToi64(UInt64.max), min, "Error 64bit zigzag on \(min)")
193+
}
194+
131195
static var allTests : [(String, (TCompactProtocolTests) -> () throws -> Void)] {
132196
return [
133197
("testInt8WriteRead", testInt8WriteRead),
@@ -138,7 +202,9 @@ class TCompactProtocolTests: XCTestCase {
138202
("testBoolWriteRead", testBoolWriteRead),
139203
("testStringWriteRead", testStringWriteRead),
140204
("testDataWriteRead", testDataWriteRead),
141-
("testStructWriteRead", testStructWriteRead)
205+
("testStructWriteRead", testStructWriteRead),
206+
("testInt32ZigZag", testInt32ZigZag),
207+
("testInt64ZigZag", testInt64ZigZag)
142208
]
143209
}
144210
}

0 commit comments

Comments
 (0)