print("running venus test script")

local vp_util = dofile("vc_util.lua")

local function for_range_test()
	local a = 0

	for i = 0,5 do
		a = a + i
	end

	assert(a == 15)
end

for_range_test()

local function for_in_test()
	local testt = {
		venus = "awesome",
		"lots of test",1,2,
		test2 = "hi"
	}

	local reft = {}
	for i,el in pairs(testt) do
		reft[i] = el
	end
	assert(vp_util.dftc(reft, testt))

	reft = {}
	for _,el in pairs(testt) do
		table.insert(reft,el)
	end

	local reft2 = {}
	foreach el in testt do
		table.insert(reft2,el)
	end
	assert(vp_util.dftc(reft, reft2))
end

for_in_test()

// comments
## yay a comment
//comment
assert("//"=="/".."/")
-- another comment
assert([[
##]]=="#".."#","comment within [[string]] falsely detected")

assert([[
fn]]=="f".."n")

local function shadow_test()
	local fn a()
		return "function"
	end
	assert(a()=="function")

	local reft = {}
	do
		(fn(...)
			local a = {...}
			foreach a in a do
				table.insert(reft,a)
			end
		end)("a","still a","also a")
	end
	assert(vp_util.dftc(reft, {"a","still a","also a"}))

	local n
	do {
		local a = 12
		n = a
	}
	assert(n == 12)

	assert(a()=="function")
end

shadow_test()

local function t() {
	return "hi"
}
assert(t()=="hi")

local fn t2() {
	return "also hi"
}
assert(type(t2)=="function")
assert(t2()=="also hi")

local b = true
if (true) {
	b = "weewoo"
}
assert(b == "weewoo")

local reft = {}
for i = 0, 10 {
	table.insert(reft,i)
}
assert(vp_util.dftc(reft,{0,1,2,3,4,5,6,7,8,9,10}))

local reft2 = {}
foreach el in {"lot's of test",2,"3",1} {
	table.insert(reft2,el)
}
assert(vp_util.dftc(reft2,{"lot's of test",2,"3",1}))

do {
	local reft = {}
	local i = 0
	while i < 10 {
		i = i + 1
		if i%3 == 0 {
			table.insert(reft,i)
		} elseif i%4 == 0 {
			table.insert(reft,i/4)
		} else {}
	}
	assert(vp_util.dftc(reft,{3,1,6,2,9}))
}

local function callit(fun,t1,t2)
	return fun(t1,t2)
end

assert(
	callit(() => {
		return "testing"
	})
	== "testing")

assert(
	callit((k,v) => {
		return k.." = "..v
	}, "this test", "more test")
	== "this test = more test"
)
	
assert(
	callit((a , b) => {
		return (a-b)*4
	}, 10, 6) == 16
)

assert(callit(()=>{},false)==nil)

---
--comment
--

local i = 0
local j = 0

i = i + 1
j = j + 2

local function decj()
	j--
	return j-- not a decrement, only returns n, this is a comment
end
assert(decj()==1)
assert(j == 1)

local fn reti()
	-- this only returns i the -- is a comment
	return i--
end

i++
assert(reti() == 2)

-- () => {}

j+= 3
assert(j == 4)
j *=-8
assert(j ==-32)
j /= -4
assert(j== 8)
j ^= 2
assert(j == 64)
j-= 32
assert(j ==32)
j .=" test"
assert(j == "32 test")

local tt = {
  {"hello", "there"},
  {"venus", "test"}
}

local fn concatsub(t) {
	local ret = {}
	foreach el in t {
	  table.insert(ret,table.concat(el," "))
	}
	return ret
}
assert(vp_util.dftc(concatsub(tt),{"hello there", "venus test"}))

assert(not (() => {if(true){return}return true})())

local ctt = {test = "hello"}
ctt.test .= " world"
assert(ctt.test == "hello world")

print("venus test end")
