Skip to content

Commit bfe1cde

Browse files
committed
TestHelpers: add debugVM and showIndex.
1 parent 5105ddd commit bfe1cde

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

Tests/PatternsTests/TestHelpers.swift

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77

88
import Foundation
9-
import Patterns
9+
@testable import Patterns
1010
import XCTest
1111

1212
extension Array where Element: Hashable {
@@ -161,3 +161,21 @@ extension StringProtocol where Index == String.Index {
161161
return result
162162
}
163163
}
164+
165+
func debugVM<Input, C: BidirectionalCollection>(_ instructions: C, thread: VMEngine<Input>.Thread, input: Input)
166+
where C.Index == Int, Input: StringProtocol, Input: RangeReplaceableCollection {
167+
for i in instructions.indices {
168+
print(i == thread.instructionIndex ? ">" : " ", terminator: "")
169+
print("\(i)".padding(toLength: 2, withPad: " ", startingAt: 0), instructions[i])
170+
}
171+
print(input.showIndex(thread.inputIndex))
172+
print()
173+
}
174+
175+
extension StringProtocol where Self: RangeReplaceableCollection {
176+
func showIndex(_ index: Index) -> Self {
177+
var result = self
178+
result.insert("_", at: index)
179+
return result
180+
}
181+
}

0 commit comments

Comments
 (0)