| 1 |
package fzf |
| 2 |
|
| 3 |
import "testing" |
| 4 |
|
| 5 |
func TestEscapeTmuxFormat(t *testing.T) { |
| 6 |
for _, tc := range []struct { |
| 7 |
given string |
| 8 |
expected string |
| 9 |
}{ |
| 10 |
{"", ""}, |
| 11 |
{" fzf ", " fzf "}, |
| 12 |
{"100%", "100%"}, |
| 13 |
// '#[' would be taken as a style directive when the label is drawn |
| 14 |
{"#[fg=red]x", "##[fg=red]x"}, |
| 15 |
// '#{' is already literal in a substituted value, but doubling it |
| 16 |
// keeps a label that fzf renders itself looking the same |
| 17 |
{"#{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 |
} |
| 28 |
|
| 29 |
func TestEscapeTmuxSeparator(t *testing.T) { |
| 30 |
for _, tc := range []struct { |
| 31 |
given string |
| 32 |
expected string |
| 33 |
}{ |
| 34 |
{"", ""}, |
| 35 |
{" fzf ", " fzf "}, |
| 36 |
{"#", "#"}, |
| 37 |
{"#{pane_id}", "#{pane_id}"}, |
| 38 |
{"100%", "100%"}, |
| 39 |
// tmux drops a trailing ';' and everything after it, so only that |
| 40 |
// one is escaped |
| 41 |
{";", `\;`}, |
| 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 |
} |