blob: c2cc5feace56970bfbe5c0f697d7c44b00aa7784 [file] [log] [blame]
Václav Kubernát11afac72018-07-18 14:59:53 +02001/*
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 "ast_commands.hpp"
11#include "parser.hpp"
12#include "static_schema.hpp"
13
14TEST_CASE("ls")
15{
16 auto schema = std::make_shared<StaticSchema>();
17 schema->addModule("example");
18 schema->addModule("second");
19 schema->addContainer("", "example:a");
20 schema->addContainer("", "second:a");
21 schema->addContainer("", "example:b");
22 schema->addContainer("example:a", "example:a2");
23 schema->addContainer("example:b", "example:b2");
24 schema->addContainer("example:a/example:a2", "example:a3");
25 schema->addContainer("example:b/example:b2", "example:b3");
26 schema->addList("", "example:list", {"number"});
27 schema->addContainer("example:list", "example:contInList");
28 schema->addList("", "example:twoKeyList", {"number", "name"});
29 Parser parser(schema);
30 std::string input;
31 std::ostringstream errorStream;
32
33 SECTION("valid input")
34 {
35 ls_ expected;
36
37 SECTION("no arguments")
38 {
39 input = "ls";
40 }
41
42 SECTION("with path argument")
43 {
44 input = "ls example:a";
45 expected.m_path = path_{{node_(module_{"example"}, container_{"a"})}};
46 }
47
48 command_ command = parser.parseCommand(input, errorStream);
49 REQUIRE(command.type() == typeid(ls_));
50 REQUIRE(boost::get<ls_>(command) == expected);
51 }
52 SECTION("invalid input")
53 {
54 SECTION("invalid path")
55 {
56 input = "ls example:nonexistent";
57 }
58
59 REQUIRE_THROWS(parser.parseCommand(input, errorStream));
60 }
61}