<commit_before>#include <climits>

// PUBLIC API
#include <disir/disir.h>

#include "test_helper.h"


class ConfigKeyvalTest : public testing::DisirTestTestPlugin
{
protected:
    void SetUp()
    {
        DisirTestTestPlugin::SetUp ();

        mold = NULL;
        context_mold = NULL;
        context_config = NULL;
        context_keyval = NULL;

        status = disir_mold_input (instance, "test", "basic_keyval", &mold);
        ASSERT_STATUS (DISIR_STATUS_OK, status);

        status = dc_config_begin (mold, &context_config);
        ASSERT_STATUS (DISIR_STATUS_OK, status);
        ASSERT_TRUE (context_config != NULL);

        status = dc_begin (context_config, DISIR_CONTEXT_KEYVAL, &context_keyval);
        ASSERT_STATUS (DISIR_STATUS_OK, status);
        ASSERT_TRUE (context_keyval != NULL);
    }

    void TearDown()
    {
        if (mold)
        {
            status = disir_mold_finished (&mold);
            EXPECT_STATUS (DISIR_STATUS_OK, status);
        }
        if (context_mold)
        {
            status = dc_putcontext (&context_mold);
            EXPECT_STATUS (DISIR_STATUS_OK, status);
        }
        if (context_config)
        {
            status = dc_destroy (&context_config);
            EXPECT_STATUS (DISIR_STATUS_OK, status);
        }
        if (context_keyval)
        {
            status = dc_destroy (&context_keyval);
            EXPECT_STATUS (DISIR_STATUS_OK, status);
        }

        DisirTestTestPlugin::TearDown ();
    }

public:
    enum disir_status status;
    struct disir_mold *mold;
    struct disir_context *context_mold;
    struct disir_context *context_config;
    struct disir_context *context_keyval;
};

class ConfigKeyvalIntegerTest : public ConfigKeyvalTest
{
protected:
    void SetUp()
    {
        ConfigKeyvalTest::SetUp ();

        status = dc_set_name (context_keyval, "key_integer", strlen ("key_integer"));
        ASSERT_STATUS (DISIR_STATUS_OK, status);
    }
};

class ConfigKeyvalStringTest : public ConfigKeyvalTest
{
protected:
    void SetUp()
    {
        ConfigKeyvalTest::SetUp ();

        status = dc_set_name (context_keyval, "key_string", strlen ("key_string"));
        ASSERT_STATUS (DISIR_STATUS_OK, status);
    }
};


TEST_F (ConfigKeyvalTest, set_name_doesnt_exist_shall_fail)
{
    const char name[] = "this_name_doesnt_exist";

    status = dc_set_name (context_keyval, name, strlen (name));
    // XXX: Should be a better return status
    ASSERT_STATUS (DISIR_STATUS_INVALID_ARGUMENT, status);

    // XXX Assert error message
}

TEST_F (ConfigKeyvalTest, set_name_that_exists_shall_succeed)
{
    status = dc_set_name (context_keyval, "key_string", strlen ("key_string"));
    ASSERT_STATUS (DISIR_STATUS_OK, status);
}


TEST_F (ConfigKeyvalTest, set_integer_value_before_name_shall_fail)
{
    status = dc_set_value_integer (context_keyval, 72);
    ASSERT_STATUS (DISIR_STATUS_MOLD_MISSING, status);
    ASSERT_STREQ ("cannot set value on context without a MOLD",
                  dc_context_error (context_keyval));
}

TEST_F (ConfigKeyvalTest, set_string_value_before_name_shall_fail)
{
    status = dc_set_value_string (context_keyval, "mys", strlen ("mys"));
    ASSERT_STATUS (DISIR_STATUS_MOLD_MISSING, status);
    ASSERT_STREQ ("cannot set value on context without a MOLD",
                  dc_context_error (context_keyval));

}

TEST_F (ConfigKeyvalIntegerTest, set_value_integer_shall_succeed)
{
    status = dc_set_value_integer (context_keyval, 74);
    ASSERT_STATUS (DISIR_STATUS_OK, status);
}

TEST_F (ConfigKeyvalIntegerTest, get_value_integer_shall_succeed)
{
    int64_t value = LLONG_MAX;
    status = dc_get_value_integer (context_keyval, &value);
    ASSERT_STATUS (DISIR_STATUS_OK, status);

    ASSERT_EQ (0, value);
}
<commit_msg>test: config_keyval - set float without a name<commit_after>#include <climits>

// PUBLIC API
#include <disir/disir.h>

#include "test_helper.h"


class ConfigKeyvalTest : public testing::DisirTestTestPlugin
{
protected:
    void SetUp()
    {
        DisirTestTestPlugin::SetUp ();

        mold = NULL;
        context_mold = NULL;
        context_config = NULL;
        context_keyval = NULL;

        status = disir_mold_input (instance, "test", "basic_keyval", &mold);
        ASSERT_STATUS (DISIR_STATUS_OK, status);

        status = dc_config_begin (mold, &context_config);
        ASSERT_STATUS (DISIR_STATUS_OK, status);
        ASSERT_TRUE (context_config != NULL);

        status = dc_begin (context_config, DISIR_CONTEXT_KEYVAL, &context_keyval);
        ASSERT_STATUS (DISIR_STATUS_OK, status);
        ASSERT_TRUE (context_keyval != NULL);
    }

    void TearDown()
    {
        if (mold)
        {
            status = disir_mold_finished (&mold);
            EXPECT_STATUS (DISIR_STATUS_OK, status);
        }
        if (context_mold)
        {
            status = dc_putcontext (&context_mold);
            EXPECT_STATUS (DISIR_STATUS_OK, status);
        }
        if (context_config)
        {
            status = dc_destroy (&context_config);
            EXPECT_STATUS (DISIR_STATUS_OK, status);
        }
        if (context_keyval)
        {
            status = dc_destroy (&context_keyval);
            EXPECT_STATUS (DISIR_STATUS_OK, status);
        }

        DisirTestTestPlugin::TearDown ();
    }

public:
    enum disir_status status;
    struct disir_mold *mold;
    struct disir_context *context_mold;
    struct disir_context *context_config;
    struct disir_context *context_keyval;
};

class ConfigKeyvalIntegerTest : public ConfigKeyvalTest
{
protected:
    void SetUp()
    {
        ConfigKeyvalTest::SetUp ();

        status = dc_set_name (context_keyval, "key_integer", strlen ("key_integer"));
        ASSERT_STATUS (DISIR_STATUS_OK, status);
    }
};

class ConfigKeyvalStringTest : public ConfigKeyvalTest
{
protected:
    void SetUp()
    {
        ConfigKeyvalTest::SetUp ();

        status = dc_set_name (context_keyval, "key_string", strlen ("key_string"));
        ASSERT_STATUS (DISIR_STATUS_OK, status);
    }
};


TEST_F (ConfigKeyvalTest, set_name_doesnt_exist_shall_fail)
{
    const char name[] = "this_name_doesnt_exist";

    status = dc_set_name (context_keyval, name, strlen (name));
    // XXX: Should be a better return status
    ASSERT_STATUS (DISIR_STATUS_INVALID_ARGUMENT, status);

    // XXX Assert error message
}

TEST_F (ConfigKeyvalTest, set_name_that_exists_shall_succeed)
{
    status = dc_set_name (context_keyval, "key_string", strlen ("key_string"));
    ASSERT_STATUS (DISIR_STATUS_OK, status);
}


TEST_F (ConfigKeyvalTest, set_integer_value_before_name_shall_fail)
{
    status = dc_set_value_integer (context_keyval, 72);
    ASSERT_STATUS (DISIR_STATUS_MOLD_MISSING, status);
    ASSERT_STREQ ("cannot set value on context without a MOLD",
                  dc_context_error (context_keyval));
}

TEST_F (ConfigKeyvalTest, set_string_value_before_name_shall_fail)
{
    status = dc_set_value_string (context_keyval, "mys", strlen ("mys"));
    ASSERT_STATUS (DISIR_STATUS_MOLD_MISSING, status);
    ASSERT_STREQ ("cannot set value on context without a MOLD",
                  dc_context_error (context_keyval));
}

TEST_F (ConfigKeyvalTest, set_float_value_before_name_shall_fail)
{
    status = dc_set_value_float (context_keyval, 3.12);
    ASSERT_STATUS (DISIR_STATUS_MOLD_MISSING, status);
    ASSERT_STREQ ("cannot set value on context without a MOLD",
                  dc_context_error (context_keyval));
}

TEST_F (ConfigKeyvalIntegerTest, set_value_integer_shall_succeed)
{
    status = dc_set_value_integer (context_keyval, 74);
    ASSERT_STATUS (DISIR_STATUS_OK, status);
}

TEST_F (ConfigKeyvalIntegerTest, get_value_integer_shall_succeed)
{
    int64_t value = LLONG_MAX;
    status = dc_get_value_integer (context_keyval, &value);
    ASSERT_STATUS (DISIR_STATUS_OK, status);

    ASSERT_EQ (0, value);
}

{'fraction_non_alphanumeric': 0.09287886467308668, 'fraction_numerical': 0.0021540800810947794, 'mean_word_length': 3.3131147540983608, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '3387207', 'n_tokens_mistral': 2589, 'n_tokens_neox': 2533, 'n_words': 528}