#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright 2020 The ChromiumOS Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Tests for tiny_render."""
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),
"hello, world!",
)
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
\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 world!',
)
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: