<commit_before>#include <stdio.h>
#include <check.h>
#include <json-c/json_object.h>
#include "check_import.h"
#include <jstruct/jstruct.h>
#include <jstruct/jstruct_private.h>
#include <jstruct/import.h>
#include "data/basic.h"

#define BIG_INT64 0xFFFFFFFFF

struct my_json_data get_data() {
    static char *data_tags[] = {"main", "data", "sample"};
    struct my_json_data data = {
        .id=BIG_INT64,
        ._id=2,
        .ratio=3.5,
        .active=true,
        .name="main_data",
        .tags=data_tags,
        .tags__length__=3,
    };
    return data;
}

void test_data(struct my_json_data data, struct json_object *obj) {
    struct json_object *prop;
    ck_assert_ptr_ne(obj, NULL);

    ck_assert(json_object_object_get_ex(obj, "id", &prop) == true);
    ck_assert_int_eq(json_object_get_int64(prop), data.id);
    ck_assert(json_object_object_get_ex(obj, "_id", &prop) == false);

    ck_assert(json_object_object_get_ex(obj, "ratio", &prop) == true);
    ck_assert(json_object_get_double(prop) == data.ratio);

    ck_assert(json_object_object_get_ex(obj, "active", &prop) == true);
    ck_assert(json_object_get_boolean(prop) == true);

    ck_assert(json_object_object_get_ex(obj, "other_name", &prop) == true);
    ck_assert_str_eq(json_object_get_string(prop), data.name);

    ck_assert(json_object_object_get_ex(obj, "tags", &prop) == true);
    ck_assert_int_eq(json_object_array_length(prop), data.tags__length__);
    int i;
    for (i =0; i < data.tags__length__; ++i) {
        ck_assert_str_eq(json_object_get_string(json_object_array_get_idx(prop, i)), data.tags[i]);
    }
}

START_TEST(import_basic_data) {
    struct my_json_data data = get_data();
    struct json_object *obj = json_object_new_object();
    jstruct_import(obj, &data, my_json_data, NULL);
    fprintf(stdout, "JSON INPUT: %s\n", json_object_to_json_string(obj));
    fflush(stdout);
    test_data(data, obj);

} END_TEST

START_TEST(import_struct_data_with_errors) {
    // TODO: do this
} END_TEST

START_TEST(import_struct_data) {
// TODO: Milestone 4 is nested and array data
#ifdef M4<commit_msg>Correct comment.<commit_after>#include <stdio.h>
#include <check.h>
#include <json-c/json_object.h>
#include "check_import.h"
#include <jstruct/jstruct.h>
#include <jstruct/jstruct_private.h>
#include <jstruct/import.h>
#include "data/basic.h"

#define BIG_INT64 0xFFFFFFFFF

struct my_json_data get_data() {
    static char *data_tags[] = {"main", "data", "sample"};
    struct my_json_data data = {
        .id=BIG_INT64,
        ._id=2,
        .ratio=3.5,
        .active=true,
        .name="main_data",
        .tags=data_tags,
        .tags__length__=3,
    };
    return data;
}

void test_data(struct my_json_data data, struct json_object *obj) {
    struct json_object *prop;
    ck_assert_ptr_ne(obj, NULL);

    ck_assert(json_object_object_get_ex(obj, "id", &prop) == true);
    ck_assert_int_eq(json_object_get_int64(prop), data.id);
    ck_assert(json_object_object_get_ex(obj, "_id", &prop) == false);

    ck_assert(json_object_object_get_ex(obj, "ratio", &prop) == true);
    ck_assert(json_object_get_double(prop) == data.ratio);

    ck_assert(json_object_object_get_ex(obj, "active", &prop) == true);
    ck_assert(json_object_get_boolean(prop) == true);

    ck_assert(json_object_object_get_ex(obj, "other_name", &prop) == true);
    ck_assert_str_eq(json_object_get_string(prop), data.name);

    ck_assert(json_object_object_get_ex(obj, "tags", &prop) == true);
    ck_assert_int_eq(json_object_array_length(prop), data.tags__length__);
    int i;
    for (i =0; i < data.tags__length__; ++i) {
        ck_assert_str_eq(json_object_get_string(json_object_array_get_idx(prop, i)), data.tags[i]);
    }
}

START_TEST(import_basic_data) {
    struct my_json_data data = get_data();
    struct json_object *obj = json_object_new_object();
    jstruct_import(obj, &data, my_json_data, NULL);
    fprintf(stdout, "JSON INPUT: %s\n", json_object_to_json_string(obj));
    fflush(stdout);
    test_data(data, obj);

} END_TEST

START_TEST(import_struct_data_with_errors) {
    // TODO: do this
} END_TEST

START_TEST(import_struct_data) {
// TODO: Milestone 5 is nested and array data (feature complete!)
#ifdef M5
{'fraction_non_alphanumeric': 0.13635291342297712, 'fraction_numerical': 0.006605331446095777, 'mean_word_length': 4.557011795543906, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '5484142', 'n_tokens_mistral': 1641, 'n_tokens_neox': 1589, 'n_words': 272}