[tarantool-patches] Re: [PATCH v2 2/2] lua: add key_def lua module
Alexander Turenko
alexander.turenko at tarantool.org
Wed Apr 3 14:46:44 MSK 2019
> > +-- Case: extract_key().
> > +test:test('extract_key()', function(test)
> > + test:plan(9)
> > +
> > + test:is_deeply(key_def_a:extract_key(tuple_a):totable(), {1}, 'case 1')
> > + test:is_deeply(key_def_b:extract_key(tuple_a):totable(), {1, 22}, 'case 2')
> > +
> > + -- JSON path.
> > + local res = key_def_lib.new({
> > + {type = 'string', fieldno = 1, path = 'a.b'},
> > + }):extract_key(box.tuple.new({{a = {b = 'foo'}}})):totable()
> > + test:is_deeply(res, {'foo'}, 'JSON path (tuple argument)')
> > +
> > + local res = key_def_lib.new({
> > + {type = 'string', fieldno = 1, path = 'a.b'},
> > + }):extract_key({{a = {b = 'foo'}}}):totable()
> > + test:is_deeply(res, {'foo'}, 'JSON path (table argument)')
>
> I like key_def_new_cases - they are very easy to read or extend.
> I don't quite like the tests below, because they refer to objects
> created a few screens above (tuple_a, key_def_a, etc). Could you
> please rewrite them in a similar to key_def_new_cases fashion,
> without referring to any predefined variables?
It is easy to separate test cases from a testing code in case of one
function like key_def.new(), but it is not so easy when we need to test
several functions with different behaviour. So I vote up for inlining
related data (tuple_a and so on) to test cases, but doubt these cases
could be written in such declarative manner as I did for key_def.new().
Thank you for the detailed review (eps. for the case that passes over
validation)!
WBR, Alexander Turenko.
More information about the Tarantool-patches
mailing list