Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 CESNET, https://photonics.cesnet.cz/ |
| 3 | * Copyright (C) 2018 FIT CVUT, https://fit.cvut.cz/ |
| 4 | * |
| 5 | * Written by Václav Kubernát <kubervac@fit.cvut.cz> |
| 6 | * |
| 7 | */ |
| 8 | |
| 9 | #include "trompeloeil_catch.h" |
Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 10 | #include "ast_commands.hpp" |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 11 | #include "parser.hpp" |
| 12 | #include "schema.hpp" |
| 13 | |
| 14 | TEST_CASE("leaf editing") |
| 15 | { |
| 16 | Schema schema; |
| 17 | schema.addContainer("", "contA"); |
| 18 | schema.addLeaf("", "leaf"); |
| 19 | schema.addLeaf("contA", "leafInCont"); |
| 20 | schema.addList("", "list", {"number"}); |
| 21 | schema.addLeaf("list", "leafInList"); |
| 22 | Parser parser(schema); |
| 23 | std::string input; |
| 24 | std::ostringstream errorStream; |
| 25 | |
| 26 | SECTION("valid input") |
| 27 | { |
| 28 | set_ expected; |
| 29 | |
| 30 | SECTION("set leaf some_data") |
| 31 | { |
| 32 | input = "set leaf some_data"; |
| 33 | expected.m_path.m_nodes.push_back(leaf_("leaf")); |
| 34 | expected.m_data = "some_data"; |
| 35 | } |
| 36 | |
| 37 | SECTION("set contA/leafInCont more_data") |
| 38 | { |
| 39 | input = "set contA/leafInCont more_data"; |
| 40 | expected.m_path.m_nodes.push_back(container_("contA")); |
| 41 | expected.m_path.m_nodes.push_back(leaf_("leafInCont")); |
| 42 | expected.m_data = "more_data"; |
| 43 | } |
| 44 | |
| 45 | command_ command = parser.parseCommand(input, errorStream); |
| 46 | REQUIRE(command.type() == typeid(set_)); |
| 47 | REQUIRE(boost::get<set_>(command) == expected); |
| 48 | } |
| 49 | |
| 50 | SECTION("invalid input") |
| 51 | { |
| 52 | SECTION("missing space between a command and its arguments") |
| 53 | { |
| 54 | SECTION("setleaf some_data") |
| 55 | { |
| 56 | input = "setleaf some_data"; |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | SECTION("missing space between arguments") |
| 61 | { |
| 62 | SECTION("set leaflol") |
| 63 | { |
| 64 | input = "set leaflol"; |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | SECTION("non-leaf identifiers") |
| 69 | { |
| 70 | SECTION("set nonexistent blabla") |
| 71 | { |
| 72 | input = "set nonexistent blabla"; |
| 73 | } |
| 74 | |
| 75 | SECTION("set contA abde") |
| 76 | { |
| 77 | input = "set contA abde"; |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | REQUIRE_THROWS(parser.parseCommand(input, errorStream)); |
| 82 | } |
| 83 | } |