The ported engine wins every conflict: main's post-fork patches to the hand-rolled Scanner and TokenEventParser land on deleted files and are dropped; their behaviors are carried by the port and guarded by the whole-suite conformance gate (402/402 passing). Merge adaptations, all gates green (style, namespacing, forbidden patterns, changelog, roadmap, swiftformat, swiftlint strict, build, full test suite, whole-suite conformance sweep): - PureYAMLJSON representability rules move onto the Check algebra, replacing the retired legacy Rule type. - The permissive tag-handle pre-pass is removed; the port rejects an undefined handle at parse time (suite case QLJ7) and the validation report carries it as a parse diagnostic. - EventStreamComposer's nested types split one-per-file per the namespacing gate. - Tests pinned to old-engine behavior were re-verified against the reference and updated: libyaml rejects an explicit-key continuation ending at a value colon, and suite case QB6E requires rejecting a quoted continuation at column 0. - CHANGELOG unreleased entries from both lines are preserved in two groups with a provenance note. Closes #1, closes #3
54 lines
2.6 KiB
Swift
54 lines
2.6 KiB
Swift
import PureYAML
|
|
@testable import PureYAMLJSON
|
|
import Testing
|
|
|
|
@Suite("JSON representability rules")
|
|
struct JSONRuleTests {
|
|
private func mapping(_ pairs: [PureYAML.Model.Pair]) -> PureYAML.Model.Value {
|
|
.mapping(.init(pairs))
|
|
}
|
|
|
|
@Test("mappingKeysAreStrings fails on a complex key")
|
|
func test_mappingKeysAreStrings_fails() {
|
|
let document = mapping([.init(keyNode: .sequence([.int(1)]), value: .int(2))])
|
|
let issues = PureYAML.Validation.Validator(checks: [PureYAML.Validation.AnyCheck(PureYAML.Validation.BuiltinCheck.mappingKeysAreStrings)]).collect(document).issues
|
|
#expect(issues.count == 1)
|
|
#expect(issues.first?.reason == "Mapping key '[1]' is not a string")
|
|
}
|
|
|
|
@Test("mappingKeysAreStrings passes when every key is a string")
|
|
func test_mappingKeysAreStrings_passes() {
|
|
let document = mapping([.init(key: "a", value: .int(1))])
|
|
let issues = PureYAML.Validation.Validator(checks: [PureYAML.Validation.AnyCheck(PureYAML.Validation.BuiltinCheck.mappingKeysAreStrings)]).collect(document).issues
|
|
#expect(issues.isEmpty)
|
|
}
|
|
|
|
@Test("numbersAreFinite fails on infinity at the value's path")
|
|
func test_numbersAreFinite_fails() {
|
|
let document = mapping([.init(key: "x", value: .double(.infinity))])
|
|
let issues = PureYAML.Validation.Validator(checks: [PureYAML.Validation.AnyCheck(PureYAML.Validation.BuiltinCheck.numbersAreFinite)]).collect(document).issues
|
|
#expect(issues.count == 1)
|
|
#expect(issues.first?.reason == "Number 'inf' is not finite")
|
|
}
|
|
|
|
@Test("numbersAreFinite passes on a large finite double")
|
|
func test_numbersAreFinite_passes() {
|
|
let document = mapping([.init(key: "x", value: .double(.greatestFiniteMagnitude))])
|
|
let issues = PureYAML.Validation.Validator(checks: [PureYAML.Validation.AnyCheck(PureYAML.Validation.BuiltinCheck.numbersAreFinite)]).collect(document).issues
|
|
#expect(issues.isEmpty)
|
|
}
|
|
|
|
@Test("The representability set catches a duplicate key")
|
|
func test_representability_catchesDuplicate() {
|
|
let document = mapping([.init(key: "a", value: .int(1)), .init(key: "a", value: .int(2))])
|
|
#expect(!PureYAML.JSON.Validator.isRepresentable(document))
|
|
}
|
|
|
|
@Test("A plain string-keyed finite tree is representable")
|
|
func test_representability_acceptsPlainTree() {
|
|
let document = mapping([.init(key: "a", value: .int(1)), .init(key: "b", value: .double(1.5))])
|
|
#expect(PureYAML.JSON.Validator.isRepresentable(document))
|
|
#expect(PureYAML.JSON.Validator.issues(for: document).isEmpty)
|
|
}
|
|
}
|