@testable import PureYAML import Testing @Suite("Double-quoted escape sequences") struct DoubleQuotedEscapeTests { @Test("Every YAML 1.2 escape decodes to its character", arguments: [ ("\"\\0\"\n", "\u{00}"), ("\"\\a\"\n", "\u{07}"), ("\"\\b\"\n", "\u{08}"), ("\"\\t\"\n", "\t"), ("\"\\n\"\n", "\n"), ("\"\\v\"\n", "\u{0B}"), ("\"\\f\"\n", "\u{0C}"), ("\"\\r\"\n", "\r"), ("\"\\e\"\n", "\u{1B}"), ("\"a\\ b\"\n", "a b"), ("\"\\\"\"\n", "\""), ("\"\\/\"\n", "/"), ("\"\\\\\"\n", "\\"), ("\"\\N\"\n", "\u{85}"), ("\"\\_\"\n", "\u{A0}"), ("\"\\L\"\n", "\u{2028}"), ("\"\\P\"\n", "\u{2029}"), ("\"\\x41\"\n", "A"), ("\"\\u0041\"\n", "A"), ("\"\\U0001F600\"\n", "\u{1F600}"), ]) func test_validEscapeDecodes(_ yaml: String, _ expected: String) throws { #expect(try PureYAML.parse(yaml) == .string(expected)) } @Test("An unknown or truncated escape is rejected", arguments: [ "\"\\.\"\n", // not an escape character "\"\\'\"\n", // single quote is not escaped in a double-quoted scalar "\"\\q\"\n", // unknown letter "\"\\x4\"\n", // truncated hex "\"\\U12\"\n", // truncated 32-bit hex ]) func test_invalidEscapeIsRejected(_ yaml: String) throws { #expect(throws: PureYAML.Parsing.ParseError.self) { try PureYAML.parse(yaml) } } @Test("An escaped line break joins the lines with no separator") func test_escapedLineBreakJoinsLines() throws { #expect(try PureYAML.parse("\"a\\\n b\"\n") == .string("ab")) #expect(try PureYAML.parse("\"one \\\n two\"\n") == .string("one two")) } }