xtool.git
Publicgit clone https://git.maproj.org/xtool.gitxtool.git / Tests / XToolTests / MatcherTests.swift
MatcherTests.swift52 lines · 1.6 KiBRaw
| 1 | import Testing |
| 2 | @testable import XToolSupport |
| 3 | |
| 4 | extension SDKEntry { |
| 5 | fileprivate static let test = E("Root", [ |
| 6 | E("Intermediate", [ |
| 7 | E("Leaf"), |
| 8 | ]), |
| 9 | E("AnotherLeaf"), |
| 10 | E("BeforeWildcard", [ |
| 11 | E(nil, [ |
| 12 | E("AfterWildcard"), |
| 13 | ]), |
| 14 | ]), |
| 15 | ]) |
| 16 | } |
| 17 | |
| 18 | @Test func testMatcherSupportsSlices() { |
| 19 | let s = SDKEntry.test |
| 20 | |
| 21 | let slice0 = ["Root"].map { $0[...] }[0...] |
| 22 | #expect(s.matches(slice0)) |
| 23 | |
| 24 | let slice1 = ["foo", "bar", "Root"].map { $0[...] }[2...] |
| 25 | #expect(s.matches(slice1)) |
| 26 | |
| 27 | let slice2 = ["foo", "bar", "NotRoot"].map { $0[...] }[2...] |
| 28 | #expect(!s.matches(slice2)) |
| 29 | } |
| 30 | |
| 31 | @Test func testMatcherLeaves() { |
| 32 | let s = SDKEntry.test |
| 33 | |
| 34 | #expect(s.matches(["Root", "Intermediate"])) |
| 35 | #expect(!s.matches(["Root", "NotIntermediate"])) |
| 36 | |
| 37 | #expect(s.matches(["Root", "Intermediate", "Leaf"])) |
| 38 | #expect(!s.matches(["Root", "Intermediate", "NotLeaf"])) |
| 39 | #expect(s.matches(["Root", "Intermediate", "Leaf", "AfterLeaf"])) |
| 40 | |
| 41 | #expect(s.matches(["Root", "AnotherLeaf"])) |
| 42 | #expect(s.matches(["Root", "AnotherLeaf", "AfterAnotherLeaf"])) |
| 43 | |
| 44 | #expect(!s.matches(["Junk", "Root"])) |
| 45 | |
| 46 | #expect(s.matches(["Root", "BeforeWildcard"])) |
| 47 | #expect(s.matches(["Root", "BeforeWildcard", "Blah"])) |
| 48 | #expect(s.matches(["Root", "BeforeWildcard", "Blah", "AfterWildcard"])) |
| 49 | #expect(s.matches(["Root", "BeforeWildcard", "Blah", "AfterWildcard", "Suffix"])) |
| 50 | #expect(!s.matches(["Root", "BeforeWildcard", "Blah", "NotAfterWildcard"])) |
| 51 | #expect(!s.matches(["Root", "BeforeWildcard", "Blah", "NotAfterWildcard", "Suffix"])) |
| 52 | } |