Skip to content

Commit

Permalink
✅ Move to Testing framework
Browse files Browse the repository at this point in the history
  • Loading branch information
oschrenk committed Jan 19, 2025
1 parent 3909632 commit 4b2d6d5
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 102 deletions.
64 changes: 32 additions & 32 deletions Tests/CalendarFilterTest.swift
Original file line number Diff line number Diff line change
@@ -1,132 +1,132 @@
import EventKit
import Testing

@testable import plan
import XCTest

final class CalendarFilterTests: XCTestCase {
func testAlwaysAccept() {
@Suite final class CalendarFilterTests {
@Test func testAlwaysAccept() {
let calendar = PlanCalendar.generate()
let expected = true
let actual = CalendarFilter.Accept().accept(calendar)

XCTAssertEqual(actual, expected, "The calendar was not accepted")
#expect(actual == expected, "The calendar was not accepted")
}

func testSelectCalendarsMatching() {
@Test func testSelectCalendarsMatching() {
let calendar = PlanCalendar.generate()
let expected = true
let actual = CalendarFilter.Select(uuids: [calendar.id]).accept(calendar)

XCTAssertEqual(actual, expected, "The calendar was not accepted")
#expect(actual == expected, "The calendar was not accepted")
}

func testSelectCalendarsEmptyArray() {
@Test func testSelectCalendarsEmptyArray() {
let calendar = PlanCalendar.generate()
let expected = true
let actual = CalendarFilter.Select(uuids: []).accept(calendar)

XCTAssertEqual(actual, expected, "The calendar was not accepted")
#expect(actual == expected, "The calendar was not accepted")
}

func testIgnoreCalendarsMatching() {
@Test func testIgnoreCalendarsMatching() {
let calendar = PlanCalendar.generate()
let expected = false
let actual = CalendarFilter.Ignore(uuids: [calendar.id]).accept(calendar)

XCTAssertEqual(actual, expected, "The calendar was accepted")
#expect(actual == expected, "The calendar was accepted")
}

func testIgnoreCalendarsEmptyArray() {
@Test func testIgnoreCalendarsEmptyArray() {
let calendar = PlanCalendar.generate()
let expected = true
let actual = CalendarFilter.Ignore(uuids: []).accept(calendar)

XCTAssertEqual(actual, expected, "The calendar was not accepted")
#expect(actual == expected, "The calendar was not accepted")
}

func testIgnoreCalendarSourcesMatching() {
@Test func testIgnoreCalendarSourcesMatching() {
let source = "Personal"
let calendar = PlanCalendar.generate(source: source)
let expected = false
let actual = CalendarFilter.IgnoreSources(sources: [source]).accept(calendar)

XCTAssertEqual(actual, expected, "The calendar was accepted")
#expect(actual == expected, "The calendar was accepted")
}

func testIgnoreCalendarSourcesEmptyArray() {
@Test func testIgnoreCalendarSourcesEmptyArray() {
let calendar = PlanCalendar.generate()
let expected = true
let actual = CalendarFilter.IgnoreSources(sources: []).accept(calendar)

XCTAssertEqual(actual, expected, "The calendar was rejected")
#expect(actual == expected, "The calendar was rejected")
}

func testSelectCalendarSourcesMatching() {
@Test func testSelectCalendarSourcesMatching() {
let source = "Personal"
let calendar = PlanCalendar.generate(source: source)
let expected = true
let actual = CalendarFilter.SelectSources(sources: [source]).accept(calendar)

XCTAssertEqual(actual, expected, "The calendar was rejected")
#expect(actual == expected, "The calendar was rejected")
}

func testSelectCalendarSourcesNotMatching() {
@Test func testSelectCalendarSourcesNotMatching() {
let source = "Personal"
let calendar = PlanCalendar.generate(source: source)
let expected = false
let actual = CalendarFilter.SelectSources(sources: ["not-existing"]).accept(calendar)

XCTAssertEqual(actual, expected, "The calendar was accepted")
#expect(actual == expected, "The calendar was accepted")
}

func testSelectCalendarSourcesEmptyArray() {
@Test func testSelectCalendarSourcesEmptyArray() {
let calendar = PlanCalendar.generate()
let expected = true
let actual = CalendarFilter.SelectSources(sources: []).accept(calendar)

XCTAssertEqual(actual, expected, "The calendar was rejected")
#expect(actual == expected, "The calendar was rejected")
}

func testIgnoreCalendarTypesMatching() {
@Test func testIgnoreCalendarTypesMatching() {
let type = EKCalendarType.birthday
let calendar = PlanCalendar.generate(type: type)
let expected = false
let actual = CalendarFilter.IgnoreTypes(types: [type]).accept(calendar)

XCTAssertEqual(actual, expected, "The calendar was accepted")
#expect(actual == expected, "The calendar was accepted")
}

func testIgnoreCalendarTypesEmptyArray() {
@Test func testIgnoreCalendarTypesEmptyArray() {
let calendar = PlanCalendar.generate()
let expected = true
let actual = CalendarFilter.IgnoreTypes(types: []).accept(calendar)

XCTAssertEqual(actual, expected, "The calendar was rejected")
#expect(actual == expected, "The calendar was rejected")
}

func testSelectCalendarTypesMatching() {
@Test func testSelectCalendarTypesMatching() {
let type = EKCalendarType.birthday
let calendar = PlanCalendar.generate(type: type)
let expected = true
let actual = CalendarFilter.SelectTypes(types: [type]).accept(calendar)

XCTAssertEqual(actual, expected, "The calendar was rejected")
#expect(actual == expected, "The calendar was rejected")
}

func testSelectCalendarTypesNotMatching() {
@Test func testSelectCalendarTypesNotMatching() {
let type = EKCalendarType.calDAV
let calendar = PlanCalendar.generate(type: type)
let expected = false
let actual = CalendarFilter.SelectTypes(types: [EKCalendarType.birthday]).accept(calendar)

XCTAssertEqual(actual, expected, "The calendar was accepted")
#expect(actual == expected, "The calendar was accepted")
}

func testSelectCalendarTypesEmptyArray() {
@Test func testSelectCalendarTypesEmptyArray() {
let calendar = PlanCalendar.generate()
let expected = true
let actual = CalendarFilter.SelectTypes(types: []).accept(calendar)

XCTAssertEqual(actual, expected, "The calendar was rejected")
#expect(actual == expected, "The calendar was rejected")
}
}
60 changes: 30 additions & 30 deletions Tests/EventFilterTest.swift
Original file line number Diff line number Diff line change
@@ -1,122 +1,122 @@
@testable import plan
import XCTest
import Testing

final class EventFilterTests: XCTestCase {
func testAlwaysAccept() {
@Suite final class EventFilterTests {
@Test func testAlwaysAccept() {
let event = Event.generate()
let expected = true
let actual = EventFilter.Accept().accept(event)

XCTAssertEqual(actual, expected, "The event was not accepted")
#expect(actual == expected)
}

func testIgnoreTagsNoTags() {
@Test func testIgnoreTagsNoTags() {
let event = Event.generate(tags: ["timeblock"])
let expected = true
let actual = EventFilter.IgnoreTags(tags: []).accept(event)

XCTAssertEqual(actual, expected, "The event was falsely accepted")
#expect(actual == expected)
}

func testIgnoreTagsMatchingTags() {
@Test func testIgnoreTagsMatchingTags() {
let event = Event.generate(tags: ["timeblock"])
let expected = false
let actual = EventFilter.IgnoreTags(tags: ["timeblock"]).accept(event)

XCTAssertEqual(actual, expected, "The event was falsely accepted")
#expect(actual == expected)
}

func testIgnoreTagsNotMatchingTags() {
@Test func testIgnoreTagsNotMatchingTags() {
let event = Event.generate(tags: ["foo"])
let expected = true
let actual = EventFilter.IgnoreTags(tags: ["timeblock"]).accept(event)

XCTAssertEqual(actual, expected, "The event was falsely ignored")
#expect(actual == expected)
}

func testIgnoreAnAllDayEvent() {
@Test func testIgnoreAnAllDayEvent() {
let event = Event.generate(allDay: true)
let expected = false
let actual = EventFilter.IgnoreAllDay().accept(event)

XCTAssertEqual(actual, expected, "The event was falsely accepted")
#expect(actual == expected)
}

func testAcceptAnNonAllDayEvent() {
@Test func testAcceptAnNonAllDayEvent() {
let event = Event.generate(allDay: false)
let expected = true
let actual = EventFilter.IgnoreAllDay().accept(event)

XCTAssertEqual(actual, expected, "The event was falsely ignored")
#expect(actual == expected)
}

func testIgnoringEventMatchingTitle() {
@Test func testIgnoringEventMatchingTitle() {
let event = Event.generate(title: "foo matching")
let expected = false
let actual = EventFilter.IgnorePatternTitle(pattern: "foo").accept(event)

XCTAssertEqual(actual, expected, "The event was falsely accepted")
#expect(actual == expected)
}

func testAcceptingEventNotMatchingTitle() {
@Test func testAcceptingEventNotMatchingTitle() {
let event = Event.generate(title: "foo matching")
let expected = true
let actual = EventFilter.IgnorePatternTitle(pattern: "bar").accept(event)

XCTAssertEqual(actual, expected, "The event was falsely ignored")
#expect(actual == expected)
}

func testAcceptingEventWithAtLeastTwoAttendees() {
@Test func testAcceptingEventWithAtLeastTwoAttendees() {
let event = Event.generate(attendees: ["personA", "personB"])
let expected = true
let actual = EventFilter.MinNumAttendees(count: 2).accept(event)

XCTAssertEqual(actual, expected, "The event was falsely ignored")
#expect(actual == expected)
}

func testAcceptingEventWithTooFewAttendees() {
@Test func testAcceptingEventWithTooFewAttendees() {
let event = Event.generate(attendees: ["personA", "personB"])
let expected = false
let actual = EventFilter.MinNumAttendees(count: 3).accept(event)

XCTAssertEqual(actual, expected, "The event was falsely accepted")
#expect(actual == expected)
}

func testAcceptingEventWithFewAttendees() {
@Test func testAcceptingEventWithFewAttendees() {
let event = Event.generate(attendees: ["personA", "personB"])
let expected = true
let actual = EventFilter.MaxNumAttendees(count: 3).accept(event)

XCTAssertEqual(actual, expected, "The event was falsely ignored")
#expect(actual == expected)
}

func testAcceptingEventWithTooManyAttendees() {
@Test func testAcceptingEventWithTooManyAttendees() {
let event = Event.generate(attendees: ["personA", "personB", "personC"])
let expected = false
let actual = EventFilter.MaxNumAttendees(count: 2).accept(event)

XCTAssertEqual(actual, expected, "The event was falsely accepted")
#expect(actual == expected)
}

func testAcceptCombinedFilter() {
@Test func testAcceptCombinedFilter() {
let event = Event.generate(attendees: ["personA", "personB", "personC"])
let expected = true
let min = EventFilter.MinNumAttendees(count: 2)
let max = EventFilter.MaxNumAttendees(count: 4)

let actual = EventFilter.Combined(filters: [min, max]).accept(event)

XCTAssertEqual(actual, expected, "The event was falsely ignored")
#expect(actual == expected)
}

func testRejectCombinedFilter() {
@Test func testRejectCombinedFilter() {
let event = Event.generate(attendees: ["personA", "personB", "personC"])
let expected = false
let min = EventFilter.MinNumAttendees(count: 4)
let max = EventFilter.MaxNumAttendees(count: 2)

let actual = EventFilter.Combined(filters: [min, max]).accept(event)

XCTAssertEqual(actual, expected, "The event was falsely accepted")
#expect(actual == expected)
}
}
16 changes: 8 additions & 8 deletions Tests/LegendTests.swift
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
@testable import plan
import XCTest
import Testing

final class LegendTests: XCTestCase {
func testWithoutEmoji() {
@Suite final class LegendTests {
@Test func testWithoutEmoji() {
let input = "Banana"
let expected = Legend(description: "Banana", icon: "")
let output = input.asLegend()

XCTAssertEqual(output, expected, "The emoji was not correctly extracted")
#expect(output == expected)
}

func testLeadingSimpleEmoji() {
@Test func testLeadingSimpleEmoji() {
let input = "🍌 Banana"
let expected = Legend(description: "Banana", icon: "🍌")
let output = input.asLegend()

XCTAssertEqual(output, expected, "The emoji was not correctly extracted")
#expect(output == expected)
}

func testLeadingCombinedEmoji() {
@Test func testLeadingCombinedEmoji() {
// 'Thumbs up' with 'Emoji Modifier Fitzpatrick Type-4':
let input = "👍🏽 Thumb"
let expected = Legend(description: "Thumb", icon: "👍🏽")
let output = input.asLegend()

XCTAssertEqual(output, expected, "The emoji was not correctly extracted")
#expect(output == expected)
}
}
26 changes: 9 additions & 17 deletions Tests/ObjectTests.swift
Original file line number Diff line number Diff line change
@@ -1,30 +1,22 @@
@testable import plan
import XCTest
import Testing

final class ObjectTests: XCTestCase {
func testKeyPathOnKeywords() {
@Suite final class ObjectTests {
@Test func testKeyPathOnKeywords() {
let event = Event.generate(title: "test")
do {

#expect(throws: Never.self) {
let expected = try Object.valueForKeyPath(event, "schedule.start.in") as? Int ?? -1
let output = 0

XCTAssertEqual(output, expected, "The fields were not the same")
} catch {
XCTFail("Expected no error, but got \(error)")
#expect(output == expected)
}
}

func testNotComparable() {
@Test func testNotComparable() {
let event = Event.generate(title: "test")
do {
XCTAssertThrowsError(try Object.valueForKeyPath(event, "schedule.start")) { error in
XCTAssertTrue(
error is Object.PathError,
"Unexpected error type: \(type(of: error))"
)

XCTAssertEqual(error as? Object.PathError, .notComparable)
}
#expect(throws: Object.PathError.self) {
try Object.valueForKeyPath(event, "schedule.start")
}
}
}
Loading

0 comments on commit 4b2d6d5

Please sign in to comment.