Skip to content

Commit d5f7373

Browse files
committed
fixing a typo from swift-aws; add more tests.
1 parent a18023f commit d5f7373

File tree

2 files changed

+82
-41
lines changed

2 files changed

+82
-41
lines changed

[email protected]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
//
2121

2222
import PackageDescription
23-
d
23+
2424
let package = Package(
2525
name: "INIParser",
2626
products: [

Tests/INIParserTests/INIParserTests.swift

Lines changed: 81 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -21,49 +21,90 @@ import XCTest
2121
@testable import INIParser
2222

2323
class INIParserTests: XCTestCase {
24-
func testExample() {
25-
let raw = """
26-
; last modified 1 April 2017 by Rockford Wei
27-
## This is another comment
28-
freeVar1 = 1
29-
freeVar2 = 2;
30-
url = http://example.com/results?limit=10
31-
[owner]
32-
name = Rocky
33-
organization = PerfectlySoft
34-
;
35-
[database]
36-
server = 192.0.2.42 ; use IP address in case network name resolution is not working
3724

38-
port = 143
39-
file = \"中文.dat ' ' \"
40-
[汉化]
41-
变量1 = 🇨🇳 ;使用utf8
42-
变量2 = 加拿大。
43-
[ 乱死了 ]
44-
"""
25+
let path = "/tmp/a.ini"
4526

46-
let path = "/tmp/a.ini"
47-
do {
48-
try raw.write(to: URL.init(fileURLWithPath: path), atomically: true, encoding: .utf8)
49-
let ini = try INIParser(path)
50-
XCTAssertEqual(ini.anonymousSection["freeVar1"] ?? "", "1")
51-
XCTAssertEqual(ini.anonymousSection["freeVar2"] ?? "", "2")
52-
XCTAssertEqual(ini.anonymousSection["url"] ?? "", "http://example.com/results?limit=10")
53-
XCTAssertEqual(ini.sections["owner"]?["name"] ?? "", "Rocky")
54-
XCTAssertEqual(ini.sections["owner"]?["organization"] ?? "", "PerfectlySoft")
55-
XCTAssertEqual(ini.sections["database"]?["server"] ?? "", "192.0.2.42")
56-
XCTAssertEqual(ini.sections["database"]?["port"] ?? "", "143")
57-
XCTAssertEqual(ini.sections["database"]?["file"] ?? "", "\"中文.dat \' \' \"")
58-
XCTAssertEqual(ini.sections["汉化"]?["变量1"] ?? "", "🇨🇳")
59-
XCTAssertEqual(ini.sections["汉化"]?["变量2"] ?? "", "加拿大。")
60-
}catch (let err) {
61-
XCTFail(err.localizedDescription)
62-
}
27+
override func setUp() {
28+
let raw =
29+
"""
30+
; last modified 1 April 2017 by Rockford Wei
31+
## This is another comment
32+
freeVar1 = 1
33+
freeVar2 = 2;
34+
url = http://example.com/results?limit=10
35+
[owner]
36+
name = Rocky
37+
organization = PerfectlySoft
38+
;
39+
[database]
40+
server = 192.0.2.42 ; use IP address in case network name resolution is not working
41+
42+
port = 143
43+
file = \"中文.dat ' ' \"
44+
[汉化]
45+
变量1 = 🇨🇳 ;使用utf8
46+
变量2 = 加拿大。
47+
[ 乱死了 ]
48+
"""
49+
do {
50+
try raw.write(to: URL.init(fileURLWithPath: path), atomically: true, encoding: .utf8)
51+
}catch (let err) {
52+
XCTFail(err.localizedDescription)
53+
}
54+
}
55+
56+
func validate(ini: INIParser) {
57+
XCTAssertEqual(ini.anonymousSection["freeVar1"] ?? "", "1")
58+
XCTAssertEqual(ini.anonymousSection["freeVar2"] ?? "", "2")
59+
XCTAssertEqual(ini.anonymousSection["url"] ?? "", "http://example.com/results?limit=10")
60+
XCTAssertEqual(ini.sections["owner"]?["name"] ?? "", "Rocky")
61+
XCTAssertEqual(ini.sections["owner"]?["organization"] ?? "", "PerfectlySoft")
62+
XCTAssertEqual(ini.sections["database"]?["server"] ?? "", "192.0.2.42")
63+
XCTAssertEqual(ini.sections["database"]?["port"] ?? "", "143")
64+
XCTAssertEqual(ini.sections["database"]?["file"] ?? "", "\"中文.dat \' \' \"")
65+
XCTAssertEqual(ini.sections["汉化"]?["变量1"] ?? "", "🇨🇳")
66+
XCTAssertEqual(ini.sections["汉化"]?["变量2"] ?? "", "加拿大。")
67+
}
68+
69+
func testExample() {
70+
do {
71+
let ini = try INIParser(path)
72+
validate(ini: ini)
73+
}catch (let err) {
74+
XCTFail(err.localizedDescription)
75+
}
76+
}
77+
78+
func testData() {
79+
do {
80+
let url = URL(fileURLWithPath: path)
81+
let data = try Data(contentsOf: url)
82+
let ini = try INIParser(data: data)
83+
validate(ini: ini)
84+
}catch (let err) {
85+
XCTFail(err.localizedDescription)
86+
}
87+
}
88+
89+
func testString() {
90+
do {
91+
let url = URL(fileURLWithPath: path)
92+
let data = try Data(contentsOf: url)
93+
let string = String(data: data, encoding: .utf8) ?? "fault"
94+
let ini = try INIParser(string: string)
95+
validate(ini: ini)
96+
}catch (let err) {
97+
XCTFail(err.localizedDescription)
6398
}
99+
}
64100

101+
override func tearDown() {
102+
unlink(path)
103+
}
65104

66-
static var allTests = [
67-
("testExample", testExample),
68-
]
105+
static var allTests = [
106+
("testExample", testExample),
107+
("testData", testData),
108+
("testString", testString)
109+
]
69110
}

0 commit comments

Comments
 (0)