|
| 1 | +// This test file has been translated from swift/test/StringProcessing/Parse/forward-slash-regex-skipping-allowed.swift |
| 2 | + |
| 3 | +import XCTest |
| 4 | + |
| 5 | +final class ForwardSlashRegexSkippingAllowedTests: XCTestCase { |
| 6 | + func testForwardSlashRegexSkippingAllowed1() { |
| 7 | + AssertParse( |
| 8 | + """ |
| 9 | + // Make sure we can skip in all of the below cases. |
| 10 | + """ |
| 11 | + ) |
| 12 | + } |
| 13 | + |
| 14 | + func testForwardSlashRegexSkippingAllowed2() { |
| 15 | + AssertParse( |
| 16 | + #""" |
| 17 | + // The printing implementation differs in asserts and no-asserts builds, it will |
| 18 | + // either print `"Parse.NumFunctionsParsed" 0` or not print it at all. Make sure |
| 19 | + // we don't output any non-zero value. |
| 20 | + // CHECK-NOT: {{"Parse.NumFunctionsParsed" [^0]}} |
| 21 | + """# |
| 22 | + ) |
| 23 | + } |
| 24 | + |
| 25 | + func testForwardSlashRegexSkippingAllowed3() { |
| 26 | + AssertParse( |
| 27 | + """ |
| 28 | + // Ensures there is a parse error |
| 29 | + var 1️⃣: Int |
| 30 | + """, |
| 31 | + diagnostics: [ |
| 32 | + // TODO: Old parser expected error on line 2: expected pattern |
| 33 | + DiagnosticSpec(message: "expected pattern in variable"), |
| 34 | + ] |
| 35 | + ) |
| 36 | + } |
| 37 | + |
| 38 | + func testForwardSlashRegexSkippingAllowed4() { |
| 39 | + AssertParse( |
| 40 | + """ |
| 41 | + // Balanced `{}`, so okay. |
| 42 | + func a() { 1️⃣/ {}/ } |
| 43 | + """, |
| 44 | + diagnostics: [ |
| 45 | + DiagnosticSpec(message: "unexpected code '/ {}/' in function"), |
| 46 | + ] |
| 47 | + ) |
| 48 | + } |
| 49 | + |
| 50 | + func testForwardSlashRegexSkippingAllowed5() { |
| 51 | + AssertParse( |
| 52 | + #""" |
| 53 | + func b() { 1️⃣/ \{}/ } |
| 54 | + """#, |
| 55 | + diagnostics: [ |
| 56 | + DiagnosticSpec(message: #"unexpected code '/ \{}/' in function"#), |
| 57 | + ] |
| 58 | + ) |
| 59 | + } |
| 60 | + |
| 61 | + func testForwardSlashRegexSkippingAllowed6() { |
| 62 | + AssertParse( |
| 63 | + #""" |
| 64 | + func c() { 1️⃣/ {"{"}/ } |
| 65 | + """#, |
| 66 | + diagnostics: [ |
| 67 | + DiagnosticSpec(message: #"unexpected code '/ {"{"}/' in function"#), |
| 68 | + ] |
| 69 | + ) |
| 70 | + } |
| 71 | + |
| 72 | + func testForwardSlashRegexSkippingAllowed7() { |
| 73 | + AssertParse( |
| 74 | + """ |
| 75 | + // Some cases of infix '/' that we should continue to skip. |
| 76 | + func d() { |
| 77 | + _ = 1 / 2 + 3 * 4 |
| 78 | + _ = 1 / 2 / 3 / 4 |
| 79 | + } |
| 80 | + """ |
| 81 | + ) |
| 82 | + } |
| 83 | + |
| 84 | + func testForwardSlashRegexSkippingAllowed8() { |
| 85 | + AssertParse( |
| 86 | + #""" |
| 87 | + func e() { |
| 88 | + let arr = [1, 2, 3] |
| 89 | + _ = arr.reduce(0, /) / 2 |
| 90 | + func foo(_ i: Int, _ fn: () -> Void) {} |
| 91 | + foo(1 / 2 / 3, { print("}}}{{{") }) |
| 92 | + } |
| 93 | + """# |
| 94 | + ) |
| 95 | + } |
| 96 | + |
| 97 | + func testForwardSlashRegexSkippingAllowed9() { |
| 98 | + AssertParse( |
| 99 | + """ |
| 100 | + // Some cases of prefix '/' that we should continue to skip. |
| 101 | + prefix operator / |
| 102 | + prefix func / <T> (_ x: T) -> T { x } |
| 103 | + """ |
| 104 | + ) |
| 105 | + } |
| 106 | + |
| 107 | + func testForwardSlashRegexSkippingAllowed10() { |
| 108 | + AssertParse( |
| 109 | + """ |
| 110 | + enum E { |
| 111 | + case e |
| 112 | + func foo<T>(_ x: T) {} |
| 113 | + } |
| 114 | + """ |
| 115 | + ) |
| 116 | + } |
| 117 | + |
| 118 | + func testForwardSlashRegexSkippingAllowed11() { |
| 119 | + AssertParse( |
| 120 | + """ |
| 121 | + func f() { |
| 122 | + _ = /E.e |
| 123 | + (/E.e).foo(/0) |
| 124 | + func foo<T, U>(_ x: T, _ y: U) {} |
| 125 | + foo(/E.e, /E.e) |
| 126 | + foo((/E.e), /E.e) |
| 127 | + foo((/)(E.e), /E.e) |
| 128 | + func bar<T>(_ x: T) -> Int { 0 } |
| 129 | + _ = bar(/E.e) / 2 |
| 130 | + } |
| 131 | + """ |
| 132 | + ) |
| 133 | + } |
| 134 | + |
| 135 | + func testForwardSlashRegexSkippingAllowed12() { |
| 136 | + AssertParse( |
| 137 | + """ |
| 138 | + postfix operator / |
| 139 | + prefix func / <T> (_ x: T) -> T { x } |
| 140 | + """ |
| 141 | + ) |
| 142 | + } |
| 143 | + |
| 144 | + func testForwardSlashRegexSkippingAllowed13() { |
| 145 | + AssertParse( |
| 146 | + """ |
| 147 | + // Some cases of postfix '/' that we should continue to skip. |
| 148 | + func g() { |
| 149 | + _ = 0/ |
| 150 | + _ = 0/ / 1/ |
| 151 | + _ = 1/ + 1/ |
| 152 | + _ = 1 + 2/ |
| 153 | + } |
| 154 | + """ |
| 155 | + ) |
| 156 | + } |
| 157 | + |
| 158 | +} |
0 commit comments