@@ -49,7 +49,13 @@ class LexerTests: XCTestCase {
49
49
}
50
50
51
51
func testSkipsWhitespace( ) throws {
52
- let token = try lexOne ( " \n \n foo \n \n " )
52
+ let token = try lexOne ( """
53
+
54
+
55
+ foo
56
+
57
+
58
+ """ )
53
59
54
60
let expected = Token (
55
61
kind: . name,
@@ -64,7 +70,10 @@ class LexerTests: XCTestCase {
64
70
}
65
71
66
72
func testSkipsComments( ) throws {
67
- let token = try lexOne ( " #comment \r \n foo#comment " )
73
+ let token = try lexOne ( """
74
+ #comment \r
75
+ foo#comment
76
+ """ )
68
77
69
78
let expected = Token (
70
79
kind: . name,
@@ -94,7 +103,13 @@ class LexerTests: XCTestCase {
94
103
}
95
104
96
105
func testErrorsRespectWhitespaces( ) throws {
97
- XCTAssertThrowsError ( try lexOne ( " \n \n ? \n \n " ) )
106
+ XCTAssertThrowsError ( try lexOne ( """
107
+
108
+
109
+ ?
110
+
111
+
112
+ """ ) )
98
113
// 'Syntax Error GraphQL (3:5) Unexpected character "?".\n' +
99
114
// '\n' +
100
115
// '2: \n' +
@@ -218,7 +233,10 @@ class LexerTests: XCTestCase {
218
233
XCTAssertThrowsError ( try lexOne ( " \" null-byte is not \u{0000} end of file \" " ) )
219
234
// "Syntax Error GraphQL (1:19) Invalid character within String: "\\u0000"."
220
235
221
- XCTAssertThrowsError ( try lexOne ( " \" multi \n line \" " ) )
236
+ XCTAssertThrowsError ( try lexOne ( """
237
+ " multi
238
+ line "
239
+ """ ) )
222
240
// "Syntax Error GraphQL (1:7) Unterminated string"
223
241
224
242
XCTAssertThrowsError ( try lexOne ( " \" multi \r line \" " ) )
@@ -700,7 +718,12 @@ class LexerTests: XCTestCase {
700
718
}
701
719
702
720
func testDoubleLinkedList( ) throws {
703
- let q = " { \n #comment \n field \n } "
721
+ let q = """
722
+ {
723
+ #comment
724
+ field
725
+ }
726
+ """
704
727
let lexer = createLexer ( source: Source ( body: q) )
705
728
706
729
let startToken = lexer. token
@@ -749,28 +772,83 @@ class LexerTests: XCTestCase {
749
772
750
773
func testBlockStringIndentAndBlankLine( ) throws {
751
774
let rawString =
752
- " \n \n \n TopLevel { \n indented \n alsoIndented \n } \n \n \n \t \t \n "
775
+ """
776
+
777
+
778
+
779
+ TopLevel {
780
+ indented
781
+ alsoIndented
782
+ }
783
+
784
+
785
+ \t \t
786
+
787
+ """
753
788
let cleanedString = blockStringValue ( rawValue: rawString)
754
789
755
- XCTAssertEqual ( cleanedString, " TopLevel { \n indented \n alsoIndented \n } " )
790
+ XCTAssertEqual ( cleanedString, """
791
+ TopLevel {
792
+ indented
793
+ alsoIndented
794
+ }
795
+ """ )
756
796
}
757
797
758
798
func testBlockStringDoubleIndentAndBlankLine( ) throws {
759
799
let rawString =
760
- " \n \n \n TopLevel { \n indented: { \n foo: String \n } \n alsoIndented \n } \n \n \n \t \t \n "
800
+ """
801
+
802
+
803
+
804
+ TopLevel {
805
+ indented: {
806
+ foo: String
807
+ }
808
+ alsoIndented
809
+ }
810
+
811
+
812
+ \t \t
813
+
814
+ """
761
815
let cleanedString = blockStringValue ( rawValue: rawString)
762
816
763
817
XCTAssertEqual (
764
818
cleanedString,
765
- " TopLevel { \n indented: { \n foo: String \n } \n alsoIndented \n } "
819
+ """
820
+ TopLevel {
821
+ indented: {
822
+ foo: String
823
+ }
824
+ alsoIndented
825
+ }
826
+ """
766
827
)
767
828
}
768
829
769
830
func testBlockStringIndentAndBlankLineFirstLineNotIndent( ) throws {
770
- let rawString = " \n \n \n TopLevel { \n indented \n alsoIndented \n } \n \n \n \t \t \n "
831
+ let rawString = """
832
+
833
+
834
+
835
+ TopLevel {
836
+ indented
837
+ alsoIndented
838
+ }
839
+
840
+
841
+ \t \t
842
+
843
+ """
771
844
let cleanedString = blockStringValue ( rawValue: rawString)
772
845
773
- XCTAssertEqual ( cleanedString, " TopLevel { \n indented \n alsoIndented \n } " )
846
+ XCTAssertEqual ( cleanedString, """
847
+ TopLevel {
848
+ indented
849
+ alsoIndented
850
+ }
851
+ """ )
774
852
}
775
853
776
854
func testBlockStringIndentBlankLineFirstLineNotIndentWeird( ) throws {
@@ -787,21 +865,43 @@ class LexerTests: XCTestCase {
787
865
"""
788
866
let cleanedString = blockStringValue ( rawValue: rawString)
789
867
790
- XCTAssertEqual ( cleanedString, " TopLevel { \n indented \n alsoIndented \n } " )
868
+ XCTAssertEqual ( cleanedString, """
869
+ TopLevel {
870
+ indented
871
+ alsoIndented
872
+ }
873
+ """ )
791
874
}
792
875
793
876
func testBlockStringIndentMultilineWithSingleSpaceIndent( ) throws {
794
- let rawString = " Multi-line string \n With Inner \" foo \" \n should be Valid "
877
+ let rawString = """
878
+ Multi-line string
879
+ With Inner \" foo \"
880
+ should be Valid
881
+ """
795
882
let cleanedString = blockStringValue ( rawValue: rawString)
796
883
797
- XCTAssertEqual ( cleanedString, " Multi-line string \n With Inner \" foo \" \n should be Valid " )
884
+ XCTAssertEqual ( cleanedString, """
885
+ Multi-line string
886
+ With Inner \" foo \"
887
+ should be Valid
888
+ """ )
798
889
}
799
890
800
891
func testBlockStringIndentMultilineWithSingleSpaceIndentExtraLines( ) throws {
801
- let rawString = " \n Multi-line string \n With Inner \" foo \" \n should be Valid \n "
892
+ let rawString = """
893
+
894
+ Multi-line string
895
+ With Inner \" foo \"
896
+ should be Valid
897
+ """
802
898
let cleanedString = blockStringValue ( rawValue: rawString)
803
899
804
- XCTAssertEqual ( cleanedString, " Multi-line string \n With Inner \" foo \" \n should be Valid " )
900
+ XCTAssertEqual ( cleanedString, """
901
+ Multi-line string
902
+ With Inner \" foo \"
903
+ should be Valid
904
+ """ )
805
905
}
806
906
807
907
// Lexer tests for Blockstring token parsing
@@ -820,7 +920,15 @@ class LexerTests: XCTestCase {
820
920
XCTAssertEqual (
821
921
token,
822
922
expected,
823
- " \n expected: \n \( dump ( expected) ) \n \n got: \n \( dump ( token) ) \n "
923
+ """
924
+
925
+ expected:
926
+ \( dump ( expected) )
927
+
928
+ got:
929
+ \( dump ( token) )
930
+
931
+ """
824
932
)
825
933
}
826
934
@@ -838,13 +946,25 @@ class LexerTests: XCTestCase {
838
946
end: 61 ,
839
947
line: 1 ,
840
948
column: 1 ,
841
- value: " Multi-line string \n With Inner \" foo \" \n should be Valid "
949
+ value: """
950
+ Multi-line string
951
+ With Inner \" foo \"
952
+ should be Valid
953
+ """
842
954
)
843
955
844
956
XCTAssertEqual (
845
957
token,
846
958
expected,
847
- " \n expected: \n \( dump ( expected) ) \n \n got: \n \( dump ( token) ) \n "
959
+ """
960
+
961
+ expected:
962
+ \( dump ( expected) )
963
+
964
+ got:
965
+ \( dump ( token) )
966
+
967
+ """
848
968
)
849
969
}
850
970
@@ -863,10 +983,20 @@ class LexerTests: XCTestCase {
863
983
end: 59 ,
864
984
line: 1 ,
865
985
column: 1 ,
866
- value: " Multi-line string \n with Inner \" foo \" \n should be valid "
986
+ value: """
987
+ Multi-line string
988
+ with Inner " foo "
989
+ should be valid
990
+ """
867
991
)
868
992
869
- XCTAssertEqual ( token, expected, " expected: \n \( dump ( expected) ) \n got: \n \( dump ( token) ) \n " )
993
+ XCTAssertEqual ( token, expected, """
994
+ expected:
995
+ \( dump ( expected) )
996
+ got:
997
+ \( dump ( token) )
998
+
999
+ """ )
870
1000
}
871
1001
872
1002
func testBlockStringUnescapedReturnsIndentTest( ) throws {
@@ -885,10 +1015,21 @@ class LexerTests: XCTestCase {
885
1015
end: 79 ,
886
1016
line: 1 ,
887
1017
column: 1 ,
888
- value: " Multi-line string { \n with Inner \" foo \" \n should be valid indented \n } "
1018
+ value: """
1019
+ Multi-line string {
1020
+ with Inner \" foo \"
1021
+ should be valid indented
1022
+ }
1023
+ """
889
1024
)
890
1025
891
- XCTAssertEqual ( token, expected, " expected: \n \( dump ( expected) ) \n got: \n \( dump ( token) ) \n " )
1026
+ XCTAssertEqual ( token, expected, """
1027
+ expected:
1028
+ \( dump ( expected) )
1029
+ got:
1030
+ \( dump ( token) )
1031
+
1032
+ """ )
892
1033
}
893
1034
894
1035
func testIndentedBlockStringWithIndents( ) throws {
@@ -910,26 +1051,47 @@ class LexerTests: XCTestCase {
910
1051
end: 103 ,
911
1052
line: 1 ,
912
1053
column: 5 ,
913
- value: " Multi-line string { \n with Inner \" foo \" \n should be valid indented \n } "
1054
+ value: """
1055
+ Multi-line string {
1056
+ with Inner \" foo \"
1057
+ should be valid indented
1058
+ }
1059
+ """
914
1060
)
915
1061
916
1062
print ( sourceStr)
917
1063
918
- XCTAssertEqual ( token, expected, " expected: \n \( dump ( expected) ) \n got: \n \( dump ( token) ) \n " )
1064
+ XCTAssertEqual ( token, expected, """
1065
+ expected:
1066
+ \( dump ( expected) )
1067
+ got:
1068
+ \( dump ( token) )
1069
+
1070
+ """ )
919
1071
}
920
1072
921
1073
// Test empty strings & multi-line string lexer token parsing
922
1074
923
1075
func testEmptyQuote( ) throws {
924
1076
let token = try lexOne ( #" "" "# )
925
1077
let expected = Token ( kind: . string, start: 1 , end: 3 , line: 1 , column: 2 , value: " " )
926
- XCTAssertEqual ( token, expected, " \n \( dump ( expected) ) \n \( dump ( token) ) \n " )
1078
+ XCTAssertEqual ( token, expected, """
1079
+
1080
+ \( dump ( expected) )
1081
+ \( dump ( token) )
1082
+
1083
+ """ )
927
1084
}
928
1085
929
1086
func testEmptySimpleBlockString( ) throws {
930
1087
let token = try lexOne ( #" """""" "# )
931
1088
let expected = Token ( kind: . blockstring, start: 1 , end: 7 , line: 1 , column: 2 , value: " " )
932
- XCTAssertEqual ( token, expected, " \n \( dump ( expected) ) \n \( dump ( token) ) \n " )
1089
+ XCTAssertEqual ( token, expected, """
1090
+
1091
+ \( dump ( expected) )
1092
+ \( dump ( token) )
1093
+
1094
+ """ )
933
1095
}
934
1096
935
1097
func testEmptyTrimmedCharactersBlockString( ) throws {
@@ -938,7 +1100,12 @@ class LexerTests: XCTestCase {
938
1100
"""
939
1101
"""# )
940
1102
let expected = Token ( kind: . blockstring, start: 0 , end: 7 , line: 1 , column: 1 , value: " " )
941
- XCTAssertEqual ( token, expected, " \n \( dump ( expected) ) \n \( dump ( token) ) \n " )
1103
+ XCTAssertEqual ( token, expected, """
1104
+
1105
+ \( dump ( expected) )
1106
+ \( dump ( token) )
1107
+
1108
+ """ )
942
1109
}
943
1110
944
1111
func testEscapedTripleQuoteInBlockString( ) throws {
@@ -955,6 +1122,11 @@ class LexerTests: XCTestCase {
955
1122
column: 1 ,
956
1123
value: " \" \" \" "
957
1124
)
958
- XCTAssertEqual ( token, expected, " \n \( dump ( expected) ) \n \( dump ( token) ) \n " )
1125
+ XCTAssertEqual ( token, expected, """
1126
+
1127
+ \( dump ( expected) )
1128
+ \( dump ( token) )
1129
+
1130
+ """ )
959
1131
}
960
1132
}
0 commit comments