Skip to content

Commit

Permalink
Test mark-dir on and off.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisant996 committed Feb 28, 2021
1 parent 45f521b commit b299dac
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 86 deletions.
2 changes: 0 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`).

<br/>
<br/>
Expand Down
197 changes: 113 additions & 84 deletions clink/lib/test/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,95 +11,124 @@
#include <core/str_compare.h>
#include <lib/match_generator.h>

#include <readline/readline.h>

//------------------------------------------------------------------------------
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();
}
}
}

0 comments on commit b299dac

Please sign in to comment.