Esempio n. 1
0
 def test_simple(self):
     sb = StringBuilderRepr.ll_new(3)
     StringBuilderRepr.ll_append_char(sb, 'x')
     StringBuilderRepr.ll_append(sb, llstr("abc"))
     StringBuilderRepr.ll_append_slice(sb, llstr("foobar"), 2, 5)
     StringBuilderRepr.ll_append_multiple_char(sb, 'y', 3)
     s = StringBuilderRepr.ll_build(sb)
     assert hlstr(s) == "xabcobayyy"
Esempio n. 2
0
 def test_shrinking(self):
     sb = StringBuilderRepr.ll_new(100)
     StringBuilderRepr.ll_append(sb, llstr("abc" * 11))
     assert StringBuilderRepr.ll_getlength(sb) == 33
     s = StringBuilderRepr.ll_build(sb)
     assert hlstr(s) == "abc" * 11
     assert StringBuilderRepr.ll_getlength(sb) == 33
Esempio n. 3
0
 def test_shrinking(self):
     sb = StringBuilderRepr.ll_new(100)
     StringBuilderRepr.ll_append(sb, llstr("abc" * 11))
     assert StringBuilderRepr.ll_getlength(sb) == 33
     s = StringBuilderRepr.ll_build(sb)
     assert hlstr(s) == "abc" * 11
     assert StringBuilderRepr.ll_getlength(sb) == 33
Esempio n. 4
0
 def test_nooveralloc(self):
     sb = StringBuilderRepr.ll_new(33)
     StringBuilderRepr.ll_append(sb, llstr("abc" * 11))
     assert StringBuilderRepr.ll_getlength(sb) == 33
     s = StringBuilderRepr.ll_build(sb)
     assert hlstr(s) == "abc" * 11
     assert StringBuilderRepr.ll_getlength(sb) == 33
Esempio n. 5
0
 def test_nooveralloc(self):
     sb = StringBuilderRepr.ll_new(33)
     StringBuilderRepr.ll_append(sb, llstr("abc" * 11))
     assert StringBuilderRepr.ll_getlength(sb) == 33
     s = StringBuilderRepr.ll_build(sb)
     assert hlstr(s) == "abc" * 11
     assert StringBuilderRepr.ll_getlength(sb) == 33
Esempio n. 6
0
 def test_charp(self):
     sb = StringBuilderRepr.ll_new(32)
     with rffi.scoped_str2charp("hello world") as p:
         StringBuilderRepr.ll_append_charpsize(sb, p, 12)
     with rffi.scoped_str2charp("0123456789abcdefghijklmn") as p:
         StringBuilderRepr.ll_append_charpsize(sb, p, 24)
     s = StringBuilderRepr.ll_build(sb)
     assert hlstr(s) == "hello world\x000123456789abcdefghijklmn"
Esempio n. 7
0
 def test_charp(self):
     sb = StringBuilderRepr.ll_new(32)
     with rffi.scoped_str2charp("hello world") as p:
         StringBuilderRepr.ll_append_charpsize(sb, p, 12)
     with rffi.scoped_str2charp("0123456789abcdefghijklmn") as p:
         StringBuilderRepr.ll_append_charpsize(sb, p, 24)
     s = StringBuilderRepr.ll_build(sb)
     assert hlstr(s) == "hello world\x000123456789abcdefghijklmn"
Esempio n. 8
0
 def test_grow_when_exactly_full(self):
     sb = StringBuilderRepr.ll_new(33)
     StringBuilderRepr.ll_append(sb, llstr("abc" * 11))
     StringBuilderRepr.ll_append(sb, llstr("def"))
     s = StringBuilderRepr.ll_build(sb)
     assert hlstr(s) == "abc" * 11 + "def"
Esempio n. 9
0
 def test_grow_two_halves(self):
     sb = StringBuilderRepr.ll_new(32)
     StringBuilderRepr.ll_append(sb, llstr("abc" * 11))
     s = StringBuilderRepr.ll_build(sb)
     assert hlstr(s) == "abc" * 11
Esempio n. 10
0
 def test_grow_when_append_char(self):
     sb = StringBuilderRepr.ll_new(33)
     StringBuilderRepr.ll_append(sb, llstr("abc" * 11))
     StringBuilderRepr.ll_append_char(sb, "d")
     s = StringBuilderRepr.ll_build(sb)
     assert hlstr(s) == "abc" * 11 + "d"
Esempio n. 11
0
 def test_simple(self):
     sb = StringBuilderRepr.ll_new(3)
     assert StringBuilderRepr.ll_getlength(sb) == 0
     StringBuilderRepr.ll_append_char(sb, 'x')
     assert StringBuilderRepr.ll_getlength(sb) == 1
     StringBuilderRepr.ll_append(sb, llstr("abc"))
     assert StringBuilderRepr.ll_getlength(sb) == 4
     StringBuilderRepr.ll_append_slice(sb, llstr("foobar"), 2, 5)
     assert StringBuilderRepr.ll_getlength(sb) == 7
     StringBuilderRepr.ll_append_multiple_char(sb, 'y', 3)
     assert StringBuilderRepr.ll_getlength(sb) == 10
     s = StringBuilderRepr.ll_build(sb)
     assert hlstr(s) == "xabcobayyy"
     assert StringBuilderRepr.ll_getlength(sb) == 10
Esempio n. 12
0
 def test_simple(self):
     sb = StringBuilderRepr.ll_new(3)
     assert StringBuilderRepr.ll_getlength(sb) == 0
     StringBuilderRepr.ll_append_char(sb, 'x')
     assert StringBuilderRepr.ll_getlength(sb) == 1
     StringBuilderRepr.ll_append(sb, llstr("abc"))
     assert StringBuilderRepr.ll_getlength(sb) == 4
     StringBuilderRepr.ll_append_slice(sb, llstr("foobar"), 2, 5)
     assert StringBuilderRepr.ll_getlength(sb) == 7
     StringBuilderRepr.ll_append_multiple_char(sb, 'y', 3)
     assert StringBuilderRepr.ll_getlength(sb) == 10
     s = StringBuilderRepr.ll_build(sb)
     assert hlstr(s) == "xabcobayyy"
     assert StringBuilderRepr.ll_getlength(sb) == 10
Esempio n. 13
0
 def test_grow_when_append_char(self):
     sb = StringBuilderRepr.ll_new(33)
     StringBuilderRepr.ll_append(sb, llstr("abc" * 11))
     StringBuilderRepr.ll_append_char(sb, "d")
     s = StringBuilderRepr.ll_build(sb)
     assert hlstr(s) == "abc" * 11 + "d"
Esempio n. 14
0
 def test_large_build(self):
     s1 = 'xyz' * 500
     s2 = 'XYZ' * 500
     #
     sb = StringBuilderRepr.ll_new(32)
     StringBuilderRepr.ll_append(sb, llstr(s1))
     s = StringBuilderRepr.ll_build(sb)
     assert hlstr(s) == s1
     #
     sb = StringBuilderRepr.ll_new(32)
     StringBuilderRepr.ll_append(sb, llstr(s1))
     StringBuilderRepr.ll_append(sb, llstr(s2))
     s = StringBuilderRepr.ll_build(sb)
     assert hlstr(s) == s1 + s2
     #
     sb = StringBuilderRepr.ll_new(32)
     StringBuilderRepr.ll_append(sb, llstr(s1))
     s = StringBuilderRepr.ll_build(sb)
     assert hlstr(s) == s1
     StringBuilderRepr.ll_append(sb, llstr(s2))
     s = StringBuilderRepr.ll_build(sb)
     assert hlstr(s) == s1 + s2
     #
     sb = StringBuilderRepr.ll_new(32)
     StringBuilderRepr.ll_append(sb, llstr(s1))
     StringBuilderRepr.ll_append_char(sb, '.')
     s = StringBuilderRepr.ll_build(sb)
     assert hlstr(s) == s1 + '.'
     #
     for start in [0, 1]:
         for stop in [len(s1), len(s1) - 1]:
             sb = StringBuilderRepr.ll_new(32)
             StringBuilderRepr.ll_append_slice(sb, llstr(s1), start, stop)
             s = StringBuilderRepr.ll_build(sb)
             assert hlstr(s) == s1[start:stop]
Esempio n. 15
0
 def test_nooveralloc(self):
     sb = StringBuilderRepr.ll_new(3)
     StringBuilderRepr.ll_append(sb, llstr("abc"))
     assert StringBuilderRepr.ll_build(sb) == sb.buf
Esempio n. 16
0
 def test_grow_when_exactly_full(self):
     sb = StringBuilderRepr.ll_new(33)
     StringBuilderRepr.ll_append(sb, llstr("abc" * 11))
     StringBuilderRepr.ll_append(sb, llstr("def"))
     s = StringBuilderRepr.ll_build(sb)
     assert hlstr(s) == "abc" * 11 + "def"
Esempio n. 17
0
 def test_grow_two_halves(self):
     sb = StringBuilderRepr.ll_new(32)
     StringBuilderRepr.ll_append(sb, llstr("abc" * 11))
     s = StringBuilderRepr.ll_build(sb)
     assert hlstr(s) == "abc" * 11
Esempio n. 18
0
 def test_several_builds(self):
     sb = StringBuilderRepr.ll_new(32)
     s = StringBuilderRepr.ll_build(sb)
     assert hlstr(s) == ""
     assert s == StringBuilderRepr.ll_build(sb)
     assert s == StringBuilderRepr.ll_build(sb)
     #
     sb = StringBuilderRepr.ll_new(32)
     StringBuilderRepr.ll_append(sb, llstr("abcdefgh" * 3))  # not full
     s = StringBuilderRepr.ll_build(sb)
     assert hlstr(s) == "abcdefgh" * 3
     assert s == StringBuilderRepr.ll_build(sb)
     assert s == StringBuilderRepr.ll_build(sb)
     StringBuilderRepr.ll_append(sb, llstr("extra"))  # overflow
     s = StringBuilderRepr.ll_build(sb)
     assert hlstr(s) == "abcdefgh" * 3 + "extra"
     assert s == StringBuilderRepr.ll_build(sb)
     assert s == StringBuilderRepr.ll_build(sb)
Esempio n. 19
0
 def test_several_builds(self):
     sb = StringBuilderRepr.ll_new(32)
     s = StringBuilderRepr.ll_build(sb)
     assert hlstr(s) == ""
     assert s == StringBuilderRepr.ll_build(sb)
     assert s == StringBuilderRepr.ll_build(sb)
     #
     sb = StringBuilderRepr.ll_new(32)
     StringBuilderRepr.ll_append(sb, llstr("abcdefgh" * 3))   # not full
     s = StringBuilderRepr.ll_build(sb)
     assert hlstr(s) == "abcdefgh" * 3
     assert s == StringBuilderRepr.ll_build(sb)
     assert s == StringBuilderRepr.ll_build(sb)
     StringBuilderRepr.ll_append(sb, llstr("extra"))    # overflow
     s = StringBuilderRepr.ll_build(sb)
     assert hlstr(s) == "abcdefgh" * 3 + "extra"
     assert s == StringBuilderRepr.ll_build(sb)
     assert s == StringBuilderRepr.ll_build(sb)