build(types): luassert

This commit is contained in:
Aire-One 2023-04-17 00:02:18 +02:00
parent 1a8844db43
commit 93a61cc8a8
6 changed files with 360 additions and 0 deletions

2
types/luassert.d.tl Normal file
View File

@ -0,0 +1,2 @@
return require("luassert.assert")

204
types/luassert/assert.d.tl Normal file
View File

@ -0,0 +1,204 @@
local record ArrayAssert
has_holes:function(integer)
has_no_holes:function()
end
local record SpyAssert
was_called:function(integer)
was_not_called:function(integer)
was_called_with:function(...:any)
was_not_called_with:function(...:any)
was_returned_with:function(...:any)
was_not_returned_with:function(...:any)
was_called_at_least:function(integer)
was_called_at_most:function(integer)
was_called_more_than:function(integer)
was_called_less_than:function(integer)
was_not_called_at_least:function(integer)
was_not_called_at_most:function(integer)
was_not_called_more_than:function(integer)
was_not_called_less_than:function(integer)
called:function(integer)
not_called:function()
called_with:function(...:any)
not_called_with:function(...:any)
returned_with:function(...:any)
not_returned_with:function(...:any)
called_at_least:function(integer)
called_at_most:function(integer)
called_more_than:function(integer)
called_less_than:function(integer)
end
-- We use asserts instead of assert here to avoid tl warning
local record asserts
-- True / false
is_not_true:function(any, string):any, string
is_true:function(any, string):any, string
is_not_false:function(any, string):any, string
is_false:function(any, string):any, string
is_not_truthy:function(any, string):any, string
is_truthy:function(any, string):any, string
truthy:function(any, string):any, string
not_truthy:function(any, string):any, string
is_not_falsy:function(any, string):any, string
is_falsy:function(any, string):any, string
falsy:function(any, string):any, string
not_falsy:function(any, string):any, string
-- Same-ness
same:function(any, any, string):any, any, string
is_same:function(any, any, string):any, any, string
is_not_same:function(any, any, string):any, any, string
are_same:function(any, any, string):any, any, string
are_not_same:function(any, any, string):any, any, string
-- Equality
are_not_equal:function(any, any, string):any, any, string
are_not_equals:function(any, any, string):any, any, string
is_not_equal:function(any, any, string):any, any, string
is_not_equals:function(any, any, string):any, any, string
equal:function(any, any, string):any, any, string
equals:function(any, any, string):any, any, string
not_equals:function(any, any, string):any, any, string
not_equal:function(any, any, string):any, any, string
equals_not:function(any, any, string):any, any, string
equal_not:function(any, any, string):any, any, string
is_equal:function(any, any, string):any, any, string
is_equals:function(any, any, string):any, any, string
are_equal:function(any, any, string):any, any, string
are_equals:function(any, any, string):any, any, string
-- Nearness
is_near:function(number, number, number, string):number, number, number, string
is_not_near:function(number, number, number, string):number, number, number, string
-- Uniqueness
is_unique:function({any}, string):{any}, string
is_not_unique:function({any}, string):{any}, string
are_unique:function({any}, string):{any}, string
are_not_unique:function({any}, string):{any}, string
-- Errors function
is_error:function(function(), any, string):{any}
error:function(function(), any, string):{any}
errors:function(function(), any, string):{any}
no_errors:function(function(), any, string):{any}
has_no_errors:function(function(), any, string):{any}
has_no_error:function(function(), any, string):{any}
has_error:function(function(), any, string):{any}
has_errors:function(function(), any, string):{any}
record Callable
metamethod __call: function(self: Callable)
end
-- Errors Callable
is_error:function(Callable, any, string):{any}
error:function(Callable, any, string):{any}
errors:function(Callable, any, string):{any}
no_errors:function(Callable, any, string):{any}
has_no_errors:function(Callable, any, string):{any}
has_no_error:function(Callable, any, string):{any}
has_error:function(Callable, any, string):{any}
has_errors:function(Callable, any, string):{any}
-- Errors matches
does_error_match:function(function(), string, string)
matches_error:function(function(), string, string)
has_no_error_match:function(function(), string, string)
does_not_match_error:function(function(), string, string)
error_matches:function(function(), string, string):{any}
no_error_matches:function(function(), string, string):{any}
-- Errors matches callable
does_error_match:function(Callable, string, string)
matches_error:function(Callable, string, string)
has_no_error_match:function(Callable, string, string)
does_not_match_error:function(Callable, string, string)
error_matches:function(Callable, string, string):{any}
no_error_matches:function(Callable, string, string):{any}
-- matches
matches:function(string, string, string)
has_match:function(string, string, string):{string}
has_no_match:function(string, string, string):{string}
-- type checking
is_boolean:function(any, string):any, string
is_not_boolean:function(any, string):any, string
is_number:function(any, string):any, string
is_not_number:function(any, string):any, string
is_string:function(any, string):any, string
is_not_string:function(any, string):any, string
is_table:function(any, string):any, string
is_not_table:function(any, string):any, string
is_function:function(any, string):any, string
is_not_function:function(any, string):any, string
is_userdata:function(any, string):any, string
is_not_userdata:function(any, string):any, string
is_thread:function(any, string):any, string
is_not_thread:function(any, string):any, string
is_nil:function(any, string):any, string
is_not_nil:function(any, string):any, string
-- misc
set_parameter:function(self:asserts, string, integer)
returned_arguments:function(...:any)
not_returned_arguments:function(...:any)
has_holes:function({any})
has_no_holes:function({any})
array:function({any}):ArrayAssert
spy:function(any):SpyAssert
stub:function(any):SpyAssert
get_level:function(self:asserts, any)
level:function(self:asserts, integer)
has_property:function(any, string)
end
return asserts

102
types/luassert/match.d.tl Normal file
View File

@ -0,0 +1,102 @@
local record Matcher
metamethod __call: function(self: Matcher, any)
end
local record match
_:function(any)
match:function(any):Matcher
-- truthiness
is_true:function():Matcher
is_false:function():Matcher
is_not_true:function():Matcher
is_not_false:function():Matcher
is_truthy:function():Matcher
is_falsy:function():Matcher
is_not_truthy:function():Matcher
is_not_falsy:function():Matcher
not_false:function():Matcher
truthy:function():Matcher
falsy:function():Matcher
-- type matching
is_boolean:function(any):Matcher
is_function:function():Matcher
is_nil:function():Matcher
is_number:function():Matcher
is_string:function():Matcher
is_table:function(any):Matcher
is_thread:function():Matcher
is_ref:function(any):Matcher
is_userdata:function():Matcher
boolean:function(any):Matcher
number:function():Matcher
string:function():Matcher
table:function(any):Matcher
thread:function():Matcher
userdata:function():Matcher
ref:function():Matcher
not_boolean:function(any):Matcher
not_function:function():Matcher
not_nil:function():Matcher
not_number:function():Matcher
not_string:function():Matcher
not_table:function(any):Matcher
not_thread:function():Matcher
not_userdata:function():Matcher
not_ref:function():Matcher
is_not_boolean:function(any):Matcher
is_not_function:function():Matcher
is_not_nil:function():Matcher
is_not_number:function():Matcher
is_not_string:function():Matcher
is_not_table:function(any):Matcher
is_not_thread:function():Matcher
is_not_userdata:function():Matcher
is_not_ref:function():Matcher
-- equality
is_equals:function():Matcher
is_equal:function(any):Matcher
is_same:function(any):Matcher
equals:function(any):Matcher
equal:function(any):Matcher
same:function(any):Matcher
is_unique:function():Matcher
is_not_unique:function():Matcher
-- group matching
is_all_of:function(...:any):Matcher
is_any_of:function(...:any):Matcher
is_none_of:function(...:any):Matcher
all_of:function(...:any):Matcher
any_of:function(...:any):Matcher
none_of:function(...:any):Matcher
not_all_of:function(...:any):Matcher
not_any_of:function(...:any):Matcher
not_none_of:function(...:any):Matcher
-- misc
matches:function(string, number):Matcher
has_match:function(string, number):Matcher
near:function(number, number):Matcher
is_near:function(number, number):Matcher
is_not_near:function(number, number):Matcher
end
return match

9
types/luassert/mock.d.tl Normal file
View File

@ -0,0 +1,9 @@
local record mock
clear:function(any)
revert:function(any)
new:function<T>(T, boolean):T
end
return mock

14
types/luassert/spy.d.tl Normal file
View File

@ -0,0 +1,14 @@
local record spy
clear:function(self:spy):spy
revert:function(self:spy):spy
on:function(any, string):spy
-- To call spy methods, cast it back to spy with 'as'
new:function<T>(T):T
metamethod __call: function(self: spy, ...:any)
end
return spy

29
types/luassert/stub.d.tl Normal file
View File

@ -0,0 +1,29 @@
local record stub
record Defaults
returns:function(...:any)
invokes:function(function(...:any))
end
record OnCallWith
returns:function(...:any)
invokes:function(function(...:any))
end
clear:function(self:stub):stub
revert:function(self:stub):stub
on_call_with:function(...:any):OnCallWith
returns:function(...:any):stub
invokes:function(function(...:any)):stub
-- table, key, return values
new:function(any, string, ...:any):stub
by_default:Defaults
metamethod __call: function(self: stub, ...:any)
end
return stub