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

#define PASS "PASS"
#define FAIL "FAIL"

#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) > 60 ? "%.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)


int main(void)
{
    int pass_count = 0;
    int fail_count = 0;
    json_init();
    test_section("str")
    {
        struct json_iter iter;
        struct json_pair pair;
        json_char buffer[8];

        const json_char buf[] = "{\"name\":\"value\"}";
        iter = json_begin(buf, sizeof buf);

        iter = json_parse(&pair, &iter);
        test_assert(!iter.err);
        test_assert(!json_cmp(&pair.name, "\"name\""));
        test_assert(!json_cmp(&pair.value, "\"value\""));
        test_assert(json_type(&pair.value) == JSON_STRING);
        test_assert(pair.value.children == 0);

        json_deq(&pair.value);
        test_assert(json_cpy(buffer, sizeof buffer, &pair.value) == 5);
        test_assert(!strcmp((char*)&buffer[0], "value"));
    }

    test_section("num")
    {
        json_number num;
        struct json_iter iter;
        struct json_pair pair;
        const json_char buf[] = "\n{\n\"test\":13\n}\n";
        iter = json_begin(buf, sizeof buf);

        iter = json_parse(&pair, &iter);
        test_assert(!iter.err);
        test_assert(!json_cmp(&pair.name, "\"test\""));
        test_assert(!json_cmp(&pair.value, "13"));
        test_assert(json_type(&pair.value) == JSON_NUMBER);

        test_assert(json_num(&num, &pair.value) == JSON_NUMBER);
        test_assert(num == 13.0);
    }<commit_msg>removed unneeded cast<commit_after>/*
    Copyright (c) 2015
    vurtun <<EMAIL>>
    MIT license
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "json.h"

#define PASS "PASS"
#define FAIL "FAIL"

#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) > 60 ? "%.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)


int main(void)
{
    int pass_count = 0;
    int fail_count = 0;
    json_init();
    test_section("str")
    {
        struct json_iter iter;
        struct json_pair pair;
        json_char buffer[8];

        const json_char buf[] = "{\"name\":\"value\"}";
        iter = json_begin(buf, sizeof buf);

        iter = json_parse(&pair, &iter);
        test_assert(!iter.err);
        test_assert(!json_cmp(&pair.name, "\"name\""));
        test_assert(!json_cmp(&pair.value, "\"value\""));
        test_assert(json_type(&pair.value) == JSON_STRING);
        test_assert(pair.value.children == 0);

        json_deq(&pair.value);
        test_assert(json_cpy(buffer, sizeof buffer, &pair.value) == 5);
        test_assert(!strcmp(&buffer[0], "value"));
    }

    test_section("num")
    {
        json_number num;
        struct json_iter iter;
        struct json_pair pair;
        const json_char buf[] = "\n{\n\"test\":13\n}\n";
        iter = json_begin(buf, sizeof buf);

        iter = json_parse(&pair, &iter);
        test_assert(!iter.err);
        test_assert(!json_cmp(&pair.name, "\"test\""));
        test_assert(!json_cmp(&pair.value, "13"));
        test_assert(json_type(&pair.value) == JSON_NUMBER);

        test_assert(json_num(&num, &pair.value) == JSON_NUMBER);
        test_assert(num == 13.0);
    }
{'fraction_non_alphanumeric': 0.22929797870028254, 'fraction_numerical': 0.011736579004564224, 'mean_word_length': 2.421561338289963, 'pattern_counts': {'":': 4, '<': 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': '4562123', 'n_tokens_mistral': 1564, 'n_tokens_neox': 1486, 'n_words': 310}