forked from nicklockwood/ShapeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMetadataTests.swift
More file actions
92 lines (82 loc) · 3.1 KB
/
MetadataTests.swift
File metadata and controls
92 lines (82 loc) · 3.1 KB
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
//
// MetadataTests.swift
// SVGPathTests
//
// Created by Nick Lockwood on 04/07/2021.
// Copyright © 2019 Nick Lockwood. All rights reserved.
//
#if !os(WASI)
@testable import SVGPath
import XCTest
private let projectDirectory = URL(fileURLWithPath: #file)
.deletingLastPathComponent().deletingLastPathComponent()
private let changelogURL = projectDirectory
.appendingPathComponent("CHANGELOG.md")
private let projectURL = projectDirectory
.appendingPathComponent("SVGPath.xcodeproj")
.appendingPathComponent("project.pbxproj")
private let projectVersion: String = {
let string = try! String(contentsOf: projectURL)
let start = string.range(of: "MARKETING_VERSION = ")!.upperBound
let end = string.range(of: ";", range: start ..< string.endIndex)!.lowerBound
return String(string[start ..< end])
}()
private let changelogTitles: [Substring] = {
let changelog = try! String(contentsOf: changelogURL, encoding: .utf8)
var range = changelog.startIndex ..< changelog.endIndex
var matches = [Substring]()
while let match = changelog.range(
of: "## \\[[^]]+\\]\\([^)]+\\) \\([^)]+\\)",
options: .regularExpression,
range: range
) {
matches.append(changelog[match])
range = match.upperBound ..< changelog.endIndex
}
return matches
}()
class MetadataTests: XCTestCase {
// MARK: releases
func testProjectVersionMatchesChangelog() throws {
let changelog = try String(contentsOf: changelogURL, encoding: .utf8)
let range = try XCTUnwrap(changelog.range(of: "releases/tag/"))
XCTAssertTrue(
changelog[range.upperBound...].hasPrefix(projectVersion),
"Marketing version \(projectVersion) does not match most recent tag in CHANGELOG.md"
)
}
func testLatestVersionInChangelog() throws {
let changelog = try String(contentsOf: changelogURL, encoding: .utf8)
XCTAssertTrue(
changelog.contains("[\(projectVersion)]"),
"CHANGELOG.md does not mention latest release"
)
XCTAssertTrue(
changelog.contains(
"(https://github.com/nicklockwood/SVGPath/releases/tag/\(projectVersion))"
),
"CHANGELOG.md does not include correct link for latest release"
)
}
func testChangelogDatesAreAscending() throws {
var lastDate: Date?
let dateParser = DateFormatter()
dateParser.timeZone = TimeZone(identifier: "UTC")
dateParser.locale = Locale(identifier: "en_GB")
dateParser.dateFormat = " (yyyy-MM-dd)"
for title in changelogTitles {
let dateRange = try XCTUnwrap(title.range(
of: " \\([^)]+\\)$",
options: .regularExpression
))
let dateString = String(title[dateRange])
let date = try XCTUnwrap(dateParser.date(from: dateString))
if let lastDate, date > lastDate {
XCTFail("\(title) has newer date than subsequent version (\(date) vs \(lastDate))")
return
}
lastDate = date
}
}
}
#endif