Beispiel #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"
Beispiel #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
Beispiel #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
Beispiel #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
Beispiel #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
Beispiel #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"
Beispiel #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"
Beispiel #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"
Beispiel #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
Beispiel #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"
Beispiel #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
Beispiel #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
Beispiel #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"
Beispiel #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]
Beispiel #15
0
 def test_nooveralloc(self):
     sb = StringBuilderRepr.ll_new(3)
     StringBuilderRepr.ll_append(sb, llstr("abc"))
     assert StringBuilderRepr.ll_build(sb) == sb.buf
Beispiel #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"
Beispiel #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
Beispiel #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)
Beispiel #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)