##// END OF EJS Templates
Added 18 more citation tests...
Jonathan Frederic -
Show More
@@ -17,7 +17,7 b' from nose.tools import assert_equal'
17 # Tests
17 # Tests
18 #-----------------------------------------------------------------------------
18 #-----------------------------------------------------------------------------
19
19
20 test_md = """
20 test_md = {"""
21 # My Heading
21 # My Heading
22
22
23 Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus ac magna non augue
23 Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus ac magna non augue
@@ -32,9 +32,7 b' relations like 1<2 & 4>5.</p>'
32 * One <cite data-cite="jdfreder">Jonathan</cite>.
32 * One <cite data-cite="jdfreder">Jonathan</cite>.
33 * Two <cite data-cite="carreau">Matthias</cite>.
33 * Two <cite data-cite="carreau">Matthias</cite>.
34 * Three <cite data-cite="ivanov">Paul</cite>.
34 * Three <cite data-cite="ivanov">Paul</cite>.
35 """
35 """: """
36
37 test_md_parsed = """
38 # My Heading
36 # My Heading
39
37
40 Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus ac magna non augue
38 Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus ac magna non augue
@@ -49,13 +47,106 b' relations like 1<2 & 4>5.</p>'
49 * One \cite{jdfreder}.
47 * One \cite{jdfreder}.
50 * Two \cite{carreau}.
48 * Two \cite{carreau}.
51 * Three \cite{ivanov}.
49 * Three \cite{ivanov}.
52 """
50 """,
51
52 # No citations
53 r"""The quick brown fox jumps over the lazy dog.""":
54 r"""The quick brown fox jumps over the lazy dog.""",
55
56 # Simple inline
57 r"""Foo <cite data-cite=asdf>Text</cite> bar""":
58 r"""Foo \cite{asdf} bar""",
59
60 # Multiline
61 r"""<cite data-cite=ewqr>Text
62 </cite>Foo""":
63 r"""\cite{ewqr}Foo""",
64
65 # Nested tags
66 r"""<div><div data-cite=Foo><div>Text</div></div></div> Bar""":
67 r"""<div>\cite{Foo}</div> Bar""",
68
69 # Including Maths
70 r"""Foo $3*2*1$ <div data-cite=Foo>Text</div> Bar""":
71 r"""Foo $3*2*1$ \cite{Foo} Bar""",
72
73 # Missing end tag
74 r"""<cite data-cite=asdf>Test Foo""":
75 r"""\cite{asdf}""",
76
77 r"""<cite data-cite=asdf><cite>Test Foo""":
78 r"""\cite{asdf}""",
79
80 r"""<cite data-cite=asdf><cite>Test</cite> Foo""":
81 r"""\cite{asdf}""",
82
83 # Multiple arguments
84 r"""<cite width=qwer data-cite=asdf>Test</cite> Foo""":
85 r"""\cite{asdf} Foo""",
86
87 # Wrong capitalization
88 r"""<CITE data-cite=asdf>Test</cite> Foo""":
89 r"""\cite{asdf} Foo""",
90
91 r"""<cite DATA-CITE=asdf>Test</cite> Foo""":
92 r"""\cite{asdf} Foo""",
93
94 # Wrong end tag
95 r"""<asd data-cite=wer> ksjfs </asdf> sdf ds """:
96 r"""\cite{wer}""",
97
98 r"""<asd data-cite=wer>""":
99 r"""\cite{wer}""",
100
101 # Invalid tag names
102 r"""<frog> <foo data-cite=wer></foo>""":
103 r"""<frog> \cite{wer}""",
104
105 # Non-nested tags
106 r"""<strong> <h1> <cite data-cite=asdf></cite>Test</strong> Foo </h1>""":
107 r"""<strong> <h1> \cite{asdf}Test</strong> Foo </h1>""",
108
109 # LXML errors
110 r"""Foo
111 \begin{eqnarray}
112 1 & <cite data-cite=bar>bar1</cite> \\
113 3 & 4 \\
114 \end{eqnarray}""":
115 r"""Foo
116 \begin{eqnarray}
117 1 & \cite{bar} \\
118 3 & 4 \\
119 \end{eqnarray}""",
120
121 r"""
122 1<2 is true, but 3>4 is false.
123
124 $1<2$ is true, but $3>4$ is false.
125
126 1<2 it is even worse if it is alone in a line.""":
127 r"""
128 1<2 is true, but 3>4 is false.
129
130 $1<2$ is true, but $3>4$ is false.
131
132 1<2 it is even worse if it is alone in a line.""",
133
134 r"""
135 1 < 2 is true, but 3 > 4 is false
136
137 $1 < 2$ is true, but $3 > 4$ is false
138
139 1 < 2 it is even worse if it is alone in a line.
140 """:
141 r"""
142 1 < 2 is true, but 3 > 4 is false
143
144 $1 < 2$ is true, but $3 > 4$ is false
145
146 1 < 2 it is even worse if it is alone in a line.
147 """}
53
148
54 def test_citation2latex():
149 def test_citation2latex():
55 """Are citations parsed properly?"""
150 """Are citations parsed properly?"""
56 try:
151 for input, output in test_md.items():
57 from lxml import html #analysis:ignore
152 yield (assert_equal, citation2latex(input), output)
58 except ImportError:
59 assert_equal(test_md, citation2latex(test_md))
60 else:
61 assert_equal(test_md_parsed, citation2latex(test_md))
General Comments 0
You need to be logged in to leave comments. Login now