poke-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] pk_mi_json convert functions and tests.


From: Konstantinos Chasialis
Subject: Re: [PATCH] pk_mi_json convert functions and tests.
Date: Wed, 29 Jul 2020 23:17:14 +0300
User-agent: SquirrelMail/1.4.23 [email.uoa.gr]

> PK_MI_DEBUG doesn't seem to be used anywhere... please remove it :)


Done.

> Hm?  Why?  Isn't `json_object' a typedef of `struct json_object'?

I will rename all struct json_object to json_object for consistency then. :)

> Hmm, wouldn't it be worth it to have the different JSON values stored in
> files instead?
>
> Actually...  we could hack a little infrastructure here for having test
> files like:
>
> ---- begin of foo.json ----
> /* Preamble */
> ##
> -3500 as int<12>
> ##
> { "PokeValue" :
>  {
>    "type" : "Integer", "value" : -3500, "size" : 12
>  }
> }
> ---- end of foo.json -----
>
> We could make the testsuite to load all the .json files in the
> directory.
>
> For each .json file, you can use libpoke in order to parse the preamble
> (everything until the first ##) as Poke code:
>
> int pk_compile_buffer (pk_compiler pkc, const char *buffer,
>                        const char **end);
>
> Then you can use libpoke to parse the desired value (between the first
> and second ##):
>
> int pk_compile_expression (pk_compiler pkc, const char *buffer,
>                            const char **end, pk_val *val);
>
> That will give you the pk_val you want to compare to.  Then you can read
> the rest of the file and parse it as JSON with json-c.  Then you call
> json_to_val and compare.
>
> And there you go: generic test driver and it is SO easy to add more
> tests :)
>
> Example for a struct:
>
> ---- begin of bar.json ---
> deftype Foo = struct { int i; long j; };
> ##
> Foo { i = 10, j = 20 }
> ##
> { "PokeValue" :
>  {
>   "type" : "Struct",
>   "fields" :
>   [
>     {
>      "i" : { "type" : "Integer", "value" : 10, "size" : 32 },
>      "j" : ...
>     }
>   ]
>   ...
>  }
> }
> ---- end of bar.json ----
>
> WDYT?
>

This is a great idea, I will implement it for sure.
Thanks!




reply via email to

[Prev in Thread] Current Thread [Next in Thread]