<commit_before>#include <config.h>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

#include "internal.h"
#include "virjson.h"
#include "testutils.h"

#define VIR_FROM_THIS VIR_FROM_NONE

struct testInfo {
    const char *doc;
    const char *expect;
    bool pass;
};


static int
testJSONFromString(const void *data)
{
    const struct testInfo *info = data;
    virJSONValuePtr json;
    int ret = -1;

    json = virJSONValueFromString(info->doc);

    if (info->pass) {
        if (!json) {
            VIR_TEST_VERBOSE("Fail to parse %s\n", info->doc);
            ret = -1;
            goto cleanup;
        } else {
            VIR_TEST_DEBUG("Parsed %s\n", info->doc);
        }
    } else {
        if (json) {
            VIR_TEST_VERBOSE("Should not have parsed %s\n", info->doc);
            ret = -1;
            goto cleanup;
        } else {
            VIR_TEST_DEBUG("Fail to parse %s\n", info->doc);
        }
    }

    ret = 0;

 cleanup:<commit_msg>tests: virjson: Modify logic in testJSONFromString<commit_after>#include <config.h>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

#include "internal.h"
#include "virjson.h"
#include "testutils.h"

#define VIR_FROM_THIS VIR_FROM_NONE

struct testInfo {
    const char *doc;
    const char *expect;
    bool pass;
};


static int
testJSONFromString(const void *data)
{
    const struct testInfo *info = data;
    virJSONValuePtr json;
    int ret = -1;

    json = virJSONValueFromString(info->doc);

    if (!json) {
        if (info->pass) {
            VIR_TEST_VERBOSE("Fail to parse %s\n", info->doc);
            goto cleanup;
        } else {
            VIR_TEST_DEBUG("Fail to parse %s\n", info->doc);
            ret = 0;
            goto cleanup;
        }
    }

    if (!info->pass) {
        VIR_TEST_VERBOSE("Should not have parsed %s\n", info->doc);
        goto cleanup;
    }

    VIR_TEST_DEBUG("Parsed %s\n", info->doc);

    ret = 0;

 cleanup:
{'fraction_non_alphanumeric': 0.13219829744616926, 'fraction_numerical': 0.0035052578868302454, 'mean_word_length': 2.254071661237785, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 26, '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': '6112445', 'n_tokens_mistral': 711, 'n_tokens_neox': 684, 'n_words': 172}