#!/usr/bin/env python3 #****************************************************************************** # Copyright (C) 2018 Thomas "Cakeisalie5" Touhey # This file is part of the textoutpc project, which is MIT-licensed. #****************************************************************************** """ Unit tests for the Python version of textout. Uses the builtin `unittest` module. """ import unittest as _unittest __all__ = ["TextoutHTMLTest"] # Define the tests. __test_cases = { # Basic text. '': '', 'lol': '

lol

', '': \ '

<script>alert(1);</script>

', # Other tests. (?) '[a][c][/a]': '

[a][c][/a]

', '[a][a]': '

[a][a]

', "[<>]><[/<>]": "

[<>]><[/<>]

", # Autolinking. '(http://www.example.org/some-[damn-url]-(youknow))': \ '

(' \ 'http://www.example.org/some-[damn-url]-(youknow))

', 'https://thomas.touhey.fr/, tu vois ?': \ '

https://thomas.touhey.fr/' \ ', tu vois ?

', # Basic text styling. '[u][b][a][i][/b]': "

[a]

", '[u][b]a[/]mdr': '

amdr

', # Blocks, alignment. '[left]': '', '[left]lol[/]hi': '

lol

hi

', 'a[justify]b': '

a

b

', 'a[i]': '

a

', 'a[i][justify]b': '

a

' \ '

b

', 'a[i]k[center]b': '

ak

' \ '

b

', 'a[i]k[center][b]b[justify]c[/center]d[/]wouhou': \ '

ak

' \ '

b

' \ '

c

' \ '

dwouhou

', # Show tag for super preprocessing blocks. '[show]lol': '

lol

', '[quote][show][justify]hehe': \ '

' \ '<div class="align-justify">' \ '<p>hehe</p></div>' \ '

', # Titles. 'lolk[title]smth': '

lolk

' '

smth

', '[subtitle]<>': '

<>

', # Fonts. '[arial]test': '

test

', '[font=mono]stereo': \ '

stereo

', '[haettenschweiler]': '', '[font=hello]yea': '

[font=hello]yea

', # Color. 'yea[color=blue]dabadee': \ '

yeadabadee

', '[color=#12345F]a': '

a

', '[color=#123]a': '

a

', '[color=123]a': '

a

', '[color=chucknorris]a': '

a

', '[color=rgb(1, 22,242)]a': '

a

', '[color= rgb (1,22, 242 , 50.0% )]a': '

a

', '[color=rgba(1,22,242,0.500)]a': '

a

', '[color=rbga(5, 7)]b': '

b

', '[color=hsl(0, 1,50.0%)]r': '

r

', # TODO: hls, hwb # Links. '[url]': '

[url]

', '[url=https://thomas.touhey.fr/]mon profil est le meilleur[/url]': '

mon profil est le meilleur' \ '

', '[url=https://thomas.touhey.fr/]': \ '

https://thomas.touhey.fr/' \ '

', '[url=http://hey.org/lol[]>"a]': '

' \ 'http://hey.org/lol[]>"a

', '[url]javascript:alert(1)[/url]': '

[url]javascript:alert(1)[/url]

', '[url][/url]': \ '

[url]<script>alert(1);</script>[/url]

', '[profil]cake[/profil]': \ '

cake

', '[profile]ekac': \ '

ekac

', # Quotes. '[quote]': '', '[quote]a': \ '

a

', '[quote=Test 1 :)]lel[/quote]': \ '

Test 1 ' \ ' a écrit :

' \ 'lel

', # Spoilers. '[spoiler]': '', '[spoiler=Hello|world> :D]Close this, quick![/spoiler]': \ '

Hello' \ '

world' \ '>

' \ '

Close this, quick!

', # Code. '[code]': '', "`[code]`": '

[code]

', '[inlinecode]': '', "[inlinecode]`[/inlinecode]": '

`

', "[b]a[noeval]b[/b]c[/noeval]d": "

ab[/b]cd

", "a[noeval]b[noeval]c[/noeval]d[/noeval]e": "

ab[noeval]c[/noeval]de

", "[noeval]``[/noeval]": "

``

", '[noeval]<>[/noeval]': '

<>

', # Pictures. '[img]': '

[img]

', '[img]"incroyable<>"[/img]': \ '

[img]"incroyable<>"[/img]

', '[img=right|float|12x345]https://example.org/image.png': \ '', # Videos. '[video]">[/video]': \ '

[video]"><script>alert(1)</script>' \ '[/video]

', '[video][/video]': \ '

[video]<script>alert(document.cookie)</script>' \ '[/video]

', '[video]https://www.youtube.com/watch?v=6odDOOyUawY[/video]': \ '
', '[video]https://www.youtube.com/watch?v=': \ '

' \ 'https://www.youtube.com/watch?v=<script>alert(1)' \ '</script>

', '[video=left|float|4:3]https://www.youtube.com/watch?v=XEjLoHdbVeE': \ '
', 'lol[youtube]h4WLX8hfpJw': '

lol

', '[color=blue][youtube]h4WLX8hfpJw': \ '
' \ '
', '[color=blue]oh[youtube]h4WLX8hfpJw': \ '

oh

' \ '
', # Progress bars. '[progress=lol]mdr[/progress]': '

[progress=lol]mdr[/progress]

', # Text rotation obfuscation. '[rot13]obawbhe[/rot13]': '

bonjour

', # Lists. '[list]haha[b][*]wow[*]incredible[/b][/*]wow[*]yuy[/list]': \ '', '[list]\n[*]bonjour': '', # Smileys. ':)': '

', ':):)': '

:):)

', ':) :D': '

' \ '

', } # Define the tests wrapper, and define the classes. _cnt = 0 _len = len(str(len(__test_cases))) _templ = """\ def test_html{n:0>{l}}(self): import textoutpc as _textoutpc self.assertEqual(_textoutpc.tohtml({i}), {r}, \\ "for the following text: " + {i}) """ def _wrap_test(inp, res): global _cnt _cnt += 1 return _templ.format(n = _cnt, l = _len, i = repr(inp), r = repr(res)) exec("class TextoutHTMLTest(_unittest.TestCase):\n maxDiff = None\n" + \ '\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.