|
| 1 | +//===----------------------------------------------------------------------===// |
| 2 | +// |
| 3 | +// This source file is part of the Swift.org open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2014 - 2023 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 | + |
1 | 13 | import SwiftParser |
2 | 14 | import SwiftParserDiagnostics |
3 | 15 | import SwiftSyntax |
4 | 16 | import XCTest |
5 | 17 | import _SwiftSyntaxTestSupport |
6 | 18 |
|
7 | 19 | final class FixItTests: XCTestCase { |
8 | | - func testEditsForFixIt() { |
9 | | - let testCases: [[(range: Range<Int>, replacement: String)]] = [ |
10 | | - [(9..<15, "Multiident "), (15..<21, "")], |
11 | | - [(9..<15, "MultiIdent "), (15..<21, "")] |
12 | | - ] |
| 20 | + func testEditsForFixIt() throws { |
| 21 | + let markedSource = "protocol 0️⃣Multi 1️⃣ident 2️⃣{}" |
| 22 | + let (markers, source) = extractMarkers(markedSource) |
| 23 | + let positions = ["0️⃣", "1️⃣", "2️⃣"].compactMap { markers[$0] } |
| 24 | + XCTAssertEqual(positions.count, 3) |
13 | 25 |
|
14 | | - let markedSource = "protocol Multi 1️⃣ident {}" |
15 | | - let (_, source) = extractMarkers(markedSource) |
| 26 | + let expectedEdits = [ |
| 27 | + SourceEdit(range: AbsolutePosition(utf8Offset: positions[0]) ..< AbsolutePosition(utf8Offset: positions[1]), replacement: "Multiident "), |
| 28 | + SourceEdit(range: AbsolutePosition(utf8Offset: positions[1]) ..< AbsolutePosition(utf8Offset: positions[2]), replacement: "") |
| 29 | + ] |
16 | 30 | let tree = Parser.parse(source: source) |
17 | 31 | let diags = ParseDiagnosticsGenerator.diagnostics(for: tree) |
18 | 32 | XCTAssertEqual(diags.count, 1) |
19 | | - let diag = diags.first! |
| 33 | + let diag = try XCTUnwrap(diags.first) |
20 | 34 | XCTAssertEqual(diag.fixIts.count, 2) |
21 | | - |
22 | | - for i in 0..<diag.fixIts.count { |
23 | | - let fixIt = diag.fixIts[i] |
24 | | - let changes = fixIt.changes |
25 | | - let edits = fixIt.edits |
26 | | - XCTAssertNotEqual(changes.count, edits.count) |
27 | | - let expctedEdits = testCases[i] |
28 | | - XCTAssertEqual(expctedEdits.count, edits.count) |
29 | | - for j in 0..<edits.count { |
30 | | - let edit = edits[j] |
31 | | - let expectedEdit = expctedEdits[j] |
32 | | - XCTAssertEqual(edit.range, AbsolutePosition(utf8Offset: expectedEdit.range.lowerBound)..<AbsolutePosition(utf8Offset: expectedEdit.range.upperBound)) |
33 | | - XCTAssertEqual(edit.replacement, expectedEdit.replacement) |
34 | | - } |
35 | | - } |
| 35 | + |
| 36 | + let fixIt = try XCTUnwrap(diag.fixIts.first) |
| 37 | + let changes = fixIt.changes |
| 38 | + let edits = fixIt.edits |
| 39 | + XCTAssertNotEqual(changes.count, edits.count) |
| 40 | + XCTAssertEqual(expectedEdits, edits) |
36 | 41 | } |
37 | 42 | } |
0 commit comments