Václav Kubernát | d666296 | 2018-03-22 17:41:33 +0100 | [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" |
| 10 | #include "CParser.hpp" |
| 11 | #include "CTree.hpp" |
| 12 | #include "ast.hpp" |
| 13 | |
| 14 | TEST_CASE("cd") |
| 15 | { |
| 16 | CTree tree; |
| 17 | tree.addContainer("", "a"); |
| 18 | tree.addContainer("", "b"); |
| 19 | tree.addContainer("a", "a2"); |
| 20 | tree.addContainer("b", "b2"); |
| 21 | tree.addContainer("a/a2", "a3"); |
| 22 | tree.addContainer("b/b2", "b3"); |
| 23 | |
| 24 | CParser parser(tree); |
| 25 | cd_ expected; |
| 26 | |
| 27 | std::string input; |
| 28 | |
| 29 | SECTION("basic cd parsing") |
| 30 | { |
| 31 | SECTION("a") |
| 32 | { |
| 33 | input = "cd a"; |
| 34 | expected.m_path.m_nodes.push_back(container_("a")); |
| 35 | } |
| 36 | |
| 37 | SECTION("b") |
| 38 | { |
| 39 | input = "cd b"; |
| 40 | expected.m_path.m_nodes.push_back(container_("b")); |
| 41 | } |
| 42 | |
| 43 | |
| 44 | SECTION("a/a2") |
| 45 | { |
| 46 | input = "cd a/a2"; |
| 47 | expected.m_path.m_nodes.push_back(container_("a")); |
| 48 | expected.m_path.m_nodes.push_back(container_("a2")); |
| 49 | } |
| 50 | |
| 51 | SECTION("b/b2") |
| 52 | { |
| 53 | input = "cd b/b2"; |
| 54 | expected.m_path.m_nodes.push_back(container_("b")); |
| 55 | expected.m_path.m_nodes.push_back(container_("b2")); |
| 56 | } |
| 57 | |
| 58 | cd_ command = parser.parseCommand(input); |
| 59 | REQUIRE(command == expected); |
| 60 | } |
| 61 | |
| 62 | SECTION("InvalidNodeException") |
| 63 | { |
| 64 | SECTION("x") |
| 65 | { |
| 66 | input = "cd x"; |
| 67 | } |
| 68 | |
| 69 | SECTION("a/x") |
| 70 | { |
| 71 | input = "cd a/x"; |
| 72 | } |
| 73 | REQUIRE_THROWS_AS(parser.parseCommand(input), InvalidNodeException); |
| 74 | } |
| 75 | } |