aboutsummaryrefslogtreecommitdiff
path: root/MapTests/MapParserStrategyTests.swift
diff options
context:
space:
mode:
authorRuben Beltran del Rio <git@r.bdr.sh>2025-07-04 17:06:28 +0200
committerRuben Beltran del Rio <git@r.bdr.sh>2025-07-04 17:06:28 +0200
commitc843d34f56c207abcf4b93e424125eea2dc601e0 (patch)
tree415dc2d9be4be31e290e1dd1dedb0b630c5e8fc6 /MapTests/MapParserStrategyTests.swift
parented10ac191df473c92c4fec495aafa7f569d108c8 (diff)
Upgrade to Swift 6
Diffstat (limited to 'MapTests/MapParserStrategyTests.swift')
-rw-r--r--MapTests/MapParserStrategyTests.swift163
1 files changed, 163 insertions, 0 deletions
diff --git a/MapTests/MapParserStrategyTests.swift b/MapTests/MapParserStrategyTests.swift
new file mode 100644
index 0000000..c9f92e8
--- /dev/null
+++ b/MapTests/MapParserStrategyTests.swift
@@ -0,0 +1,163 @@
+// Copyright (C) 2024 Rubén Beltrán del Río
+
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+import CoreGraphics
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see https://map.tranquil.systems.
+import Testing
+
+@testable import Map
+
+struct MapParserStrategyTests {
+
+ @Test func testVertexParserStrategyCanHandle() async throws {
+ let strategy = VertexParserStrategy()
+
+ #expect(strategy.canHandle(line: "Node (10, 20)"))
+ #expect(strategy.canHandle(line: "NodeWithDecimals (30.5, 40.2)"))
+ #expect(strategy.canHandle(line: "Multi Word Node (0, 100)"))
+ #expect(strategy.canHandle(line: "Node C (50, 60) [square]"))
+
+ #expect(!strategy.canHandle(line: "Node A -> Node B"))
+ #expect(!strategy.canHandle(line: "[Note] (10, 20) Test"))
+ #expect(!strategy.canHandle(line: "Invalid line"))
+ }
+
+ @Test func testVertexParserStrategyHandle() async throws {
+ let strategy = VertexParserStrategy()
+ let vertices: [String: Vertex] = [:]
+
+ let (type, object) = strategy.handle(index: 0, line: "Test Node (25, 75)", vertices: vertices)
+
+ #expect(String(describing: type) == String(describing: Vertex.self))
+ let vertex = object as! Vertex
+ #expect(vertex.id == 0)
+ #expect(vertex.label == "Test Node")
+ #expect(vertex.position.x == 25.0)
+ #expect(vertex.position.y == 75.0)
+ #expect(vertex.shape == .circle)
+ }
+
+ @Test func testVertexParserStrategyHandleWithShape() async throws {
+ let strategy = VertexParserStrategy()
+ let vertices: [String: Vertex] = [:]
+
+ let (type, object) = strategy.handle(
+ index: 1, line: "Shaped Node (10, 20) [triangle]", vertices: vertices)
+
+ #expect(String(describing: type) == String(describing: Vertex.self))
+ let vertex = object as! Vertex
+ #expect(vertex.shape == .triangle)
+ }
+
+ @Test func testEdgeParserStrategyCanHandle() async throws {
+ let strategy = EdgeParserStrategy()
+
+ #expect(strategy.canHandle(line: "Node A -- Node B"))
+ #expect(strategy.canHandle(line: "Node A -> Node B"))
+ #expect(strategy.canHandle(line: "Multi Word A -> Multi Word B"))
+
+ #expect(!strategy.canHandle(line: "Node A (10, 20)"))
+ #expect(!strategy.canHandle(line: "[Note] (10, 20) Test"))
+ #expect(!strategy.canHandle(line: "Invalid line"))
+ }
+
+ @Test func testEdgeParserStrategyHandle() async throws {
+ let strategy = EdgeParserStrategy()
+ let vertices: [String: Vertex] = [
+ "Node A": Vertex(id: 0, label: "Node A", position: CGPoint(x: 10, y: 20)),
+ "Node B": Vertex(id: 1, label: "Node B", position: CGPoint(x: 30, y: 40)),
+ ]
+
+ let (type, object) = strategy.handle(index: 2, line: "Node A -> Node B", vertices: vertices)
+
+ #expect(String(describing: type) == String(describing: MapEdge.self))
+ let edge = object as! MapEdge
+ #expect(edge.id == 2)
+ #expect(edge.origin.x == 10.0)
+ #expect(edge.origin.y == 20.0)
+ #expect(edge.destination.x == 30.0)
+ #expect(edge.destination.y == 40.0)
+ #expect(edge.arrowhead == true)
+ }
+
+ @Test func testEdgeParserStrategyHandleWithMissingVertex() async throws {
+ let strategy = EdgeParserStrategy()
+ let vertices: [String: Vertex] = [
+ "Node A": Vertex(id: 0, label: "Node A", position: CGPoint(x: 10, y: 20))
+ ]
+
+ let (type, object) = strategy.handle(index: 2, line: "Node A -> Node B", vertices: vertices)
+
+ #expect(String(describing: type) == String(describing: NSObject.self))
+ #expect(object is NSObject)
+ }
+
+ @Test func testNoteParserStrategyCanHandle() async throws {
+ let strategy = NoteParserStrategy()
+
+ #expect(strategy.canHandle(line: "[Note] (10, 20) Test note"))
+ #expect(strategy.canHandle(line: "[Note] (50.5, 60.2) Multi word note"))
+
+ #expect(!strategy.canHandle(line: "Node A (10, 20)"))
+ #expect(!strategy.canHandle(line: "Node A -> Node B"))
+ #expect(!strategy.canHandle(line: "Invalid line"))
+ }
+
+ @Test func testBlockerParserStrategyCanHandle() async throws {
+ let strategy = BlockerParserStrategy()
+
+ #expect(strategy.canHandle(line: "[Blocker] Node A"))
+ #expect(strategy.canHandle(line: "[Blocker] Multi Word Node"))
+
+ #expect(!strategy.canHandle(line: "Node A (10, 20)"))
+ #expect(!strategy.canHandle(line: "[Note] (10, 20) Test"))
+ #expect(!strategy.canHandle(line: "Invalid line"))
+ }
+
+ @Test func testOpportunityParserStrategyCanHandle() async throws {
+ let strategy = OpportunityParserStrategy()
+
+ #expect(strategy.canHandle(line: "[Evolution] Node A +15"))
+ #expect(strategy.canHandle(line: "[Evolution] Node B -10"))
+ #expect(strategy.canHandle(line: "[Evolution] Multi Word Node +5.5"))
+
+ #expect(!strategy.canHandle(line: "Node A (10, 20)"))
+ #expect(!strategy.canHandle(line: "[Blocker] Node A"))
+ #expect(!strategy.canHandle(line: "Invalid line"))
+ }
+
+ @Test func testStageParserStrategyCanHandle() async throws {
+ let strategy = StageParserStrategy()
+
+ #expect(strategy.canHandle(line: "[I] 25"))
+ #expect(strategy.canHandle(line: "[II] 50.5"))
+ #expect(strategy.canHandle(line: "[III] 75"))
+
+ #expect(!strategy.canHandle(line: "[IV] 100"))
+ #expect(!strategy.canHandle(line: "Node A (10, 20)"))
+ #expect(!strategy.canHandle(line: "Invalid line"))
+ }
+
+ @Test func testGroupParserStrategyCanHandle() async throws {
+ let strategy = GroupParserStrategy()
+
+ #expect(strategy.canHandle(line: "[Group] Node A, Node B"))
+ #expect(strategy.canHandle(line: "[Group] Node A, Node B, Node C"))
+ #expect(strategy.canHandle(line: "[Group] Multi Word A, Multi Word B"))
+
+ #expect(!strategy.canHandle(line: "Node A (10, 20)"))
+ #expect(!strategy.canHandle(line: "[Note] (10, 20) Test"))
+ #expect(!strategy.canHandle(line: "Invalid line"))
+ }
+
+}