|
| 1 | +//===----------------------------------------------------------------------===// |
| 2 | +// |
| 3 | +// This source file is part of the Swift.org open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2014 - 2022 Apple Inc. and the Swift project authors |
| 6 | +// Licensed under Apache License v2.0 with Runtime Library Exception |
| 7 | +// |
| 8 | +// See https://swift.org/LICENSE.txt for license information |
| 9 | +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors |
| 10 | +// |
| 11 | +//===----------------------------------------------------------------------===// |
| 12 | + |
| 13 | +// This test file has been translated from swift/test/StringProcessing/Parse/raw_string.swift |
| 14 | + |
| 15 | +import XCTest |
| 16 | + |
| 17 | +final class RawStringTests: XCTestCase { |
| 18 | + func testRawString1() { |
| 19 | + AssertParse( |
| 20 | + """ |
| 21 | + import Swift |
| 22 | + """ |
| 23 | + ) |
| 24 | + } |
| 25 | + |
| 26 | + func testRawString2() { |
| 27 | + AssertParse( |
| 28 | + ##""" |
| 29 | + _ = #""" |
| 30 | + ################################################################### |
| 31 | + ## This source file is part of the Swift.org open source project ## |
| 32 | + ################################################################### |
| 33 | + """# |
| 34 | + """## |
| 35 | + ) |
| 36 | + } |
| 37 | + |
| 38 | + func testRawString3() { |
| 39 | + AssertParse( |
| 40 | + ####""" |
| 41 | + _ = #""" |
| 42 | + # H1 # |
| 43 | + ## H2 ## |
| 44 | + ### H3 ### |
| 45 | + """# |
| 46 | + """#### |
| 47 | + ) |
| 48 | + } |
| 49 | + |
| 50 | + func testRawString5() { |
| 51 | + AssertParse( |
| 52 | + ###""" |
| 53 | + _ = ##""" |
| 54 | + One |
| 55 | + ""Alpha"" |
| 56 | + """## |
| 57 | + """### |
| 58 | + ) |
| 59 | + } |
| 60 | + |
| 61 | + func testRawString6() { |
| 62 | + AssertParse( |
| 63 | + ###""" |
| 64 | + _ = ##""" |
| 65 | + Two |
| 66 | + Beta |
| 67 | + """## |
| 68 | + """### |
| 69 | + ) |
| 70 | + } |
| 71 | + |
| 72 | + func testRawString7() { |
| 73 | + AssertParse( |
| 74 | + ##""" |
| 75 | + _ = #""" |
| 76 | + Three\r |
| 77 | + Gamma\ |
| 78 | + """# |
| 79 | + """## |
| 80 | + ) |
| 81 | + } |
| 82 | + |
| 83 | + func testRawString8() { |
| 84 | + AssertParse( |
| 85 | + ####""" |
| 86 | + _ = ###""" |
| 87 | + Four \(foo) |
| 88 | + Delta |
| 89 | + """### |
| 90 | + """#### |
| 91 | + ) |
| 92 | + } |
| 93 | + |
| 94 | + func testRawString9() { |
| 95 | + AssertParse( |
| 96 | + ###""" |
| 97 | + _ = ##""" |
| 98 | + print(""" |
| 99 | + Five\##n\##n\##nEpsilon |
| 100 | + """) |
| 101 | + """## |
| 102 | + """### |
| 103 | + ) |
| 104 | + } |
| 105 | + |
| 106 | + func testRawString10() { |
| 107 | + AssertParse( |
| 108 | + """ |
| 109 | + // ===---------- Single line --------=== |
| 110 | + """ |
| 111 | + ) |
| 112 | + } |
| 113 | + |
| 114 | + func testRawString11() { |
| 115 | + AssertParse( |
| 116 | + ##""" |
| 117 | + _ = #""Zeta""# |
| 118 | + """## |
| 119 | + ) |
| 120 | + } |
| 121 | + |
| 122 | + func testRawString12() { |
| 123 | + AssertParse( |
| 124 | + ##""" |
| 125 | + _ = #""Eta"\#n\#n\#n\#""# |
| 126 | + """## |
| 127 | + ) |
| 128 | + } |
| 129 | + |
| 130 | + func testRawString13() { |
| 131 | + AssertParse( |
| 132 | + ##""" |
| 133 | + _ = #""Iota"\n\n\n\""# |
| 134 | + """## |
| 135 | + ) |
| 136 | + } |
| 137 | + |
| 138 | + func testRawString14() { |
| 139 | + AssertParse( |
| 140 | + ##""" |
| 141 | + _ = #"a raw string with \" in it"# |
| 142 | + """## |
| 143 | + ) |
| 144 | + } |
| 145 | + |
| 146 | + func testRawString15() { |
| 147 | + AssertParse( |
| 148 | + ###""" |
| 149 | + _ = ##""" |
| 150 | + a raw string with """ in it |
| 151 | + """## |
| 152 | + """### |
| 153 | + ) |
| 154 | + } |
| 155 | + |
| 156 | + func testRawString16() { |
| 157 | + AssertParse( |
| 158 | + """ |
| 159 | + // ===---------- False Multiline Delimiters --------=== |
| 160 | + """ |
| 161 | + ) |
| 162 | + } |
| 163 | + |
| 164 | + func testRawString17() { |
| 165 | + AssertParse( |
| 166 | + ##""" |
| 167 | + /// Source code contains zero-width character in this format: `#"[U+200B]"[U+200B]"#` |
| 168 | + /// The check contains zero-width character in this format: `"[U+200B]\"[U+200B]"` |
| 169 | + /// If this check fails after you implement `diagnoseZeroWidthMatchAndAdvance`, |
| 170 | + /// then you may need to tweak how to test for single-line string literals that |
| 171 | + /// resemble a multiline delimiter in `advanceIfMultilineDelimiter` so that it |
| 172 | + /// passes again. |
| 173 | + /// See https://github.com/apple/swift/issues/51192. |
| 174 | + _ = #"""# |
| 175 | + """## |
| 176 | + ) |
| 177 | + } |
| 178 | + |
| 179 | + func testRawString18() { |
| 180 | + AssertParse( |
| 181 | + ##""" |
| 182 | + _ = #""""# |
| 183 | + """## |
| 184 | + ) |
| 185 | + } |
| 186 | + |
| 187 | + func testRawString19() { |
| 188 | + AssertParse( |
| 189 | + ##""" |
| 190 | + _ = #"""""# |
| 191 | + """## |
| 192 | + ) |
| 193 | + } |
| 194 | + |
| 195 | + func testRawString20() { |
| 196 | + AssertParse( |
| 197 | + ##""" |
| 198 | + _ = #""""""# |
| 199 | + """## |
| 200 | + ) |
| 201 | + } |
| 202 | + |
| 203 | + func testRawString21() { |
| 204 | + AssertParse( |
| 205 | + ##""" |
| 206 | + _ = #"""# |
| 207 | + """## |
| 208 | + ) |
| 209 | + } |
| 210 | + |
| 211 | + func testRawString22() { |
| 212 | + AssertParse( |
| 213 | + ###""" |
| 214 | + _ = ##""" foo # "# "## |
| 215 | + """### |
| 216 | + ) |
| 217 | + } |
| 218 | + |
| 219 | + func testRawString23() { |
| 220 | + AssertParse( |
| 221 | + ####""" |
| 222 | + _ = ###""" "# "## "### |
| 223 | + """#### |
| 224 | + ) |
| 225 | + } |
| 226 | + |
| 227 | + func testRawString24() { |
| 228 | + AssertParse( |
| 229 | + ####""" |
| 230 | + _ = ###"""##"### |
| 231 | + """#### |
| 232 | + ) |
| 233 | + } |
| 234 | + |
| 235 | + func testRawString25() { |
| 236 | + AssertParse( |
| 237 | + ##""" |
| 238 | + _ = "interpolating \(#"""false delimiter"#)" |
| 239 | + """## |
| 240 | + ) |
| 241 | + } |
| 242 | + |
| 243 | + func testRawString26() { |
| 244 | + AssertParse( |
| 245 | + ##""" |
| 246 | + _ = """ |
| 247 | + interpolating \(#"""false delimiters"""#) |
| 248 | + """ |
| 249 | + """## |
| 250 | + ) |
| 251 | + } |
| 252 | + |
| 253 | + func testRawString27() { |
| 254 | + AssertParse( |
| 255 | + ##""" |
| 256 | + let foo = "Interpolation" |
| 257 | + _ = #"\b\b \#(foo)\#(foo) Kappa"# |
| 258 | + """## |
| 259 | + ) |
| 260 | + } |
| 261 | + |
| 262 | + func testRawString28() { |
| 263 | + AssertParse( |
| 264 | + ###""" |
| 265 | + _ = """ |
| 266 | + interpolating \(##""" |
| 267 | + delimited \##("string")\#n\##n |
| 268 | + """##) |
| 269 | + """ |
| 270 | + """### |
| 271 | + ) |
| 272 | + } |
| 273 | + |
| 274 | + func testRawString30() { |
| 275 | + AssertParse( |
| 276 | + ##""" |
| 277 | + #"unused literal"# |
| 278 | + """## |
| 279 | + ) |
| 280 | + } |
| 281 | + |
| 282 | + func testRawString32() { |
| 283 | + AssertParse( |
| 284 | + ##""" |
| 285 | + _ = #"This is a string"# |
| 286 | + """## |
| 287 | + ) |
| 288 | + } |
| 289 | + |
| 290 | + func testRawString33() { |
| 291 | + AssertParse( |
| 292 | + ######""" |
| 293 | + _ = #####"This is a string"##### |
| 294 | + """###### |
| 295 | + ) |
| 296 | + } |
| 297 | + |
| 298 | + func testRawString34() { |
| 299 | + AssertParse( |
| 300 | + ###""" |
| 301 | + _ = #"enum\s+.+\{.*case\s+[:upper:]"# |
| 302 | + _ = #"Alice: "How long is forever?" White Rabbit: "Sometimes, just one second.""# |
| 303 | + _ = #"\#\#1"# |
| 304 | + _ = ##"\#1"## |
| 305 | + _ = #"c:\windows\system32"# |
| 306 | + _ = #"\d{3) \d{3} \d{4}"# |
| 307 | + _ = #""" |
| 308 | + a string with |
| 309 | + """ |
| 310 | + in it |
| 311 | + """# |
| 312 | + _ = #"a raw string containing \r\n"# |
| 313 | + _ = #""" |
| 314 | + [ |
| 315 | + { |
| 316 | + "id": "12345", |
| 317 | + "title": "A title that \"contains\" \\\"" |
| 318 | + } |
| 319 | + ] |
| 320 | + """# |
| 321 | + _ = #"# #"# |
| 322 | + """### |
| 323 | + ) |
| 324 | + } |
| 325 | +} |
0 commit comments