2021-05-20 22:05:57 +08:00
|
|
|
|
2021-05-22 21:27:40 +08:00
|
|
|
## Function Tests.
|
2021-05-20 22:05:57 +08:00
|
|
|
|
2021-05-22 21:27:40 +08:00
|
|
|
def f1 return 'f1' end assert(f1() == 'f1')
|
|
|
|
def f2() return 'f2' end assert(f2() == 'f2')
|
|
|
|
def f3(a, b, c, d) return c end
|
2021-05-20 22:05:57 +08:00
|
|
|
assert(f3('a', 'b', 'c', 'd') == 'c')
|
|
|
|
|
2021-05-22 21:27:40 +08:00
|
|
|
## Forward call.
|
2021-05-20 22:05:57 +08:00
|
|
|
val = before_defn()
|
|
|
|
def before_defn()
|
|
|
|
return 'defined after the call'
|
|
|
|
end
|
|
|
|
assert(val == 'defined after the call')
|
2021-05-22 21:27:40 +08:00
|
|
|
|
|
|
|
## Chain call tests. (concatenative programming)
|
|
|
|
|
|
|
|
def fn1(data) return '[fn1:' + data + ']' end
|
|
|
|
def fn2(data, suffix) return '[fn2:' + data + '|' + suffix + ']' end
|
|
|
|
def fn3(data) return '[fn3:' + data + ']' end
|
|
|
|
|
|
|
|
result = 'data' -> fn1 -> fn2{'suff'} -> fn3
|
|
|
|
assert(result == '[fn3:[fn2:[fn1:data]|suff]]')
|
|
|
|
|
2021-06-10 07:35:14 +08:00
|
|
|
# str_lower(s) function refactored to s.lower attribute.
|
|
|
|
#result = ' tEST+InG ' -> str_strip -> str_lower
|
|
|
|
#assert(result == 'test+ing')
|
2021-06-16 02:54:30 +08:00
|
|
|
|
|
|
|
# If we got here, that means all test were passed.
|
|
|
|
print('All TESTS PASSED')
|