beta-0.89.2
[luatex.git] / source / texk / web2c / luatexdir / luazip / tests / test_zip.lua
blob84e2cae4ec05578c04e164866220f89ca563b364
1 --[[------------------------------------------------------------------------
2 test_zip.lua
3 test code for luazip
4 --]]------------------------------------------------------------------------
6 -- compatibility code for Lua version 5.0 providing 5.1 behavior
7 if string.find (_VERSION, "Lua 5.0") and not package then
8 if not LUA_PATH then
9 LUA_PATH = os.getenv("LUA_PATH") or "./?.lua;"
10 end
11 require"compat-5.1"
12 package.cpath = os.getenv("LUA_CPATH") or "./?.so;./?.dll;./?.dylib"
13 end
15 require('zip')
17 function test_open ()
18 local zfile, err = zip.open('luazip.zip')
20 assert(zfile, err)
22 print("File list begin")
23 for file in zfile:files() do
24 print(file.filename)
25 end
26 print("File list ended OK!")
27 print()
29 print("Testing zfile:open")
30 local f1, err = zfile:open('README')
31 assert(f1, err)
33 local f2, err = zfile:open('luazip.h')
34 assert(f2, err)
35 print("zfile:open OK!")
36 print()
38 print("Testing reading by number")
39 local c = f1:read(1)
40 while c ~= nil do
41 io.write(c)
42 c = f1:read(1)
43 end
45 print()
46 print("OK")
47 print()
48 end
50 function test_openfile ()
51 print("Testing the openfile magic")
53 local d, err = zip.openfile('a/b/c/d.txt')
54 assert(d, err)
56 local e, err = zip.openfile('a/b/c/e.txt')
57 assert(e == nil, err)
59 local d2, err = zip.openfile('a2/b2/c2/d2.txt', "ext2")
60 assert(d2, err)
62 local e2, err = zip.openfile('a2/b2/c2/e2.txt', "ext2")
63 assert(e2 == nil, err)
65 local d3, err = zip.openfile('a3/b3/c3/d3.txt', {"ext2", "ext3"})
66 assert(d3, err)
68 local e3, err = zip.openfile('a3/b3/c3/e3.txt', {"ext2", "ext3"})
69 assert(e3 == nil, err)
71 print("Smooth magic!")
72 print()
73 end
75 test_open()
76 test_openfile()