This repository has been archived by the owner on Apr 15, 2018. It is now read-only.
forked from ClearTables/ClearTables
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-common.lua
57 lines (49 loc) · 2.56 KB
/
test-common.lua
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
56
--[[
This file is part of ClearTables
@author Paul Norman <[email protected]>
@copyright 2015-2016 Paul Norman, MIT license
]]--
require ("common")
print("common.lua tests")
print("TESTING: oneway")
assert(oneway(nil) == nil, "test failed: oneway(nil) == nil")
assert(oneway('-1') == 'reverse', "test failed: oneway('-1') == 'reverse'")
assert(oneway('no') == 'false', "test failed: oneway('no') == 'false'")
assert(oneway('false') == 'false', "test failed: oneway('false') == 'false'")
assert(oneway('yes') == 'true', "test failed: oneway('yes') == 'true'")
assert(oneway('foo') == 'true', "test failed: oneway('foo') == 'true'")
print("TESTING: layer")
assert(layer(nil) == "0", "test failed: nil")
assert(layer("0") == "0", "test failed: 0")
assert(layer("-1") == "-1", "test failed: -1")
assert(layer("1") == "1", "test failed: 1")
assert(layer("1.5") == "0", "test failed: 1.5")
assert(layer("foo") == "0", "test failed: text")
assert(layer("f1") == "0", "test failed: char num")
assert(layer("1f") == "0", "test failed: num char")
print("TESTING: access")
assert(access(nil) == nil, "test failed: nil")
assert(access("foo") == nil, "test failed: unknown")
assert(access("yes") == "yes", "test failed: yes")
assert(access("private") == "no", "test failed: private")
assert(access("no") == "no", "test failed: no")
assert(access("permissive") == "yes", "test failed: permissive")
assert(access("delivery") == "partial", "test failed: delivery")
assert(access("designated") == "yes", "test failed: designated")
assert(access("destination") == "partial", "test failed: destination")
assert(access("customers") == "partial", "test failed: customers")
print("TESTING: height")
assert(height(nil) == nil, "test failed: nil")
assert(height("foo") == nil, "test failed: unknown")
assert(height("5") == "5", "test failed: 1 digit")
assert(height("56") == "56", "test failed: multi-digit")
assert(height("5.6") == "5.6", "test failed: decimal")
assert(height("5e6") == nil, "test failed: number with text")
assert(height("10000000000") == nil, "test failed: overflow")
print("TESTING: names")
assert(names(nil) == nil, "test failed: nil")
assert(names({}) == nil, "test failed: empty")
assert(names({foo="bar"}) == nil, "test failed: non-names")
assert(names({["name:foo"]="bar"}) == '"foo"=>"bar"', "test failed: one lang")
local name1 = names({["name:aa"]="foo", ["name:zz"]="bar"})
assert(name1 == '"aa"=>"foo","zz"=>"bar"' or name1 == '"zz"=>"bar","aa"=>"foo"', "test failed: two langs")