summaryrefslogtreecommitdiffstats
path: root/tests/lib/script1.lua
blob: 6361c960a771a0f13bc66c7013702b19fbc2bcab (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
51
52
53
54
-- Positive testing

function foo(a, b)
  a = a + 1
  b = b + 1
  return {
    a = a,
    b = b,
  }
end

function bar(a, b)
  a = a + 1
  b = b + 1
  c = 303
  return {
    b = b,
    c = c,
  }
end

function fact(n)
  -- outer function must return a table
  -- inner functions can be used to recurse or as helpers
  function helper(m)
    if m == 0 then
      return 1
    else
      return m * helper(m - 1)
    end
  end
  return {
    ans = helper(n)
  }
end

-- Negative testing

function bad_return1()
end

function bad_return2()
  return 123
end

function bad_return3()
  return {}
end

function bad_return4()
  error("Something bad!")
end