lean2/tests/lua/threads/th5.lua

37 lines
1.8 KiB
Lua
Raw Normal View History

S = State()
assert(is_State(S))
S:eval([[ local x = ...; assert(x == 10) ]], 10)
S:eval([[ local f = ...; assert(f) ]], true)
S:eval([[ local f = ...; assert(not f) ]], false)
S:eval([[ local s = ...; assert(s == "foo") ]], "foo")
S:eval([[ local f = ...; assert(f(1) == 3) ]], function (x) return x + 2 end)
local val = 10
S:eval([[ local f = ...; assert(f(1) == 11) ]], function (x) return x + val end)
S:eval([[ local o = ...; assert(o == name("a")) ]], name("a"))
S:eval([[ local o = ...; assert(o == Const("a")) ]], Const("a"))
S:eval([[ local o = ...; assert(is_context(o)) ]], context())
S:eval([[ local o = ...; assert(is_environment(o)) ]], environment())
S:eval([[ local o = ...; assert(o == mpz(100)) ]], mpz(100))
S:eval([[ local o = ...; assert(o == mpq(100)/3) ]], mpq(100)/3)
S:eval([[ local o = ...; assert(is_options(o)) ]], options())
S:eval([[ local o = ...; assert(is_sexpr(o)) ]], sexpr())
S:eval([[ local o = ...; assert(o:is_cons()) ]], sexpr(1, 2))
S:eval([[ local o = ...; assert(is_format(o)) ]], format("1"))
S:eval([[ local o = ...; assert(is_context_entry(o)) ]], context_entry("a", Const("T")))
S:eval([[ local o = ...; assert(is_local_entry(o)) ]], mk_lift(1, 2))
S:eval([[ local o = ...; assert(is_local_context(o)) ]], local_context())
S:eval([[ local o1, o2, o3 = ...; assert(is_sexpr(o1)); assert(is_name(o2)); assert(o3 == 10) ]], sexpr(), name("foo"), 10)
assert(not pcall(function() S:eval([[ x = ]]) end))
local T = thread(S, [[ local x = ...; return x + 10, x - 10 ]], 10)
assert(is_thread(T))
local r1, r2 = T:wait()
assert(r1 == 20)
assert(r2 == 0)
assert(not pcall(function() S:eval([[ x = ]]) end))
local T2 = thread(S, [[ local x = ...; error("failed") ]], 10)
local ok, msg = pcall(function() T2:wait() end)
assert(not ok)
assert(string.sub(msg, -7) == "failed\n")
local T3 = thread(S, [[ local x = ...; return x + 10, x - 10 ]], 10)
T3 = nil