<commit_before>// Copyright 2015 <NAME>

#include <limits>
#include <string>

#include "./test.hpp"

#include "./catch.hpp"

using namespace ReQL;

TEST_CASE("Expr array", "[c][expr][array]") {
  ReQL_Obj_t ary;

  const uint32_t size = 5;

  ReQL_Obj_t *arr[size];

  reql_array_init(&ary, arr, size);

  CHECK(reql_datum_type(&ary) == REQL_R_ARRAY);

  CHECK(reql_size(&ary) == 0);

  SECTION("over fill array") {
    uint32_t i;

    for (i=0; i < size; ++i) {
      CHECK(reql_array_append(&ary, &ary) == 0);
    }

    CHECK(reql_array_append(&ary, &ary) != 0);
  }

  SECTION("grow and shrink") {
    reql_array_append(&ary, &ary);

    CHECK(reql_array_pop(&ary) != NULL);
    CHECK(reql_array_last(&ary) == NULL);
    CHECK(reql_array_pop(&ary) == NULL);
  }

  SECTION("insert after end") {
    CHECK(reql_array_insert(&ary, &ary, size * 2) != 0);
  }
}

TEST_CASE("Expr object", "[c][expr][object]") {
  ReQL_Obj_t obj, key, val;

  ReQL_Pair_t pair[1];

  reql_object_init(&obj, pair, 1);

  CHECK(reql_datum_type(&obj) == REQL_R_OBJECT);

  const uint32_t size = 4;

  uint8_t *buf = new uint8_t[size];
  const uint8_t string[] = "key";

  reql_string_init(&key, buf, size);
  reql_string_append(&key, string, size);

  reql_null_init(&val);

  CHECK(reql_object_add(&obj, &key, &val) == 0);

  SECTION("verify insert") {
    CHECK(reql_object_get(&obj, &key) != NULL);

    ReQL_Obj_t *res = reql_object_get(&obj, &key);

    CHECK(reql_datum_type(res) == REQL_R_NULL);
  }

  SECTION("reuse key") {
    ReQL_Obj_t new_val;

    const double num = 3.14;

    reql_number_init(&new_val, num);

    CHECK(reql_object_add(&obj, &key, &new_val) == 0);
    CHECK(reql_object_get(&obj, &key) != NULL);

    ReQL_Obj_t *res = reql_object_get(&obj, &key);

    CHECK(reql_datum_type(res) == REQL_R_NUM);
    CHECK(reql_to_number(res) == Approx(num));
  }

  SECTION("duplicate key") {
    ReQL_Obj_t new_key, new_val;

    const double num = 3.14;

    uint8_t *new_buf = new uint8_t[size];
    const uint8_t new_string[] = "key";

    reql_string_init(&new_key, new_buf, size);
    reql_string_append(&new_key, new_string, size);

    reql_number_init(&new_val, num);

    CHECK(reql_object_add(&obj, &new_key, &new_val) == 0);
    CHECK(reql_object_get(&obj, &new_key) != NULL);

    ReQL_Obj_t *res = reql_object_get(&obj, &new_key);

    CHECK(reql_datum_type(res) == REQL_R_NUM);

    delete [] new_buf;
  }

  SECTION("out of space") {
    ReQL_Obj_t new_key, new_val;

    const double num = 3.14;

    uint8_t *new_buf = new uint8_t[size];
    const uint8_t new_string[] = "new";

    reql_string_init(&new_key, new_buf, size);
    reql_string_append(&new_key, new_string, size);

    reql_number_init(&new_val, num);

    CHECK(reql_object_add(&obj, &new_key, &new_val) != 0);
    CHECK(reql_object_get(&obj, &new_key) == NULL);

    ReQL_Obj_t *res = reql_object_get(&obj, &key);

    CHECK(reql_datum_type(res) == REQL_R_NULL);

    delete [] new_buf;
  }

  delete [] buf;
}

TEST_CASE("Expr", "[c][expr]") {
  ReQL_Obj_t val;

  SECTION("bool") {<commit_msg>Improve a test to ensure more space is requested.<commit_after>// Copyright 2015 <NAME>

#include <limits>
#include <string>

#include "./test.hpp"

#include "./catch.hpp"

using namespace ReQL;

TEST_CASE("Expr array", "[c][expr][array]") {
  ReQL_Obj_t ary;

  const uint32_t size = 5;

  ReQL_Obj_t *arr[size];

  reql_array_init(&ary, arr, size);

  CHECK(reql_datum_type(&ary) == REQL_R_ARRAY);

  CHECK(reql_size(&ary) == 0);

  SECTION("over fill array") {
    uint32_t i;

    for (i=0; i < size; ++i) {
      CHECK(reql_array_append(&ary, &ary) == 0);
    }

    CHECK(reql_array_append(&ary, &ary) != 0);
  }

  SECTION("grow and shrink") {
    reql_array_append(&ary, &ary);

    CHECK(reql_array_pop(&ary) != NULL);
    CHECK(reql_array_last(&ary) == NULL);
    CHECK(reql_array_pop(&ary) == NULL);
  }

  SECTION("insert after end") {
    CHECK(reql_array_insert(&ary, &ary, size * 2) != 0);
  }
}

TEST_CASE("Expr object", "[c][expr][object]") {
  ReQL_Obj_t obj, key, val;

  ReQL_Pair_t pair[1];

  reql_object_init(&obj, pair, 1);

  CHECK(reql_datum_type(&obj) == REQL_R_OBJECT);

  const uint32_t size = 4;

  uint8_t *buf = new uint8_t[size];
  const uint8_t string[] = "key";

  reql_string_init(&key, buf, size);
  reql_string_append(&key, string, size);

  reql_null_init(&val);

  CHECK(reql_object_add(&obj, &key, &val) == 0);

  SECTION("verify insert") {
    CHECK(reql_object_get(&obj, &key) != NULL);

    ReQL_Obj_t *res = reql_object_get(&obj, &key);

    CHECK(reql_datum_type(res) == REQL_R_NULL);
  }

  SECTION("reuse key") {
    ReQL_Obj_t new_val;

    const double num = 3.14;

    reql_number_init(&new_val, num);

    CHECK(reql_object_add(&obj, &key, &new_val) == 0);
    CHECK(reql_object_get(&obj, &key) != NULL);

    ReQL_Obj_t *res = reql_object_get(&obj, &key);

    CHECK(reql_datum_type(res) == REQL_R_NUM);
    CHECK(reql_to_number(res) == Approx(num));
  }

  SECTION("duplicate key") {
    ReQL_Obj_t new_key, new_val;

    const double num = 3.14;

    uint8_t *new_buf = new uint8_t[size];
    const uint8_t new_string[] = "key";

    reql_string_init(&new_key, new_buf, size);
    reql_string_append(&new_key, new_string, size);

    reql_number_init(&new_val, num);

    CHECK(reql_object_add(&obj, &new_key, &new_val) == 0);
    CHECK(reql_object_get(&obj, &new_key) != NULL);

    ReQL_Obj_t *res = reql_object_get(&obj, &new_key);

    CHECK(reql_datum_type(res) == REQL_R_NUM);

    delete [] new_buf;
  }

  SECTION("out of space") {
    ReQL_Obj_t new_key, new_val;

    const double num = 3.14;

    uint8_t *new_buf = new uint8_t[size];
    const uint8_t new_string[] = "new";

    reql_string_init(&new_key, new_buf, size);
    reql_string_append(&new_key, new_string, size);

    reql_number_init(&new_val, num);

    CHECK(reql_object_add(&obj, &new_key, &new_val) > 1);
    CHECK(reql_object_get(&obj, &new_key) == NULL);

    ReQL_Obj_t *res = reql_object_get(&obj, &key);

    CHECK(reql_datum_type(res) == REQL_R_NULL);

    delete [] new_buf;
  }

  delete [] buf;
}

TEST_CASE("Expr", "[c][expr]") {
  ReQL_Obj_t val;

  SECTION("bool") {
{'fraction_non_alphanumeric': 0.1642152901244545, 'fraction_numerical': 0.013576854695328915, 'mean_word_length': 4.047308319738988, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 10, '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': '3549619', 'n_tokens_mistral': 2679, 'n_tokens_neox': 2529, 'n_words': 466}