Skip to content

Commit 4f9b54d

Browse files
committed
content test: Test parsing headings
1 parent cc96907 commit 4f9b54d

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

test/model/content_test.dart

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:checks/checks.dart';
2+
import 'package:html/parser.dart';
23
import 'package:test/scaffolding.dart';
34
import 'package:zulip/model/content.dart';
45

@@ -11,6 +12,16 @@ void testParse(String name, String html, List<BlockContentNode> nodes) {
1112
});
1213
}
1314

15+
UnimplementedBlockContentNode blockUnimplemented(String html) {
16+
var fragment = HtmlParser(html, parseMeta: false).parseFragment();
17+
return UnimplementedBlockContentNode(htmlNode: fragment.nodes.single);
18+
}
19+
20+
UnimplementedInlineContentNode inlineUnimplemented(String html) {
21+
var fragment = HtmlParser(html, parseMeta: false).parseFragment();
22+
return UnimplementedInlineContentNode(htmlNode: fragment.nodes.single);
23+
}
24+
1425
void main() {
1526
// When writing test cases in this file:
1627
//
@@ -147,5 +158,41 @@ void main() {
147158
ParagraphNode(nodes: [TextNode('world')]),
148159
]);
149160

161+
group('parse headings', () {
162+
testParse('plain h6',
163+
// "###### six"
164+
'<h6>six</h6>', const [
165+
HeadingNode(level: HeadingLevel.h6, nodes: [TextNode('six')])]);
166+
167+
testParse('containing inline markup',
168+
// "###### one [***`two`***](https://example/)"
169+
'<h6>one <a href="https://example/"><strong><em><code>two'
170+
'</code></em></strong></a></h6>', const [
171+
HeadingNode(level: HeadingLevel.h6, nodes: [
172+
TextNode('one '),
173+
LinkNode(nodes: [StrongNode(nodes: [
174+
EmphasisNode(nodes: [InlineCodeNode(nodes: [
175+
TextNode('two')])])])]),
176+
])]);
177+
178+
testParse('amidst paragraphs',
179+
// "intro\n###### section\ntext"
180+
"<p>intro</p>\n<h6>section</h6>\n<p>text</p>", const [
181+
ParagraphNode(nodes: [TextNode('intro')]),
182+
HeadingNode(level: HeadingLevel.h6, nodes: [TextNode('section')]),
183+
ParagraphNode(nodes: [TextNode('text')]),
184+
]);
185+
186+
testParse('h1, h2, h3, h4, h5 unimplemented',
187+
// "# one\n## two\n### three\n#### four\n##### five"
188+
'<h1>one</h1>\n<h2>two</h2>\n<h3>three</h3>\n<h4>four</h4>\n<h5>five</h5>', [
189+
blockUnimplemented('<h1>one</h1>'),
190+
blockUnimplemented('<h2>two</h2>'),
191+
blockUnimplemented('<h3>three</h3>'),
192+
blockUnimplemented('<h4>four</h4>'),
193+
blockUnimplemented('<h5>five</h5>'),
194+
]);
195+
});
196+
150197
// TODO write more tests for this code
151198
}

0 commit comments

Comments
 (0)