# LAMMPS Documentation Utilities # # Copyright (C) 2015 Richard Berger # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU 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 General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . import unittest import tempfile import io import os from lammpsdoc import txt2html class TestBasicFormatting(unittest.TestCase): def setUp(self): self.txt2html = txt2html.Txt2Html() def test_empty_string(self): self.assertEqual(self.txt2html.convert(""), "\n" "\n") def test_single_paragraph(self): self.assertEqual(self.txt2html.convert("Hello World!\n"), "\n" "

Hello World!\n" "

\n" "\n") def test_two_paragraphs(self): s = self.txt2html.convert("Hello World!\n\nBye World!\n") self.assertEqual(s, "\n" "

Hello World!\n" "

\n" "

Bye World!\n" "

\n" "\n") def test_line_concat(self): s = self.txt2html.convert("Hello World!\\\nBye World!\n") self.assertEqual(s, "\n" "

Hello World!Bye World!\n" "

\n" "\n") def test_html_pass_through(self): s = self.txt2html.convert("
Raw HTML
\n") self.assertEqual(s, "\n" "
Raw HTML
\n\n" "\n") def test_ignore_rst(self): s = self.txt2html.convert("\n") self.assertEqual("\n" "\n", s) def test_ignore_html_only_markup(self): s = self.txt2html.convert("\n" "Hello World!\n" "\n") self.assertEqual("\n" "\n" "Hello World!\n" "\n\n" "\n", s) class TestMarkup(unittest.TestCase): def setUp(self): self.markup = txt2html.HTMLMarkup() self.txt2html = txt2html.Txt2Html() def test_bold(self): self.assertEqual("bold", self.markup.convert("[bold]")) def test_italic(self): self.assertEqual("italic", self.markup.convert("{italic}")) def test_escape_markup(self): s = self.markup.convert("[bold] = \\[bold\\]\n" "{italic} = \\{italic\\}\n") self.assertEqual("bold = [bold]\n" "italic = {italic}\n", s) def test_link_markup(self): self.assertEqual("Text", self.markup.convert('"Text"_link')) def test_multiline_link_markup(self): s = self.txt2html.convert('"Te\n' 'xt"_link') self.assertEqual("\n" "

Te\n" "xt\n" "

\n" "\n", s) def test_ignore_punctuation_in_link(self): self.assertEqual("Text.", self.markup.convert('"Text"_link.')) self.assertEqual("Text,", self.markup.convert('"Text"_link,')) self.assertEqual("Text;", self.markup.convert('"Text"_link;')) self.assertEqual("Text:", self.markup.convert('"Text"_link:')) self.assertEqual("Text?", self.markup.convert('"Text"_link?')) self.assertEqual("Text!", self.markup.convert('"Text"_link!')) self.assertEqual("Text(", self.markup.convert('"Text"_link(')) self.assertEqual("Text)", self.markup.convert('"Text"_link)')) def test_replace_alias_link(self): self.markup.add_link_alias("link", "replacement") self.assertEqual("Text", self.markup.convert('"Text"_link')) class TestFormatting(unittest.TestCase): def setUp(self): self.txt2html = txt2html.Txt2Html() def test_paragraph_formatting(self): s = self.txt2html.convert("Hello :p\n") self.assertEqual(s, "\n" "

Hello \n" "

\n" "\n") def test_two_paragraphs_through_formatting(self): text = "Hello :p\nBye :p\n" p = list(self.txt2html.paragraphs(text)) s = self.txt2html.convert(text) self.assertEqual(len(p), 2) self.assertEqual(s, "\n" "

Hello \n" "

\n" "

Bye \n" "

\n" "\n") def test_break_formatting(self): s = self.txt2html.convert("Hello :b\n") self.assertEqual(s, "\n" "Hello \n" "
\n" "\n") def test_preformat_formatting(self): s = self.txt2html.convert("Hello :pre\n") self.assertEqual(s, "\n" "
Hello \n"
                             "
\n" "\n") def test_center_formatting(self): s = self.txt2html.convert("Hello :c\n") self.assertEqual(s, "\n" "
Hello \n" "
\n" "\n") def test_header_formatting(self): s = self.txt2html.convert("Level 1 :h1\n" "Level 2 :h2\n" "Level 3 :h3\n" "Level 4 :h4\n" "Level 5 :h5\n" "Level 6 :h6\n") self.assertEqual(s, "\n" "

Level 1 \n" "

\n" "

Level 2 \n" "

\n" "

Level 3 \n" "

\n" "

Level 4 \n" "

\n" "
Level 5 \n" "
\n" "
Level 6 \n" "
\n" "\n") def test_all_paragraphs(self): s = self.txt2html.convert("one\n" "two\n" "three :all(p)\n") self.assertEqual("\n" "

one

\n" "

two

\n" "

three

\n" "\n" "\n", s) def test_all_centered(self): s = self.txt2html.convert("one\n" "two\n" "three :all(c)\n") self.assertEqual("\n" "
one
\n" "
two
\n" "
three
\n" "\n" "\n", s) def test_all_breaks(self): s = self.txt2html.convert("one\n" "two\n" "three :all(b)\n") self.assertEqual("\n" "one
\n" "two
\n" "three
\n" "\n" "\n", s) def test_links_with_all_breaks(self): s = self.txt2html.convert("\"one\"_link\n" "\"two\"_link\n" "\"three\"_link :all(b)\n") self.assertEqual("\n" "one
\n" "two
\n" "three
\n" "\n" "\n", s) def test_two_similar_links(self): s = self.txt2html.convert("\"one\"_linkA and \"one\"_linkAB\n") self.assertEqual("\n" "

one and one\n" "

\n" "\n", s) def test_all_breaks_in_paragraph(self): s = self.txt2html.convert("one\n" "two\n" "three :all(b),p\n") self.assertEqual("\n" "

one
\n" "two
\n" "three
\n" "

\n" "\n", s) def test_all_list_items(self): s = self.txt2html.convert("one\n" "two\n" "three :all(l)\n") self.assertEqual("\n" "
  • one\n" "
  • two\n" "
  • three \n" "\n" "\n", s) def test_two_commands(self): s = self.txt2html.convert("one :ulb,l\n") self.assertEqual("\n" "