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