Skip to content

Instantly share code, notes, and snippets.

@mdales
Last active September 8, 2022 07:38
Show Gist options
  • Save mdales/b6964ed17273acd6eef1cc45e616fdd1 to your computer and use it in GitHub Desktop.
Save mdales/b6964ed17273acd6eef1cc45e616fdd1 to your computer and use it in GitHub Desktop.
That thing where you find the YAML parser you're using will parse JSON too 🤦🏼
func testNotYAMLFront() throws {
let testdoc = """
---
{"title": "hello, world"}
---
"""
// I only use a YAML parser, so this should throw
// XCTAssertThrowsError(try FrontMatterDocument(data: Data(testdoc.utf8))) { error in
// XCTAssertEqual(error as? FrontMatterDocumentError, .FailedToParseYAML)
// }
// Erm, okay, that didn't throw, but at least I shouldn't get any data?
let document = try FrontMatterDocument(data: Data(testdoc.utf8))
// XCTAssertEqual(document.frontMatter.count, 0)
// I got data, wtf?
print("\(document.frontMatter)")
// Prints ["title": FrontMatter.FrontMatterValue.stringValue("hello, world")]
// Dawning realisation that Yams will apparently parse JSON?
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment