Skip to content

Commit

Permalink
Updated unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
orchetect committed Nov 19, 2024
1 parent f86488d commit 49cda5a
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions Tests/MarkersExtractorTests/BasicMarkersTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import TimecodeKitCore
)
#expect(marker0.position == tc("00:00:29:14", at: fr))
#expect(marker0.parentInfo == parentInfo)
#expect(marker0.xmlPath == "/fcpxml[1]/library[1]/event[1]/project[1]/sequence[1]/spine[1]/title[1]/marker[1]")

let marker1 = try #require(markers[safe: 1])
#expect(marker1.type == .marker(.toDo(completed: false)))
Expand All @@ -66,6 +67,7 @@ import TimecodeKitCore
)
#expect(marker1.position == tc("00:00:29:15", at: fr))
#expect(marker1.parentInfo == parentInfo)
#expect(marker1.xmlPath == "/fcpxml[1]/library[1]/event[1]/project[1]/sequence[1]/spine[1]/title[1]/marker[2]")

let marker2 = try #require(markers[safe: 2])
#expect(marker2.type == .marker(.toDo(completed: true)))
Expand All @@ -77,6 +79,7 @@ import TimecodeKitCore
)
#expect(marker2.position == tc("00:00:29:15", at: fr))
#expect(marker2.parentInfo == parentInfo)
#expect(marker2.xmlPath == "/fcpxml[1]/library[1]/event[1]/project[1]/sequence[1]/spine[1]/title[1]/marker[3]")

let marker3 = try #require(markers[safe: 3])
#expect(marker3.type == .marker(.chapter(posterOffset: Fraction(11, 30))))
Expand All @@ -88,6 +91,7 @@ import TimecodeKitCore
)
#expect(marker3.position == tc("00:00:29:17", at: fr))
#expect(marker3.parentInfo == parentInfo)
#expect(marker3.xmlPath == "/fcpxml[1]/library[1]/event[1]/project[1]/sequence[1]/spine[1]/title[1]/chapter-marker[1]")
}

/// Ensure that duplicate marker ID uniquing works correctly for all marker ID naming modes.
Expand Down Expand Up @@ -198,6 +202,63 @@ import TimecodeKitCore
}
}
}

@Test func basicMarkers_xPath() async throws {
let xml = try XMLDocument(data: fcpxmlTestData)

let marker0XPath = "/fcpxml[1]/library[1]/event[1]/project[1]/sequence[1]/spine[1]/title[1]/marker[1]"

do {
let settings = try MarkersExtractor.Settings(
fcpxml: FCPXMLFile(fileContents: xml),
outputDir: FileManager.default.temporaryDirectory
)

let extractor = MarkersExtractor(settings: settings)

let markers = try await extractor.extractMarkers().markers

let marker0 = try #require(markers[safe: 0])

// verify XPath string
#expect(marker0.xmlPath == marker0XPath)
}

// look up XPath
let marker0Nodes = try xml.nodes(forXPath: marker0XPath)
try #require(marker0Nodes.count == 1)
let marker0Node = try #require(marker0Nodes.first?.asElement)
let marker0AsMarker = try #require(marker0Node.fcpAsMarker)

// verify marker
#expect(marker0AsMarker.name == "Marker 1")
#expect(marker0AsMarker.note == "some notes here")

// mutate marker XML element
marker0AsMarker.name = "Renamed Marker"
marker0AsMarker.note = "new notes here"

// verify updated marker in-place
#expect(marker0AsMarker.name == "Renamed Marker")
#expect(marker0AsMarker.note == "new notes here")

do {
let settings = try MarkersExtractor.Settings(
fcpxml: FCPXMLFile(fileContents: xml),
outputDir: FileManager.default.temporaryDirectory
)

let extractor = MarkersExtractor(settings: settings)

let markers = try await extractor.extractMarkers().markers

let marker0 = try #require(markers[safe: 0])

// verify updated marker
#expect(marker0.name == "Renamed Marker")
#expect(marker0.notes == "new notes here")
}
}
}

private let fcpxmlTestData = fcpxmlTestString.data(using: .utf8)!
Expand Down

0 comments on commit 49cda5a

Please sign in to comment.