aboutsummaryrefslogtreecommitdiff
path: root/cros_utils/tiny_render_test.py
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2021-07-15 01:28:48 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2021-07-15 01:28:48 +0000
commitf3bf46bb50d5113aa736e03885bb2d80e0e9e290 (patch)
tree73936aba47fe1dc71e9cc05af9747036e935608c /cros_utils/tiny_render_test.py
parentb75f321fc8978b92ce3db6886ccb966768f0c7a8 (diff)
parent4e4201457e5f51a132101c611c79ccff9f713c8b (diff)
downloadtoolchain-utils-android12-mainline-conscrypt-release.tar.gz
Snap for 7550844 from 4e4201457e5f51a132101c611c79ccff9f713c8b to mainline-conscrypt-releaseandroid-mainline-12.0.0_r8android-mainline-12.0.0_r25android12-mainline-conscrypt-release
Change-Id: I2e1a3b1c2065a7c2fdf4a758a1d068de65141066
Diffstat (limited to 'cros_utils/tiny_render_test.py')
-rwxr-xr-xcros_utils/tiny_render_test.py177
1 files changed, 177 insertions, 0 deletions
diff --git a/cros_utils/tiny_render_test.py b/cros_utils/tiny_render_test.py
new file mode 100755
index 00000000..114a1796
--- /dev/null
+++ b/cros_utils/tiny_render_test.py
@@ -0,0 +1,177 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+# Copyright 2020 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Tests for tiny_render."""
+
+from __future__ import print_function
+
+import unittest
+
+import tiny_render
+
+
+# Admittedly, the HTML generated by this isn't always _beautiful_ to read
+# (especially with e.g., ordered lists). Since the intent is for the HTML to be
+# shipped alongside the plain-text, the hope is that people won't have to
+# subject themselves to reading the HTML often. :)
+class Test(unittest.TestCase):
+ """Tests for tiny_render."""
+
+ def test_bold(self):
+ pieces = [
+ tiny_render.Bold('hello'),
+ ', ',
+ tiny_render.Bold(['world', '!']),
+ ]
+
+ self.assertEqual(
+ tiny_render.render_text_pieces(pieces),
+ '**hello**, **world!**',
+ )
+
+ self.assertEqual(
+ tiny_render.render_html_pieces(pieces),
+ '<b>hello</b>, <b>world!</b>',
+ )
+
+ def test_line_break(self):
+ pieces = [
+ 'hello',
+ tiny_render.line_break,
+ ['world', '!'],
+ ]
+
+ self.assertEqual(
+ tiny_render.render_text_pieces(pieces),
+ 'hello\nworld!',
+ )
+
+ self.assertEqual(
+ tiny_render.render_html_pieces(pieces),
+ 'hello<br />\nworld!',
+ )
+
+ def test_linkification(self):
+ pieces = [
+ 'hello ',
+ tiny_render.Link(href='https://google.com', inner='world!'),
+ ]
+
+ self.assertEqual(
+ tiny_render.render_text_pieces(pieces),
+ 'hello world!',
+ )
+
+ self.assertEqual(
+ tiny_render.render_html_pieces(pieces),
+ 'hello <a href="https://google.com">world!</a>',
+ )
+
+ def test_unordered_list(self):
+ pieces = [
+ 'hello:',
+ tiny_render.UnorderedList([
+ 'world',
+ 'w o r l d',
+ ]),
+ ]
+
+ self.assertEqual(
+ tiny_render.render_text_pieces(pieces),
+ '\n'.join((
+ 'hello:',
+ ' - world',
+ ' - w o r l d',
+ )),
+ )
+
+ self.assertEqual(
+ tiny_render.render_html_pieces(pieces),
+ '\n'.join((
+ 'hello:<ul>',
+ '<li>world</li>',
+ '<li>w o r l d</li>',
+ '</ul>',
+ '',
+ )),
+ )
+
+ def test_nested_unordered_list(self):
+ pieces = [
+ 'hello:',
+ tiny_render.UnorderedList([
+ 'world',
+ ['and more:', tiny_render.UnorderedList(['w o r l d'])],
+ 'world2',
+ ])
+ ]
+
+ self.assertEqual(
+ tiny_render.render_text_pieces(pieces),
+ '\n'.join((
+ 'hello:',
+ ' - world',
+ ' - and more:',
+ ' - w o r l d',
+ ' - world2',
+ )),
+ )
+
+ self.assertEqual(
+ tiny_render.render_html_pieces(pieces),
+ '\n'.join((
+ 'hello:<ul>',
+ '<li>world</li>',
+ '<li>and more:<ul>',
+ '<li>w o r l d</li>',
+ '</ul>',
+ '</li>',
+ '<li>world2</li>',
+ '</ul>',
+ '',
+ )),
+ )
+
+ def test_switch(self):
+ pieces = ['hello ', tiny_render.Switch(text='text', html='html')]
+ self.assertEqual(tiny_render.render_text_pieces(pieces), 'hello text')
+ self.assertEqual(tiny_render.render_html_pieces(pieces), 'hello html')
+
+ def test_golden(self):
+ pieces = [
+ 'hello',
+ tiny_render.UnorderedList([
+ tiny_render.Switch(text='text', html=tiny_render.Bold('html')),
+ 'the',
+ tiny_render.Bold('sun'),
+ ]),
+ tiny_render.line_break,
+ ['is', ' out!'],
+ ]
+
+ self.assertEqual(
+ tiny_render.render_text_pieces(pieces), '\n'.join((
+ 'hello',
+ ' - text',
+ ' - the',
+ ' - **sun**',
+ 'is out!',
+ )))
+
+ self.assertEqual(
+ tiny_render.render_html_pieces(pieces), '\n'.join((
+ 'hello<ul>',
+ '<li><b>html</b></li>',
+ '<li>the</li>',
+ '<li><b>sun</b></li>',
+ '</ul>',
+ '<br />',
+ 'is out!',
+ )))
+
+
+if __name__ == '__main__':
+ unittest.main()