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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
#!/usr/bin/env python
# Copyright (c) 2013 Yu-Jie Lin
# Licensed under the BSD License, for detailed license information, see COPYING
import doctest
import unittest
import smartypants
from smartypants import Attr, smartyPants as sp
class SmartyPantsTestCase(unittest.TestCase):
def test_change_default_attr(self):
TEXT = '"foo" -- bar'
attr = Attr.q
Attr.default = attr
self.assertEqual(Attr.default, attr)
T = sp(TEXT)
E = '“foo” -- bar'
self.assertEquals(T, E)
attr = Attr.q | Attr.d
Attr.default = attr
self.assertEqual(Attr.default, attr)
T = sp(TEXT)
E = '“foo” — bar'
self.assertEquals(T, E)
def test_dates(self):
self.assertEqual(sp("1440-80's"), "1440-80’s")
self.assertEqual(sp("1440-'80s"), "1440-‘80s")
self.assertEqual(sp("1440---'80s"), "1440–‘80s")
self.assertEqual(sp("1960s"), "1960s") # no effect.
self.assertEqual(sp("1960's"), "1960’s")
self.assertEqual(sp("one two '60s"), "one two ‘60s")
self.assertEqual(sp("'60s"), "‘60s")
def test_skip_tags(self):
T = sp('''<script type="text/javascript">
<!--
var href = "http://www.google.com";
var linktext = "google";
document.write('<a href="' + href + '">' + linktext + "</a>");
//-->
</script>''')
E = '''<script type="text/javascript">
<!--
var href = "http://www.google.com";
var linktext = "google";
document.write('<a href="' + href + '">' + linktext + "</a>");
//-->
</script>'''
self.assertEqual(T, E)
def test_convert_quot(self):
TEXT = (
"<p>He said "Let's write some code." "
"This code here <code>if True:\n\tprint "Okay"</code> "
"is python code.</p>")
T = sp(TEXT)
E = ("<p>He said "Let’s write some code." "
"This code here <code>if True:\n\tprint "Okay"</code> "
"is python code.</p>")
self.assertEqual(T, E)
T = sp(TEXT, Attr.w)
E = ('<p>He said "Let\'s write some code." '
"This code here <code>if True:\n\tprint "Okay"</code> "
"is python code.</p>")
self.assertEqual(T, E)
T = sp(TEXT, Attr.q | Attr.w)
E = ("<p>He said “Let’s write some code.” "
"This code here <code>if True:\n\tprint "Okay"</code> "
"is python code.</p>")
self.assertEqual(T, E)
def test_ordinal_numbers(self):
self.assertEqual(sp("21st century"), "21st century") # no effect.
self.assertEqual(sp("3rd"), "3rd") # no effect.
def test_educated_quotes(self):
self.assertEqual(sp('"Isn\'t this fun?"'),
'“Isn’t this fun?”')
def test_deprecated_str_attr(self):
TEXT = '"foo" -- bar'
T = sp(TEXT, 'q')
E = '“foo” -- bar'
self.assertEquals(T, E)
T = sp(TEXT, 'qd')
E = '“foo” — bar'
self.assertEquals(T, E)
def load_tests(loader, tests, pattern):
tests.addTests(doctest.DocTestSuite(smartypants))
return tests
|