1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2023 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
//
@testable import Testing
@Suite("Test.ID.Selection Tests")
struct Test_ID_SelectionTests {
@Test("Single-element key path")
func singleElementKeyPath() {
let selection = Test.ID.Selection(testIDs: [["A"]])
#expect(selection.contains(["A"]))
#expect(!selection.contains(["X"]))
}
@Test("One-element key path before two-element key path")
func oneElementKeyPathBeforeTwoElementKeyPath() {
let selection = Test.ID.Selection(testIDs: [["A"], ["A", "B"]])
#expect(selection.contains(["A"]))
#expect(selection.contains(["A", "B"]))
#expect(selection.contains(["A", "B", "C"]))
#expect(selection.contains(["A", "X"]))
#expect(selection.contains(["A", "X", "Y"]))
#expect(!selection.contains(["X"]))
}
@Test("Two-element key path before one-element key path")
func twoElementKeyPathBeforeOneElementKeyPath() {
let selection = Test.ID.Selection(testIDs: [["A", "B"], ["A"]])
#expect(selection.contains(["A"]))
#expect(selection.contains(["A", "B"]))
#expect(selection.contains(["A", "B", "C"]))
#expect(selection.contains(["A", "X"]))
#expect(selection.contains(["A", "X", "Y"]))
#expect(!selection.contains(["X"]))
}
@Test("Two peer key paths")
func twoPeerKeyPaths() {
let selection = Test.ID.Selection(testIDs: [["A", "B"], ["A", "C"]])
#expect(selection.contains(["A"]))
#expect(selection.contains(["A", "B"]))
#expect(selection.contains(["A", "B", "D"]))
#expect(selection.contains(["A", "C"]))
#expect(!selection.contains(["A", "X"]))
#expect(!selection.contains(["A", "X", "Y"]))
#expect(!selection.contains(["X"]))
}
@Test("Short key path before long key path")
func shortKeyPathBeforeLongKeyPath() {
let selection = Test.ID.Selection(testIDs: [["A", "B"], ["A", "B", "C", "D"]])
#expect(selection.contains(["A"]))
#expect(selection.contains(["A", "B"]))
#expect(selection.contains(["A", "B", "J"]))
#expect(selection.contains(["A", "B", "C"]))
#expect(selection.contains(["A", "B", "C", "D"]))
#expect(selection.contains(["A", "B", "C", "D", "E"]))
#expect(!selection.contains(["A", "X"]))
#expect(!selection.contains(["A", "X", "Y"]))
#expect(!selection.contains(["X"]))
}
@Test("Long key path before short key path")
func longKeyPathBeforeShortKeyPath() {
let selection = Test.ID.Selection(testIDs: [["A", "B", "C", "D"], ["A", "B"]])
#expect(selection.contains(["A"]))
#expect(selection.contains(["A", "B"]))
#expect(selection.contains(["A", "B", "J"]))
#expect(selection.contains(["A", "B", "C"]))
#expect(selection.contains(["A", "B", "C", "D"]))
#expect(selection.contains(["A", "B", "C", "D", "E"]))
#expect(!selection.contains(["A", "X"]))
#expect(!selection.contains(["A", "X", "Y"]))
#expect(!selection.contains(["X"]))
}
@Test("Long key path, then short key path, then medium key path")
func longKeyPathThenShortKeyPathThenMediumKeyPath() {
let selection = Test.ID.Selection(testIDs: [["A", "B", "C", "D", "E"], ["A"], ["A", "B", "C"]])
#expect(selection.contains(["A"]))
#expect(selection.contains(["A", "B"]))
#expect(selection.contains(["A", "B", "J"]))
#expect(selection.contains(["A", "B", "C"]))
#expect(selection.contains(["A", "B", "C", "D"]))
#expect(selection.contains(["A", "B", "C", "D", "E"]))
#expect(selection.contains(["A", "B", "C", "D", "E", "F"]))
#expect(selection.contains(["A", "X"]))
#expect(selection.contains(["A", "X", "Y"]))
#expect(!selection.contains(["X"]))
}
@Test("Inverted lookup")
func invertedLookup() {
let selection = Test.ID.Selection(testIDs: [["A", "B", "C", "D", "E"], ["A", "B", "C"]])
#expect(!selection.contains(["A"], inferAncestors: false))
#expect(!selection.contains(["A", "B"], inferAncestors: false))
#expect(!selection.contains(["A", "B", "J"], inferAncestors: false))
#expect(selection.contains(["A", "B", "C"], inferAncestors: false))
#expect(selection.contains(["A", "B", "C", "D"], inferAncestors: false))
#expect(selection.contains(["A", "B", "C", "D", "E"], inferAncestors: false))
#expect(selection.contains(["A", "B", "C", "D", "E", "F"], inferAncestors: false))
#expect(!selection.contains(["A", "X"], inferAncestors: false))
#expect(!selection.contains(["A", "X", "Y"], inferAncestors: false))
#expect(!selection.contains(["X"], inferAncestors: false))
}
}
|