summaryrefslogtreecommitdiff
path: root/support/escapeTeXt/escapeTeXt_test.py
blob: e60953385a92e738a37279d9d384ed4323f5cf16 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#! /usr/bin/python2.3 -u
# escapeTeXt_test.py
#  Do unit testing of the escapeTeXt routines
# 2006-Aug-25 Jim Hefferon
import re
  
import unittest

from escapeTeXt import *

class escapetext_test(unittest.TestCase):
    """Test the escapetext class
    """
    def test_generic(self):
        # sanity check
        s="Hello, World!"
        et=escapetext(s)
        self.failUnlessEqual(s,
                             et.output())
        # does it substitute at all?
        s="abc $ def"
        t="abc \\$ def"
        self.failUnlessEqual(t,
                             escapetext(s).output())
        # bunch of routine substitutions
        expected=[("abc { def","abc \\{ def"),
                  ("abc } def","abc \\} def"),
                  ("abc % def","abc \\% def"),
                  ("abc _ def","abc \\_ def"),
                  ("abc & def","abc \\& def"),
                  ("abc # def","abc \\# def"),
                  ("abc < def","abc {\\textless} def"),
                  ("abc > def","abc {\\textgreater} def"),
                  ]
        for (s,t) in expected:
            self.failUnlessEqual(t,
                                 escapetext(s).output())
        # does it substitute twice on one row?
        s="abc $ def % ghi"
        t="abc \\$ def \\% ghi"
        self.failUnlessEqual(t,
                             escapetext(s).output())
        # backslash
        s="abc \ def"
        t="abc {\\textbackslash} def"
        self.failUnlessEqual(t,
                             escapetext(s).output())
        # single quotes
        s="abc 'def' ghi"
        t="abc `def' ghi"
        self.failUnlessEqual(t,
                             escapetext(s).output())
        # single quote next to double quote
        s="\"'abc'\" def"
        t="``\\,`abc'\\,'' def"
        self.failUnlessEqual(t,
                             escapetext(s).output())
        
    def test_refinements(self):
        # single quote next to double quote
        s="look on p. 23."
        t="look on p.\\,23."
        self.failUnlessEqual(t,
                             escapetext(s,refinements=True).output())
        # en dash
        s="pages 2-3"
        t="pages 2--3"
        self.failUnlessEqual(t,
                             escapetext(s,refinements=True).output())
        # em dash
        s="but-no"
        t="but---no"
        self.failUnlessEqual(t,
                             escapetext(s,refinements=True).output())
        
    def test_feed(self):
        # single quote next to double quote
        s1="abc $ def"
        s2="ghi % jkl"
        t1="abc \\$ defghi \\% jkl"
        et=escapetext(s1)
        et.feed(s2)
        self.failUnlessEqual(t1,
                             et.output())
        s3='mno "yes" pqr'
        t2="mno ``yes'' pqr"
        et.feed(s3)
        self.failUnlessEqual(t2,
                             et.output())


if __name__=='__main__':
    unittest.main()