CSV parser
When testing using the Symmetric properties of my solution (without using the maps
module) - CSV parser, I encountered an unexpected problem - the generator csv_source()
produces asymmetric data.
[[
{[],[125]},
{[113],[56,113]},
{[],[120]},
{[98],[]},
{[],[]}
]]
As a result, my encoder cannot distribute data correctly, which causes an error. I think the problem is with the generators. I should test them.
I noticed that the author only tests the final generator - csv_source()
(pages 141-142), and does not test intermediate ones. Well, I’ll fill this gap and share the results. Maybe I will found something interesting. To implement this idea, the generators under test need to be exported.
-export([unquoted_text/0,quotable_text/0,field/0,name/0,record/1,entry/2,header/1]).
Next, in the console, we observe generated data of our generators one by one.
>rebar3 as test shell
Eshell V11.2 (abort with ^G)
unquoted_text
1> proper_gen:pick(prop_csv_tuple:unquoted_text()).
{ok,"!!'+"}
2> proper_gen:pick(prop_csv_tuple:unquoted_text()).
{ok,":-F_ d"}
3> proper_gen:pick(prop_csv_tuple:unquoted_text()).
{ok,"1>[Os8"}
4> proper_gen:pick(prop_csv_tuple:unquoted_text()).
{ok,"A;Ar8l"}
quotable_text
5> proper_gen:pick(prop_csv_tuple:quotable_text()).
{ok,"+JqhA="}
6> proper_gen:pick(prop_csv_tuple:quotable_text()).
{ok,"Flgvs"}
7> proper_gen:pick(prop_csv_tuple:quotable_text()).
{ok,"IA2:h;FB"}
8> proper_gen:pick(prop_csv_tuple:quotable_text()).
{ok,"blw"}
9> proper_gen:pick(prop_csv_tuple:quotable_text()).
{ok,"E"}
10> proper_gen:pick(prop_csv_tuple:quotable_text()).
{ok,"Bt,M\nno"}
11> proper_gen:pick(prop_csv_tuple:quotable_text()).
{ok,"LBf7VdMto"}
field
12> proper_gen:pick(prop_csv_tuple:field()).
{ok,"N]~/P\\TQ`s"}
13> proper_gen:pick(prop_csv_tuple:field()).
{ok,"8u0u2g"}
14> proper_gen:pick(prop_csv_tuple:field()).
{ok,"wcbQ.2R"}
15> proper_gen:pick(prop_csv_tuple:field()).
{ok,"VB`UFwD'7"}
16> proper_gen:pick(prop_csv_tuple:field()).
{ok,"%"}
17> proper_gen:pick(prop_csv_tuple:field()).
{ok,"+"}
18> proper_gen:pick(prop_csv_tuple:field()).
{ok,"-?`1a2T_"}
19> proper_gen:pick(prop_csv_tuple:field()).
{ok,":H"}
20> proper_gen:pick(prop_csv_tuple:field()).
{ok,".py`o`%HsE"}
name
21> proper_gen:pick(prop_csv_tuple:name()).
{ok,"[Z* Nf-"}
22> proper_gen:pick(prop_csv_tuple:name()).
{ok,"Xz4S{vy6@E"}
23> proper_gen:pick(prop_csv_tuple:name()).
{ok,"G*Ng`G"}
24> proper_gen:pick(prop_csv_tuple:name()).
{ok,"r\\;!bgnT"}
25> proper_gen:pick(prop_csv_tuple:name()).
{ok,"@L;Vz6z?;7"}
Unfortunately, we cannot run generators that require input numeric values in the console, since the functions that we need for this are hidden inside the PropEr framework. So let’s get down to writing and testing properties.
We will implement the properties of the generators and check them.
$ rebar3 proper -d apps/bday/test -m prop_csv_tuple -p prop_unquoted_text
$ rebar3 proper -d apps/bday/test -m prop_csv_tuple -p prop_quotable_text
$ rebar3 proper -d apps/bday/test -m prop_csv_tuple -p prop_field
$ rebar3 proper -d apps/bday/test -m prop_csv_tuple -p prop_header
$ rebar3 proper -d apps/bday/test -m prop_csv_tuple -p prop_record
Source code.
to be continued…