Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### master
- if installed use `gawk` instead of `awk` (@metcalfc)
- add stored search for matching git SHAs (@jbnicolai)
- add stored search for matching email addresses (@davidjb)

### v2.1.0, Jan 01, 2015
- combine send-keys calls to reduce flickering (@toupeira)
Expand Down
4 changes: 4 additions & 0 deletions copycat.tmux
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ set_default_stored_searches() {
local digit_search="$(get_tmux_option "$copycat_digit_search_option" "$default_digit_search_key")"
local hash_search="$(get_tmux_option "$copycat_hash_search_option" "$default_hash_search_key")"
local ip_search="$(get_tmux_option "$copycat_ip_search_option" "$default_ip_search_key")"
local email_search="$(get_tmux_option "$copycat_email_search_option" "$default_email_search_key")"

if stored_search_not_defined "$url_search"; then
tmux set-option -g "${COPYCAT_VAR_PREFIX}_${url_search}" "(https?://|git@|git://|ssh://|ftp://|file:///)[[:alnum:]?=%/_.:,;~@!#$&()*+-]*"
Expand All @@ -29,6 +30,9 @@ set_default_stored_searches() {
if stored_search_not_defined "$ip_search"; then
tmux set-option -g "${COPYCAT_VAR_PREFIX}_${ip_search}" "[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}"
fi
if stored_search_not_defined "$email_search"; then
tmux set-option -g "${COPYCAT_VAR_PREFIX}_${email_search}" '[[:alnum:].!#$%&*+/=?^_\`{|}~-]+@[[:alnum:]-]+(\.[[:alnum:]]+)*'
fi
}

set_start_bindings() {
Expand Down
3 changes: 3 additions & 0 deletions scripts/variables.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ copycat_hash_search_option="@copycat_hash_search"

default_ip_search_key="M-i"
copycat_ip_search_option="@copycat_ip_search"

default_email_search_key="C-e"
copycat_email_search_option="@copycat_email_search"
23 changes: 23 additions & 0 deletions test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,26 @@ Tests are written with the [expect tool](http://expect.sourceforge.net/).
From the `tmux copycat` project top directory run:

$ ./run-tests

### Debugging tests

In your tests, you can add a call to expect's interactive debugger with
``debug 1`` where you'd like to start debugging.

From the `tmux copycat` project top directory, bring up and access the given Vagrant VM:

$ vagrant up [ubuntu|centos]
$ vagrant ssh [ubuntu|centos]

and inside the VM, run the tests manually:

$ cd /vagrant
$ ./test/run-tests-within-vm

During this process, you can watch the progress of the tests interactively
by attaching yourself to the existing ``tmux`` server within the VM by
running ``tmux attach-session``. Note that there may be multiple sessions
and windows in use, depending on how many times your tests have run, so
check through each until you find the applicable one. Take care not to
disrupt the tests whilst running or you will encounter false results!

3 changes: 2 additions & 1 deletion test/helpers/expect_copycat_assertions.exp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ proc _display_highlighted_with_checker_text {checker} {
_copy_mode_copy
send ""
sleep 0.1
send "echo $checker"
send "echo '$checker"
sleep 0.1
_tmux_paste
send "'"
send "\r"
}

Expand Down
5 changes: 5 additions & 0 deletions test/helpers/expect_copycat_helpers.exp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ proc tmux_ctrl_t {} {
sleep 0.7
}

proc tmux_ctrl_e {} {
send ""
sleep 0.7
}

proc search {text} {
send "/"
sleep 0.2
Expand Down
2 changes: 1 addition & 1 deletion test/helpers/expect_helpers.exp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ proc clear_screen {} {
}

proc display_text {text} {
send "echo $text\r"
send "echo '$text'\r"
sleep 0.1
}

Expand Down
155 changes: 155 additions & 0 deletions test/test_email_search.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
#!/usr/bin/env expect

source "./test/helpers/setup.exp"

# searches at the top of the pane
#--------------------------------
display_text "[email protected]"
tmux_ctrl_e
assert_highlighted "[email protected]" "top of the pane, email"

new_tmux_pane
display_text "[email protected]"
tmux_ctrl_e
assert_highlighted "[email protected]" "top of the pane, email country code"

# middle of pane searches
#------------------------
new_tmux_pane
create_output
clear_screen
display_text "[email protected]"
tmux_ctrl_e
assert_highlighted "[email protected]" "middle of the pane, email, beginning of the line"

display_text "random [email protected]"
tmux_ctrl_e
assert_highlighted "[email protected]" "middle of the pane, email, not beginning of the line"

display_text "[email protected]"
tmux_ctrl_e
assert_highlighted "[email protected]" "middle of the pane, email, beginning of the line"

display_text "some text [email protected]"
tmux_ctrl_e
assert_highlighted "[email protected]" "middle of the pane, email, not beginning of the line"

create_output
sleep 0.2
send " [email protected] "
sleep 0.2
tmux_ctrl_e
assert_highlighted "[email protected]" "middle of the pane, email, pane bottom"

# other email structures
#-----------------------
new_tmux_pane
create_output
clear_screen

display_text "[email protected]"
tmux_ctrl_e
assert_highlighted "[email protected]" "middle of the pane, dotted email"

display_text "[email protected]"
tmux_ctrl_e
assert_highlighted "[email protected]" "middle of the pane, dotted email with plus"

display_text "[email protected]"
tmux_ctrl_e
assert_highlighted "[email protected]" "middle of the pane, new gTLDs, .mueseum"

display_text "[email protected]"
tmux_ctrl_e
assert_highlighted "[email protected]" "middle of the pane, new gTLDs, .party"

display_text "example.\!\#\$%&*+/=?^_`\{|\}[email protected]"
tmux_ctrl_e
assert_highlighted "example.\!\#\$%&*+/=?^_`\{|\}[email protected]" "middle of the pane, all special characters"

# emails in html
#---------------
new_tmux_pane
display_text "<a href='mailto:[email protected]?subject=Test'>asdf</a>"
tmux_ctrl_e
assert_highlighted "[email protected]" "email, subject in html"

# match selection when line contains escaped chars
#-------------------------------------------------
new_tmux_pane
display_text "User ID: example\r\nEmail: [email protected]\r\n"
tmux_ctrl_e
assert_highlighted "[email protected]" "match selection when line contains escaped chars"

# result navigation
#------------------
new_tmux_pane
display_text "[email protected]"
display_text "[email protected]"
display_text "[email protected]"
tmux_ctrl_e
# [email protected]
next_match
# [email protected]
next_match
# [email protected]
next_match
# [email protected]
next_match
# [email protected]
previous_match
# [email protected]
assert_highlighted "[email protected]" "result navigation at the top of the pane"

create_output
display_text "[email protected]"
display_text "[email protected]"
tmux_ctrl_e
# [email protected]
next_match
# [email protected]
next_match
# [email protected]
previous_match
# [email protected]
assert_highlighted "[email protected]" "result navigation, middle of the pane"

# 2 matches on the same line
#---------------------------
new_tmux_pane
display_text "[email protected] [email protected]"
tmux_ctrl_e
assert_highlighted "[email protected]" "2 matches on the same line, first match"

display_text "[email protected] [email protected]"
tmux_ctrl_e
next_match
assert_highlighted "[email protected]" "2 matches on the same line, second match"

# no match, first and last match
#-------------------------------
new_tmux_pane
tmux_ctrl_e
assert_on_screen "No results!" "No results is displayed when no results"

display_text "[email protected]"
tmux_ctrl_e
next_match
next_match
assert_on_screen "Last match!" "'Last match' is displayed when last match"
# exit copycat mode
send ""

new_tmux_pane
display_text "[email protected]"
tmux_ctrl_e
next_match
previous_match
previous_match
assert_on_screen "First match!" "'First match' is displayed when first match"
# exit copycat mode
send ""

# quit
#-----
teardown_and_exit
4 changes: 2 additions & 2 deletions test/test_file_search.exp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ next_match
# /file/1.txt
previous_match
# /file/2.txt
assert_highlighted " /file/2.txt" "result navigation at the top of the pane"
assert_highlighted "/file/2.txt" "result navigation at the top of the pane"

create_output
display_text "/file/1.txt"
Expand All @@ -79,7 +79,7 @@ next_match
# /file/1.txt
previous_match
# /file/2.txt
assert_highlighted " /file/2.txt" "result navigation, middle of the pane"
assert_highlighted "/file/2.txt" "result navigation, middle of the pane"

# 2 matches on the same line
#---------------------------
Expand Down