aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_util.py
blob: 8f826a0c6f31292f2b99228a263b53c603e78f77 (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
# -*- coding: utf-8 -*-

import unittest
from mako import util
from test import eq_

class UtilTest(unittest.TestCase):
    def test_fast_buffer_write(self):
        buf = util.FastEncodingBuffer()
        buf.write("string a ")
        buf.write("string b")
        eq_(buf.getvalue(), "string a string b")

    def test_fast_buffer_truncate(self):
        buf = util.FastEncodingBuffer()
        buf.write("string a ")
        buf.write("string b")
        buf.truncate()
        buf.write("string c ")
        buf.write("string d")
        eq_(buf.getvalue(), "string c string d")

    def test_fast_buffer_encoded(self):
        s = u"drôl m’a rée « S’il"
        buf = util.FastEncodingBuffer(encoding='utf-8')
        buf.write(s[0:10])
        buf.write(s[10:])
        q = buf.getvalue()
        eq_(buf.getvalue(), s.encode('utf-8'))