assert multimethod

Methods

assert(val:Any, pattern:Any, msg:Str='Assertion failed') Source: stdlib.ngs:301
Throws AssertFail with given message if val does not match the pattern

Returns

val

Example

my_template.get('concept', []).assert(Arr)
assert(loginResult, {'access_token': Str}, "access_token must be present in response")
assert(val:Any, pattern:Any, e:Exception) Source: stdlib.ngs:308
Throws e with given message if val does not match the pattern

Returns

val
assert(val:Any, msg:Str='Assertion failed') Source: stdlib.ngs:324
Throws AssertFail with given message if val is falsy

Parameters

valif evaluates to false, causes AssertFail exception
msgmessage for the exception, defaults to "Assertion failed"

Returns

val

Example

my_array=[]
# ... Code that adds elements to my_array ...
assert(my_array.len() > 3, "my_array must have more than 3 elements")  # AssertFail exception, with the given message
assert(f:Fun, t:Type, msg:Str='Assertion failed') Source: stdlib.ngs:334
Throws AssertFail with given function does not throw exception of the given type.

Parameters

fFun
tSubtype of Exception

Returns

The exception

Example

assert({1/0}, DivisionByZero)
assert(p:Path) Source: stdlib.ngs:5926
Checks that the given path exists. Throws AssertFail otherwise.

Returns

p
assert(p:Program) Source: stdlib.ngs:5958
Checks that given program is found in path. Throws AssertFail otherwise.

Returns

p