#!/usr/bin/env python # -*- coding: utf-8 -*- # Copyright (c) 2013, 2016 Yu-Jie Lin # Licensed under the BSD License, for detailed license information, see COPYING import doctest import unittest import smartypants from smartypants import smartypants as sp from smartypants import Attr 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('''''') E = '''''' self.assertEqual(T, E) def test_convert_quot(self): TEXT = ( "
He said "Let's write some code." "
"This code here if True:\n\tprint "Okay"
"
"is python code.
He said "Let’s write some code." "
"This code here if True:\n\tprint "Okay"
"
"is python code.
He said "Let\'s write some code." '
"This code here if True:\n\tprint "Okay"
"
"is python code.
He said “Let’s write some code.” "
"This code here if True:\n\tprint "Okay"
"
"is python code.
foo -- "bar"\n' '
' ) T = sp(TEXT) E = ( 'foo — “bar”\n' '
' ) self.assertEqual(T, E) # nothing should be converted for TEXT in ('', '', ' '): self.assertEqual(sp(TEXT), TEXT) # not comments self.assertEqual(sp(''), '') self.assertEqual(sp('