summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/acceptance/acceptance_test.rb26
-rw-r--r--test/test_choices.c16
2 files changed, 34 insertions, 8 deletions
diff --git a/test/acceptance/acceptance_test.rb b/test/acceptance/acceptance_test.rb
index 13af803..cbc6d45 100644
--- a/test/acceptance/acceptance_test.rb
+++ b/test/acceptance/acceptance_test.rb
@@ -447,6 +447,29 @@ class FzyTest < Minitest::Test
TTY
end
+ def test_field
+ @tty = interactive_fzy(input: %w[1/foo 2/bar], args: "-d/ -f2 -F1")
+ @tty.assert_matches(">\nfoo\nbar")
+
+ @tty.send_keys("foo\r")
+ @tty.assert_matches "1" # the first field
+ end
+
+ def test_field_input_only
+ @tty = interactive_fzy(input: %w[1:foo 2:bar], args: "-f2")
+ @tty.assert_matches ">\nfoo\nbar"
+
+ @tty.send_keys("bar\r")
+ @tty.assert_matches "2:bar" # the whole line
+
+ end
+
+ def test_field_ignored_line
+ # not enough fields for -f or -F
+ @tty = interactive_fzy(input: %w[1:foo:x 2:baz 3 4:bar:y], args: "-f2 -F3")
+ @tty.assert_matches ">\nfoo\nbar"
+ end
+
def test_show_info
@tty = interactive_fzy(input: %w[foo bar baz], args: "-i")
@tty.assert_matches ">\n[3/3]\nfoo\nbar\nbaz"
@@ -469,6 +492,9 @@ Usage: fzy [OPTION]...
-0, --read-null Read input delimited by ASCII NUL characters
-j, --workers NUM Use NUM workers for searching. (default is # of CPUs)
-i, --show-info Show selection info line
+ -d, --delimiter=DELIM Use DELIM to split the line to fields (default ':')
+ -f, --field=NUM Use field NUM for searching (default is the whole line)
+ -F, --output-field=NUM Use field NUM for output (default is the whole line)
-h, --help Display this help and exit
-v, --version Output version information and exit
TTY
diff --git a/test/test_choices.c b/test/test_choices.c
index d86bc12..b198d16 100644
--- a/test/test_choices.c
+++ b/test/test_choices.c
@@ -56,8 +56,8 @@ TEST test_choices_1() {
choices_next(&choices);
ASSERT_SIZE_T_EQ(0, choices.selection);
- ASSERT(!strcmp(choices_get(&choices, 0), "tags"));
- ASSERT_EQ(NULL, choices_get(&choices, 1));
+ ASSERT(!strcmp(choices_get_search(&choices, 0), "tags"));
+ ASSERT_EQ(NULL, choices_get_search(&choices, 1));
PASS();
}
@@ -85,7 +85,7 @@ TEST test_choices_2() {
choices_search(&choices, "te");
ASSERT_SIZE_T_EQ(1, choices.available);
ASSERT_SIZE_T_EQ(0, choices.selection);
- ASSERT_STR_EQ("test", choices_get(&choices, 0));
+ ASSERT_STR_EQ("test", choices_get_search(&choices, 0));
choices_next(&choices);
ASSERT_SIZE_T_EQ(0, choices.selection);
@@ -102,8 +102,8 @@ TEST test_choices_2() {
choices_search(&choices, "ts");
ASSERT_SIZE_T_EQ(2, choices.available);
ASSERT_SIZE_T_EQ(0, choices.selection);
- ASSERT_STR_EQ("test", choices_get(&choices, 0));
- ASSERT_STR_EQ("tags", choices_get(&choices, 1));
+ ASSERT_STR_EQ("test", choices_get_search(&choices, 0));
+ ASSERT_STR_EQ("tags", choices_get_search(&choices, 1));
PASS();
}
@@ -114,14 +114,14 @@ TEST test_choices_without_search() {
ASSERT_SIZE_T_EQ(0, choices.available);
ASSERT_SIZE_T_EQ(0, choices.selection);
ASSERT_SIZE_T_EQ(0, choices.size);
- ASSERT_EQ(NULL, choices_get(&choices, 0));
+ ASSERT_EQ(NULL, choices_get_search(&choices, 0));
choices_add(&choices, "test");
ASSERT_SIZE_T_EQ(0, choices.available);
ASSERT_SIZE_T_EQ(0, choices.selection);
ASSERT_SIZE_T_EQ(1, choices.size);
- ASSERT_EQ(NULL, choices_get(&choices, 0));
+ ASSERT_EQ(NULL, choices_get_search(&choices, 0));
PASS();
}
@@ -148,7 +148,7 @@ TEST test_choices_large_input() {
/* Must match `seq 0 99999 | grep '.*1.*2.*' | wc -l` */
ASSERT_SIZE_T_EQ(8146, choices.available);
- ASSERT_STR_EQ("12", choices_get(&choices, 0));
+ ASSERT_STR_EQ("12", choices_get_search(&choices, 0));
for(int i = 0; i < N; i++) {
free(strings[i]);