Skip to content

Commit 5d0cd7a

Browse files
lgachespaulofaria
authored andcommitted
fix issue #6 compilation warnings (#8)
* fix issue #6 compilation warnings * update travis ci scripts * missed _isDebugAssertConfiguration * add test to debugDescription * clean warning
1 parent 913eec5 commit 5d0cd7a

File tree

4 files changed

+181
-137
lines changed

4 files changed

+181
-137
lines changed

.travis.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ os:
66
language: generic
77
sudo: required
88
dist: trusty
9-
osx_image: xcode8
10-
install:
11-
- eval "$(curl -sL https://raw.githubusercontent.com/Zewo/Zewo/master/Scripts/Travis/install.sh)"
9+
osx_image: xcode8.1
1210
script:
13-
- bash <(curl -s https://raw.githubusercontent.com/Zewo/Zewo/master/Scripts/Travis/build-test.sh) GraphQL
14-
#after_success:
15-
- bash <(curl -s https://raw.githubusercontent.com/Zewo/Zewo/master/Scripts/Travis/report-coverage.sh)
11+
- eval "$(curl -sL https://raw.githubusercontent.com/lgaches/swifttravisci/master/travisci)"
12+
- eval "$(curl -sL https://raw.githubusercontent.com/lgaches/swifttravisci/master/codecov)"

Sources/GraphQL/Map/Map.swift

Lines changed: 4 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -663,11 +663,11 @@ extension Map : ExpressibleByStringLiteral {
663663
public init(unicodeScalarLiteral value: String) {
664664
self = .string(value)
665665
}
666-
666+
667667
public init(extendedGraphemeClusterLiteral value: String) {
668668
self = .string(value)
669669
}
670-
670+
671671
public init(stringLiteral value: StringLiteralType) {
672672
self = .string(value)
673673
}
@@ -682,133 +682,11 @@ extension Map : ExpressibleByArrayLiteral {
682682
extension Map : ExpressibleByDictionaryLiteral {
683683
public init(dictionaryLiteral elements: (String, Map)...) {
684684
var dictionary = [String: Map](minimumCapacity: elements.count)
685-
685+
686686
for (key, value) in elements {
687687
dictionary[key] = value
688688
}
689-
690-
self = .dictionary(dictionary)
691-
}
692-
}
693-
694-
// MARK: CustomStringConvertible
695-
696-
extension Map : CustomStringConvertible {
697-
public var description: String {
698-
var indentLevel = 0
699-
700-
let escapeMapping: [Character: String] = [
701-
"\r": "\\r",
702-
"\n": "\\n",
703-
"\t": "\\t",
704-
"\\": "\\\\",
705-
"\"": "\\\"",
706-
707-
"\u{2028}": "\\u2028",
708-
"\u{2029}": "\\u2029",
709-
710-
"\r\n": "\\r\\n"
711-
]
712-
713-
func escape(_ source: String) -> String {
714-
var string = "\""
715-
716-
for character in source.characters {
717-
if let escapedSymbol = escapeMapping[character] {
718-
string.append(escapedSymbol)
719-
} else {
720-
string.append(character)
721-
}
722-
}
723-
724-
string.append("\"")
725-
return string
726-
}
727-
728-
func serialize(map: Map) -> String {
729-
switch map {
730-
case .null: return "null"
731-
case .bool(let bool): return String(bool)
732-
case .double(let number): return String(number)
733-
case .int(let number): return String(number)
734-
case .string(let string): return escape(string)
735-
case .array(let array): return serialize(array: array)
736-
case .dictionary(let dictionary): return serialize(dictionary: dictionary)
737-
}
738-
}
739689

740-
func serialize(array: [Map]) -> String {
741-
var string = "["
742-
743-
if _isDebugAssertConfiguration() {
744-
indentLevel += 1
745-
}
746-
747-
for index in 0 ..< array.count {
748-
if _isDebugAssertConfiguration() {
749-
string += "\n"
750-
string += indent()
751-
}
752-
753-
string += serialize(map: array[index])
754-
755-
if index != array.count - 1 {
756-
if _isDebugAssertConfiguration() {
757-
string += ", "
758-
} else {
759-
string += ","
760-
}
761-
}
762-
}
763-
764-
if _isDebugAssertConfiguration() {
765-
indentLevel -= 1
766-
return string + "\n" + indent() + "]"
767-
} else {
768-
return string + "]"
769-
}
770-
}
771-
772-
func serialize(dictionary: [String: Map]) -> String {
773-
var string = "{"
774-
var index = 0
775-
776-
if _isDebugAssertConfiguration() {
777-
indentLevel += 1
778-
}
779-
780-
for (key, value) in dictionary.sorted(by: {$0.0 < $1.0}) {
781-
if _isDebugAssertConfiguration() {
782-
string += "\n"
783-
string += indent()
784-
string += escape(key) + ": " + serialize(map: value)
785-
} else {
786-
string += escape(key) + ":" + serialize(map: value)
787-
}
788-
789-
if index != dictionary.count - 1 {
790-
if _isDebugAssertConfiguration() {
791-
string += ", "
792-
} else {
793-
string += ","
794-
}
795-
}
796-
797-
index += 1
798-
}
799-
800-
if _isDebugAssertConfiguration() {
801-
indentLevel -= 1
802-
return string + "\n" + indent() + "}"
803-
} else {
804-
return string + "}"
805-
}
806-
}
807-
808-
func indent() -> String {
809-
return String(repeating: " ", count: indentLevel)
810-
}
811-
812-
return serialize(map: self)
690+
self = .dictionary(dictionary)
813691
}
814692
}
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
2+
import Foundation
3+
4+
// MARK: CustomStringConvertible
5+
6+
extension Map : CustomStringConvertible {
7+
public var description: String {
8+
return description(debug: false)
9+
}
10+
}
11+
12+
// MARK: CustomDebugStringConvertible
13+
14+
extension Map:CustomDebugStringConvertible {
15+
public var debugDescription:String {
16+
return description(debug: true)
17+
}
18+
}
19+
20+
21+
// MARK: Generic Description
22+
extension Map {
23+
public func description(debug: Bool) -> String {
24+
var indentLevel = 0
25+
26+
let escapeMapping: [Character: String] = [
27+
"\r": "\\r",
28+
"\n": "\\n",
29+
"\t": "\\t",
30+
"\\": "\\\\",
31+
"\"": "\\\"",
32+
33+
"\u{2028}": "\\u2028",
34+
"\u{2029}": "\\u2029",
35+
36+
"\r\n": "\\r\\n"
37+
]
38+
39+
func escape(_ source: String) -> String {
40+
var string = "\""
41+
42+
for character in source.characters {
43+
if let escapedSymbol = escapeMapping[character] {
44+
string.append(escapedSymbol)
45+
} else {
46+
string.append(character)
47+
}
48+
}
49+
50+
string.append("\"")
51+
return string
52+
}
53+
54+
func serialize(map: Map) -> String {
55+
switch map {
56+
case .null: return "null"
57+
case .bool(let bool): return String(bool)
58+
case .double(let number): return String(number)
59+
case .int(let number): return String(number)
60+
case .string(let string): return escape(string)
61+
case .array(let array): return serialize(array: array)
62+
case .dictionary(let dictionary): return serialize(dictionary: dictionary)
63+
}
64+
}
65+
66+
func serialize(array: [Map]) -> String {
67+
var string = "["
68+
69+
if debug {
70+
indentLevel += 1
71+
}
72+
73+
for index in 0 ..< array.count {
74+
if debug {
75+
string += "\n"
76+
string += indent()
77+
}
78+
79+
string += serialize(map: array[index])
80+
81+
if index != array.count - 1 {
82+
if debug {
83+
string += ", "
84+
} else {
85+
string += ","
86+
}
87+
}
88+
}
89+
90+
if debug {
91+
indentLevel -= 1
92+
return string + "\n" + indent() + "]"
93+
} else {
94+
return string + "]"
95+
}
96+
}
97+
98+
func serialize(dictionary: [String: Map]) -> String {
99+
var string = "{"
100+
var index = 0
101+
102+
if debug {
103+
indentLevel += 1
104+
}
105+
106+
for (key, value) in dictionary.sorted(by: {$0.0 < $1.0}) {
107+
if debug {
108+
string += "\n"
109+
string += indent()
110+
string += escape(key) + ": " + serialize(map: value)
111+
} else {
112+
string += escape(key) + ":" + serialize(map: value)
113+
}
114+
115+
if index != dictionary.count - 1 {
116+
if debug {
117+
string += ", "
118+
} else {
119+
string += ","
120+
}
121+
}
122+
123+
index += 1
124+
}
125+
126+
if debug {
127+
indentLevel -= 1
128+
return string + "\n" + indent() + "}"
129+
} else {
130+
return string + "}"
131+
}
132+
}
133+
134+
func indent() -> String {
135+
return String(repeating: " ", count: indentLevel)
136+
}
137+
138+
return serialize(map: self)
139+
}
140+
}

Tests/GraphQLTests/MapTests/MapTests.swift

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -547,12 +547,40 @@ public class MapTests : XCTestCase {
547547

548548
let description = "{\"array\":[[],true,{},4.2,1969,null,\"foo\\nbar\"],\"bool\":true,\"dictionary\":{\"array\":[],\"bool\":true,\"dictionary\":{},\"double\":4.2,\"int\":1969,\"null\":null,\"string\":\"foo\\nbar\"},\"double\":4.2,\"int\":1969,\"null\":null,\"string\":\"foo\\nbar\"}"
549549

550-
if _isDebugAssertConfiguration() {
551-
XCTAssertEqual(buffer.description.characters.count, 465)
552-
} else {
553-
XCTAssertEqual(buffer.description, description)
554-
}
550+
XCTAssertEqual(buffer.description, description)
551+
555552
}
553+
554+
func testDebugDescription() {
555+
let buffer: Map = [
556+
"array": [
557+
[],
558+
true,
559+
[:],
560+
4.20,
561+
1969,
562+
nil,
563+
"foo\nbar",
564+
],
565+
"bool": true,
566+
"dictionary": [
567+
"array": [],
568+
"bool": true,
569+
"dictionary": [:],
570+
"double": 4.20,
571+
"int": 1969,
572+
"null": nil,
573+
"string": "foo\nbar",
574+
],
575+
"double": 4.20,
576+
"int": 1969,
577+
"null": nil,
578+
"string": "foo\nbar",
579+
]
580+
581+
XCTAssertEqual(buffer.debugDescription.characters.count, 465)
582+
}
583+
556584

557585
func testEquality() {
558586
let a: Map = "foo"
@@ -735,6 +763,7 @@ extension MapTests {
735763
("testCreation", testCreation),
736764
("testConversion", testConversion),
737765
("testDescription", testDescription),
766+
("testDebugDescription", testDebugDescription),
738767
("testEquality", testEquality),
739768
("testIndexPath", testIndexPath),
740769
("testMapInitializable", testMapInitializable),

0 commit comments

Comments
 (0)