<commit_before>/*
    Copyright (c) 2014
    vurtun <<EMAIL>>
    MIT license
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "json.h"

#define test_section(desc) \
    do { \
        printf("--------------- {%s} ---------------\n", desc);\
    } while (0);

#define test_assert(cond) \
    do { \
        int pass = cond; \
        printf("[%s] %s:%d: ", pass ? "PASS" : "FAIL", __FILE__, __LINE__);\
        printf((strlen(#cond) > 50 ? "%.47s...\n" : "%s\n"), #cond);\
        if (pass) pass_count++; else fail_count++; \
    } while (0)

#define test_result()\
    do { \
        printf("------------------------------------------------------\n"); \
        printf("-- Result:  %3d Total   %3d Passed      %3d Failed  --\n", \
                pass_count  + fail_count, pass_count, fail_count); \
        printf("------------------------------------------------------\n"); \
    } while (0)

static int pass_count;
static int fail_count;

int main(void)
{
    test_section("str")
    {
        const json_char *buf = (json_char*)"{\"name\"=\"value\"}";
        json_size size = strlen((const char*)buf);

        struct json_iter iter;
        iter = json_begin((json_char*)buf, size);

        json_pair pair;
        iter = json_parse(&iter, pair);
        test_assert(!iter.err);
        test_assert(!json_cmp(&pair[JSON_NAME], (json_char*)"name"));
        test_assert(!json_cmp(&pair[JSON_VALUE], (json_char*)"value"));
    }

    test_section("num")
    {
        const json_char *buf = (const json_char*)"{\"name\"=1234}";
        const json_size size = strlen((const char*)buf);

        struct json_iter iter;
        iter = json_begin((json_char*)buf, size);

        json_pair pair;
        iter = json_parse(&iter, pair);
        test_assert(!iter.err);
        test_assert(!json_cmp(&pair[JSON_NAME], (json_char*)"name"));
        test_assert(!json_cmp(&pair[JSON_VALUE], (json_char*)"1234"));
    }

    test_section("utf8")
    {
        const json_char *buf = (const json_char*)"{\"name\"=\"$¢€𤪤\"}";
        const json_size size = strlen((const char*)buf);

        struct json_iter iter;
        iter = json_begin((json_char*)buf, size);

        json_pair pair;
        iter = json_parse(&iter, pair);
        test_assert(!iter.err);
        test_assert(!json_cmp(&pair[JSON_NAME], (json_char*)"name"));
        test_assert(!json_cmp(&pair[JSON_VALUE], (json_char*)"$¢€𤪤"));
    }

    test_section("array")
    {
        const json_char *buf = (const json_char*)"{\"list\"=[1,2,3,4]}";
        json_size size = strlen((const char*)buf);

        struct json_iter iter;
        iter = json_begin((json_char*)buf, size);

        json_pair pair;
        iter = json_parse(&iter, pair);
        test_assert(!iter.err);
        test_assert(!json_cmp(&pair[JSON_NAME], (json_char*)"list"));
        test_assert(!json_cmp(&pair[JSON_VALUE], (json_char*)"[1,2,3,4]"));

        struct json_token tok;
        iter = json_begin(pair[1].str, pair[1].len);

        int i = 0;
        const json_char* check = (const json_char*)"1234";
        do {
            iter = json_read(&iter, &tok);
            test_assert(tok.str[0] == check[i++]);
        } while (!iter.err);
    }

    test_section("sub")
    {
        const json_char *buf = (const json_char*)"{\"sub\"={\"a\"=\"b\"}}";
        json_size size = strlen((const char*)buf);

        struct json_iter iter;
        iter = json_begin((json_char*)buf, size);

        json_pair pair;
        iter = json_parse(&iter, pair);
        test_assert(!iter.err);
        test_assert(!json_cmp(&pair[JSON_NAME], (json_char*)"sub"));
        test_assert(!json_cmp(&pair[JSON_VALUE], (json_char*)"{\"a\"=\"b\"}"));

        iter = json_begin(pair[1].str, pair[1].len);
        iter = json_parse(&iter, pair);
        test_assert(!iter.err);
        test_assert(!json_cmp(&pair[JSON_NAME], (json_char*)"a"));
        test_assert(!json_cmp(&pair[JSON_VALUE], (json_char*)"b"));
    }
    test_result();
    exit(EXIT_SUCCESS);
}
<commit_msg>changed ptr to array<commit_after>/*
    Copyright (c) 2014
    vurtun <<EMAIL>>
    MIT license
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "json.h"

#define test_section(desc) \
    do { \
        printf("--------------- {%s} ---------------\n", desc);\
    } while (0);

#define test_assert(cond) \
    do { \
        int pass = cond; \
        printf("[%s] %s:%d: ", pass ? "PASS" : "FAIL", __FILE__, __LINE__);\
        printf((strlen(#cond) > 50 ? "%.47s...\n" : "%s\n"), #cond);\
        if (pass) pass_count++; else fail_count++; \
    } while (0)

#define test_result()\
    do { \
        printf("------------------------------------------------------\n"); \
        printf("-- Result:  %3d Total   %3d Passed      %3d Failed  --\n", \
                pass_count  + fail_count, pass_count, fail_count); \
        printf("------------------------------------------------------\n"); \
    } while (0)

static int pass_count;
static int fail_count;

int main(void)
{
    test_section("str")
    {
        struct json_iter iter;
        const json_char buf[] = "{\"name\"=\"value\"}";
        iter = json_begin(buf, sizeof buf);

        json_pair pair;
        iter = json_parse(&iter, pair);
        test_assert(!iter.err);
        test_assert(!json_cmp(&pair[JSON_NAME], (json_char*)"name"));
        test_assert(!json_cmp(&pair[JSON_VALUE], (json_char*)"value"));
    }

    test_section("num")
    {
        struct json_iter iter;
        const json_char buf[] = "{\"name\"=1234}";
        iter = json_begin(buf, sizeof buf);

        json_pair pair;
        iter = json_parse(&iter, pair);
        test_assert(!iter.err);
        test_assert(!json_cmp(&pair[JSON_NAME], (json_char*)"name"));
        test_assert(!json_cmp(&pair[JSON_VALUE], (json_char*)"1234"));
    }

    test_section("utf8")
    {
        struct json_iter iter;
        const json_char buf[] = "{\"name\"=\"$¢€𤪤\"}";
        iter = json_begin(buf, sizeof buf);

        json_pair pair;
        iter = json_parse(&iter, pair);
        test_assert(!iter.err);
        test_assert(!json_cmp(&pair[JSON_NAME], (json_char*)"name"));
        test_assert(!json_cmp(&pair[JSON_VALUE], (json_char*)"$¢€𤪤"));
    }

    test_section("array")
    {
        struct json_iter iter;
        const json_char buf[] = "{\"list\"=[1,2,3,4]}";
        iter = json_begin(buf, sizeof buf);

        json_pair pair;
        iter = json_parse(&iter, pair);
        test_assert(!iter.err);
        test_assert(!json_cmp(&pair[JSON_NAME], (json_char*)"list"));
        test_assert(!json_cmp(&pair[JSON_VALUE], (json_char*)"[1,2,3,4]"));

        int i = 0;
        iter = json_begin(pair[1].str, pair[1].len);
        const json_char check[] = "1234";
        do {
            struct json_token tok;
            iter = json_read(&iter, &tok);
            test_assert(tok.str[0] == check[i++]);
        } while (!iter.err);
    }

    test_section("sub")
    {
        struct json_iter iter;
        const json_char buf[] = "{\"sub\"={\"a\"=\"b\"}}";
        iter = json_begin(buf, sizeof buf);

        json_pair pair;
        iter = json_parse(&iter, pair);
        test_assert(!iter.err);
        test_assert(!json_cmp(&pair[JSON_NAME], (json_char*)"sub"));
        test_assert(!json_cmp(&pair[JSON_VALUE], (json_char*)"{\"a\"=\"b\"}"));

        iter = json_begin(pair[1].str, pair[1].len);
        iter = json_parse(&iter, pair);
        test_assert(!iter.err);
        test_assert(!json_cmp(&pair[JSON_NAME], (json_char*)"a"));
        test_assert(!json_cmp(&pair[JSON_VALUE], (json_char*)"b"));
    }
    test_result();
    exit(EXIT_SUCCESS);
}

{'fraction_non_alphanumeric': 0.21462140992167103, 'fraction_numerical': 0.010704960835509139, 'mean_word_length': 2.2641670217298677, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7398393', 'n_tokens_mistral': 2608, 'n_tokens_neox': 2531, 'n_words': 469}