tmux_test.go
This file
Path
src/tmux_test.go
53 lines · 1.2 KiB · Go
Last changed by
Escape trailing semicolon in tmux command argumentJunegunn Choibefore adoption5763168
History of this fileTake it
1package fzf23import "testing"45func TestEscapeTmuxFormat(t *testing.T) {6 for _, tc := range []struct {7 given string8 expected string9 }{10 {"", ""},11 {" fzf ", " fzf "},12 {"100%", "100%"},13 // '#[' would be taken as a style directive when the label is drawn14 {"#[fg=red]x", "##[fg=red]x"},15 // '#{' is already literal in a substituted value, but doubling it16 // keeps a label that fzf renders itself looking the same17 {"#{pane_id}", "##{pane_id}"},18 {" C# notes #S ", " C## notes ##S "},19 {";", `\;`},20 {"; rm", "; rm"},21 {"C#;", `C##\;`},22 } {23 if actual := escapeTmuxFormat(tc.given); actual != tc.expected {24 t.Errorf("expected %q, got %q", tc.expected, actual)25 }26 }27}2829func TestEscapeTmuxSeparator(t *testing.T) {30 for _, tc := range []struct {31 given string32 expected string33 }{34 {"", ""},35 {" fzf ", " fzf "},36 {"#", "#"},37 {"#{pane_id}", "#{pane_id}"},38 {"100%", "100%"},39 // tmux drops a trailing ';' and everything after it, so only that40 // one is escaped41 {";", `\;`},42 {"abc;", `abc\;`},43 {";;", `;\;`},44 {`foo\;`, `foo\\;`},45 {"; rm", "; rm"},46 {" ; ", " ; "},47 {"a;b", "a;b"},48 } {49 if actual := escapeTmuxSeparator(tc.given); actual != tc.expected {50 t.Errorf("expected %q, got %q", tc.expected, actual)51 }52 }53}