mirror of
https://github.com/rafagafe/tiny-json.git
synced 2025-07-14 15:22:10 +00:00
More tests are added.
This commit is contained in:
parent
37937178bc
commit
03665370ba
55
tests.c
55
tests.c
@ -65,7 +65,7 @@ static int primitive( void ) {
|
|||||||
"\"boolvar1\": true,"
|
"\"boolvar1\": true,"
|
||||||
"\"nullvar\": null,"
|
"\"nullvar\": null,"
|
||||||
"\"scientific\": 5368.32e-3,"
|
"\"scientific\": 5368.32e-3,"
|
||||||
"\"real\": -0.004,"
|
"\"real\": -0.25,"
|
||||||
"}";
|
"}";
|
||||||
|
|
||||||
json_t const* json = json_create( str, pool, qty );
|
json_t const* json = json_create( str, pool, qty );
|
||||||
@ -103,8 +103,8 @@ static int primitive( void ) {
|
|||||||
json_t const* real = json_getProperty( json, "real" );
|
json_t const* real = json_getProperty( json, "real" );
|
||||||
check( real );
|
check( real );
|
||||||
check( JSON_REAL == json_getType( real ) );
|
check( JSON_REAL == json_getType( real ) );
|
||||||
check( !strcmp( "-0.004", json_getValue( real ) ) );
|
check( !strcmp( "-0.25", json_getValue( real ) ) );
|
||||||
check( -0.004 == json_getReal( real ) );
|
check( -0.25 == json_getReal( real ) );
|
||||||
|
|
||||||
json_t const* scientific = json_getProperty( json, "scientific" );
|
json_t const* scientific = json_getProperty( json, "scientific" );
|
||||||
check( scientific );
|
check( scientific );
|
||||||
@ -135,6 +135,48 @@ static int text( void ) {
|
|||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int goodformats( void ) {
|
||||||
|
json_t pool[4];
|
||||||
|
unsigned const qty = sizeof pool / sizeof *pool;
|
||||||
|
{
|
||||||
|
char str[] = "{\"qwerty\":false,}";
|
||||||
|
json_t const* root = json_create( str, pool, qty );
|
||||||
|
check( root );
|
||||||
|
}
|
||||||
|
{
|
||||||
|
char str[] = "{\"a\":[0,]}";
|
||||||
|
json_t const* root = json_create( str, pool, qty );
|
||||||
|
check( root );
|
||||||
|
}
|
||||||
|
{
|
||||||
|
char str[] = "{\"a\":[0],}";
|
||||||
|
json_t const* root = json_create( str, pool, qty );
|
||||||
|
check( root );
|
||||||
|
}
|
||||||
|
{
|
||||||
|
char str[] = "{\"qwerty\":654,}";
|
||||||
|
json_t const* root = json_create( str, pool, qty );
|
||||||
|
check( root );
|
||||||
|
}
|
||||||
|
{
|
||||||
|
char str[] = "{\"qwerty\":\"asdfgh\",}";
|
||||||
|
json_t const* root = json_create( str, pool, qty );
|
||||||
|
check( root );
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
char str[] = "{,\"qwerty\":\"asdfgh\",}";
|
||||||
|
json_t const* root = json_create( str, pool, qty );
|
||||||
|
check( root );
|
||||||
|
}
|
||||||
|
{
|
||||||
|
char str[] = "{,\"a\":1, , \"b\":2,,,,}";
|
||||||
|
json_t const* root = json_create( str, pool, qty );
|
||||||
|
check( root );
|
||||||
|
}
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
|
||||||
static int array( void ) {
|
static int array( void ) {
|
||||||
json_t pool[7];
|
json_t pool[7];
|
||||||
unsigned const qty = sizeof pool / sizeof *pool;
|
unsigned const qty = sizeof pool / sizeof *pool;
|
||||||
@ -217,7 +259,11 @@ int badformat( void ) {
|
|||||||
json_t const* json = json_create( str, pool, qty );
|
json_t const* json = json_create( str, pool, qty );
|
||||||
check( json );
|
check( json );
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
char str[] = "{\"var\":,9}";
|
||||||
|
json_t const* json = json_create( str, pool, qty );
|
||||||
|
check( !json );
|
||||||
|
}
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -241,6 +287,7 @@ static struct test const tests[] = {
|
|||||||
{ text, "Text" },
|
{ text, "Text" },
|
||||||
{ array, "Array" },
|
{ array, "Array" },
|
||||||
{ badformat, "Bad format" },
|
{ badformat, "Bad format" },
|
||||||
|
{ goodformats, "Formats" },
|
||||||
};
|
};
|
||||||
|
|
||||||
int main( void ) {
|
int main( void ) {
|
||||||
|
Loading…
Reference in New Issue
Block a user