#include "tile/base/config/ini_file_configuration.h"
#include "gtest/gtest.h"

const char *kIniFileConfig = R"(
# comment 1
; comment 2
  # commet 3
  ; commment 4
a=1
[sec1]
a=2
[sec3]
a=3
[sec2.kk]
a=4
)";

namespace tile {

static_assert(!detail::HasClassofImpl<IniFileConfiguration, Configuration>::value, "");

TEST(IniFileConfig, LoadFromIStream)
{
    std::stringstream ss(kIniFileConfig);
    Configuration::Ptr config = MakeRefCounted<IniFileConfiguration>();
    ASSERT_FALSE(config->Has("a"));
    ASSERT_FALSE(config->Has("sec1.a"));
    ASSERT_FALSE(config->Has("sec3.a"));
    if (config.Is<IniFileConfiguration>()) {
        IniFileConfiguration::Ptr ini = config.As<IniFileConfiguration>();
        ASSERT_TRUE(ini->load(ss));
    }
    ASSERT_TRUE(config->Has("a"));
    ASSERT_TRUE(config->Has("sec1.a"));
    ASSERT_TRUE(config->Has("sec3.a"));
    ASSERT_TRUE(config->Has("sec2.kk.a"));

    ASSERT_TRUE(config->GetInt("a"));
    ASSERT_TRUE(config->GetInt("sec1.a"));
    ASSERT_EQ(1, *config->GetInt("a"));
    ASSERT_EQ(2, *config->GetInt("sec1.a"));
    ASSERT_EQ(3, *config->GetInt("sec3.a"));
    ASSERT_EQ(4, *config->GetInt("sec2.kk.a"));
}
}// namespace tile
