Skip to content

Commit 99d5659

Browse files
committed
content test: Test parsing remaining block content
1 parent fe1428d commit 99d5659

File tree

1 file changed

+53
-1
lines changed

1 file changed

+53
-1
lines changed

test/model/content_test.dart

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,13 @@ void main() {
151151
// Block content.
152152
//
153153

154+
testParse('parse <br> in block context',
155+
'<br><p>a</p><br>', const [ // TODO not sure how to reproduce this example
156+
LineBreakNode(),
157+
ParagraphNode(nodes: [TextNode('a')]),
158+
LineBreakNode(),
159+
]);
160+
154161
testParse('parse two plain-text paragraphs',
155162
// "hello\n\nworld"
156163
'<p>hello</p>\n<p>world</p>', const [
@@ -237,5 +244,50 @@ void main() {
237244
]);
238245
});
239246

240-
// TODO write more tests for this code
247+
testParse('parse quotations',
248+
// "```quote\nwords\n```"
249+
'<blockquote>\n<p>words</p>\n</blockquote>', const [
250+
QuotationNode([ParagraphNode(nodes: [TextNode('words')])]),
251+
]);
252+
253+
testParse('parse code blocks, no language',
254+
// "```\nverb\natim\n```"
255+
'<div class="codehilite"><pre><span></span><code>verb\natim\n</code></pre></div>', const [
256+
CodeBlockNode(text: 'verb\natim'),
257+
]);
258+
259+
testParse('parse code blocks, with highlighted language',
260+
// "```dart\nclass A {}\n```"
261+
'<div class="codehilite" data-code-language="Dart"><pre>'
262+
'<span></span><code><span class="kd">class</span><span class="w"> </span>'
263+
'<span class="nc">A</span><span class="w"> </span><span class="p">{}</span>'
264+
'\n</code></pre></div>', const [
265+
CodeBlockNode(text: 'class A {}'),
266+
]);
267+
268+
testParse('parse image',
269+
// "https://chat.zulip.org/user_avatars/2/realm/icon.png?version=3"
270+
'<div class="message_inline_image">'
271+
'<a href="https://chat.zulip.org/user_avatars/2/realm/icon.png?version=3">'
272+
'<img src="https://chat.zulip.org/user_avatars/2/realm/icon.png?version=3">'
273+
'</a></div>', const [
274+
ImageNode(srcUrl: 'https://chat.zulip.org/user_avatars/2/realm/icon.png?version=3'),
275+
]);
276+
277+
testParse('parse nested lists, quotes, headings, code blocks',
278+
// "1. > ###### two\n > * three\n\n four"
279+
'<ol>\n<li>\n<blockquote>\n<h6>two</h6>\n<ul>\n<li>three</li>\n'
280+
'</ul>\n</blockquote>\n<div class="codehilite"><pre><span></span>'
281+
'<code>four\n</code></pre></div>\n\n</li>\n</ol>', const [
282+
ListNode(ListStyle.ordered, [[
283+
QuotationNode([
284+
HeadingNode(level: HeadingLevel.h6, nodes: [TextNode('two')]),
285+
ListNode(ListStyle.unordered, [[
286+
ParagraphNode(wasImplicit: true, nodes: [TextNode('three')]),
287+
]]),
288+
]),
289+
CodeBlockNode(text: 'four'),
290+
ParagraphNode(wasImplicit: true, nodes: [TextNode('\n\n')]), // TODO avoid this; it renders wrong
291+
]]),
292+
]);
241293
}

0 commit comments

Comments
 (0)