I’ve been working on a little Mac application in my limited spare time. The component I’ve been tackling lately involves conversion between Markdown text and an
NSAttributedString. There’s no good way to test the process, but what I’ve settled on is the following:
- Convert from Markdown to
- Convert from
NSAttributedStringback to Markdown
- Convert from Markdown to HTML
- Convert the original Markdown to HTML
- Compare the result of step 3 and step 4
Normally, I hate writing unit tests. Even with a firm grasp of cyclometric complexity, it’s still a pain to figure out how many tests you need to write and what each test should actually test. But in this case, John Gruber already put together a pretty decent suite of tests for Markdown. All I need do is run each source file through my conversion test.
Right now, out of 19 tests, only 12 are failing. After I add support for HTML encoding unicode characters (which isn’t really necessary if you declare your content to be in UTF-8, but nevertheless) the rest of the errors relate to whitespace wrapping in HTML. I’m going to try adding some sort of HTML tidying to the test to see if I can losslessly massage the HTML to be more similar.
Update: After adding support for encoding non-ascii characters and piping the HTML through
tidy, all tests pass.