libshit

Just some random shit
git clone https://git.neptards.moe/neptards/libshit.git
Log | Files | Refs | Submodules | README | LICENSE

builtin.cpp (1485B)


      1 #include "translate/builtin_ctx.hpp"
      2 
      3 #include "libshit/doctest.hpp"
      4 
      5 namespace Libshit::Translate::Test
      6 {
      7   TEST_SUITE_BEGIN("Libshit::Translate::Builtin");
      8 
      9   TEST_CASE("Builtin")
     10   {
     11     BuiltinContext ctx;
     12     SUBCASE("normal check")
     13     {
     14       CHECK(ctx->menu->new_game()->ToString() == "New Game");
     15       CHECK(ctx->test->fmt(1)->ToString() == "Delete 1 file?");
     16       CHECK(ctx->test->fmt(5)->ToString() == "Delete 5 files?");
     17 
     18       CHECK(ctx->test->macro()->ToString() == "Test defbar");
     19       CHECK(ctx->test->types(3, "foo", 1.13)->ToString() == "3 foo 1.13");
     20 
     21       CHECK(ctx->test->get_foo(ctx->test->foo())->ToString() == "Foo Case");
     22       CHECK(ctx->test->get_asd(ctx->test->foo())->ToString() == "No Case");
     23 
     24       CHECK(ctx->test->gender_format(ctx->test->gender())->ToString() == "c");
     25       CHECK(ctx->test->gender_format("")->ToString() == "a");
     26 
     27       // reflective inteface still works
     28       CHECK(ctx["test"]["fmt"](4)->ToString() == "Delete 4 files?");
     29     }
     30 
     31 #if LIBSHIT_TRANSLATE_YAML
     32     SUBCASE("load new yml")
     33     {
     34       std::stringstream ss{R"(
     35 ...
     36 menu:
     37   new_game: 新しいゲーム
     38   load: ${foo nope}
     39 )"};
     40       ctx.Load(ss);
     41 
     42       CHECK(ctx->menu->new_game()->ToString() == "新しいゲーム");
     43       CHECK(ctx->menu->load()->ToString() == "defnope");
     44     }
     45 
     46     SUBCASE("load invalid yml")
     47     {
     48       std::stringstream ss{R"(
     49 ...
     50 test:
     51   types: $STRING $STRING
     52 )"};
     53       CHECK_THROWS(ctx.Load(ss));
     54     }
     55 #endif
     56   }
     57 
     58   TEST_SUITE_END();
     59 }