#include "stdafx.h"

#include "ccl/lang/Literals.h"

#include "xtr/core/PyCore.h"
#include "xtr/core/PyTextProcessor.h"

using ccl::operator""_c17;
using ccl::lang::operator""_form;

class UTPyTextProcessor : public ::testing::Test {
protected:
  using PyCore = cxxpython::PyCore;
  using PyTextProcessor = xtr::core::PyTextProcessor;

  using Morphology = ccl::lang::Morphology;

protected:
  PyCore& python{ PyCore::Instance() };
  std::unique_ptr<PyTextProcessor> processor{ nullptr };

  void SetUp() override {
    static CString path{ "C:\\Program Files\\Python312\\" };
    ASSERT_TRUE(python.Start(path));
    ASSERT_TRUE(python.LoadModule("cctext", "cctext"));
    processor = std::make_unique<PyTextProcessor>();
    processor->InitModule("cctext");
  }

  void TearDown() override {
    processor = nullptr;
    python.Stop();
  }
};

TEST_F(UTPyTextProcessor, Inflect) {
  EXPECT_EQ(processor->Inflect("", Morphology{}), "");
  EXPECT_EQ(processor->Inflect("", "sing,datv"_form), "");
  EXPECT_EQ(processor->Inflect(u8"слон"_c17, Morphology{}), u8"слон"_c17);
  EXPECT_EQ(processor->Inflect(u8"слон"_c17, "sing,datv"_form), u8"слону"_c17);
  EXPECT_EQ(processor->Inflect(u8"синий слон"_c17, "plur,datv"_form), u8"синим слонам"_c17);
  EXPECT_EQ(processor->Inflect(u8"синий слон"_c17, "ADJF,pres,datv"_form), u8"синий слон"_c17);
  EXPECT_EQ(processor->Inflect(u8"усиленно обеспечивать"_c17, "past,masc"_form), u8"усиленно обеспечивал"_c17);
  EXPECT_EQ(processor->Inflect(u8"усиленно обеспечивать"_c17, "past,masc"_form), u8"усиленно обеспечивал"_c17);
}

TEST_F(UTPyTextProcessor, InflectDependant) {
  EXPECT_EQ(processor->InflectDependant("", ""), "");
  EXPECT_EQ(processor->InflectDependant("", "invalid"), "");
  EXPECT_EQ(processor->InflectDependant("invalid", ""), "invalid");
  EXPECT_EQ(processor->InflectDependant("", u8"термин"_c17), "");
  EXPECT_EQ(processor->InflectDependant(u8"термином"_c17, ""), u8"термином"_c17);
  EXPECT_EQ(processor->InflectDependant(u8"общий"_c17, u8"мать"_c17), u8"общая"_c17);
  EXPECT_EQ(processor->InflectDependant(u8"могучий красивый"_c17, u8"русского богатыря"_c17), u8"могучего красивого"_c17);
}

TEST_F(UTPyTextProcessor, IsSubstr) {
  EXPECT_TRUE(processor->IsSubstr("", ""));
  EXPECT_TRUE(processor->IsSubstr("", "123"));
  EXPECT_FALSE(processor->IsSubstr("4", "123"));
  EXPECT_TRUE(processor->IsSubstr(u8"человек"_c17, u8"люди"_c17));
  EXPECT_TRUE(processor->IsSubstr(u8"стильный человек"_c17, u8"стильными людьми"_c17));
}
