fix `python2 setup.py build` problem when setup.cfg ends with CRLF
[liba.git] / lua / test / crc32.lua
blobbcf7196be1dd35482849c238903294895c426451
1 #!/usr/bin/env lua
3 ---@diagnostic disable: redefined-local
4 package.path = arg[0]:sub(0, -arg[0]:match("([^/\\]*)$"):len() - 1) .. "?.lua;" .. package.path
5 local test = require("test")
6 local a = require("liba")
7 test.dir(getmetatable(a.crc32))
8 local ctx = a.crc32.new("0x1EDC6F41")
9 assert(ctx)
10 local ctx = a.crc32.new("0x04C11DB7", true)
11 assert(ctx)
12 assert(type(ctx.table) == "table")
13 test.dir(getmetatable(ctx))
14 local text = "0123456789"
15 ctx:gen("0x1EDC6F41")
16 assert(a.crc32.eval(ctx, text) == "0x512B456E")
17 assert(tonumber(a.crc32.eval(ctx, a.crc32.pack(ctx, text))) == 0)
18 ctx:gen("0x04C11DB7", true)
19 assert(ctx:eval(text) == "0x450EAFB0")
20 assert(tonumber(ctx:eval(ctx:pack(text))) == 0)
21 ctx.__name = nil
22 assert(ctx.__name)
23 ctx.__call = nil
24 assert(ctx.__call)
25 ctx.__index = nil
26 assert(ctx.__index)
27 ctx.__newindex = nil
28 assert(ctx.__newindex)
29 ---@class a.crc32
30 ---@field __name string
31 ---@field __call function
32 ---@field __index table
33 ---@field __newindex table