Main Menu

L1Expect

Started by l1a2r3s4x, Apr 04, 2022, 10:03 PM

Previous topic - Next topic
i wrote a little api to test the parameter of a function.

you need only write

ex = require("expact")
myFunction = ex.create({ex.tStr, ex.tNum}, myFunction)

and you function test is the first parameter is a string and the second is a number, and fire an error like "parameter 1 is table (expact string)" if a parameter has a wrong type.

for more complex check you can write:
- ex.create({{ex.tStr, ex.tNum}, {ex.tFunc}}, myfunction)
    to test parameter 1 can hac String or Number
- ex.create({{name = "text", ex.tStr}}, myfunc
    to return "parameter text is wrongtype (expect string)"
- ex.create({max = 1, ex.tStr}, myfunc)
   to check the maximum of parameters
- ex.create({{ex.tStr, ex.tNil}}, myfunction)
   to check a optional string

the First parameter of create must be a table that define the expect:
- [optional] max: define a maximum of parameters
- [optional] maxSupplier: a string supplier for error text by to many args.
- [optional] messageSupplier: a string supplier for error text for wrong parameter for all parameter
-
  • whit number x=1 to n: table whit infos for parameter x
  - [optional] name: name for parameter x
  - [optional] messageSupplier: a string supplier explicit for parameter x
  - [maybe optional] test: a predicate to test type, not need if a list of test define
  - [maybe optional] expectType: a string for the error message, not need if a lift of test define
  -
  • whit number x=1 to n: list of test for mutlipe types
    - test: a predicate to test type
    - expectType: a string for the error message

for test there a some predefined table
ex.testFunction ex.tFunc: test function
ex.testTable ex.tTab: test Table
ex.testString ex.tStr: test String
ex.testNumber ex.tNum: test Number
ex.testBoolean ex.tBool: test Boolean
ex.testThread ex.tThread: test Thread(coroutines)
ex.testNil ex.tNil: test Nil

i planed a constructorfunction to test field of table, but this is not implemented yet

i hope this can help someone.
pastebin: https://pastebin.com/FhkxA1Yn