release 0.1.15
[liba.git] / lua / test / version.lua
blob46618e9f84014c49a3705f4444682dd814338b0e
1 #!/usr/bin/env lua
3 package.path = arg[0]:sub(0, -arg[0]:match("([^/\\]*)$"):len() - 1) .. "?.lua;" .. package.path
4 local test = require("test")
5 local a = require("liba")
6 test.dir(getmetatable(a.version))
7 local v000 = a.version.new()
8 local v100 = a.version.new(1)
9 local v010 = a.version.new(0, 1)
10 local v001 = a.version.new(0, 0, 1)
11 local vctx = a.version.new(a.VERSION)
12 assert(type(vctx.major) == "number")
13 assert(type(vctx.minor) == "number")
14 assert(type(vctx.third) == "number")
15 assert(type(vctx.extra) == "number")
16 assert(type(vctx.alpha) == "string")
17 assert(a.version.eq(v000, v000))
18 assert(a.version.ne(v000, v010))
19 assert(a.version.lt(v000, v010))
20 assert(not a.version.lt(v000, v000))
21 assert(a.version.gt(v010, v000))
22 assert(not a.version.gt(v000, v000))
23 assert(a.version.le(v000, v010))
24 assert(not a.version.le(v010, v000))
25 assert(a.version.ge(v010, v000))
26 assert(not a.version.ge(v000, v010))
27 assert(a.version.cmp(v000, v100) < 0)
28 assert(a.version.cmp(v000, v010) < 0)
29 assert(a.version.cmp(v000, v001) < 0)
30 assert(a.version.cmp(v100, v000) > 0)
31 assert(a.version.cmp(v010, v000) > 0)
32 assert(a.version.cmp(v001, v000) > 0)
33 assert(a.version.cmp(v000, v000) == 0)
34 assert(v000 == v000)
35 assert(v000 ~= v010)
36 assert(v000 < v010)
37 assert(not (v000 < v000))
38 assert(v010 > v000)
39 assert(not (v000 > v000))
40 assert(v000 <= v010)
41 assert(not (v010 <= v000))
42 assert(v010 >= v010)
43 assert(not (v000 >= v010))
44 test.dir(vctx.__index)
45 vctx.__lt = nil
46 assert(vctx.__lt)
47 vctx.__le = nil
48 assert(vctx.__le)
49 vctx.__eq = nil
50 assert(vctx.__eq)
51 vctx.__name = nil
52 assert(vctx.__name)
53 vctx.__call = nil
54 assert(vctx.__call)
55 vctx.__index = nil
56 assert(vctx.__index)
57 vctx.__newindex = nil
58 assert(vctx.__newindex)
59 vctx.__tostring = nil
60 assert(vctx.__tostring)
61 test.log("version", a.VERSION)
62 test.log("major", a.version.MAJOR)
63 test.log("minor", a.version.MINOR)
64 test.log("patch", a.version.PATCH)
65 test.log("tweak", a.version.TWEAK)
66 test.log(vctx(), "0.0.0", a.version.check())
67 ---@class a.version
68 ---@field __lt function
69 ---@field __le function
70 ---@field __eq function
71 ---@field __name string
72 ---@field __call function
73 ---@field __index table
74 ---@field __newindex table
75 ---@field __tostring function