summaryrefslogtreecommitdiff
path: root/Tools/LuaMacro/tests/test-test.lua
blob: 42f78609e29464cbd064bf6a3e14dcae85b3343a (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
require_ 'assert'

-- can compare table values as well
assert_ 2 == 2
assert_ print == print
assert_ {one=1,two=2} == {two=2,one=1}

assert_ 'hello' matches '^hell'
assert_ 2 > 1

--assert_ 3 < 2 -- quite wrong!

-- if the first expression returns multiple values, then
-- the second can match this with parentheses

function two() return 40,2 end

assert_ two() == (40,2)

function three() return {1,2},nil,'three' end

assert_ three() == ({1,2},nil,'three')

-- 'throws' only succeeds if the expression did actually raise an error,
-- and the error string does match the error message.

function bad() error 'something bad!' end

assert_ bad() throws "something bad!"

a = nil

assert_ a.x throws "attempt to index global 'a'"

-- can of course redefine assert_...
def_ assert assert_

-- This is an experimental feature, which matches two numbers up to the
-- precision supplied in the second number. This only happens if the test
-- number has a fractional part, and the number must be explicitly
-- be in %f formaat.
assert 3.1412 == 3.14
assert 2302.24432 == 2302.2
assert 100 == 100
assert 1.1e-3 == 0.001