1plugin = 2{ 3 type = "piglet", 4 name = "piglet::buffer", 5 test = function() 6 dofile(SCRIPT_DIR .. "/../common.lua") 7 return run_tests(tests) 8 end 9} 10 11tests = 12{ 13 init_with_raw_buffer = function() 14 local rb = RawBuffer.new("abcdefghijklmnopqrstuvwxyz") 15 local buf = Buffer.new(rb) 16 assert(buf) 17 end, 18 19 init_with_string = function() 20 local buf = Buffer.new("abcdefg") 21 assert(buf) 22 end, 23 24 init_with_length = function() 25 local buf = Buffer.new(128) 26 assert(buf) 27 end, 28 29 allocate = function() 30 local buf = Buffer.new(16) 31 assert(buf:allocate(10)) 32 assert(not buf:allocate(10)) 33 end, 34 35 clear = function() 36 local buf = Buffer.new(16) 37 buf:allocate(16) 38 buf:clear() 39 assert(buf:allocate(10)) 40 end, 41 42 to_string = function() 43 local buf = Buffer.new("abcdefgh") 44 buf:allocate(3) 45 local v = tostring(buf) 46 assert(#v == 3) 47 assert(v == "gh\0") 48 end 49} 50