Last active
September 8, 2022 07:38
-
-
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 🤦🏼
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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