-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathJSONWriterTests.swift
81 lines (56 loc) · 2.19 KB
/
JSONWriterTests.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
//
// JSONWriterTests.swift
// PotentCodables
//
// Copyright © 2021 Outfox, inc.
//
//
// Distributed under the MIT License, See LICENSE for details.
//
import Foundation
@testable import PotentJSON
import XCTest
class JSONWriterTests: XCTestCase {
func testEscapesQuotes() throws {
let json = try JSONSerialization.string(from: .string(#""test""#), options: [.escapeSlashes])
XCTAssertEqual(json, #""\"test\"""#)
}
func testEscapesForwardSlashes() throws {
let json = try JSONSerialization.string(from: .string("http://example.com/some/thing"), options: [.escapeSlashes])
XCTAssertEqual(json, #""http:\/\/example.com\/some\/thing""#)
}
func testEscapesBackwardSlashes() throws {
let json = try JSONSerialization.string(from: .string(#"c:\a\file"#), options: [.escapeSlashes])
XCTAssertEqual(json, #""c:\\a\\file""#)
}
func testEscapesBackspace() throws {
let json = try JSONSerialization.string(from: .string("\u{08}"), options: [.escapeSlashes])
XCTAssertEqual(json, #""\b""#)
}
func testEscapesFormFeed() throws {
let json = try JSONSerialization.string(from: .string("\u{0c}"), options: [.escapeSlashes])
XCTAssertEqual(json, #""\f""#)
}
func testEscapesNewLine() throws {
let json = try JSONSerialization.string(from: .string("\n"), options: [.escapeSlashes])
XCTAssertEqual(json, #""\n""#)
}
func testEscapesCarriageReturn() throws {
let json = try JSONSerialization.string(from: .string("\r"), options: [.escapeSlashes])
XCTAssertEqual(json, #""\r""#)
}
func testEscapesTab() throws {
let json = try JSONSerialization.string(from: .string("\t"), options: [.escapeSlashes])
XCTAssertEqual(json, #""\t""#)
}
func testEscapesUnicodeFormatInLongForm() throws {
let json = try JSONSerialization.string(from: .string("\u{0}"), options: [.escapeSlashes])
XCTAssertEqual(json, #""\u0000""#)
let json2 = try JSONSerialization.string(from: .string("\u{10}"), options: [.escapeSlashes])
XCTAssertEqual(json2, #""\u0010""#)
}
func testRewritesIntegerFloats() throws {
let json = try JSONSerialization.string(from: .number("100.0"), options: [.escapeSlashes])
XCTAssertEqual(json, #"100"#)
}
}