From f59d5d1b62b1c2b2f505acc535c798e7c47974df Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Tue, 24 Nov 2020 11:33:20 +0100 Subject: Add support for restricting search/output to specific fields. --- test/acceptance/acceptance_test.rb | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'test/acceptance/acceptance_test.rb') 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 -- cgit v1.2.3