-
-
Notifications
You must be signed in to change notification settings - Fork 331
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
396 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
configs = {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
---@diagnostic disable: lowercase-global | ||
---@meta | ||
|
||
---comment this api is hided | ||
---@param filename string | ||
function file(filename) | ||
end | ||
|
||
---comment | ||
---@param name string | ||
---@param block? fun() | ||
function pending(name, block) | ||
end | ||
|
||
---comment | ||
---@async | ||
function async() | ||
end | ||
|
||
---comment | ||
---@param name string | ||
---@param block fun() | ||
function describe(name, block) | ||
end | ||
|
||
context = describe | ||
|
||
expose = describe | ||
|
||
|
||
function randomize() | ||
end | ||
|
||
---comment | ||
---@param name string | ||
---@param block fun() | ||
function it(name, block) | ||
end | ||
|
||
spec = it | ||
|
||
test = it | ||
|
||
---comment | ||
---@param block fun() | ||
function before_each(block) | ||
end | ||
|
||
---comment | ||
---@param block fun() | ||
function after_each(block) | ||
end | ||
|
||
---comment | ||
---@param block fun() | ||
function setup(block) | ||
end | ||
|
||
strict_setup = setup | ||
|
||
|
||
---comment | ||
---@param block fun() | ||
function teardown(block) | ||
end | ||
|
||
strict_teardown = teardown | ||
|
||
---comment | ||
---@param block fun() | ||
function lazy_setup(block) | ||
end | ||
|
||
---comment | ||
---@param block fun() | ||
function lazy_teardown(block) | ||
end | ||
|
||
---comment | ||
---@param block fun() | ||
function finally(block) | ||
end | ||
|
||
---@type luassert | ||
assert = {} | ||
---@param key 'assertion' | 'matcher' | ||
function assert:register(key, ...) | ||
|
||
end | ||
|
||
---@type luassert_spy | ||
spy = {} | ||
---@type luassert_mock | ||
mock = {} | ||
---@type luassert_stub | ||
stub = {} | ||
---@type luassert_match | ||
match = {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
words = { "assert.%w+" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
---@meta | ||
|
||
---@class luassert | ||
---@field unique fun(v1,deep?:boolean,failure_message?:string) | ||
---@field is_unique fun(v1,deep?:boolean,failure_message?:string) | ||
---@field not_unique fun(v1,deep?:boolean,failure_message?:string) | ||
---@field near fun(expected:number|string,actual:number|string,tolerance:number|string,failure_message?:string) | ||
---@field is_near fun(expected:number|string,actual:number|string,tolerance:number|string,failure_message?:string) | ||
---@field not_near fun(expected:number|string,actual:number|string,tolerance:number|string,failure_message?:string) | ||
---@field matches fun(pattern:string,actual:string|number,init?:number,plain?:boolean,failure_message?:string) | ||
---@field is_matches fun(pattern:string,actual:string|number,init?:number,plain?:boolean,failure_message?:string) | ||
---@field not_matches fun(pattern:string,actual:string|number,init?:number,plain?:boolean,failure_message?:string) | ||
---@field equal fun(v1,v2,failure_message?:string) | ||
---@field equals fun(v1:table,v2:table,failure_message?:string) | ||
---@field is_equal fun(v1,v2,failure_message?:string) | ||
---@field is_equals fun(v1:table,v2:table,failure_message?:string) | ||
---@field not_equal fun(v1,v2,failure_message?:string) | ||
---@field not_equals fun(v1:table,v2:table,failure_message?:string) | ||
---@field same fun(v1,v2,failure_message?:string) | ||
---@field is_same fun(v1,v2,failure_message?:string) | ||
---@field not_same fun(v1,v2,failure_message?:string) | ||
---@field truthy fun(v1,v2,failure_message?:string) | ||
---@field falsy fun(v1,v2,failure_message?:string) | ||
---@field error fun(func:fun(),err_expected?:string,failure_message?:string) | ||
---@field errors fun(func:fun(),err_expected?:string,failure_message?:string) | ||
---@field has_error fun(func:fun(),err_expected?:string,failure_message?:string) | ||
---@field has_errors fun(func:fun(),err_expected?:string,failure_message?:string) | ||
---@field no_error fun(func:fun(),err_expected?:string,failure_message?:string) | ||
---@field no_errors fun(func:fun(),err_expected?:string,failure_message?:string) | ||
---@field error_matches fun(func:fun(),pattern:string,init?:number,plain?:boolean,failure_message?:string) | ||
---@field is_error_matches fun(func:fun(),pattern:string,init?:number,plain?:boolean,failure_message?:string) | ||
---@field not_error_matches fun(func:fun(),pattern:string,init?:number,plain?:boolean,failure_message?:string) | ||
---@field number fun(v) | ||
---@field string fun(v) | ||
---@field table fun(v) | ||
---@field userdata fun(v) | ||
---@field function fun(v) | ||
---@field thread fun(v) | ||
---@field boolean fun(v) | ||
---@field returned_arguments fun(...,fn:function) | ||
---@field property fun(name:string,obj) | ||
---@field is_number fun(v) | ||
---@field is_string fun(v) | ||
---@field is_table fun(v) | ||
---@field is_nil fun(v) | ||
---@field is_userdata fun(v) | ||
---@field is_function fun(v) | ||
---@field is_thread fun(v) | ||
---@field is_boolean fun(v) | ||
---@field is_true fun(b) | ||
---@field is_returned_arguments fun(...,fn:function) | ||
---@field is_false fun(b) | ||
---@field has_property fun(name:string,obj) | ||
---@field not_number fun(v) | ||
---@field not_string fun(v) | ||
---@field not_table fun(v) | ||
---@field not_nil fun(v) | ||
---@field not_userdata fun(v) | ||
---@field not_function fun(v) | ||
---@field not_thread fun(v) | ||
---@field not_boolean fun(v) | ||
---@field not_true fun(b) | ||
---@field not_false fun(b) | ||
---@field not_returned_arguments fun(...,fn:function) | ||
---@field no_property fun(name:string,obj) | ||
---@field message fun(failure_message:string) | ||
---@module 'luassert' | ||
local luassert = {} | ||
|
||
---comment | ||
---@param fn function | ||
---@param failure_message? string | ||
---@return luassert_spy | ||
function luassert.spy(fn,failure_message) | ||
end | ||
|
||
---comment | ||
---@param fn function | ||
---@param failure_message? string | ||
---@return luassert_stub | ||
function luassert.stub(fn,failure_message) | ||
end | ||
|
||
|
||
return luassert |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
---@meta | ||
|
||
--[[ | ||
Matchers are used to provide flexible argument matching for `called_with` and `returned_with` asserts. Just like with asserts, you can chain a modifier value using `is` or `is_not`, followed by the matcher you wish to use. Extending busted with your own matchers is done similar to asserts as well; just build a matcher with a common signature and [register it](#matcher-extend). Furthermore, matchers can be combined using [composite matchers](#matcher-composite). | ||
]] | ||
---@class luassert_match | ||
local match = {} | ||
|
||
--- this is a `placeholder`, match any thing | ||
--[[ | ||
```lua | ||
it("tests wildcard matcher", function() | ||
local s = spy.new(function() end) | ||
local _ = match._ | ||
s("foo") | ||
assert.spy(s).was_called_with(_) -- matches any argument | ||
assert.spy(s).was_not_called_with(_, _) -- does not match two arguments | ||
end) | ||
```]] | ||
match._ = {} | ||
|
||
--[[ | ||
If you're creating a spy for functions that mutate any properties on an table (for example `self`) and you want to use `was_called_with`, you should use `match.is_ref(obj)`. | ||
```lua | ||
describe("combine matchers", function() | ||
local match = require("luassert.match") | ||
it("tests ref matchers for passed in table", function() | ||
local t = { cnt = 0, } | ||
function t.incrby(t, i) t.cnt = t.cnt + i end | ||
local s = spy.on(t, "incrby") | ||
s(t, 2) | ||
assert.spy(s).was_called_with(match.is_ref(t), 2) | ||
end) | ||
it("tests ref matchers for self", function() | ||
local t = { cnt = 0, } | ||
function t:incrby(i) self.cnt = self.cnt + i end | ||
local s = spy.on(t, "incrby") | ||
t:incrby(2) | ||
assert.spy(s).was_called_with(match.is_ref(t), 2) | ||
end) | ||
end) | ||
```]] | ||
---@param obj any | ||
function match.is_ref(obj) | ||
|
||
end | ||
|
||
--[[ | ||
Combine matchers using composite matchers. | ||
```lua | ||
describe("combine matchers", function() | ||
local match = require("luassert.match") | ||
it("tests composite matchers", function() | ||
local s = spy.new(function() end) | ||
s("foo") | ||
assert.spy(s).was_called_with(match.is_all_of(match.is_not_nil(), match.is_not_number())) | ||
assert.spy(s).was_called_with(match.is_any_of(match.is_number(), match.is_string(), match.is_boolean()))) | ||
assert.spy(s).was_called_with(match.is_none_of(match.is_number(), match.is_table(), match.is_boolean()))) | ||
end) | ||
end) | ||
``` | ||
]] | ||
function match.is_all_of(...) | ||
end | ||
|
||
function match.is_any_of(...) | ||
end | ||
|
||
function match.is_none_of(...) | ||
end | ||
|
||
return match |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
---@meta | ||
|
||
---@class luassert_mock | ||
---@generic T | ||
---@param object T | ||
---@param dostub? boolean @will never call original function | ||
---@param func? any | ||
---@param target_objcet? any | ||
---@param key? any | ||
---@return T | ||
local mock = function(object, dostub, func, target_objcet, key) | ||
end | ||
|
||
---@generic T | ||
---@param object T | ||
---@param dostub? boolean @will never call original function | ||
---@param func? any | ||
---@param target_objcet? any | ||
---@param key? any | ||
---@return T | ||
function mock.new(object, dostub, func, target_objcet, key) | ||
end | ||
|
||
|
||
---@param object any | ||
function mock.clear(object) | ||
end | ||
|
||
|
||
---@param object any | ||
function mock.revert(object) | ||
end | ||
|
||
return mock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
---@meta | ||
|
||
---@class luassert_spy | ||
---@return luassert_spy | ||
local spy = function(callback) | ||
end | ||
|
||
---@param callback function | ||
---@return function warp_callback | ||
---@nodiscard | ||
function spy.new(callback) | ||
end | ||
|
||
|
||
---comment spy function on obj[name] | ||
---@param obj any | ||
---@param name string | ||
---@return any | ||
---@nodiscard | ||
function spy.on(obj, name) | ||
end | ||
|
||
|
||
---comment obj is spy | ||
---@param obj any | ||
---@return boolean | ||
function spy.is_spy(obj) | ||
end | ||
|
||
|
||
function spy.returned_with(...) | ||
end | ||
|
||
|
||
function spy.called(...) | ||
end | ||
|
||
|
||
function spy.called_with(...) | ||
end | ||
|
||
|
||
---comment | ||
---@param count integer | ||
function spy.called_at_least(count) | ||
end | ||
|
||
|
||
---comment | ||
---@param count integer | ||
function spy.called_at_most(count) | ||
end | ||
|
||
|
||
---comment | ||
---@param count integer | ||
function spy.called_more_than(count) | ||
end | ||
|
||
|
||
---comment | ||
---@param count integer | ||
function spy.called_less_than(count) | ||
end | ||
|
||
|
||
return spy; |
Oops, something went wrong.