<commit_before><commit_msg>testing of element constructor and exceptions<commit_after>#include "../element.h"
#include "gtest/gtest.h"
#include <sstream>
#include <string>
#include <iostream>
#include <array>
#include <vector>
#include <set>

TEST(Element, CreateFromCStr)
{
  bson::Element e("hello world");
  ASSERT_EQ(bson::STRING, e.get_type());
  ASSERT_EQ(std::string("hello world"), e.data<std::string>());
}

TEST(Element, CreateFromCStrBumType)
{
  ASSERT_THROW(bson::Element e("hello world", bson::INT32), bson::type_error);
}

TEST(Element, CreateFromCStrBumTypeText)
{
  try
  {
    bson::Element e("hello world", bson::INT32);
    FAIL();
  }
  catch (bson::type_error & e)
  {
    ASSERT_STREQ("Invalid conversion from C++ type: std::string to BSON type: int32", e.what());
  }
}

TEST(Element, UnknownException)
{
  bson::Element e;
  std::ostringstream ss;
  ASSERT_THROW(e.encode(ss), bson::type_UNKNOWN);
}

TEST(Element, UnknownExceptionText)
{
  bson::Element e;
  std::ostringstream ss;
  try
  {
    e.encode(ss);
  }
  catch (bson::type_UNKNOWN & e)
  {
    ASSERT_STREQ("_UNKNOWN type not implemented", e.what());
  }
}
{'fraction_non_alphanumeric': 0.16535433070866143, 'fraction_numerical': 0.005249343832020997, 'mean_word_length': 5.251366120218579, 'pattern_counts': {'":': 0, '<': 10, '<?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': '3556000', 'n_tokens_mistral': 427, 'n_tokens_neox': 423, 'n_words': 84}