From b299dacaa0b5dd232537ce9e009631614de10f4e Mon Sep 17 00:00:00 2001 From: Chris Antos Date: Sun, 28 Feb 2021 03:43:05 -0800 Subject: [PATCH] Test mark-dir on and off. --- TODO.md | 2 - clink/lib/test/file.cpp | 197 +++++++++++++++++++++++----------------- 2 files changed, 113 insertions(+), 86 deletions(-) diff --git a/TODO.md b/TODO.md index 66191cc7a..44455d37f 100644 --- a/TODO.md +++ b/TODO.md @@ -31,8 +31,6 @@ _This todo list describes ChrisAnt996's current intended roadmap for Clink's fut - But the hard part is handling duplicates (especially with different match types). Could maybe pass the index in the matches array, but that requires tighter interdependence between Readline and its host. ## Tests -- The tests use the current user's .inputrc file, but they should use preset values instead. -- Add tests for `mark-directories` off vs on to make sure both work correctly (for both `complete` and `menu-complete`).

diff --git a/clink/lib/test/file.cpp b/clink/lib/test/file.cpp index 8cb4d5e33..5088ce536 100644 --- a/clink/lib/test/file.cpp +++ b/clink/lib/test/file.cpp @@ -11,95 +11,124 @@ #include #include +#include + +//------------------------------------------------------------------------------ +static const char* dyn_section(const char* section, const char* mode) +{ + static char buf[128]; + sprintf_s(buf, "%s (%s)", section, mode); + return buf; +} + //------------------------------------------------------------------------------ TEST_CASE("File match generator") { fs_fixture fs; - line_editor_tester tester; - tester.get_editor()->add_generator(file_match_generator()); - - SECTION("File system matches") - { - tester.set_input(""); - tester.set_expected_matches("case_map-1", "case_map_2", "dir1\\", - "dir2\\", "file1", "file2"); - tester.run(); - } - - SECTION("Single file") - { - tester.set_input("file1"); - tester.set_expected_matches("file1"); - tester.run(); - } - - SECTION("Single dir") - { - tester.set_input("dir1"); - tester.set_expected_matches("dir1\\"); - tester.run(); - } - - SECTION("Dir slash flip") - { - tester.set_input("dir1/" DO_COMPLETE); - tester.set_expected_matches("dir1\\only", "dir1\\file1", "dir1\\file2"); - tester.set_expected_output("dir1\\"); - tester.run(); - } - - SECTION("Path slash flip") - { - tester.set_input("dir1/on" DO_COMPLETE); - tester.set_expected_output("dir1\\only "); - tester.run(); - } - - SECTION("Case mapping matches") - { - str_compare_scope _(str_compare_scope::relaxed); - - tester.set_input("case-m" DO_COMPLETE); - tester.set_expected_matches("case_map-1", "case_map_2"); - tester.set_expected_output("case_map"); - tester.run(); - } - - SECTION("Relative") - { - REQUIRE(os::set_current_dir("dir1")); - - tester.set_input("../dir1/on" DO_COMPLETE); - tester.set_expected_output("..\\dir1\\only "); - tester.run(); - - REQUIRE(os::set_current_dir("..")); - } - - SECTION("cmd-style drive relative") - { - str<280> fs_path; - path::join(fs.get_root(), "dir1", fs_path); - - const char* env_vars[] = { "=m:", fs_path.c_str(), nullptr }; - - env_fixture env(env_vars); - tester.set_input("m:" DO_COMPLETE); - tester.set_expected_output("m:"); - tester.set_expected_matches("m:only", "m:file1", "m:file2"); - tester.run(); - } - SECTION("redundant separators") + static const char* env_inputrc[] = { + "clink_inputrc", "dummy_to_use_defaults", + nullptr + }; + env_fixture env(env_inputrc); + + static const char* inputrc_vars[] = { + "set mark-directories on", "mark-dir=ON", + "set mark-directories off", "mark-dir=off", + nullptr + }; + for (int v = 0; inputrc_vars[v]; v += 2) { - tester.set_input("dir1\\\\\\" DO_COMPLETE); - tester.set_expected_matches("dir1\\only", "dir1\\file1", "dir1\\file2"); - tester.set_expected_output("dir1\\"); - tester.run(); - - tester.set_input("dir1\\\\\\f" DO_COMPLETE); - tester.set_expected_matches("dir1\\file1", "dir1\\file2"); - tester.set_expected_output("dir1\\file"); - tester.run(); + const char* mode = inputrc_vars[v + 1]; + str<> setvar(inputrc_vars[v]); + REQUIRE(rl_parse_and_bind(setvar.data()) == 0); + + line_editor_tester tester; + tester.get_editor()->add_generator(file_match_generator()); + + SECTION(dyn_section("File system matches", mode)) + { + tester.set_input(""); + tester.set_expected_matches("case_map-1", "case_map_2", "dir1\\", + "dir2\\", "file1", "file2"); + tester.run(); + } + + SECTION(dyn_section("Single file", mode)) + { + tester.set_input("file1"); + tester.set_expected_matches("file1"); + tester.run(); + } + + SECTION(dyn_section("Single dir", mode)) + { + tester.set_input("dir1"); + tester.set_expected_matches("dir1\\"); + tester.run(); + } + + SECTION(dyn_section("Dir slash flip", mode)) + { + tester.set_input("dir1/" DO_COMPLETE); + tester.set_expected_matches("dir1\\only", "dir1\\file1", "dir1\\file2"); + tester.set_expected_output("dir1\\"); + tester.run(); + } + + SECTION(dyn_section("Path slash flip", mode)) + { + tester.set_input("dir1/on" DO_COMPLETE); + tester.set_expected_output("dir1\\only "); + tester.run(); + } + + SECTION(dyn_section("Case mapping matches", mode)) + { + str_compare_scope _(str_compare_scope::relaxed); + + tester.set_input("case-m" DO_COMPLETE); + tester.set_expected_matches("case_map-1", "case_map_2"); + tester.set_expected_output("case_map"); + tester.run(); + } + + SECTION(dyn_section("Relative", mode)) + { + REQUIRE(os::set_current_dir("dir1")); + + tester.set_input("../dir1/on" DO_COMPLETE); + tester.set_expected_output("..\\dir1\\only "); + tester.run(); + + REQUIRE(os::set_current_dir("..")); + } + + SECTION(dyn_section("cmd-style drive relative", mode)) + { + str<280> fs_path; + path::join(fs.get_root(), "dir1", fs_path); + + const char* env_vars[] = { "=m:", fs_path.c_str(), nullptr }; + + env_fixture env(env_vars); + tester.set_input("m:" DO_COMPLETE); + tester.set_expected_output("m:"); + tester.set_expected_matches("m:only", "m:file1", "m:file2"); + tester.run(); + } + + SECTION(dyn_section("redundant separators", mode)) + { + tester.set_input("dir1\\\\\\" DO_COMPLETE); + tester.set_expected_matches("dir1\\only", "dir1\\file1", "dir1\\file2"); + tester.set_expected_output("dir1\\"); + tester.run(); + + tester.set_input("dir1\\\\\\f" DO_COMPLETE); + tester.set_expected_matches("dir1\\file1", "dir1\\file2"); + tester.set_expected_output("dir1\\file"); + tester.run(); + } } }