Files
resgen.swift/Tests/ResgenSwiftTests/Strings/SectionTests.swift
T
t.schmitt ac5d9cef58
openium/resgen.swift/pipeline/head There was a failure building this commit
openium/resgen.swift/pipeline/pr-master There was a failure building this commit
Migrate tests from XCTest to Swift Testing
- Convert XCTestCase classes to structs with @Test functions
- Replace XCTAssert* with #expect, and force unwraps/XCTFail with #require
- Resolve test bundle via a class token in the CLI smoke test (Swift Testing
  does not register the .xctest bundle in Bundle.allBundles)
- Rename adaptForXCTest() to adaptForTest()
2026-11-23 15:53:21 +01:00

108 lines
2.8 KiB
Swift

//
// SectionTests.swift
//
//
// Created by Thibaut Schmitt on 06/09/2022.
//
import Foundation
import Testing
@testable import ResgenSwift
struct SectionTests {
// MARK: - Match line
@Test
func matchingDefinition() throws {
// Given
let line = "[[section_name]]"
// When
let section = try #require(Section.match(line))
// Expect
#expect(section.name == "section_name")
}
@Test
func notMatchingDefinition() {
// Given
let lines = ["section_name",
"[section_name]",
"[section_name",
"[[section_name",
"[[section_name]",
"section_name]",
"section_name]]",
"[section_name]]"]
// When
let matches = lines.compactMap { Section.match($0) }
// Expect
#expect(matches.isEmpty == true)
}
// MARK: - Matching tags
@Test
func matchingTags() {
// Given
let section = Section(name: "section_name")
section.definitions = [
{
let def = Definition(name: "definition_name")
def.tags = ["ios","iosonly"]
return def
}(),
{
let def = Definition(name: "definition_name_two")
def.tags = ["droid","droidonly"]
return def
}()
]
// When
let match1 = section.hasOneOrMoreMatchingTags(tags: ["ios"])
let match2 = section.hasOneOrMoreMatchingTags(tags: ["iosonly"])
let match3 = section.hasOneOrMoreMatchingTags(tags: ["droid"])
let match4 = section.hasOneOrMoreMatchingTags(tags: ["droidonly"])
// Expect
#expect(match1)
#expect(match2)
#expect(match3)
#expect(match4)
}
@Test
func notMatchingTags() {
// Given
let section = Section(name: "section_name")
section.definitions = [
{
let def = Definition(name: "definition_name")
def.tags = ["ios","iosonly"]
return def
}(),
{
let def = Definition(name: "definition_name_two")
def.tags = ["droid","droidonly"]
return def
}()
]
// When
let match1 = section.hasOneOrMoreMatchingTags(tags: ["web"])
let match2 = section.hasOneOrMoreMatchingTags(tags: ["webonly"])
let match3 = section.hasOneOrMoreMatchingTags(tags: ["azerty"])
// Expect
#expect(match1 == false)
#expect(match2 == false)
#expect(match3 == false)
}
}