mkhtml2: if linkend does not resolve output inner data
[gtk-doc.git] / tests / mk_to_db.py
blob8cc59782ed3ce0dfb3829ffa7d232237ce84b73d
1 # -*- python; coding: utf-8 -*-
3 # gtk-doc - GTK DocBook documentation generator.
4 # Copyright (C) 2015 Christoph Reiter
5 # 2017 Stefan Sauer
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 import unittest
24 from gtkdoc import md_to_db
27 class TestConverter(unittest.TestCase):
29 def setUp(self):
30 md_to_db.Init()
32 def test_main(self):
33 input_ = """\
34 SUPPORTED MARKDOWN
35 ==================
37 Atx-style Headers
38 -----------------
40 # Header 1
42 ## Header 2 ##
44 Setext-style Headers
45 --------------------
47 Header 1
48 ========
50 Header 2
51 --------
53 Ordered (unnested) Lists
54 ------------------------
56 1. item 1
58 1. item 2 with loooong *foo*
59 description
61 3. item 3
63 Note: we require a blank line above the list items
64 """
66 expexted = """\
67 <para>SUPPORTED MARKDOWN</para>
68 <para>Atx-style Headers</para>
69 <refsect2><title>Header 1</title><refsect3><title>Header 2</title></refsect3>
70 <refsect3><title>Setext-style Headers</title></refsect3>
71 </refsect2>
72 <refsect2><title>Header 1</title><para>Header 2</para>
73 <para>Ordered (unnested) Lists</para>
74 <orderedlist>
75 <listitem>
76 <para>item 1</para>
77 </listitem>
78 <listitem>
79 <para>item 2 with loooong *foo*
80 description</para>
81 </listitem>
82 <listitem>
83 <para>item 3</para>
84 </listitem>
85 </orderedlist>
86 <para>Note: we require a blank line above the list items</para>
87 </refsect2>
88 """
90 output = md_to_db.MarkDownParse(input_, "")
91 self.assertEqual(expexted, output)
93 def test_docbook(self):
94 input_ = """\
95 <itemizedlist>
96 <listitem><para>foo</para></listitem>
97 </itemizedlist>
98 """
100 # docbook should stay the same
101 output = md_to_db.MarkDownParse(input_, "")
102 self.assertEqual(input_, output)
104 def test_header(self):
105 input_ = """
106 widget lifecycle, states and style.
108 # Height-for-width Geometry Management # {#geometry-management}
110 GTK+ uses a height-for-width (and wid
113 expected = """\
114 <para>widget lifecycle, states and style.</para>
115 <refsect2 id="geometry-management"><title>Height-for-width Geometry Management</title><para>GTK+ uses a height-for-width (and wid</para>
116 </refsect2>
119 output = md_to_db.MarkDownParse(input_, "")
120 self.assertEqual(expected, output)
122 def test_lists(self):
123 input_ = """\
124 bla bla
125 bla:
127 - The channel was just created, and has not been written to or read from yet.
130 - The channel is write-only.
134 expected = """\
135 <para>bla bla
136 bla:</para>
137 <itemizedlist>
138 <listitem>
139 <para>The channel was just created, and has not been written to or read from yet.
140 bla</para>
141 </listitem>
142 <listitem>
143 <para>The channel is write-only.</para>
144 </listitem>
145 </itemizedlist>
146 <para>foo</para>
148 output = md_to_db.MarkDownParse(input_, "")
149 self.assertEqual(expected, output)
151 def test_paragraphs(self):
152 input_ = """\
153 foo,
154 bar.
156 foo,
157 bar.
159 foo,
160 bar.
162 expected = """\
163 <para>foo,
164 bar.</para>
165 <para>foo,
166 bar.</para>
167 <para>foo,
168 bar.</para>
170 output = md_to_db.MarkDownParse(input_, "")
171 self.assertEqual(expected, output)
173 def test_reference(self):
174 input_ = """\
175 The #GData struct is an opaque data structure to represent a
176 [Keyed Data List][glib-Keyed-Data-Lists]. It should only be
177 accessed via the following functions."""
179 expected = """\
180 <para>The <link linkend="GData"><type>GData</type></link> struct is an opaque data structure to represent a
181 <link linkend="glib-Keyed-Data-Lists">Keyed Data List</link>. It should only be
182 accessed via the following functions.</para>
185 output = md_to_db.MarkDownParse(input_, "")
186 self.assertEqual(expected, output)
188 def test_reference2(self):
189 input_ = "a [foo][bar] b [quux][baz]"
190 expected = '<para>a <link linkend="bar">foo</link> b <link linkend="baz">quux</link></para>\n'
191 output = md_to_db.MarkDownParse(input_, "")
192 self.assertEqual(expected, output)
194 def test_reference_empty(self):
195 input_ = "[][]"
196 # expected = '<para><ulink url=""></ulink></para>\n'
197 expected = '<para><link linkend=""></link></para>\n'
198 output = md_to_db.MarkDownParse(input_, "")
199 self.assertEqual(expected, output)
201 def test_inline_code(self):
202 input_ = "a `abc`"
203 expected = '<para>a <literal>abc</literal></para>\n'
204 output = md_to_db.MarkDownParse(input_, "")
205 self.assertEqual(expected, output)
207 def test_inline_code2(self):
208 input_ = "a `[][]`"
209 expected = '<para>a <literal>[][]</literal></para>\n'
210 output = md_to_db.MarkDownParse(input_, "")
211 self.assertEqual(expected, output)
213 def test_code(self):
214 input_ = """\
215 |[<!-- language="C" -->
216 GdkEvent *event;
217 GdkEventType type;
219 type = event->type;
223 expected = '''\
224 <informalexample><programlisting role="example" language="C"><![CDATA[
225 GdkEvent *event;
226 GdkEventType type;
228 type = event->type;
229 ]]></programlisting></informalexample>
230 <para></para>
232 output = md_to_db.MarkDownParse(input_, "")
233 self.assertEqual(expected, output)
235 def test_plain(self):
236 input_ = u"""\
237 |[<!-- language="plain" -->
238 frame
239 ├── border
240 ├── <label widget>
241 ╰── <child>
245 expected = u"""\
246 <informalexample><screen><![CDATA[
247 frame
248 ├── border
249 ├── <label widget>
250 ╰── <child>
251 ]]></screen></informalexample>
252 <para></para>
255 output = md_to_db.MarkDownParse(input_, "")
256 self.assertEqual(expected, output)
259 if __name__ == '__main__':
260 unittest.main()