diff options
| author | thecharlesblake | 2018-04-04 11:22:44 +0100 |
|---|---|---|
| committer | thecharlesblake | 2018-04-04 11:22:44 +0100 |
| commit | 26d2836487847bec34adce7d80009ab6c89fa2c3 (patch) | |
| tree | 76a7689cbf10258fafd657671dd36cca7d0f7ddb /src/test/deal_parser_test.cpp | |
| parent | Add deal parser tests (diff) | |
| download | metasol-26d2836487847bec34adce7d80009ab6c89fa2c3.tar.gz metasol-26d2836487847bec34adce7d80009ab6c89fa2c3.zip | |
Add rules parsing tests
Diffstat (limited to 'src/test/deal_parser_test.cpp')
| -rw-r--r-- | src/test/deal_parser_test.cpp | 148 |
1 files changed, 131 insertions, 17 deletions
diff --git a/src/test/deal_parser_test.cpp b/src/test/deal_parser_test.cpp index 77a33ff..750913d 100644 --- a/src/test/deal_parser_test.cpp +++ b/src/test/deal_parser_test.cpp @@ -4,26 +4,140 @@ #include <gtest/gtest.h> -#include "test_helper.h" -#include "../main/game/game_state.h" -#include "../main/game/global_cache.h" +#include <rapidjson/stringbuffer.h> +#include <rapidjson/document.h> -typedef sol_rules::build_policy pol; +#include "../main/input-output/input/json-parsing/deal_parser.h" +#include "../main/input-output/input/json-parsing/json_helper.h" -TEST(FoundationsDominance, SameSuit) { - test_helper::run_foundations_dominance_test(pol::SAME_SUIT, { - "AC","2C","3C","4C","AH","2H","3H","4H","AS","2S","3S","4S","AD", - "2D","3D","4D"}); +using namespace std; +using namespace rapidjson; + +void run_deal_parser_test(bool, const char*); + +TEST(DealParser, SimpleTableauLetter) { + run_deal_parser_test(true, R"( +{ + "tableau piles": [ + ["AS"] + ] +} +)"); +} + +TEST(DealParser, SimpleTableauNumber) { + run_deal_parser_test(true, R"( +{ + "tableau piles": [ + ["1S"] + ] +} +)"); +} + +TEST(DealParser, IllegalTableauNumber) { + run_deal_parser_test(false, R"( +{ + "tableau piles": [ + ["14S"] + ] +} +)"); +} + +TEST(DealParser, IllegalTableauSuit) { + run_deal_parser_test(false, R"( +{ + "tableau piles": [ + ["14A"] + ] +} +)"); +} + +TEST(DealParser, SimpleTableauCase) { + run_deal_parser_test(true, R"( +{ + "tableau piles": [ + ["kc"] + ] +} +)"); } -TEST(FoundationsDominance, RedBlack) { - test_helper::run_foundations_dominance_test(pol::RED_BLACK, { - "AC","2C","AH","2H","AS","3H","2S","AD","3C","4H","3S","2D","4C", - "4S","3D","4D"}); +TEST(DealParser, AdvancedTableau) { + run_deal_parser_test(true, R"( +{ + "tableau piles": [ + ["5S","13C","4C","3C","2S","2c"], + ["5D","qD","3S","1d","2D"], + ["5H","4S","JH","3h","2H"] + ] +} +)"); +} + +TEST(DealParser, Hole) { + run_deal_parser_test(true, R"( +{ + "tableau piles": [ + ["5S","13C","4C"] + ], + "hole": "qD" +} +)"); } -TEST(FoundationsDominance, AnySuit) { - test_helper::run_foundations_dominance_test(pol::ANY_SUIT, { - "AC","2C","AH","2H","AS","2S","AD","3C","3H","3S","2D","4C","4H", - "4S","3D","4D"}); -}
\ No newline at end of file +TEST(DealParser, Stock) { + run_deal_parser_test(true, R"( +{ + "tableau piles": [ + ["5S","13C","4C"] + ], + "stock": ["1S","JC","7H"] +} +)"); +} + +TEST(DealParser, Waste) { + run_deal_parser_test(true, R"( +{ + "tableau piles": [ + ["5S","13C","4C"] + ], + "waste": ["1S","JC","7H"] +} +)"); +} + +TEST(DealParser, IllegalPileType) { + run_deal_parser_test(false, R"( +{ + "tableau piles": [ + ["5S","13C","4C"] + ], + "other": ["1S","JC","7H"] +} +)"); +} + +void run_deal_parser_test(bool validity, const char* json) { + Document in_doc; + in_doc.Parse(json); + if (in_doc.HasParseError()) { + throw runtime_error("invalid json"); + } + + Document val_doc; + val_doc.Parse(deal_parser::deal_schema_json().c_str()); + SchemaDocument sd(val_doc); + SchemaValidator validator(sd); + bool acc = in_doc.Accept(validator); + if (acc) { + ASSERT_TRUE(validity == acc) << "JSON accepted when it should not have " + "been:\n" << json; + } else { + ASSERT_TRUE(validity == acc) << json_helper::schema_err_str(validator) + << "\n" << json; + } +} |
