aboutsummaryrefslogtreecommitdiffstats
path: root/tests.py
blob: f98d48d82d2e6efe53563a6347f7d784fbd0cea6 (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
#!/usr/bin/python2
# Copyright 2004, Nick Mathewson.  See LICENSE for licensing info.

"""Unit tests for anonbib."""

import BibTeX
import metaphone
#import reconcile
#import writeHTML
#import updateCache

import unittest

class MetaphoneTests(unittest.TestCase):
    def testMetaphone(self):
        pass

class BibTeXTests(unittest.TestCase):
    def testTranslation(self):
        ut = BibTeX.url_untranslate
        self.assertEquals(ut("Fred"),"Fred")
        self.assertEquals(ut("Hello, World."), "Hello_2c_20World.")

        te = BibTeX.TeXescapeURL
        ute = BibTeX.unTeXescapeURL
        self.assertEquals(te("http://example/~me/my_file"),
                          r"http://example/\{}~me/my\_file")
        self.assertEquals(ute(r"http:{}//example/\{}~me/my\_file"),
                          "http://example/~me/my_file")

        h = BibTeX.htmlize
        self.assertEquals(h("Hello, world"), "Hello, world")
        self.assertEquals(h(r"\'a\`e\'{i}(\'\i)\"o&\^u"),
                          "áèí(í)ö&"
                          "û")
        self.assertEquals(h(r"\~n and \c{c}"), "ñ and ç")
        self.assertEquals(h(r"\AE---a ligature"), "Æ—a ligature")
        self.assertEquals(h(r"{\it 33}"), " 33")
        self.assertEquals(h(r"Pages 33--99 or vice--versa?"),
                          "Pages 33-99 or vice–versa?")

        t = BibTeX.txtize
        self.assertEquals(t("Hello, world"), "Hello, world")
        self.assertEquals(t(r"\'a\`e\'{i}(\'\i)\"o&\^u"),
                          "aei(i)o&u")
        self.assertEquals(t(r"\~n and \c{c}"), "n and c")
        self.assertEquals(t(r"\AE---a ligature"), "AE---a ligature")
        self.assertEquals(t(r"{\it 33}"), " 33")
        self.assertEquals(t(r"Pages 33--99 or vice--versa?"),
                          "Pages 33--99 or vice--versa?")

    def authorsParseTo(self,authors,result):
        pa = BibTeX.parseAuthor(authors)
        self.assertEquals(["|".join(["+".join(item) for item in
                                     [a.first,a.von,a.last,a.jr]])
                           for a in pa],
                          result)

    def testAuthorParsing(self):
        pa = BibTeX.parseAuthor
        PA = BibTeX.ParsedAuthor
        apt = self.authorsParseTo

        apt("Nick A. Mathewson and Roger Dingledine",
            ["Nick+A.||Mathewson|", "Roger||Dingledine|"])
        apt("John van Neumann", ["John|van|Neumann|"])
        apt("P. Q. Z. de la Paz", ["P.+Q.+Z.|de+la|Paz|"])
        apt("Cher", ["||Cher|"])
        apt("Smith, Bob", ["Bob||Smith|"])
        apt("de Smith, Bob", ["Bob|de|Smith|"])
        apt("de Smith, Bob Z", ["Bob+Z|de|Smith|"])
        #XXXX Fix this.
        #apt("Roberts Smith Wilkins, Bob Z", ["Bob+Z||Smith+Wilkins|"])
        apt("Smith, Jr, Bob", ["Bob||Smith|Jr"])

        #XXXX Fix this.
        #apt("R Jones, Jr.", ["R||Jones|Jr."])
        apt("Smith, Bob and John Smith and Last,First",
            ["Bob||Smith|", "John||Smith|", "First||Last|"])
        apt("Bob Smith and John Smith and John Doe",
            ["Bob||Smith|", "John||Smith|", "John||Doe|"])


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