Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +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 "ast_commands.hpp" |
| 11 | #include "parser.hpp" |
| 12 | #include "static_schema.hpp" |
| 13 | |
| 14 | TEST_CASE("path_completion") |
| 15 | { |
| 16 | auto schema = std::make_shared<StaticSchema>(); |
| 17 | schema->addModule("example"); |
| 18 | schema->addModule("second"); |
| 19 | schema->addContainer("", "example:ano"); |
| 20 | schema->addContainer("", "example:anoda"); |
| 21 | schema->addList("example:ano", "example:listInCont", {"number"}); |
| 22 | schema->addContainer("", "second:amelie"); |
| 23 | schema->addContainer("", "example:bota"); |
| 24 | schema->addContainer("example:ano", "example:a2"); |
| 25 | schema->addContainer("example:bota", "example:b2"); |
| 26 | schema->addContainer("example:ano/example:a2", "example:a3"); |
| 27 | schema->addContainer("example:bota/example:b2", "example:b3"); |
| 28 | schema->addList("", "example:list", {"number"}); |
| 29 | schema->addContainer("example:list", "example:contInList"); |
| 30 | schema->addList("", "example:twoKeyList", {"number", "name"}); |
| 31 | Parser parser(schema); |
| 32 | std::string input; |
| 33 | std::ostringstream errorStream; |
| 34 | std::set<std::string> expected; |
| 35 | |
| 36 | SECTION("ls ") |
| 37 | { |
| 38 | input = "ls "; |
| 39 | expected = {"example:ano", "example:anoda", "example:bota", "second:amelie", "example:list", "example:twoKeyList"}; |
| 40 | } |
| 41 | |
| 42 | SECTION("ls e") |
| 43 | { |
| 44 | input = "ls e"; |
| 45 | expected = {"xample:ano", "xample:anoda", "xample:bota", "xample:list", "xample:twoKeyList"}; |
| 46 | } |
| 47 | |
| 48 | SECTION("ls example:ano") |
| 49 | { |
| 50 | input = "ls example:ano"; |
| 51 | expected = {"", "da"}; |
| 52 | } |
| 53 | |
| 54 | SECTION("ls example:ano/example:a") |
| 55 | { |
| 56 | input = "ls example:ano/example:a"; |
| 57 | expected = {"2"}; |
| 58 | } |
| 59 | |
| 60 | SECTION("ls x") |
| 61 | { |
| 62 | input = "ls x"; |
| 63 | expected = {}; |
| 64 | } |
| 65 | |
| 66 | SECTION("ls /") |
| 67 | { |
| 68 | input = "ls /"; |
| 69 | expected = {"example:ano", "example:anoda", "example:bota", "second:amelie", "example:list", "example:twoKeyList"}; |
| 70 | } |
| 71 | |
| 72 | SECTION("ls /e") |
| 73 | { |
| 74 | input = "ls /e"; |
| 75 | expected = {"xample:ano", "xample:anoda", "xample:bota", "xample:list", "xample:twoKeyList"}; |
| 76 | } |
| 77 | |
| 78 | SECTION("ls /s") |
| 79 | { |
| 80 | input = "ls /s"; |
| 81 | expected = {"econd:amelie"}; |
| 82 | } |
| 83 | |
| 84 | SECTION("ls /example:list[number=3]/") |
| 85 | { |
| 86 | input = "ls /example:list[number=3]/"; |
| 87 | expected = {"example:contInList"}; |
| 88 | } |
| 89 | |
| 90 | SECTION("ls /example:list[number=3]/c") |
| 91 | { |
| 92 | input = "ls /example:list[number=3]/e"; |
| 93 | expected = {"xample:contInList"}; |
| 94 | } |
| 95 | |
| 96 | SECTION("ls /example:list[number=3]/a") |
| 97 | { |
| 98 | input = "ls /example:list[number=3]/a"; |
| 99 | expected = {}; |
| 100 | } |
| 101 | |
| 102 | REQUIRE(parser.completeCommand(input, errorStream) == expected); |
| 103 | } |