famedlysdk/test/markdown_test.dart

91 lines
4.2 KiB
Dart
Raw Normal View History

2020-06-03 10:16:01 +00:00
/*
* Ansible inventory script used at Famedly GmbH for managing many hosts
* Copyright (C) 2019, 2020 Famedly GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
2020-05-09 14:00:46 +00:00
import 'package:famedlysdk/src/utils/markdown.dart';
import 'package:test/test.dart';
void main() {
group('markdown', () {
final emotePacks = {
'room': {
':fox:': 'mxc://roomfox',
':bunny:': 'mxc://roombunny',
},
'user': {
':fox:': 'mxc://userfox',
':bunny:': 'mxc://userbunny',
':raccoon:': 'mxc://raccoon',
},
};
test('simple markdown', () {
2020-05-22 10:12:18 +00:00
expect(markdown('hey *there* how are **you** doing?'),
'hey <em>there</em> how are <strong>you</strong> doing?');
2020-05-09 14:00:46 +00:00
expect(markdown('wha ~~strike~~ works!'), 'wha <del>strike</del> works!');
});
test('spoilers', () {
2020-05-22 10:12:18 +00:00
expect(markdown('Snape killed ||Dumbledoor||'),
'Snape killed <span data-mx-spoiler="">Dumbledoor</span>');
expect(markdown('Snape killed ||Story|Dumbledoor||'),
'Snape killed <span data-mx-spoiler="Story">Dumbledoor</span>');
2020-05-09 14:00:46 +00:00
});
test('multiple paragraphs', () {
expect(markdown('Heya!\n\nBeep'), '<p>Heya!</p>\n<p>Beep</p>');
});
test('Other block elements', () {
expect(markdown('# blah\n\nblubb'), '<h1>blah</h1>\n<p>blubb</p>');
});
test('linebreaks', () {
expect(markdown('foxies\ncute'), 'foxies<br />\ncute');
});
test('emotes', () {
2020-05-22 10:12:18 +00:00
expect(markdown(':fox:', emotePacks),
2020-09-04 11:52:59 +00:00
'<img data-mx-emoticon="" src="mxc:&#47;&#47;roomfox" alt=":fox:" title=":fox:" height="32" vertical-align="middle" />');
2020-05-22 10:12:18 +00:00
expect(markdown(':user~fox:', emotePacks),
2020-09-04 11:52:59 +00:00
'<img data-mx-emoticon="" src="mxc:&#47;&#47;userfox" alt=":fox:" title=":fox:" height="32" vertical-align="middle" />');
2020-05-22 10:12:18 +00:00
expect(markdown(':raccoon:', emotePacks),
2020-09-04 11:52:59 +00:00
'<img data-mx-emoticon="" src="mxc:&#47;&#47;raccoon" alt=":raccoon:" title=":raccoon:" height="32" vertical-align="middle" />');
2020-05-09 14:00:46 +00:00
expect(markdown(':invalid:', emotePacks), ':invalid:');
expect(markdown(':room~invalid:', emotePacks), ':room~invalid:');
});
2020-05-15 19:00:10 +00:00
test('pills', () {
2020-05-22 10:12:18 +00:00
expect(markdown('Hey @sorunome:sorunome.de!'),
'Hey <a href="https://matrix.to/#/@sorunome:sorunome.de">@sorunome:sorunome.de</a>!');
expect(markdown('#fox:sorunome.de: you all are awesome'),
'<a href="https://matrix.to/#/#fox:sorunome.de">#fox:sorunome.de</a>: you all are awesome');
expect(markdown('!blah:example.org'),
'<a href="https://matrix.to/#/!blah:example.org">!blah:example.org</a>');
2020-05-15 19:00:10 +00:00
});
test('latex', () {
expect(markdown('meep \$\\frac{2}{3}\$'),
'meep <span data-mx-maths="\\frac{2}{3}"><code>\\frac{2}{3}</code></span>');
2020-10-24 09:50:16 +00:00
expect(markdown('meep \$hmm *yay*\$'),
'meep <span data-mx-maths="hmm *yay*"><code>hmm *yay*</code></span>');
expect(markdown('you have \$somevar and \$someothervar'),
'you have \$somevar and \$someothervar');
expect(markdown('meep ||\$\\frac{2}{3}\$||'),
'meep <span data-mx-spoiler=""><span data-mx-maths="\\frac{2}{3}"><code>\\frac{2}{3}</code></span></span>');
expect(markdown('meep `\$\\frac{2}{3}\$`'),
'meep <code>\$\\frac{2}{3}\$</code>');
expect(markdown('hey\n\$\$beep\$\$\nmeow'),
'<p>hey</p>\n<div data-mx-maths="beep">\n<pre><code>beep</code></pre>\n</div>\n<p>meow</p>');
expect(markdown('hey\n\$\$\nbeep\nboop\n\$\$\nmeow'),
'<p>hey</p>\n<div data-mx-maths="beep\nboop">\n<pre><code>beep\nboop</code></pre>\n</div>\n<p>meow</p>');
});
2020-05-09 14:00:46 +00:00
});
}