blob: ae368086a3f6eca0f51da09a261ade0492a5cdc2 [file] [log] [blame]
Václav Kubernát1d593902021-03-08 08:55:16 +01001/*
2 * Copyright (C) 2021 CESNET, https://photonics.cesnet.cz/
3 *
4 * Written by Václav Kubernát <kubervac@cesnet.cz>
5 *
6*/
7
8#include "trompeloeil_doctest.hpp"
9#include "parser.hpp"
10#include "pretty_printers.hpp"
11#include "static_schema.hpp"
12
13TEST_CASE("miscellaneous commands")
14{
15 auto schema = std::make_shared<StaticSchema>();
16 Parser parser(schema);
17 std::ostringstream errorStream;
18 SECTION("switch")
19 {
20 std::string input;
21 switch_ expected;
22 SECTION("operational")
23 {
24 expected.m_target = DatastoreTarget::Operational;
25 input = "switch operational";
26 }
27
28 SECTION("running")
29 {
30 expected.m_target = DatastoreTarget::Running;
31 input = "switch running";
32 }
33
34 SECTION("startup")
35 {
36 expected.m_target = DatastoreTarget::Startup;
37 input = "switch startup";
38 }
39 REQUIRE(boost::get<switch_>(parser.parseCommand(input, errorStream)) == expected);
40 }
aleskucera@cesnet.cz9babcca2023-10-27 23:29:48 +020041
42 SECTION("help")
43 {
44 std::string input;
45 bool expectedCommand = false;
46 SECTION("Short help")
47 {
48 input = "help";
49 }
50 SECTION("Short help with trailing whitespace")
51 {
52 input = "help ";
53 }
54 SECTION("Long help")
55 {
56 input = "help cd";
57 expectedCommand = true;
58 }
59 SECTION("Long help with trailing whitespace")
60 {
61 input = "help cd ";
62 expectedCommand = true;
63 }
64
65 auto result = boost::get<help_>(parser.parseCommand(input, errorStream));
66 REQUIRE(!!result.m_cmd == expectedCommand);
67 }
Václav Kubernát1d593902021-03-08 08:55:16 +010068}