Skip to content

Commit

Permalink
test: added man and line numbers tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AlphaJack committed Mar 17, 2024
1 parent 4d73393 commit 9a9364b
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tests/input/man_simple.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'\" t
.TH LESS 1 "Version 643: 20 Jul 2023"
.SH NAME
less \- opposite of more
.SH SYNOPSIS
.br
.B "less \-\-help"
.br
(See the OPTIONS section for alternate option syntax with long option names.)
.
.SH DESCRIPTION
.SS SUBDESCRIPTION
24 changes: 24 additions & 0 deletions tests/reference/man_simple.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.\" ┌───────────────────────────────────────────────────────────────┐
.\" │ Contents of man_simple.1 │
.\" ├───────────────────────────────────────────────────────────────┘
.\"
.\" ├──┐LESS 1
.\" │ ├── NAME
.\" │ ├── SYNOPSIS
.\" │ └──┐DESCRIPTION
.\" │ └── SUBDESCRIPTION
.\"
.\" └───────────────────────────────────────────────────────────────

'\" t
.TH LESS 1 "Version 643: 20 Jul 2023"
.SH NAME
less \- opposite of more
.SH SYNOPSIS
.br
.B "less \-\-help"
.br
(See the OPTIONS section for alternate option syntax with long option names.)
.
.SH DESCRIPTION
.SS SUBDESCRIPTION
41 changes: 41 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,47 @@ def test_stdin(self):
print("output: '" + output.getvalue() + "'")
self.assertIn("Contents of stdin.html", output.getvalue())

def test_depth(self):
test_args = [f"{self.p / 'toc' / 'cli.py'}", "-e", "html", "-d", "1", "-"]
stdin_content = """
<html>
<html>
<h1>Title</h1>
<h2>Subtitle</h2>
</html>
"""
with patch("sys.stdin", StringIO(stdin_content)):
with patch.object(sys, "argv", test_args):
output = StringIO()
with redirect_stdout(output):
main()
print("output: '" + output.getvalue() + "'")
self.assertNotIn("Subtitle", output.getvalue())

def test_line_numbers_html(self):
test_args = [f"{self.p / 'toc' / 'cli.py'}", "-e", "html", "-n", "-"]
stdin_content = "<h1>Title</h1>"
with patch("sys.stdin", StringIO(stdin_content)):
with patch.object(sys, "argv", test_args):
output = StringIO()
with redirect_stdout(output):
main()
print("output: '" + output.getvalue() + "'")
self.assertIn("Title 1", output.getvalue())

def test_line_numbers_generic(self):
test_args = [f"{self.p / 'toc' / 'cli.py'}", "-e", "tex", "-n", "-"]
stdin_content = """
% ################################################################ Preamble
"""
with patch("sys.stdin", StringIO(stdin_content)):
with patch.object(sys, "argv", test_args):
output = StringIO()
with redirect_stdout(output):
main()
print("output: '" + output.getvalue() + "'")
self.assertIn("Preamble 2", output.getvalue())

def test_output(self):
test_args = [
f"{self.p / 'toc' / 'cli.py'}",
Expand Down

0 comments on commit 9a9364b

Please sign in to comment.