mirror of
https://github.com/Oreolek/gamebookformat.git
synced 2024-05-17 16:38:20 +03:00
e5723bdf70
Instead of just [[section]] you can have [[section][name]] and depending on format the name will be displayed instead of or in addition to the section number referred to.
60 lines
1.7 KiB
Python
Executable file
60 lines
1.7 KiB
Python
Executable file
#!/usr/bin/env python2.7
|
|
|
|
import unittest
|
|
from unittest import TestCase
|
|
|
|
import output
|
|
|
|
class FakeTemplates(object):
|
|
def __init__(self, d):
|
|
self.d = d
|
|
|
|
def get(self, name):
|
|
if name in self.d:
|
|
return self.d[name]
|
|
else:
|
|
return ''
|
|
|
|
class TestOutputFormat(TestCase):
|
|
def setUp(self):
|
|
pass
|
|
|
|
def test_create(self):
|
|
of = output.OutputFormat(FakeTemplates({}), str)
|
|
|
|
def test_format_begin(self):
|
|
of = output.OutputFormat(FakeTemplates({'begin' : 'b %(max)d'}), str)
|
|
self.assertEqual(of.format_begin({'max' : 2}), 'b 2')
|
|
|
|
class TestReferenceFormatter(TestCase):
|
|
def setUp(self):
|
|
pass
|
|
|
|
def test_create(self):
|
|
rf = output.ReferenceFormatter(1, {}, None, "", "", str)
|
|
|
|
def test_get_item(self):
|
|
rf = output.ReferenceFormatter(1, {'a' : 1, 'b' : 2}, None,
|
|
"%(nr)d", "", int)
|
|
self.assertEqual(rf['nr'], 1)
|
|
|
|
def test_get_quoted_item(self):
|
|
rf = output.ReferenceFormatter(1, {'a' : 1, 'b' : 2}, None,
|
|
"%(nr)d", "", str)
|
|
self.assertEqual(rf['nr'], '1')
|
|
|
|
def test_get_reference(self):
|
|
rf = output.ReferenceFormatter(1, {'a' : 1, 'b' : 2}, None,
|
|
"%(from_nr)d to %(nr)d", "", str)
|
|
self.assertEqual(rf['b'], '1 to 2')
|
|
|
|
def test_get_named_reference(self):
|
|
rf = output.ReferenceFormatter(1, {'a' : 1, 'b' : 2}, None,
|
|
"%(from_nr)d to %(nr)d",
|
|
"%(from_nr)d to %(name)s(%(nr)d)", str)
|
|
self.assertEqual(rf.ref('b', 'name'), '1 to name(2)')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|