forked from dhamidi/leader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shell_test.go
103 lines (89 loc) · 2.6 KB
/
shell_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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package main_test
import (
"io/ioutil"
"os"
"testing"
"github.com/dhamidi/leader"
"github.com/stretchr/testify/assert"
)
func TestBash_Commandline_extracts_info_from_environment(t *testing.T) {
getenv := func(name string) string {
switch name {
case "READLINE_LINE":
return "line"
case "READLINE_POINT":
return "1"
default:
return ""
}
}
bash := main.NewBashShell(getenv)
line, cursor := bash.Commandline()
assert.Equal(t, "line", line)
assert.Equal(t, 1, cursor)
}
func TestBash_EvalNext_emits_eval_command_for_invoking_leader(t *testing.T) {
bash := main.NewBashShell(os.Getenv)
evalNext := bash.EvalNext("date", []rune("/"))
assert.Equal(t, `date; eval "$(leader print @/)"`, evalNext)
}
func TestBash_Init_returns_shell_script_for_bash_initialization(t *testing.T) {
bash := main.NewBashShell(os.Getenv)
initCode, err := ioutil.ReadFile("./assets/leader.bash.sh")
assert.NoError(t, err)
assert.Equal(t, string(initCode), bash.Init())
}
func TestZSH_Commandline_extracts_info_from_environment(t *testing.T) {
getenv := func(name string) string {
switch name {
case "BUFFER":
return "line"
case "CURSOR":
return "1"
default:
return ""
}
}
zsh := main.NewZSHShell(getenv)
line, cursor := zsh.Commandline()
assert.Equal(t, "line", line)
assert.Equal(t, 1, cursor)
}
func TestZSH_EvalNext_emits_eval_command_for_invoking_leader(t *testing.T) {
zsh := main.NewZSHShell(os.Getenv)
evalNext := zsh.EvalNext("date", []rune("/"))
assert.Equal(t, `date; eval "$(leader print @/)"`, evalNext)
}
func TestZSH_Init_returns_shell_script_for_bash_initialization(t *testing.T) {
zsh := main.NewZSHShell(os.Getenv)
initCode, err := ioutil.ReadFile("./assets/leader.zsh.sh")
assert.NoError(t, err)
assert.Equal(t, string(initCode), zsh.Init())
}
func TestFish_Commandline_extracts_info_by_running_commandline(t *testing.T) {
getenv := func(name string) string {
switch name {
case "FISH_INPUT":
return "line"
case "FISH_POINT":
return "1"
default:
return ""
}
}
fish := main.NewFishShell(getenv)
line, cursor := fish.Commandline()
assert.Equal(t, "line", line)
assert.Equal(t, 1, cursor)
}
func TestFish_EvalNext_emits_eval_command_for_invoking_leader(t *testing.T) {
fish := main.NewFishShell(os.Getenv)
evalNext := fish.EvalNext("date", []rune("/"))
assert.Equal(t, `date; eval (leader print @/)`, evalNext)
}
func TestFish_Init_returns_shell_script_for_bash_initialization(t *testing.T) {
fish := main.NewFishShell(os.Getenv)
initCode, err := ioutil.ReadFile("./assets/leader.fish.sh")
assert.NoError(t, err)
assert.Equal(t, string(initCode), fish.Init())
}