dotfiles/dot_tmux/plugins/tmux-copycat/test/helpers/expect_copycat_assertions.exp

68 lines
1.4 KiB
Text
Raw Normal View History

2023-11-13 13:48:17 +01:00
# tmux copycat assertion helpers
# Asserts text that is crrently highlighted (in copy mode).
proc assert_highlighted {text message} {
set checker [ _generate_checker ]
# Asserted text first has to be 'yanked' and displayed before `expect`.
_display_highlighted_with_checker_text "$checker"
expect {
"$checker$text" { puts " Success: $message" }
timeout { puts " Fail: $message"; exit_status_false }
}
}
proc irb_assert_highlighted {text message} {
set checker [ _generate_checker ]
_irb_display_highlighted_with_checker_text "$checker"
expect {
"$checker$text" { puts " Success: $message" }
timeout { puts " Fail: $message"; exit_status_false }
}
}
proc assert_on_screen {text message} {
expect {
"$text" { puts " Success: $message" }
timeout { puts " Fail: $message"; exit_status_false }
}
}
# private functions
proc _generate_checker {} {
set random [ expr { rand()*10000 } ]
set checker "Checker $random:"
return $checker
}
proc _display_highlighted_with_checker_text {checker} {
_copy_mode_copy
send ""
sleep 0.1
send "echo $checker"
sleep 0.1
_tmux_paste
send "\r"
}
proc _irb_display_highlighted_with_checker_text {checker} {
_copy_mode_copy
send "\r"
sleep 0.1
send "puts '$checker"
sleep 0.1
_tmux_paste
send "'"
send "\r"
}
proc _copy_mode_copy {} {
send "y"
sleep 0.2
}
proc _tmux_paste {} {
send "]"
sleep 0.1
}