diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-07 04:48:35 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-07 04:48:35 +0000 |
commit | 207df6fc406e81bfeebdff7f404bd242ff3f099f (patch) | |
tree | a1a796b056909dd0a04ffec163db9363a8757808 /test/lnav_doctests.cc | |
parent | Releasing progress-linux version 0.11.2-1~progress7.99u1. (diff) | |
download | lnav-207df6fc406e81bfeebdff7f404bd242ff3f099f.tar.xz lnav-207df6fc406e81bfeebdff7f404bd242ff3f099f.zip |
Merging upstream version 0.12.2.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | test/lnav_doctests.cc | 69 |
1 files changed, 66 insertions, 3 deletions
diff --git a/test/lnav_doctests.cc b/test/lnav_doctests.cc index 423f807..78acf8d 100644 --- a/test/lnav_doctests.cc +++ b/test/lnav_doctests.cc @@ -30,12 +30,15 @@ #include "config.h" #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN +#include "base/from_trait.hh" #include "byte_array.hh" #include "data_scanner.hh" #include "doctest/doctest.h" #include "lnav_config.hh" #include "lnav_util.hh" +#include "ptimec.hh" #include "relative_time.hh" +#include "shlex.hh" #include "unique_path.hh" using namespace std; @@ -60,6 +63,66 @@ TEST_CASE("overwritten-logfile") { } #endif +TEST_CASE("shlex::eval") +{ + std::string cmdline1 = "${semantic_highlight_color}"; + + shlex lexer(cmdline1); + + std::map<std::string, scoped_value_t> vars = { + {"semantic_highlight_color", "foo"}, + }; + + std::string out; + auto rc = lexer.eval(out, scoped_resolver{&vars}); + CHECK(rc); + CHECK(out == "foo"); +} + +TEST_CASE("shlex::split") +{ + { + std::string cmdline1 = ""; + + std::map<std::string, scoped_value_t> vars; + shlex lexer(cmdline1); + auto split_res = lexer.split(scoped_resolver{&vars}); + CHECK(split_res.isOk()); + auto args = split_res.unwrap(); + CHECK(args.empty()); + } + { + std::string cmdline1 = ":sh --name=\"foo $BAR\" echo Hello!"; + + std::map<std::string, scoped_value_t> vars; + shlex lexer(cmdline1); + auto split_res = lexer.split(scoped_resolver{&vars}); + CHECK(split_res.isOk()); + auto args = split_res.unwrap(); + for (const auto& se : args) { + printf(" range %d:%d -- %s\n", + se.se_origin.sf_begin, + se.se_origin.sf_end, + se.se_value.c_str()); + } + } + { + std::string cmdline1 = "abc def $FOO ghi"; + + std::map<std::string, scoped_value_t> vars; + shlex lexer(cmdline1); + auto split_res = lexer.split(scoped_resolver{&vars}); + CHECK(split_res.isOk()); + auto args = split_res.unwrap(); + for (const auto& se : args) { + printf(" range %d:%d -- %s\n", + se.se_origin.sf_begin, + se.se_origin.sf_end, + se.se_value.c_str()); + } + } +} + TEST_CASE("byte_array") { using my_array_t = byte_array<8>; @@ -102,8 +165,8 @@ TEST_CASE("ptime_fmt") TEST_CASE("rgb_color from string") { - string name = "SkyBlue1"; - auto color = rgb_color::from_str(name).unwrap(); + const auto name = string_fragment::from_const("SkyBlue1"); + auto color = from<rgb_color>(name).unwrap(); CHECK(color.rc_r == 135); CHECK(color.rc_g == 215); CHECK(color.rc_b == 255); @@ -223,7 +286,7 @@ TEST_CASE("data_scanner CSI") CHECK(tok_res->tr_token == DT_CSI); CHECK(tok_res->to_string() == "\x1b[32m"); tok_res = ds.tokenize2(); - CHECK(tok_res->tr_token == DT_SYMBOL); + CHECK(tok_res->tr_token == DT_WORD); CHECK(tok_res->to_string() == "Hello"); tok_res = ds.tokenize2(); CHECK(tok_res->tr_token == DT_CSI); |