From e591975f402a9f2688d8d7ea208d0ac8bad52243 Mon Sep 17 00:00:00 2001 From: Stefan Sauer Date: Fri, 26 May 2017 20:06:33 +0200 Subject: [PATCH] tests: test cleanup and more tests Add tests for the markdown parser. Rename the other test files (drop the gtkdoc prefix). Add copyright headers. --- tests/Makefile.am | 7 +- tests/{gtkdoc-check.py => check.py} | 19 +++ tests/{gtkdoc-common.py => common.py} | 20 +++ tests/mk_to_db.py | 261 ++++++++++++++++++++++++++++++++++ 4 files changed, 302 insertions(+), 5 deletions(-) rename tests/{gtkdoc-check.py => check.py} (54%) rename tests/{gtkdoc-common.py => common.py} (64%) create mode 100755 tests/mk_to_db.py diff --git a/tests/Makefile.am b/tests/Makefile.am index 873e738..794db94 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -5,7 +5,7 @@ SUBDIRS = gobject bugs annotations fail empty program . if BUILD_TESTS TESTS = \ - gtkdoc-check.py gtkdoc-common.py \ + check.py common.py mk_to_db.py \ tools.sh gobject.sh bugs.sh annotations.sh fail.sh empty.sh sanity.sh \ program.sh TESTS_ENVIRONMENT = \ @@ -20,10 +20,7 @@ TESTS_ENVIRONMENT = \ endif -EXTRA_DIST = gtkdoctest.sh \ - gtkdoc-check.py gtkdoc-common.py \ - tools.sh gobject.sh bugs.sh annotations.sh fail.sh empty.sh sanity.sh \ - program.sh +EXTRA_DIST = gtkdoctest.sh $(TESTS) # run any given test by running make .check %.check: % diff --git a/tests/gtkdoc-check.py b/tests/check.py similarity index 54% rename from tests/gtkdoc-check.py rename to tests/check.py index b8e2b6d..e6f12b5 100755 --- a/tests/gtkdoc-check.py +++ b/tests/check.py @@ -1,4 +1,23 @@ #!/usr/bin/env python +# -*- python -*- +# +# gtk-doc - GTK DocBook documentation generator. +# Copyright (C) 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 diff --git a/tests/gtkdoc-common.py b/tests/common.py similarity index 64% rename from tests/gtkdoc-common.py rename to tests/common.py index 448873a..3f78220 100755 --- a/tests/gtkdoc-common.py +++ b/tests/common.py @@ -1,4 +1,24 @@ #!/usr/bin/env python +#!/usr/bin/env python +# -*- python -*- +# +# gtk-doc - GTK DocBook documentation generator. +# Copyright (C) 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 mock import unittest diff --git a/tests/mk_to_db.py b/tests/mk_to_db.py new file mode 100755 index 0000000..646ad39 --- /dev/null +++ b/tests/mk_to_db.py @@ -0,0 +1,261 @@ +#!/usr/bin/env python +# -*- 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 MARKDOWN +Atx-style Headers +Header 1Header 2 +Setext-style Headers + +Header 1Header 2 +Ordered (unnested) Lists + + +item 1 + + +item 2 with loooong *foo* +description + + +item 3 + + +Note: 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. +bla + + +The channel is write-only. + + +foo +""" + 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_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 +├──