108 lines
2.8 KiB
Swift
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)
|
|
}
|
|
}
|