|
| 1 | +import XCTest |
| 2 | +import VisuStructCore |
| 3 | + |
| 4 | +final class MultiwayPathTests: XCTestCase { |
| 5 | + /// `[0]` Anweisung, `[1]` Fallauswahl mit zwei Fällen; im zweiten Fall eine innere Fallauswahl `[1, 1, 0]`. |
| 6 | + private func document() -> VisuStructDocument { |
| 7 | + let statement = VisuStructElement(type: .anweisung, textLines: ["x = 1"]) |
| 8 | + let inner = VisuStructElement( |
| 9 | + type: .fallauswahl, |
| 10 | + textLines: ["y"], |
| 11 | + cases: [ |
| 12 | + VisuStructCase(name: "1", elements: [statement]), |
| 13 | + VisuStructCase(name: "default", elements: [statement]), |
| 14 | + ] |
| 15 | + ) |
| 16 | + let outer = VisuStructElement( |
| 17 | + type: .fallauswahl, |
| 18 | + textLines: ["x"], |
| 19 | + cases: [ |
| 20 | + VisuStructCase(name: "1", elements: [statement]), |
| 21 | + VisuStructCase(name: "default", elements: [inner]), |
| 22 | + ] |
| 23 | + ) |
| 24 | + var doc = VisuStructDocumentEditing.newEmpty() |
| 25 | + doc.elements = [statement, outer] |
| 26 | + return doc |
| 27 | + } |
| 28 | + |
| 29 | + func testAncestorIsInnermostFallauswahl() { |
| 30 | + let doc = document() |
| 31 | + XCTAssertNil(VisuStructDocumentEditing.multiwayAncestorPath(for: nil, in: doc)) |
| 32 | + XCTAssertNil(VisuStructDocumentEditing.multiwayAncestorPath(for: [0], in: doc)) |
| 33 | + XCTAssertEqual(VisuStructDocumentEditing.multiwayAncestorPath(for: [1], in: doc), [1]) |
| 34 | + XCTAssertEqual(VisuStructDocumentEditing.multiwayAncestorPath(for: [1, 0, 0], in: doc), [1]) |
| 35 | + XCTAssertEqual(VisuStructDocumentEditing.multiwayAncestorPath(for: [1, 1, 0], in: doc), [1, 1, 0]) |
| 36 | + XCTAssertEqual(VisuStructDocumentEditing.multiwayAncestorPath(for: [1, 1, 0, 1, 0], in: doc), [1, 1, 0]) |
| 37 | + } |
| 38 | + |
| 39 | + func testCaseIndex() { |
| 40 | + XCTAssertNil(VisuStructDocumentEditing.caseIndex(of: [1], inMultiwayAt: [1])) |
| 41 | + XCTAssertNil(VisuStructDocumentEditing.caseIndex(of: nil, inMultiwayAt: [1])) |
| 42 | + XCTAssertEqual(VisuStructDocumentEditing.caseIndex(of: [1, 1, 0], inMultiwayAt: [1]), 1) |
| 43 | + } |
| 44 | +} |
0 commit comments