2018-01-02 18:57:04 +01:00
|
|
|
|
#!/usr/bin/env python3
|
2018-02-19 19:50:26 +01:00
|
|
|
|
#******************************************************************************
|
|
|
|
|
# Copyright (C) 2018 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
|
|
|
|
# This file is part of the textoutpc project, which is MIT-licensed.
|
|
|
|
|
#******************************************************************************
|
2018-01-02 18:57:04 +01:00
|
|
|
|
""" Unit tests for the Python version of textout.
|
|
|
|
|
Uses the builtin `unittest` module.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
import unittest
|
2018-01-05 03:31:33 +01:00
|
|
|
|
import textoutpc
|
2018-01-02 18:57:04 +01:00
|
|
|
|
|
|
|
|
|
# Define the tests.
|
|
|
|
|
|
|
|
|
|
__test_cases = {
|
2018-02-11 12:01:32 +01:00
|
|
|
|
# Basic text.
|
2018-01-16 13:34:11 +01:00
|
|
|
|
'': '',
|
2018-01-26 11:01:41 +01:00
|
|
|
|
'lol': '<p>lol</p>',
|
2018-02-11 12:01:32 +01:00
|
|
|
|
'<script>alert(1);</script>': \
|
|
|
|
|
'<p><script>alert(1);</script></p>',
|
2018-01-16 13:34:11 +01:00
|
|
|
|
|
2018-02-11 12:01:32 +01:00
|
|
|
|
# Other tests. (?)
|
|
|
|
|
'[a][c][/a]': '<p>[a][c][/a]</p>',
|
|
|
|
|
'[a][a]': '<p>[a][a]</p>',
|
|
|
|
|
"[<>]><[/<>]": "<p>[<>]><[/<>]</p>",
|
2018-01-02 18:57:04 +01:00
|
|
|
|
|
2018-02-11 12:01:32 +01:00
|
|
|
|
# Autolinking.
|
2018-01-02 18:57:04 +01:00
|
|
|
|
'(http://www.example.org/some-[damn-url]-(youknow))': \
|
2018-02-11 21:31:39 +01:00
|
|
|
|
'<p>(<a href="http://www.example.org/some-[damn-url]-(youknow)">' \
|
2018-01-26 11:01:41 +01:00
|
|
|
|
'http://www.example.org/some-[damn-url]-(youknow)</a>)</p>',
|
2018-02-11 12:01:32 +01:00
|
|
|
|
'https://thomas.touhey.fr/, tu vois ?': \
|
2018-02-11 21:31:39 +01:00
|
|
|
|
'<p><a href="https://thomas.touhey.fr/">https://thomas.touhey.fr/' \
|
|
|
|
|
'</a>, tu vois ?</p>',
|
2018-01-02 18:57:04 +01:00
|
|
|
|
|
2018-02-11 12:01:32 +01:00
|
|
|
|
# Basic text styling.
|
|
|
|
|
'[u][b][a][i][/b]': "<p><u><b>[a]<i></i></b></u></p>",
|
|
|
|
|
'[u][b]a[/]mdr': '<p><u><b>a</b>mdr</u></p>',
|
2018-01-02 18:57:04 +01:00
|
|
|
|
|
2018-02-11 12:01:32 +01:00
|
|
|
|
# Blocks, alignment.
|
2018-02-19 19:50:26 +01:00
|
|
|
|
'[left]': '',
|
2018-04-15 01:26:30 +02:00
|
|
|
|
'[left]lol[/]hi': '<div class="align-left"><p>lol</p></div><p>hi</p>',
|
|
|
|
|
'a[justify]b': '<p>a</p><div class="align-justify"><p>b</p></div>',
|
|
|
|
|
'a[i][justify]b': '<p>a</p>' \
|
|
|
|
|
'<div class="align-justify"><p><i>b</i></p></div>',
|
|
|
|
|
'a[i]k[center]b': '<p>a<i>k</i></p>' \
|
|
|
|
|
'<div class="align-center"><p><i>b</i></p></div>',
|
2018-02-11 12:01:32 +01:00
|
|
|
|
'a[i]k[center][b]b[justify]c[/center]d[/]wouhou': \
|
|
|
|
|
'<p>a<i>k</i></p>' \
|
2018-04-15 01:26:30 +02:00
|
|
|
|
'<div class="align-center"><p><i><b>b</b></i></p></div>' \
|
|
|
|
|
'<div class="align-justify"><p><i><b>c</b></i></p></div>' \
|
2018-02-11 12:01:32 +01:00
|
|
|
|
'<p><i>d</i>wouhou</p>',
|
|
|
|
|
|
2018-02-11 20:49:33 +01:00
|
|
|
|
# Show tag for super preprocessing blocks.
|
|
|
|
|
'[quote][show][justify]hehe': \
|
2018-04-15 01:26:30 +02:00
|
|
|
|
'<div class="citation"><p><div class="align-justify">' \
|
|
|
|
|
'<p>hehe</p></div></p></div>',
|
2018-02-11 20:49:33 +01:00
|
|
|
|
|
2018-02-11 12:01:32 +01:00
|
|
|
|
# Titles.
|
|
|
|
|
'lolk[title]smth': '<p>lolk</p>' '<h4>smth</h4>',
|
|
|
|
|
'[subtitle]<>': '<h5><></h5>',
|
|
|
|
|
|
|
|
|
|
# Fonts.
|
|
|
|
|
'[arial]test': '<p><span style="font-family: arial">test</span></p>',
|
|
|
|
|
'[font=mono]stereo': \
|
|
|
|
|
'<p><span style="font-family: monospace">stereo</span></p>',
|
|
|
|
|
'[haettenschweiler]': '',
|
|
|
|
|
'[font=hello]yea': '<p>[font=hello]yea</p>',
|
|
|
|
|
|
|
|
|
|
# Color.
|
|
|
|
|
'yea[color=blue]dabadee': \
|
|
|
|
|
'<p>yea<span style="color: #0000FF">dabadee</span></p>',
|
|
|
|
|
'[color=#12345F]a': '<p><span style="color: #12345F">a</span></p>',
|
|
|
|
|
'[color=#123]a': '<p><span style="color: #112233">a</span></p>',
|
|
|
|
|
'[color=123]a': '<p><span style="color: #010203">a</span></p>',
|
|
|
|
|
'[color=chucknorris]a': '<p><span style="color: #C00000">a</span></p>',
|
|
|
|
|
'[color=rgb(1, 22,242)]a': '<p><span style="color: #0116F2">a</span></p>',
|
|
|
|
|
'[color= rgb (1,22, 242 , 50.0% )]a': '<p><span style="color: #0116F2; ' \
|
|
|
|
|
'color: rgba(1, 22, 242, 0.5)">a</span></p>',
|
|
|
|
|
'[color=rgba(1,22,242,0.500)]a': '<p><span style="color: #0116F2; ' \
|
|
|
|
|
'color: rgba(1, 22, 242, 0.5)">a</span></p>',
|
|
|
|
|
'[color=hsl(0, 1,50.0%)]r': '<p><span style="color: #FF0000">r</span></p>',
|
|
|
|
|
# TODO: hls, hwb
|
2018-01-02 18:57:04 +01:00
|
|
|
|
|
|
|
|
|
# Links.
|
2018-02-11 12:01:32 +01:00
|
|
|
|
'[url]': '<p>[url]</p>',
|
2018-01-02 18:57:04 +01:00
|
|
|
|
'[url=https://thomas.touhey.fr/]mon profil est le meilleur[/url]':
|
2018-02-11 21:31:39 +01:00
|
|
|
|
'<p><a href="https://thomas.touhey.fr/">mon profil est le meilleur' \
|
|
|
|
|
'</a></p>',
|
2018-01-26 11:01:41 +01:00
|
|
|
|
'[url=https://thomas.touhey.fr/]': \
|
2018-02-11 21:31:39 +01:00
|
|
|
|
'<p><a href="https://thomas.touhey.fr/">https://thomas.touhey.fr/' \
|
|
|
|
|
'</a></p>',
|
2018-02-11 12:01:32 +01:00
|
|
|
|
'[url=http://hey.org/lol[]>"a]': '<p><a href="http://hey.org/lol[]>' \
|
2018-02-11 21:31:39 +01:00
|
|
|
|
'"a">' \
|
2018-02-11 12:01:32 +01:00
|
|
|
|
'http://hey.org/lol[]>"a</a></p>',
|
|
|
|
|
'[url]javascript:alert(1)[/url]': '<p>[url]javascript:alert(1)[/url]</p>',
|
|
|
|
|
'[url]<script>alert(1);</script>[/url]': \
|
|
|
|
|
'<p>[url]<script>alert(1);</script>[/url]</p>',
|
2018-01-02 18:57:04 +01:00
|
|
|
|
|
2018-02-11 12:01:32 +01:00
|
|
|
|
'[profil]cake[/profil]': \
|
|
|
|
|
'<p><a href="https://www.planet-casio.com/Fr/compte/voir_profil.php' \
|
|
|
|
|
'?membre=cake">cake</a></p>',
|
|
|
|
|
'[profile]ekac': \
|
|
|
|
|
'<p><a href="https://www.planet-casio.com/Fr/compte/voir_profil.php' \
|
|
|
|
|
'?membre=ekac">ekac</a></p>',
|
|
|
|
|
|
|
|
|
|
# Quotes.
|
|
|
|
|
'[quote]': '',
|
|
|
|
|
'[quote]a': \
|
|
|
|
|
'<div class="citation"><p>a</p></div>',
|
|
|
|
|
'[quote=Test 1 :)]lel[/quote]': \
|
|
|
|
|
'<div class="citation"><p><b>Test 1 ' \
|
2018-02-15 20:16:21 +01:00
|
|
|
|
'<img src="/images/smileys/smile.gif"> a écrit :</b></p><br />' \
|
2018-02-11 12:01:32 +01:00
|
|
|
|
'lel</p></div>',
|
2018-01-02 18:57:04 +01:00
|
|
|
|
|
|
|
|
|
# Spoilers.
|
2018-02-11 12:01:32 +01:00
|
|
|
|
'[spoiler]': '',
|
2018-01-02 18:57:04 +01:00
|
|
|
|
'[spoiler=Hello|world> :D]Close this, quick![/spoiler]': \
|
|
|
|
|
'<div class="spoiler"><div class="title on" ' \
|
|
|
|
|
'onclick="toggleSpoiler(this.parentNode, ' "'open'" ');">Hello' \
|
|
|
|
|
'</div><div class="title off" ' \
|
|
|
|
|
'onclick="toggleSpoiler(this.parentNode, ' "'close'" ');">world' \
|
2018-01-22 20:49:30 +01:00
|
|
|
|
'> <img src="/images/smileys/grin.gif"></div><div class="off">' \
|
2018-01-02 18:57:04 +01:00
|
|
|
|
'Close this, quick!</div></div>',
|
|
|
|
|
|
2018-02-11 12:01:32 +01:00
|
|
|
|
# Code.
|
|
|
|
|
'[code]': '',
|
|
|
|
|
"`[code]`": '<p><span style="font-family: monospace;">[code]</span></p>',
|
|
|
|
|
|
|
|
|
|
'[inlinecode]': '',
|
|
|
|
|
"[inlinecode]`[/inlinecode]": \
|
|
|
|
|
'<p><span style="font-family: monospace;">`</span></p>',
|
|
|
|
|
|
|
|
|
|
"[b]a[noeval]b[/b]c[/noeval]d": "<p><b>ab[/b]cd</b></p>",
|
|
|
|
|
"a[noeval]b[noeval]c[/noeval]d[/noeval]e": "<p>ab[noeval]c[/noeval]de</p>",
|
|
|
|
|
"[noeval]``[/noeval]": "<p>``</p>",
|
|
|
|
|
'[noeval]<>[/noeval]': '<p><></p>',
|
|
|
|
|
|
|
|
|
|
# Pictures.
|
|
|
|
|
'[img]': '<p>[img]</p>',
|
|
|
|
|
'[img]"incroyable<>"[/img]': \
|
|
|
|
|
'<p>[img]"incroyable<>"[/img]</p>',
|
|
|
|
|
|
2018-01-02 18:57:04 +01:00
|
|
|
|
# Videos.
|
|
|
|
|
'[video]"><script>alert(1)</script>[/video]': \
|
2018-01-26 11:01:41 +01:00
|
|
|
|
'<p>[video]"><script>alert(1)</script>' \
|
|
|
|
|
'[/video]</p>',
|
2018-01-02 18:57:04 +01:00
|
|
|
|
'[video]<script>alert(document.cookie)</script>[/video]': \
|
2018-01-26 11:01:41 +01:00
|
|
|
|
'<p>[video]<script>alert(document.cookie)</script>' \
|
|
|
|
|
'[/video]</p>',
|
2018-01-02 18:57:04 +01:00
|
|
|
|
'[video]https://www.youtube.com/watch?v=6odDOOyUawY[/video]': \
|
2018-01-20 10:26:23 +01:00
|
|
|
|
'<div class="video-wrapper video-medium"><iframe ' \
|
2018-01-02 18:57:04 +01:00
|
|
|
|
'src="https://www.youtube.com/embed/6odDOOyUawY" ' \
|
2018-01-20 10:26:23 +01:00
|
|
|
|
'frameborder="0" allowfullscreen></iframe></div>',
|
2018-01-22 20:33:25 +01:00
|
|
|
|
'[video]https://www.youtube.com/watch?v=<script>alert(1)</script>': \
|
2018-01-26 11:01:41 +01:00
|
|
|
|
'<p><a href="https://www.youtube.com/watch?v=<script>alert(1)' \
|
2018-02-11 21:31:39 +01:00
|
|
|
|
'</script>">' \
|
2018-01-19 22:44:43 +01:00
|
|
|
|
'https://www.youtube.com/watch?v=<script>alert(1)' \
|
2018-01-26 11:01:41 +01:00
|
|
|
|
'</script></a></p>',
|
2018-01-02 18:57:04 +01:00
|
|
|
|
|
2018-02-11 12:01:32 +01:00
|
|
|
|
# Progress bars.
|
|
|
|
|
'[progress=lol]mdr[/progress]': '<p>[progress=lol]mdr[/progress]</p>',
|
2018-01-19 17:55:43 +01:00
|
|
|
|
|
2018-02-11 12:01:32 +01:00
|
|
|
|
# Text rotation obfuscation.
|
|
|
|
|
'[rot13]obawbhe[/rot13]': '<p>bonjour</p>',
|
2018-01-02 18:57:04 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Define the tests wrapper, and define the classes.
|
|
|
|
|
|
|
|
|
|
_cnt = 0
|
2018-01-05 03:31:33 +01:00
|
|
|
|
_len = len(str(len(__test_cases)))
|
|
|
|
|
_templ = """\
|
|
|
|
|
def test_html{n:0>{l}}(self):
|
2018-01-16 13:34:11 +01:00
|
|
|
|
self.assertEqual({r}, textoutpc.tohtml({i}))
|
2018-01-05 03:31:33 +01:00
|
|
|
|
"""
|
|
|
|
|
|
2018-01-02 18:57:04 +01:00
|
|
|
|
def _wrap_test(inp, res):
|
|
|
|
|
global _cnt
|
|
|
|
|
|
|
|
|
|
_cnt += 1
|
2018-01-05 03:31:33 +01:00
|
|
|
|
return _templ.format(n = _cnt, l = _len, i = repr(inp), r = repr(res))
|
2018-01-02 18:57:04 +01:00
|
|
|
|
|
2018-01-19 15:15:35 +01:00
|
|
|
|
exec("class TextoutHTMLTest(unittest.TestCase):\n maxDiff = None\n" + \
|
2018-01-02 18:57:04 +01:00
|
|
|
|
'\n'.join(map(lambda args: _wrap_test(*args), __test_cases.items())),
|
|
|
|
|
globals())
|
|
|
|
|
|
|
|
|
|
# If run as main script, run the test function.
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
unittest.main()
|
|
|
|
|
|
|
|
|
|
# End of file.
|