Add fenced code block tests
diff --git a/pkgs/markdown/test/markdown_test.dart b/pkgs/markdown/test/markdown_test.dart index 3875de0..fcf76d1 100644 --- a/pkgs/markdown/test/markdown_test.dart +++ b/pkgs/markdown/test/markdown_test.dart
@@ -5,12 +5,11 @@ /// Unit tests for markdown. library markdownTests; +import 'package:unittest/unittest.dart'; + // TODO(rnystrom): Use "package:" URL (#4968). import '../lib/markdown.dart'; -// TODO(rnystrom): Better path to unittest. -import 'package:unittest/unittest.dart'; - /// Most of these tests are based on observing how showdown behaves: /// http://softwaremaniacs.org/playground/showdown-highlight/ void main() { @@ -425,6 +424,35 @@ '''); }); + group('Fenced code blocks', () { + validate('without an optional language identifier', ''' + ``` + code + ``` + ''', ''' + <pre><code>code + </code></pre> + '''); + + validate('with an optional language identifier', ''' + ```dart + code + ``` + ''', ''' + <pre><code>code + </code></pre> + '''); + + validate('escape HTML characters', ''' + ``` + <&> + ``` + ''', ''' + <pre><code><&> + </code></pre> + '''); + }); + group('Horizontal rules', () { validate('from dashes', ''' --- @@ -649,6 +677,12 @@ second</code> after</p> '''); + validate('simple double backticks', ''' + before ``source`` after + ''', ''' + <p>before <code>source</code> after</p> + '''); + validate('double backticks', ''' before ``can `contain` backticks`` after ''', ''' @@ -798,6 +832,29 @@ <p>links <a href="http://foo.com"><em>are</em></a> awesome</p> '''); }); + + group('Resolver', () { + var nyanResolver = (text) => new Text('~=[,,_${text}_,,]:3'); + validate('simple resolver', ''' + resolve [this] thing + ''', ''' + <p>resolve ~=[,,_this_,,]:3 thing</p> + ''', linkResolver: nyanResolver); + }); + + group('Custom inline syntax', () { + List<InlineSyntax> nyanSyntax = + [new TextSyntax('nyan', sub: '~=[,,_,,]:3')]; + validate('simple inline syntax', ''' + nyan + ''', ''' + <p>~=[,,_,,]:3</p> + ''', inlineSyntaxes: nyanSyntax); + + // TODO(amouravski): need more tests here for custom syntaxes, as some + // things are not quite working properly. The regexps are sometime a little + // too greedy, I think. + }); } /** @@ -825,16 +882,17 @@ } } - return Strings.join(lines, '\n'); + return lines.join('\n'); } validate(String description, String markdown, String html, - {bool verbose: false}) { + {bool verbose: false, inlineSyntaxes, linkResolver}) { test(description, () { markdown = cleanUpLiteral(markdown); html = cleanUpLiteral(html); - var result = markdownToHtml(markdown); + var result = markdownToHtml(markdown, inlineSyntaxes: inlineSyntaxes, + linkResolver: linkResolver); var passed = compareOutput(html, result); if (!passed) {