int tests_3() { const int TSTRL = 128; char tdata[2048]; char tstr[TSTRL]; int fc = 0; bool ok = false; djs_tok_t res; loadFile(tdata,"inputs/ex2.json"); djs_tok_t w2 = djs_createFrom(tdata); djs_showTok(&w2,TEST_DEBUG); const char *digits[] = { "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten" }; const int ivals[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, -10 }; const char *svals[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "[ 10 ]" }; fc += eT(djs_valid(&w2)); for (int i=0;i<10;i++) { fc += eT(ok = djs_findNamed(&w2,digits[i],&res)); fc += eT(ok = djs_getStr(&res,tstr,TSTRL)); fc += eS(tstr,svals[i]); int ival = 42; fc += eI(djs_getInt(&res,&ival),(ivals[i] > 0)); fc += (ivals[i] > 0) ? eI(ivals[i], ival) : 42; } return fc; }
int tests_1() { const int TSTRL = 128; char tdata[2048]; char tstr[TSTRL]; int fc = 0; bool ok = false; djs_tok_t res, r3; int aryLen = 0; loadFile(tdata,"inputs/example.json"); djs_tok_t whole = djs_createFrom(tdata); fc += eT(ok = djs_findNamed(&whole, "this", &res)); fc += eT(ok = djs_getStr(&res,tstr,TSTRL)); fc += eS(tstr,"that"); fc += eT(ok = djs_findNamed(&whole,"other",&res)); djs_tok_t res2; fc += eT(ok = djs_findNamed(&res,"this",&res2)); fc += eT(ok = djs_getStr(&res2,tstr,TSTRL)); fc += eS(tstr,"notthat"); fc += eT(ok = djs_findNamed(&res,"smelly",&res2)); bool smelly = false; fc += eT(ok = djs_getBool(&res2,&smelly)); fc += eT(smelly); fc += eT(ok = djs_findNamed(&res,"ugly",&res2)); bool ugly = true; fc += eT(ok = djs_getBool(&res2,&ugly)); fc += eF(ugly); fc += eT(ok = djs_findNamed(&whole,"boo",&res)); fc += eI(aryLen = djs_getLength(&res),6); bool intables[] = { true, true, false, true, false, true }; int tvals[] = { 11, 222, -1, 3333, -1, 55 }; for (int i=0;i<aryLen;i++) { djs_tok_t r2; fc += eT(ok = djs_findIndex(&res,i,&r2)); int ival; fc += eI(djs_getInt(&r2,&ival),intables[i]); if (intables[i]) { fc += eI(ival, tvals[i]); } } fc += eT(ok = djs_findNamed(&whole,"poop",&res)); fc += eT(ok = djs_findIndex(&res,2,&r3)); fc += eT(ok = djs_getStr(&r3,tstr,TSTRL)); fc += eS(tstr, "{ \"in\": 2, \"st\": 333333, \"rs\": [ 3,3,3,3,3,3 ] }"); if (fc) { printf("---- FAIL with %d errors ----\n",fc); } return fc; };
int tests_2() { const char td1[] = "{}"; const char td2[] = "[]"; int fc = 0; djs_tok_t w1 = djs_createFrom(td1); djs_tok_t w2 = djs_createFrom(td2); djs_tok_t res; bool ok = 0; fc += eT(djs_valid(&w1)); fc += eT(djs_valid(&w2)); fc += eI(djs_getLength(&w2),0); fc += eF(ok = djs_findNamed(&w1,"bob",&res)); fc += eF(ok = djs_findNamed(&w1,"",&res)); fc += eF(ok = djs_findIndex(&w2,0,&res)); fc += eF(ok = djs_findIndex(&w2,1,&res)); return fc; };
void gI() {eI();};