summaryrefslogtreecommitdiff
path: root/tests/scanner/test_xmlwriter.py
diff options
context:
space:
mode:
authorChristoph Reiter <reiter.christoph@gmail.com>2018-07-27 12:51:34 +0200
committerChristoph Reiter <reiter.christoph@gmail.com>2018-07-27 13:00:24 +0200
commitdc4c2f9d2db5563ad482a09d04aeeab6972c53ac (patch)
treed126aa4f6aebe10d4711c166a193c623f09cc8e3 /tests/scanner/test_xmlwriter.py
parentae83a2e69d2ddee3b470e3505ab27f74a1b98ea3 (diff)
downloadgobject-introspection-dc4c2f9d2db5563ad482a09d04aeeab6972c53ac.tar.gz
tests: add some basic tests for collect_attributes() and build_xml_tag()
Diffstat (limited to 'tests/scanner/test_xmlwriter.py')
-rw-r--r--tests/scanner/test_xmlwriter.py58
1 files changed, 57 insertions, 1 deletions
diff --git a/tests/scanner/test_xmlwriter.py b/tests/scanner/test_xmlwriter.py
index 36df7ab8..e24923bd 100644
--- a/tests/scanner/test_xmlwriter.py
+++ b/tests/scanner/test_xmlwriter.py
@@ -1,6 +1,6 @@
import unittest
-from giscanner.xmlwriter import XMLWriter
+from giscanner.xmlwriter import XMLWriter, collect_attributes, build_xml_tag
class TestXMLWriter(unittest.TestCase):
@@ -24,6 +24,62 @@ class TestXMLWriter(unittest.TestCase):
lines = x.split('\n')
self.assertTrue(len(lines[3]) < 80)
+ def test_collect_attributes(self):
+ ca = collect_attributes
+ res = ca('parameters', [], 6, ' ', 12)
+ self.assertEqual(res, "")
+
+ res = ca('type', [('name', 'utf8')], 12, ' ', 7)
+ self.assertEqual(res, ' name="utf8"')
+
+ res = ca('type', [('name', 'GLib.SList'), ('c:type', 'const GSList*')], 8, ' ', 6)
+ self.assertEqual(res, ' name="GLib.SList" c:type="const GSList*"')
+
+ def test_build_xml_tag(self):
+ res = build_xml_tag('tag', [('attr', 'utf8')])
+ self.assertEqual(res, '<tag attr="utf8"/>')
+
+ res = build_xml_tag('tag', [('attr', 'foo\nbar')])
+ self.assertEqual(res, '<tag attr="foo\nbar"/>')
+
+ res = build_xml_tag('tag', [('attr', '\004')])
+ self.assertEqual(res, '<tag attr="&#x4;"/>')
+
+ res = build_xml_tag('tag', [('attr', '')])
+ self.assertEqual(res, '<tag attr=""/>')
+
+ res = build_xml_tag('tag', [('attr', ' ')])
+ self.assertEqual(res, '<tag attr=" "/>')
+
+ res = build_xml_tag('tag', [('attr', '>&<')])
+ self.assertEqual(res, '<tag attr="&gt;&amp;&lt;"/>')
+
+ res = build_xml_tag('tag', [('a', 'b'), ('c', 'd')])
+ self.assertEqual(res, '<tag a="b" c="d"/>')
+
+ def test_build_xml_tag_data(self):
+ res = build_xml_tag('tag', [], b'foo')
+ self.assertEqual(res, '<tag>foo</tag>')
+
+ res = build_xml_tag('tag', [], u'\xf6\xe4\xfc')
+ self.assertEqual(res, u'<tag>\xf6\xe4\xfc</tag>')
+
+ res = build_xml_tag('tag', [], '>&<')
+ self.assertEqual(res, '<tag>&gt;&amp;&lt;</tag>')
+
+ def test_build_xml_tag_indent(self):
+ res = build_xml_tag(
+ 'tag', [('a' * 10, 'b' * 30), ('c' * 30, 'd' * 10)], None)
+ self.assertEqual(res, '''\
+<tag aaaaaaaaaa="bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
+ cccccccccccccccccccccccccccccc="dddddddddd"/>''')
+
+ res = build_xml_tag(
+ 'tag', [('a' * 10, 'b' * 30), ('c' * 30, 'd' * 10)], None, 3)
+ self.assertEqual(res, '''\
+<tag aaaaaaaaaa="bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
+ cccccccccccccccccccccccccccccc="dddddddddd"/>''')
+
if __name__ == '__main__':
unittest.main()