aboutsummaryrefslogtreecommitdiffstats
path: root/util/stream/str_ut.pyx
blob: 17bf2222501c9da0175b232e553e4771ed396b89 (plain) (blame)
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
# cython: c_string_type=str, c_string_encoding=utf8 
 
from cython.operator cimport dereference 
 
from util.generic.ptr cimport THolder 
from util.generic.string cimport TString, TStringBuf 
from util.stream.str cimport TStringOutput, TStringOutputPtr 
 
import unittest 
 
 
class TestStringOutput(unittest.TestCase): 
    def test_ctor1(self): 
        cdef TStringOutput output 
 
    def test_ctor2(self): 
        cdef TString string 
        cdef THolder[TStringOutput] string_output = THolder[TStringOutput](new TStringOutput(string)) 
 
    def test_write_char(self): 
        cdef TString string 
        cdef TStringOutputPtr string_output = TStringOutputPtr(new TStringOutput(string)) 
 
        self.assertEqual(string, "") 
        dereference(string_output.Get()).WriteChar('1') 
        self.assertEqual(string, "1") 
        dereference(string_output.Get()).WriteChar('2') 
        self.assertEqual(string, "12") 
        dereference(string_output.Get()).WriteChar('3') 
        self.assertEqual(string, "123") 
 
    def test_write_void(self): 
        cdef TString string 
        cdef TStringOutputPtr string_output = TStringOutputPtr(new TStringOutput(string)) 
 
        self.assertEqual(string, "") 
        dereference(string_output.Get()).Write("1", 1) 
        self.assertEqual(string, "1") 
        dereference(string_output.Get()).Write("2", 1) 
        self.assertEqual(string, "12") 
        dereference(string_output.Get()).Write("34", 2) 
        self.assertEqual(string, "1234") 
 
    def test_write_buf(self): 
        cdef TString string 
        cdef TStringOutputPtr string_output = TStringOutputPtr(new TStringOutput(string)) 
 
        self.assertEqual(string, "") 
        dereference(string_output.Get()).WriteBuf(TStringBuf("1")) 
        self.assertEqual(string, "1") 
        dereference(string_output.Get()).WriteBuf(TStringBuf("2")) 
        self.assertEqual(string, "12") 
        dereference(string_output.Get()).WriteBuf(TStringBuf("34")) 
        self.assertEqual(string, "1234") 
 
    def test_reserve(self): 
        cdef TString string 
        cdef TStringOutputPtr string_output = TStringOutputPtr(new TStringOutput(string)) 
        self.assertEqual(string, "") 
        dereference(string_output.Get()).Reserve(50) 
        self.assertEqual(string, "") 
        self.assertLessEqual(50, string.capacity())