<commit_before>#include <LuaContext.hpp>
#include <gtest/gtest.h>

TEST(AdvancedReadWrite, WritingVariant) {
	LuaContext context;

	boost::variant<int,std::string> val{std::string{"test"}};
    context.writeVariable("a", val);
	EXPECT_EQ("test", context.readVariable<std::string>("a"));
}

TEST(AdvancedReadWrite, ReadingVariant) {
	LuaContext context;
	
    context.writeVariable("a", "test");

	const auto val = context.readVariable<boost::variant<bool,int,std::string>>("a");
	EXPECT_EQ(2, val.which());
	EXPECT_EQ("test", boost::get<std::string>(val));
}

TEST(AdvancedReadWrite, VariantError) {
	LuaContext context;
	
    context.writeVariable("a", "test");
	EXPECT_THROW((context.readVariable<boost::variant<bool,int,bool*>>("a")), LuaContext::WrongTypeException);
}

TEST(AdvancedReadWrite, ReadingOptional) {
	LuaContext context;
	
    context.writeVariable("a", 3);
	EXPECT_EQ(3, context.readVariable<boost::optional<int>>("a").get());
	EXPECT_FALSE(context.readVariable<boost::optional<int>>("b").is_initialized());
}

TEST(AdvancedReadWrite, EmptyArray) {
	LuaContext context;

	context.writeVariable("a", LuaContext::EmptyArray);
	EXPECT_EQ("table", context.executeCode<std::string>("return type(a)"));<commit_msg>Added wrong optional type reading test<commit_after>#include <LuaContext.hpp>
#include <gtest/gtest.h>

TEST(AdvancedReadWrite, WritingVariant) {
	LuaContext context;

	boost::variant<int,std::string> val{std::string{"test"}};
    context.writeVariable("a", val);
	EXPECT_EQ("test", context.readVariable<std::string>("a"));
}

TEST(AdvancedReadWrite, ReadingVariant) {
	LuaContext context;
	
    context.writeVariable("a", "test");

	const auto val = context.readVariable<boost::variant<bool,int,std::string>>("a");
	EXPECT_EQ(2, val.which());
	EXPECT_EQ("test", boost::get<std::string>(val));
}

TEST(AdvancedReadWrite, VariantError) {
	LuaContext context;
	
    context.writeVariable("a", "test");
	EXPECT_THROW((context.readVariable<boost::variant<bool,int,bool*>>("a")), LuaContext::WrongTypeException);
}

TEST(AdvancedReadWrite, ReadingOptional) {
	LuaContext context;
	
    context.writeVariable("a", 3);
    context.writeVariable("b", "test");

	EXPECT_EQ(3, context.readVariable<boost::optional<int>>("a").get());
	EXPECT_THROW(context.readVariable<boost::optional<int>>("b"), LuaContext::WrongTypeException);
	EXPECT_FALSE(context.readVariable<boost::optional<int>>("c").is_initialized());
}

TEST(AdvancedReadWrite, EmptyArray) {
	LuaContext context;

	context.writeVariable("a", LuaContext::EmptyArray);
	EXPECT_EQ("table", context.executeCode<std::string>("return type(a)"));
{'fraction_non_alphanumeric': 0.1820964039785769, 'fraction_numerical': 0.0022953328232593728, 'mean_word_length': 8.757462686567164, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, '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': '6512733', 'n_tokens_mistral': 879, 'n_tokens_neox': 866, 'n_words': 116}