# -*- python; coding: utf-8 -*-
#
# gtk-doc - GTK DocBook documentation generator.
# Copyright (C) 2015 Christoph Reiter
# 2017 Stefan Sauer
#
# 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 2 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, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
import unittest
from gtkdoc import md_to_db
class TestConverter(unittest.TestCase):
def setUp(self):
md_to_db.Init()
def test_main(self):
input_ = """\
SUPPORTED MARKDOWN
==================
Atx-style Headers
-----------------
# Header 1
## Header 2 ##
Setext-style Headers
--------------------
Header 1
========
Header 2
--------
Ordered (unnested) Lists
------------------------
1. item 1
1. item 2 with loooong *foo*
description
3. item 3
Note: we require a blank line above the list items
"""
expexted = """\
SUPPORTED MARKDOWNAtx-style HeadersHeader 1Header 2Setext-style HeadersHeader 1Header 2Ordered (unnested) Listsitem 1item 2 with loooong *foo*
descriptionitem 3Note: we require a blank line above the list items
"""
output = md_to_db.MarkDownParse(input_, "")
self.assertEqual(expexted, output)
def test_docbook(self):
input_ = """\
foo
"""
# docbook should stay the same
output = md_to_db.MarkDownParse(input_, "")
self.assertEqual(input_, output)
def test_header(self):
input_ = """
widget lifecycle, states and style.
# Height-for-width Geometry Management # {#geometry-management}
GTK+ uses a height-for-width (and wid
"""
expected = """\
widget lifecycle, states and style.Height-for-width Geometry ManagementGTK+ uses a height-for-width (and wid
"""
output = md_to_db.MarkDownParse(input_, "")
self.assertEqual(expected, output)
def test_lists(self):
input_ = """\
bla bla
bla:
- The channel was just created, and has not been written to or read from yet.
bla
- The channel is write-only.
foo
"""
expected = """\
bla bla
bla:The channel was just created, and has not been written to or read from yet.
blaThe channel is write-only.foo
"""
output = md_to_db.MarkDownParse(input_, "")
self.assertEqual(expected, output)
# like previous, but no newlines beweteen items
def test_lists_in_paragraphs(self):
input_ = """\
before:
- item 1
- item 2
after
"""
# TODO(ensonic): figure out why we insert '\n' for 2nd listitem
expected = """\
before:item 1item 2after
"""
output = md_to_db.MarkDownParse(input_, "")
self.assertEqual(expected, output)
def test_paragraphs(self):
input_ = """\
foo,
bar.
foo,
bar.
foo,
bar.
"""
expected = """\
foo,
bar.foo,
bar.foo,
bar.
"""
output = md_to_db.MarkDownParse(input_, "")
self.assertEqual(expected, output)
def test_reference(self):
input_ = """\
The #GData struct is an opaque data structure to represent a
[Keyed Data List][glib-Keyed-Data-Lists]. It should only be
accessed via the following functions."""
expected = """\
The GData struct is an opaque data structure to represent a
Keyed Data List. It should only be
accessed via the following functions.
"""
output = md_to_db.MarkDownParse(input_, "")
self.assertEqual(expected, output)
def test_reference2(self):
input_ = "a [foo][bar] b [quux][baz]"
expected = 'a foo b quux\n'
output = md_to_db.MarkDownParse(input_, "")
self.assertEqual(expected, output)
def test_reference_empty(self):
input_ = "[][]"
# expected = '\n'
expected = '\n'
output = md_to_db.MarkDownParse(input_, "")
self.assertEqual(expected, output)
def test_inline_code(self):
input_ = "a `abc`"
expected = 'a abc\n'
output = md_to_db.MarkDownParse(input_, "")
self.assertEqual(expected, output)
def test_inline_code2(self):
input_ = "a `[][]`"
expected = 'a [][]\n'
output = md_to_db.MarkDownParse(input_, "")
self.assertEqual(expected, output)
def test_verbatim(self):
input_ = "a `` element"
expected = 'a <child> element\n'
output = md_to_db.MarkDownParse(input_, "")
self.assertEqual(expected, output)
def test_code(self):
input_ = """\
|[
GdkEvent *event;
GdkEventType type;
type = event->type;
]|
"""
expected = '''\
type;
]]>
'''
output = md_to_db.MarkDownParse(input_, "")
self.assertEqual(expected, output)
def test_plain(self):
input_ = u"""\
|[
frame
├── border
├──