Class Expect
Class for Expect.
This class follows the pattern from Lua classes.
Info:
- Author: John Erling Blad < jeblad@gmail.com >
Fields
Expect.softFail | Global assert soft fail. |
Expect.bypassEval | Global bypass eval. |
Expect.typeCheck | Global argument type checks. |
Expect.strictTaint | Global strict checking of tainting. |
Metamethods
Expect:__index () | Lookup of missing class members. |
Expect:__call () | Get a clone or create a new instance. |
Methods
Expect:create () | Create a new instance. |
Expect:_init () | Initialize a new instance. |
Expect:taint () | Set taint status. |
Expect:isTainted () | Test whether instance is tainted. |
Expect:hasSoft () | Test whether instance has soft fail. |
Expect:isSoft () | Test whether instance will soft fail. |
Expect:hasName () | Test whether instance has a name. |
Expect:getName () | Get the instance name. |
Expect:addFail () | Add callback for failing compare. |
Expect:addFailReport () | Add report for fail. |
Expect:addPass () | Add callback for passing compare. |
Expect:addPassReport () | Add report for pass. |
Expect:callbacks () | Callback on pass. |
Expect:import () | Import a compute grap. |
Expect:addProcess () | Add a process function |
Expect:compare () | Compare given values |
Expect:eval () | Eval given values. |
Expect:pick () | Pick entries |
Expect:filter () | Filter entries |
Expect:map () | Map over entries. |
Expect:first () | Make a pick for first item. |
Expect:second () | Make a pick for second item. |
Expect:third () | Make a pick for third item. |
Expect:fourth () | Make a pick for fourth item. |
Expect:fifth () | Make a pick for fifth item. |
Expect:sixth () | Make a pick for sixth item. |
Expect:seventh () | Make a pick for seventh item. |
Expect:eight () | Make a pick for eight item. |
Expect:ninth () | Make a pick for ninth item. |
Expect:tenth () | Make a pick for tenth item. |
Expect:eleventh () | Make a pick for eleventh item. |
Expect:twelfth () | Make a pick for twelfth item. |
Expect:asType () | Make a transform to get the argument type. |
Expect:asUpper () | Make a transform to get the string as upper case. |
Expect:asLower () | Make a transform to get the string as lower case. |
Expect:asUpperFirst () | Make a transform to get the string with first char as upper case. |
Expect:asLowerFirst () | Make a transform to get the string with first char as lower case. |
Expect:asReverse () | Make a transform to get the string reversed. |
Expect:asUUpper () | Make a transform to get the ustring as upper case. |
Expect:asULower () | Make a transform to get the ustring as lower case. |
Expect:asUUpperFirst () | Make a transform to get the ustring with first code point as upper case. |
Expect:asULowerFirst () | Make a transform to get the ustring with first code point as lower case. |
Expect:asUNFC () | Make a transform to get the ustring as Normalized Form "C". |
Expect:asUNFD () | Make a transform to get the ustring as Normalized Form "D". |
Expect:asNumber () | Make a transform to get the string as number. |
Expect:asString () | Make a transform to get the number as string. |
Expect:asFloor () | Make a transform to get the next lower number. |
Expect:asCeil () | Make a transform to get the next higher number. |
Expect:asRound () | Make a transform to get the rounded number. |
Expect:asInteger () | Make a transform to get the integer part of the number. |
Expect:asFraction () | Make a transform to get the fraction part of the number. |
Expect:toBeWithin () | Make a comparison to check if first is within limits of second. |
Expect:toBeEqual () | Make a comparison to check equality. |
Expect:toBeBoolEqual () | Make a comparison to check boolean equality. |
Expect:toBeStrictEqual () | Make a comparison to check strict equality. |
Expect:toBeSame () | Make a comparison to check similarity. |
Expect:toBeDeepEqual () | Make a comparison to check deep equality. |
Expect:toBeContained () | Make a comparison to check if first is contained in second. |
Expect:toBeLessThan () | Make a comparison to check if first is strict lesser than second. |
Expect:toBeGreatThan () | Make a comparison to check if first is strict greater than second. |
Expect:toBeLessOrEqual () | Make a comparison to check if first is lesser or equal than second. |
Expect:toBeGreatOrEqual () | Make a comparison to check if first is strict greater or equal than second. |
Expect:toBeMatch () | Make a comparison to check if first is a match in second. |
Expect:toBeUMatch () | Make a comparison to check if first is an Unicode match in second. |
Fields
- Expect.softFail
-
Global assert soft fail.
This toggles soft errors on eval, thus allows easy testing of the compute graph.
If set then a failure will not throw an exception.
- softFail
- Expect.bypassEval
-
Global bypass eval.
This toggle process execution, thus speeds up evaluation of the compute graph.
If set then the compute graph will not be evaluated, and failures will go undetected.
- bypassEval
- Expect.typeCheck
-
Global argument type checks.
This toggle type assertions, thus speeds up creation of the compute graph.
If set then type checks will not be done on arguments.
- typeCheck
- Expect.strictTaint
-
Global strict checking of tainting.
This toggle hard fails if an expect is tainted.
- strictTaint
Metamethods
- Expect:__index ()
-
Lookup of missing class members.
Parameters:
- key string lookup of member
Returns:
anyRaises:
on wrong argument type, unless turned off by Expect.typeCheck. - Expect:__call ()
-
Get a clone or create a new instance.
Parameters:
- ... vararg conditionally passed to create
Returns:
self
Methods
- Expect:create ()
-
Create a new instance.
Parameters:
- ...
vararg
forwarded to
_init()
Returns:
selfRaises:
on wrong arguments type, unless turned off by Expect.typeCheck. - ...
vararg
forwarded to
- Expect:_init ()
-
Initialize a new instance.
Will inherit the current value of Expect.softFail during initialization.
Parameters:
- ... vararg interpreted according to type
Returns:
selfRaises:
on wrong arguments - Expect:taint ()
-
Set taint status.
Returns:
nil or booleanRaises:
on call, if Expect.strictTaint is set. - Expect:isTainted ()
-
Test whether instance is tainted.
The instance will be tainted if the compute graph contains callbacks.
Returns:
nil or boolean - Expect:hasSoft ()
-
Test whether instance has soft fail.
This is a check on whether the soft fail is set, not the actual boolean value.
Returns:
boolean - Expect:isSoft ()
-
Test whether instance will soft fail.
This returns the actual boolean value.
Returns:
nil or boolean - Expect:hasName ()
-
Test whether instance has a name.
Returns:
boolean - Expect:getName ()
-
Get the instance name.
Returns:
string - Expect:addFail ()
-
Add callback for failing compare.
This will taint the instance.
Parameters:
- func function to call
Returns:
selfRaises:
on Expect.strictTaint is set or wrong argument type, unless turned off by Expect.typeCheck. - Expect:addFailReport ()
-
Add report for fail.
This will not taint the instance.
Parameters:
Returns:
selfRaises:
on wrong argument type, unless turned off by Expect.typeCheck. - Expect:addPass ()
-
Add callback for passing compare.
This will taint the instance.
Parameters:
- func
Returns:
selfRaises:
on Expect.strictTaint is set or wrong argument type, unless turned off by Expect.typeCheck. - Expect:addPassReport ()
-
Add report for pass.
This will not taint the instance.
Parameters:
Returns:
selfRaises:
on wrong argument type, unless turned off by Expect.typeCheck. - Expect:callbacks ()
-
Callback on pass.
The callback is evaluated right before @Expect:compare() returns.
Errors in individual callbacks will be silently ignored.
Parameters:
- cb table to call
- Expect:import ()
-
Import a compute grap.
This is scary, and graph will be tainted.
Parameters:
- procs table for the graph
Returns:
selfRaises:
on Expect.strictTaint is set, or wrong argument type, unless turned off by Expect.typeCheck. - Expect:addProcess ()
-
Add a process function
Parameters:
- proc function to be evaluated
- hold nil or boolean the previous tainting
Returns:
selfRaises:
on Expect.strictTaint is set and hold unset, or wrong argument type, unless turned off by Expect.typeCheck. - Expect:compare ()
-
Compare given values
Parameters:
- ... varargs used as arguments
Returns:
boolean,nil or string - Expect:eval ()
-
Eval given values.
If Expect.bypassEval is set, then the compute graph will not be evaluated.
Level does not work properly in the console, and the site report is simplified.
Parameters:
- level nil or num to report
- ... varargs used as arguments
Returns:
boolean,nil or string - Expect:pick ()
-
Pick entries
Process:
Parameters:
- ... varargs used as indexes
Returns:
selfRaises:
on wrong argument type, unless turned off by Expect.typeCheck. - Expect:filter ()
-
Filter entries
Process:
Parameters:
- func function to filter the set
- ... varargs arguments passed to func
Returns:
selfRaises:
on wrong argument type, unless turned off by Expect.typeCheck. - Expect:map ()
-
Map over entries.
The provided function will be mapped over arguments provided at the step.
Process:
Parameters:
- func function to map over the set
- ... varargs arguments passed to func
Returns:
self - Expect:first ()
-
Make a pick for first item.
Process:
Returns:
self - Expect:second ()
-
Make a pick for second item.
Process:
Returns:
self - Expect:third ()
-
Make a pick for third item.
Process:
Returns:
self - Expect:fourth ()
-
Make a pick for fourth item.
Process:
- Expect:fifth ()
-
Make a pick for fifth item.
Process:
Returns:
self - Expect:sixth ()
-
Make a pick for sixth item.
Process:
Returns:
self - Expect:seventh ()
-
Make a pick for seventh item.
Process:
Returns:
self - Expect:eight ()
-
Make a pick for eight item.
Process:
Returns:
self - Expect:ninth ()
-
Make a pick for ninth item.
Process:
Returns:
self - Expect:tenth ()
-
Make a pick for tenth item.
Process:
Returns:
self - Expect:eleventh ()
-
Make a pick for eleventh item.
Process:
Returns:
self - Expect:twelfth ()
-
Make a pick for twelfth item.
Process:
Returns:
self - Expect:asType ()
-
Make a transform to get the argument type.
Nicknames:
-
Expect:type
Process:
Returns:
self - Expect:asUpper ()
-
Make a transform to get the string as upper case.
Nicknames:
- Expect:upper
- Expect:asUC
- Expect:uc
Process:
Returns:
self - Expect:asLower ()
-
Make a transform to get the string as lower case.
Nicknames:
- Expect:lower
- Expect:asLC
- Expect:lc
Process:
Returns:
self - Expect:asUpperFirst ()
-
Make a transform to get the string with first char as upper case.
Nicknames:
- Expect:upperfirst
- Expect:asUCFirst
- Expect:asUCfirst
- Expect:ucfirst
Process:
Returns:
self - Expect:asLowerFirst ()
-
Make a transform to get the string with first char as lower case.
Nicknames:
- Expect:lowerfirst
- Expect:asLCFirst
- Expect:asLCfirst
- Expect:lcfirst
Process:
Returns:
self - Expect:asReverse ()
-
Make a transform to get the string reversed.
Nicknames:
-
Expect:reverse
Process:
Returns:
self - Expect:asUUpper ()
-
Make a transform to get the ustring as upper case.
Nicknames:
- Expect:uupper
- Expect:asUUC
- Expect:uuc
Process:
Returns:
self - Expect:asULower ()
-
Make a transform to get the ustring as lower case.
Nicknames:
- Expect:ulower
- Expect:asULC
- Expect:ulc
Process:
Returns:
self - Expect:asUUpperFirst ()
-
Make a transform to get the ustring with first code point as upper case.
Nicknames:
- Expect:uupperfirst
- Expect:asUUCFirst
- Expect:asUUCfirst
- Expect:uucfirst
Process:
Returns:
self - Expect:asULowerFirst ()
-
Make a transform to get the ustring with first code point as lower case.
Nicknames:
- Expect:ulowerfirst
- Expect:asULCFirst
- Expect:asULCfirst
- Expect:ulcfirst
Process:
Returns:
self - Expect:asUNFC ()
-
Make a transform to get the ustring as Normalized Form "C".
Nicknames:
- Expect:unfc
- Expect:uNFC
- Expect:nfc
Process:
Returns:
self - Expect:asUNFD ()
-
Make a transform to get the ustring as Normalized Form "D".
Nicknames:
- Expect:unfd
- Expect:uNFD
- Expect:nfd
Process:
Returns:
self - Expect:asNumber ()
-
Make a transform to get the string as number.
Nicknames:
- Expect:number
- Expect:asNum
- Expect:num
Process:
Returns:
self - Expect:asString ()
-
Make a transform to get the number as string.
Nicknames:
- Expect:string
- Expect:asStr
- Expect:str
Process:
Returns:
self - Expect:asFloor ()
-
Make a transform to get the next lower number.
Nicknames:
-
Expect:floor
Process:
Returns:
self - Expect:asCeil ()
-
Make a transform to get the next higher number.
Nicknames:
-
Expect:ceil
Process:
Returns:
self - Expect:asRound ()
-
Make a transform to get the rounded number.
Nicknames:
-
Expect:round
Process:
Returns:
self - Expect:asInteger ()
-
Make a transform to get the integer part of the number.
Nicknames:
- Expect:integer
- Expect:asInt
- Expect:int
Process:
Returns:
self - Expect:asFraction ()
-
Make a transform to get the fraction part of the number.
Nicknames:
- Expect:fraction
- Expect:asFrac
- Expect:frac
Process:
Returns:
self - Expect:toBeWithin ()
-
Make a comparison to check if first is within limits of second.
Nicknames:
- Expect:within
- Expect:isWithin
- Expect:ifWithin
Parameters:
- limit any the values must be within
- ... varargs used as values for comparison
Returns:
self - Expect:toBeEqual ()
-
Make a comparison to check equality.
Nicknames:
- Expect:equal
- Expect:isEqual
- Expect:ifEqual
Process:
Parameters:
- ... varargs used as values for comparison
Returns:
self - Expect:toBeBoolEqual ()
-
Make a comparison to check boolean equality.
Nicknames:
- Expect:boolequal
- Expect:isBoolEqual
- Expect:ifBoolEqual
Process:
Parameters:
- ... varargs used as values for comparison
Returns:
self - Expect:toBeStrictEqual ()
-
Make a comparison to check strict equality.
Nicknames:
- Expect:strictequal
- Expect:isStrictEqual
- Expect:ifStrictEqual
Process:
Parameters:
- ... varargs used as values for comparison
Returns:
self - Expect:toBeSame ()
-
Make a comparison to check similarity.
Nicknames:
- Expect:same
- Expect:isSame
- Expect:ifSame
Process:
Parameters:
- ... varargs used as values for comparison
Returns:
self - Expect:toBeDeepEqual ()
-
Make a comparison to check deep equality.
Nicknames:
- Expect:deepequal
- Expect:isDeepEqual
- Expect:ifDeepEqual
Process:
Parameters:
- ... varargs used as values for comparison
Returns:
self - Expect:toBeContained ()
-
Make a comparison to check if first is contained in second.
Note that it must be contained at the surface level.
Nicknames:
- Expect:contained
- Expect:isContained
- Expect:ifContained
Process:
Parameters:
- ... varargs used as values for comparison
Returns:
self - Expect:toBeLessThan ()
-
Make a comparison to check if first is strict lesser than second.
Nicknames:
- Expect:less
- Expect:lt
- Expect:toBeLess
- Expect:toBeLT
- Expect:isLess
- Expect:isLT
- Expect:ifLess
- Expect:ifLt
Process:
Parameters:
- ... varargs used as values for comparison
Returns:
self - Expect:toBeGreatThan ()
-
Make a comparison to check if first is strict greater than second.
Nicknames:
- Expect:great
- Expect:gt
- Expect:toBeGreat
- Expect:toBeGT
- Expect:isGreat
- Expect:isGT
- Expect:ifGreat
- Expect:ifGt
Process:
Parameters:
- ... varargs used as values for comparison
Returns:
self - Expect:toBeLessOrEqual ()
-
Make a comparison to check if first is lesser or equal than second.
Nicknames:
- Expect:lessOrEqual
- Expect:le
- Expect:toBeLE
- Expect:isLessOrEqual
- Expect:isLE
- Expect:ifLesserOrEqual
- Expect:ifLE
Process:
Parameters:
- ... varargs used as values for comparison
Returns:
self - Expect:toBeGreatOrEqual ()
-
Make a comparison to check if first is strict greater or equal than second.
Nicknames:
- Expect:greatOrEqual
- Expect:ge
- Expect:toBeGE
- Expect:isGreatOrEqual
- Expect:isGE
- Expect:ifGreatOrEqual
- Expect:ifGE
Process:
Parameters:
- ... varargs used as values for comparison
Returns:
self - Expect:toBeMatch ()
-
Make a comparison to check if first is a match in second.
Nicknames:
- Expect:match
- Expect:isMatch
- Expect:ifMatch
Process:
Parameters:
- ... varargs used as values for comparison
Returns:
self - Expect:toBeUMatch ()
-
Make a comparison to check if first is an Unicode match in second.
Nicknames:
- Expect:umatch
- Expect:isUMatch
- Expect:ifUMatch
Process:
Parameters:
- ... varargs used as values for comparison
Returns:
self