-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
ParsingTests.swift
45 lines (38 loc) · 1.21 KB
/
ParsingTests.swift
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
//
// ParsingTests.swift
// Lottie
//
// Created by Marcelo Fabri on 5/5/22.
//
import Difference
import Foundation
import XCTest
@testable import Lottie
// MARK: - ParsingTests
final class ParsingTests: XCTestCase {
func testParsingIsTheSameForBothImplementations() throws {
for url in Samples.sampleAnimationURLs {
guard url.pathExtension == "json" else { continue }
do {
let data = try Data(contentsOf: url)
let codableAnimation = try LottieAnimation.from(data: data, strategy: .legacyCodable)
let dictAnimation = try LottieAnimation.from(data: data, strategy: .dictionaryBased)
XCTAssertNoDiff(codableAnimation, dictAnimation)
} catch {
XCTFail("Error for \(url.lastPathComponent): \(error)")
}
}
}
}
func XCTAssertNoDiff<T>(
_ expected: @autoclosure () throws -> T,
_ received: @autoclosure () throws -> T,
file: StaticString = #filePath,
line: UInt = #line) rethrows
{
let expected = try expected()
let received = try received()
let diff = diff(expected, received)
let isEqual = diff.isEmpty || diff.allSatisfy(\.isEmpty)
XCTAssertTrue(isEqual, "Found difference for \n" + diff.joined(separator: ", "), file: file, line: line)
}