agedit/pkg/env/env_test.go

31 lines
554 B
Go
Raw Normal View History

2024-03-11 20:23:36 -04:00
package env
import (
"os"
"testing"
)
var (
editors = []string{"hx", "nano", "vi", "vim", "nvim", "micro", "emacs", "ed"}
)
func clearEnvForNow() {
for _, item := range []string{"EDITOR", "VISUAL"} {
2024-05-29 16:39:34 -04:00
os.Unsetenv(item)
2024-03-11 20:23:36 -04:00
}
}
func TestEditorFromEnv(t *testing.T) {
for _, item := range []string{"EDITOR", "VISUAL"} {
clearEnvForNow()
for _, editor := range editors {
if err := os.Setenv(item, editor); err != nil {
t.Fatal(err)
}
if got := GetEditor(); got != editor {
t.Fatal("got", got, "but wanted", editor)
}
}
}
}