-
Notifications
You must be signed in to change notification settings - Fork 3
/
shell_parser_test.go
45 lines (36 loc) · 1.54 KB
/
shell_parser_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main_test
import (
"testing"
"github.com/dhamidi/leader"
"github.com/stretchr/testify/assert"
)
const (
printfDate = `printf "%s\n" "$(date)"`
escapedDoubleQuote = `printf "\"hello\"\n"`
printfDateSingle = `printf '%s\n' "$(date)"`
bindMixedQuotes = `bind -x '"\\":leader'`
)
func TestShellParser_InQuotedString_returns_true_if_cursor_is_inside_double_quotes(t *testing.T) {
parser := main.NewShellParser()
assert.True(t, parser.InQuotedString(printfDate, len(`printf "`)))
}
func TestShellParser_InQuotedString_returns_false_if_cursor_is_outside_of_double_quotes(t *testing.T) {
parser := main.NewShellParser()
assert.False(t, parser.InQuotedString(printfDate, len(`printf `)))
}
func TestShellParser_InQuotedString_returns_true_if_string_contains_escaped_double_quotes(t *testing.T) {
parser := main.NewShellParser()
assert.True(t, parser.InQuotedString(escapedDoubleQuote, len(`printf "\"h`)))
}
func TestShellParser_InQuotedString_returns_true_if_cursor_is_inside_single_quotes(t *testing.T) {
parser := main.NewShellParser()
assert.True(t, parser.InQuotedString(printfDateSingle, len(`printf '`)))
}
func TestShellParser_InQuotedString_returns_false_if_cursor_is_outside_of_single_quotes(t *testing.T) {
parser := main.NewShellParser()
assert.False(t, parser.InQuotedString(printfDateSingle, len(`printf `)))
}
func TestShellParser_InQuotedString_returns_true_if_cursor_is_inside_nested_quotes(t *testing.T) {
parser := main.NewShellParser()
assert.True(t, parser.InQuotedString(bindMixedQuotes, len(`bind -x '"\`)))
}