Skip to content

Commit cfed222

Browse files
authored
Test Matchable with RawRepresentable default impl (#14)
This PR adds tests for default implementation for `Matchable` and it's also `RawRepresentable`.
1 parent 15b0b2a commit cfed222

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//
2+
// TestMatchable.swift
3+
// BinaryParseKit
4+
//
5+
// Created by Larry Zeng on 11/22/25.
6+
//
7+
8+
import BinaryParseKit
9+
import Testing
10+
11+
extension String: Matchable {
12+
public func bytesToMatch() -> [UInt8] {
13+
utf8.map(\.self)
14+
}
15+
}
16+
17+
@Suite
18+
struct MatchableTests {
19+
enum RawRepresentableMatch: UInt8, Matchable, Codable {
20+
case success = 0x00
21+
case failure = 0x01
22+
}
23+
24+
@Test(arguments: [
25+
RawRepresentableMatch.success,
26+
.failure,
27+
])
28+
func `byte generated from RawRepresentable`(_ input: RawRepresentableMatch) {
29+
#expect(input.bytesToMatch() == [input.rawValue])
30+
}
31+
32+
enum CustomRawRepresentable: String, Matchable, Codable {
33+
case first = "one"
34+
case second = "two"
35+
case third = "three"
36+
}
37+
38+
@Test(arguments: [
39+
CustomRawRepresentable.first,
40+
.second,
41+
.third,
42+
])
43+
func `bytes generated from CustomRawRepresentable`(_ input: CustomRawRepresentable) {
44+
#expect(input.bytesToMatch() == Array(input.rawValue.utf8))
45+
}
46+
}

0 commit comments

Comments
 (0)