Files
SwiftLint/Tests/CoreTests/YamlSwiftLintTests.swift
Danny Mösch ac2eda6732 Adopt Swift Testing
# Conflicts:
#	Tests/BuiltInRulesTests/FileHeaderRuleTests.swift
#	Tests/BuiltInRulesTests/FileNameNoSpaceRuleTests.swift
#	Tests/BuiltInRulesTests/IndentationWidthRuleTests.swift
#	Tests/CoreTests/RegexConfigurationTests.swift
#	Tests/CoreTests/SwiftLintFileTests.swift
#	Tests/FileSystemAccessTests/BaselineTests.swift
#	Tests/FileSystemAccessTests/ConfigurationTests+Mock.swift
#	Tests/FileSystemAccessTests/ConfigurationTests.swift
#	Tests/FileSystemAccessTests/GlobTests.swift
#	Tests/FileSystemAccessTests/MultipleConfigurationsTests.swift
#	Tests/FileSystemAccessTests/ReporterTests.swift
#	Tests/FileSystemAccessTests/SourceKitCrashTests.swift
#	Tests/FrameworkTests/CustomRulesTests.swift
#	Tests/FrameworkTests/LinterCacheTests.swift
#	Tests/FrameworkTests/RuleConfigurationTests.swift
#	Tests/FrameworkTests/SwiftVersionTests.swift
#	Tests/GeneratedTests/GeneratedTests_02.swift
#	Tests/GeneratedTests/GeneratedTests_03.swift
#	Tests/GeneratedTests/GeneratedTests_04.swift
#	Tests/GeneratedTests/GeneratedTests_05.swift
#	Tests/GeneratedTests/GeneratedTests_06.swift
#	Tests/GeneratedTests/GeneratedTests_07.swift
#	Tests/GeneratedTests/GeneratedTests_08.swift
#	Tests/GeneratedTests/GeneratedTests_09.swift
#	Tests/GeneratedTests/GeneratedTests_10.swift
#	Tests/IntegrationTests/ConfigPathResolutionTests.swift
#	Tests/IntegrationTests/IntegrationTests.swift
#	Tests/TestHelpers/TestHelpers.swift
2026-06-06 11:07:04 +02:00

42 lines
1.9 KiB
Swift

import Foundation
import SwiftLintCore
import TestHelpers
import Testing
import Yams
@Suite
struct YamlSwiftLintTests {
@Test
func flattenYaml() throws {
let yamlDict = try #require(try Yams.load(yaml: try getTestYaml()) as? [String: Any])
let dict1 = try #require(yamlDict["dictionary1"] as? [Swift.String: Any])
let dict2 = try #require(yamlDict["dictionary2"] as? [Swift.String: Any])
#expect(dict1["bool"] as? Bool == true && dict2["bool"] as? Bool == true)
#expect(dict1["int"] as? Int == 1 && dict2["int"] as? Int == 1)
#expect(dict1["double"] as? Double == 1.0 && dict2["double"] as? Double == 1.0)
#expect(dict1["string"] as? String == "string" && dict2["string"] as? String == "string")
let array1 = try #require(dict1["array"] as? [Any])
let array2 = try #require(dict2["array"] as? [Any])
#expect(array1[0] as? Bool == true && array2[0] as? Bool == true)
#expect(array1[1] as? Int == 1 && array2[1] as? Int == 1)
#expect(array1[2] as? Double == 1.0 && array2[2] as? Double == 1.0)
#expect(array1[3] as? String == "string" && array2[3] as? String == "string")
let dictFromArray1 = try #require(array1[4] as? [Swift.String: Any])
let dictFromArray2 = try #require(array2[4] as? [Swift.String: Any])
#expect(dictFromArray1["bool"] as? Bool == true && dictFromArray2["bool"] as? Bool == true)
#expect(dictFromArray1["int"] as? Int == 1 && dictFromArray2["int"] as? Int == 1)
#expect(dictFromArray1["double"] as? Double == 1.0 && dictFromArray2["double"] as? Double == 1.0)
#expect(dictFromArray1["string"] as? String == "string" && dictFromArray2["string"] as? String == "string")
}
private func getTestYaml() throws -> String {
try String(
contentsOf: TestResources.path().appending(path: "test.yml", directoryHint: .notDirectory),
encoding: .utf8
)
}
}