Mercurial > jouvence
annotate tests/test_renderer.py @ 33:7c39da93a0ce
docs: Add logo, do a few text changes.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Mon, 16 Jan 2017 21:49:48 -0800 |
parents | 142a53d6e558 |
children |
rev | line source |
---|---|
1
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
1 import pytest |
13 | 2 from jouvence.renderer import BaseTextRenderer |
1
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
3 |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
4 |
3
6019eee799bf
Add base classes for rendering.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
5 class TestTextRenderer(BaseTextRenderer): |
6019eee799bf
Add base classes for rendering.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
6 def make_bold(self, text): |
1
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
7 return 'B:' + text + ':B' |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
8 |
3
6019eee799bf
Add base classes for rendering.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
9 def make_italics(self, text): |
1
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
10 return 'I:' + text + ':I' |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
11 |
3
6019eee799bf
Add base classes for rendering.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
12 def make_underline(self, text): |
1
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
13 return 'U:' + text + ':U' |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
14 |
22
142a53d6e558
Add support for notes.
Ludovic Chabant <ludovic@chabant.com>
parents:
13
diff
changeset
|
15 def make_note(self, text): |
142a53d6e558
Add support for notes.
Ludovic Chabant <ludovic@chabant.com>
parents:
13
diff
changeset
|
16 return 'N:' + text + ':N' |
142a53d6e558
Add support for notes.
Ludovic Chabant <ludovic@chabant.com>
parents:
13
diff
changeset
|
17 |
1
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
18 |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
19 @pytest.mark.parametrize('intext, expected', [ |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
20 ("_Underline_", "U:Underline:U"), |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
21 ("Here's an _underline_.", "Here's an U:underline:U."), |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
22 ("Here's an _underline_ too", "Here's an U:underline:U too"), |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
23 ("This is not_underline_", "This is not_underline_"), |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
24 ("This is not _underline_either", "This is not _underline_either"), |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
25 ("This is _two underlined_ words.", "This is U:two underlined:U words."), |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
26 ("This is _three underlined words_.", |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
27 "This is U:three underlined words:U."), |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
28 ("This is an \_escaped_ one.", "This is an _escaped_ one.") |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
29 ]) |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
30 def test_underline(intext, expected): |
3
6019eee799bf
Add base classes for rendering.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
31 r = TestTextRenderer() |
1
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
32 out = r.render_text(intext) |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
33 assert out == expected |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
34 |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
35 |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
36 @pytest.mark.parametrize('intext, expected', [ |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
37 ("*Italics*", "I:Italics:I"), |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
38 ("Here's some *italics*.", "Here's some I:italics:I."), |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
39 ("Here's some *italics* too", "Here's some I:italics:I too"), |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
40 ("This is not*italics*", "This is not*italics*"), |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
41 ("This is not *italics*either", "This is not *italics*either"), |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
42 ("This is *two italics* words.", "This is I:two italics:I words."), |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
43 ("This is *three italics words*.", |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
44 "This is I:three italics words:I."), |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
45 ("This is some \*escaped* one.", "This is some *escaped* one.") |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
46 ]) |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
47 def test_italics(intext, expected): |
3
6019eee799bf
Add base classes for rendering.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
48 r = TestTextRenderer() |
1
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
49 out = r.render_text(intext) |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
50 assert out == expected |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
51 |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
52 |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
53 @pytest.mark.parametrize('intext, expected', [ |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
54 ("**Bold**", "B:Bold:B"), |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
55 ("Here's some **bold**.", "Here's some B:bold:B."), |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
56 ("Here's some **bold** too", "Here's some B:bold:B too"), |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
57 ("This is not**bold**", "This is not**bold**"), |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
58 ("This is not **bold**either", "This is not **bold**either"), |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
59 ("This is **two bold** words.", "This is B:two bold:B words."), |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
60 ("This is **three bold words**.", |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
61 "This is B:three bold words:B."), |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
62 ("This is some \**escaped** one.", "This is some **escaped** one.") |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
63 ]) |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
64 def test_bold(intext, expected): |
3
6019eee799bf
Add base classes for rendering.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
65 r = TestTextRenderer() |
1
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
66 out = r.render_text(intext) |
74b83e3d921e
Add more states, add more tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
67 assert out == expected |
22
142a53d6e558
Add support for notes.
Ludovic Chabant <ludovic@chabant.com>
parents:
13
diff
changeset
|
68 |
142a53d6e558
Add support for notes.
Ludovic Chabant <ludovic@chabant.com>
parents:
13
diff
changeset
|
69 |
142a53d6e558
Add support for notes.
Ludovic Chabant <ludovic@chabant.com>
parents:
13
diff
changeset
|
70 def test_note(): |
142a53d6e558
Add support for notes.
Ludovic Chabant <ludovic@chabant.com>
parents:
13
diff
changeset
|
71 r = TestTextRenderer() |
142a53d6e558
Add support for notes.
Ludovic Chabant <ludovic@chabant.com>
parents:
13
diff
changeset
|
72 out = r.render_text( |
142a53d6e558
Add support for notes.
Ludovic Chabant <ludovic@chabant.com>
parents:
13
diff
changeset
|
73 "This is JACK[[Do we have a better name?]]. He likes movies.") |
142a53d6e558
Add support for notes.
Ludovic Chabant <ludovic@chabant.com>
parents:
13
diff
changeset
|
74 expected = "This is JACKN:Do we have a better name?:N. He likes movies." |
142a53d6e558
Add support for notes.
Ludovic Chabant <ludovic@chabant.com>
parents:
13
diff
changeset
|
75 assert out == expected |
142a53d6e558
Add support for notes.
Ludovic Chabant <ludovic@chabant.com>
parents:
13
diff
changeset
|
76 |
142a53d6e558
Add support for notes.
Ludovic Chabant <ludovic@chabant.com>
parents:
13
diff
changeset
|
77 |
142a53d6e558
Add support for notes.
Ludovic Chabant <ludovic@chabant.com>
parents:
13
diff
changeset
|
78 def test_note_with_line_break(): |
142a53d6e558
Add support for notes.
Ludovic Chabant <ludovic@chabant.com>
parents:
13
diff
changeset
|
79 r = TestTextRenderer() |
142a53d6e558
Add support for notes.
Ludovic Chabant <ludovic@chabant.com>
parents:
13
diff
changeset
|
80 out = r.render_text( |
142a53d6e558
Add support for notes.
Ludovic Chabant <ludovic@chabant.com>
parents:
13
diff
changeset
|
81 "This is JACK[[Do we have a better name?\n" |
142a53d6e558
Add support for notes.
Ludovic Chabant <ludovic@chabant.com>
parents:
13
diff
changeset
|
82 "I think we did]]. He likes movies.") |
142a53d6e558
Add support for notes.
Ludovic Chabant <ludovic@chabant.com>
parents:
13
diff
changeset
|
83 expected = ("This is JACKN:Do we have a better name?\n" |
142a53d6e558
Add support for notes.
Ludovic Chabant <ludovic@chabant.com>
parents:
13
diff
changeset
|
84 "I think we did:N. He likes movies.") |
142a53d6e558
Add support for notes.
Ludovic Chabant <ludovic@chabant.com>
parents:
13
diff
changeset
|
85 assert out == expected |
142a53d6e558
Add support for notes.
Ludovic Chabant <ludovic@chabant.com>
parents:
13
diff
changeset
|
86 |
142a53d6e558
Add support for notes.
Ludovic Chabant <ludovic@chabant.com>
parents:
13
diff
changeset
|
87 |
142a53d6e558
Add support for notes.
Ludovic Chabant <ludovic@chabant.com>
parents:
13
diff
changeset
|
88 def test_note_multiple(): |
142a53d6e558
Add support for notes.
Ludovic Chabant <ludovic@chabant.com>
parents:
13
diff
changeset
|
89 r = TestTextRenderer() |
142a53d6e558
Add support for notes.
Ludovic Chabant <ludovic@chabant.com>
parents:
13
diff
changeset
|
90 out = r.render_text( |
142a53d6e558
Add support for notes.
Ludovic Chabant <ludovic@chabant.com>
parents:
13
diff
changeset
|
91 "This is JACK[[Do we have a better name?]]. " |
142a53d6e558
Add support for notes.
Ludovic Chabant <ludovic@chabant.com>
parents:
13
diff
changeset
|
92 "He likes movies[[or plays?]].") |
142a53d6e558
Add support for notes.
Ludovic Chabant <ludovic@chabant.com>
parents:
13
diff
changeset
|
93 expected = ("This is JACKN:Do we have a better name?:N. " |
142a53d6e558
Add support for notes.
Ludovic Chabant <ludovic@chabant.com>
parents:
13
diff
changeset
|
94 "He likes moviesN:or plays?:N.") |
142a53d6e558
Add support for notes.
Ludovic Chabant <ludovic@chabant.com>
parents:
13
diff
changeset
|
95 assert out == expected |