| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /// Unit tests for markdown. | 5 /// Unit tests for markdown. |
| 6 #library('markdown_tests'); | 6 #library('markdown_tests'); |
| 7 | 7 |
| 8 // TODO(rnystrom): Move this test into pkg/dartdoc/test. | 8 // TODO(rnystrom): Use "package:" URL (#4968). |
| 9 #import('../../pkg/dartdoc/lib/markdown.dart'); | 9 #import('../lib/markdown.dart'); |
| 10 | 10 |
| 11 // TODO(rnystrom): Better path to unittest. | 11 // TODO(rnystrom): Better path to unittest. |
| 12 #import('../../pkg/unittest/unittest.dart'); | 12 #import('../../unittest/unittest.dart'); |
| 13 #import('test_utils.dart'); | |
| 14 | 13 |
| 15 /// Most of these tests are based on observing how showdown behaves: | 14 /// Most of these tests are based on observing how showdown behaves: |
| 16 /// http://softwaremaniacs.org/playground/showdown-highlight/ | 15 /// http://softwaremaniacs.org/playground/showdown-highlight/ |
| 17 void main() { | 16 void main() { |
| 18 group('Paragraphs', () { | 17 group('Paragraphs', () { |
| 19 validate('consecutive lines form a single paragraph', ''' | 18 validate('consecutive lines form a single paragraph', ''' |
| 20 This is the first line. | 19 This is the first line. |
| 21 This is the second line. | 20 This is the second line. |
| 22 ''', ''' | 21 ''', ''' |
| 23 <p>This is the first line. | 22 <p>This is the first line. |
| (...skipping 713 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 737 <p>links <a href="http://foo.com">are</a> awesome</p> | 736 <p>links <a href="http://foo.com">are</a> awesome</p> |
| 738 '''); | 737 '''); |
| 739 validate('can style link contents', ''' | 738 validate('can style link contents', ''' |
| 740 links [*are*](http://foo.com) awesome | 739 links [*are*](http://foo.com) awesome |
| 741 ''', ''' | 740 ''', ''' |
| 742 <p>links <a href="http://foo.com"><em>are</em></a> awesome</p> | 741 <p>links <a href="http://foo.com"><em>are</em></a> awesome</p> |
| 743 '''); | 742 '''); |
| 744 }); | 743 }); |
| 745 } | 744 } |
| 746 | 745 |
| 746 /** |
| 747 * Removes eight spaces of leading indentation from a multiline string. |
| 748 * |
| 749 * Note that this is very sensitive to how the literals are styled. They should |
| 750 * be: |
| 751 * ''' |
| 752 * Text starts on own line. Lines up with subsequent lines. |
| 753 * Lines are indented exactly 8 characters from the left margin.''' |
| 754 * |
| 755 * This does nothing if text is only a single line. |
| 756 */ |
| 757 // TODO(nweiz): Make this auto-detect the indentation level from the first |
| 758 // non-whitespace line. |
| 759 String cleanUpLiteral(String text) { |
| 760 var lines = text.split('\n'); |
| 761 if (lines.length <= 1) return text; |
| 762 |
| 763 for (var j = 0; j < lines.length; j++) { |
| 764 if (lines[j].length > 8) { |
| 765 lines[j] = lines[j].substring(8, lines[j].length); |
| 766 } else { |
| 767 lines[j] = ''; |
| 768 } |
| 769 } |
| 770 |
| 771 return Strings.join(lines, '\n'); |
| 772 } |
| 773 |
| 747 validate(String description, String markdown, String html) { | 774 validate(String description, String markdown, String html) { |
| 748 test(description, () { | 775 test(description, () { |
| 749 markdown = cleanUpLiteral(markdown); | 776 markdown = cleanUpLiteral(markdown); |
| 750 html = cleanUpLiteral(html); | 777 html = cleanUpLiteral(html); |
| 751 | 778 |
| 752 var result = markdownToHtml(markdown); | 779 var result = markdownToHtml(markdown); |
| 753 var passed = compareOutput(html, result); | 780 var passed = compareOutput(html, result); |
| 754 | 781 |
| 755 if (!passed) { | 782 if (!passed) { |
| 756 // Remove trailing newline. | 783 // Remove trailing newline. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 789 | 816 |
| 790 // If one string runs out of non-ignored strings, the other must too. | 817 // If one string runs out of non-ignored strings, the other must too. |
| 791 if (i == a.length) return j == b.length; | 818 if (i == a.length) return j == b.length; |
| 792 if (j == b.length) return i == a.length; | 819 if (j == b.length) return i == a.length; |
| 793 | 820 |
| 794 if (a[i] != b[j]) return false; | 821 if (a[i] != b[j]) return false; |
| 795 i++; | 822 i++; |
| 796 j++; | 823 j++; |
| 797 } | 824 } |
| 798 } | 825 } |
| OLD | NEW |