leafo / tableshape

Test the shape or structure of a Lua table, inspired by React.PropTypes & LPeg

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Request] types.map_of(key_type, value_type)

Nayruden opened this issue · comments

Please add types.maps_of(...), which could be used as follows

local dictionary_shape = types.map_of(types.string, types.string)

assert(dictionary_shape:check_value({"apple"="red", "watermelon"="green"}))

-- error: item 'shoe' in map does not match: got type `number`, expected `string`
assert(dictionary_shape:check_value({"apple"="red", "watermelon"="green", "shoe"=4}))

The error is notional.

commented

opening again to remind me to write docs

commented

new version released