aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/LuaSL/testLua/yueliang-0.4.1/orig-5.0.3/test/test_lzio.lua
blob: cfd3f4b89c9759adcc8021bf8c75bab679267e59 (plain)
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
--[[--------------------------------------------------------------------

  test_lzio.lua
  Test for lzio.lua
  This file is part of Yueliang.

  Copyright (c) 2005 Kein-Hong Man <khman@users.sf.net>
  The COPYRIGHT file describes the conditions
  under which this software may be distributed.

  See the ChangeLog for more information.

----------------------------------------------------------------------]]

-- manual test for lzio.lua lua-style chunk reader

require("../lzio")

local z
function dump(z)
  while true do
    local c = luaZ:zgetc(z)
    io.stdout:write("("..c..")")
    if c == "EOZ" then break end
  end
  io.stdout:write("\n")
end

-- luaZ:make_getS or luaZ:make_getF creates a chunk reader
-- luaZ:init makes a zio stream

-- [[
z = luaZ:init(luaZ:make_getS("hello, world!"), nil, "=string")
dump(z)
z = luaZ:init(luaZ:make_getS(", world!"), "hello", "=string")
dump(z)
z = luaZ:init(luaZ:make_getS("line1\nline2\n"), "", "=string")
dump(z)
z = luaZ:init(luaZ:make_getF("test_lzio.lua"), nil, "=string")
dump(z)
--]]

-- test read beyond end of file
-- bug reported by Adam429
--[[
z = luaZ:init(luaZ:make_getF("test_lzio.lua"), nil, "=string")
while true do
  local c = luaZ:zgetc(z)
  io.stdout:write("("..c..")")
  if c == "EOZ" then break end
end
print(luaZ:zgetc(z))
print(luaZ:zgetc(z))
io.stdout:write("\n")
--]]