Refactor eval code (#1591)
* 1 * globsearch * hidden * some more options * ignorecase and ignoredia * fix ignorecase/ignoredia turns out position and loadfile are required here too since the list of files can change (similar to hidden option) * incfilter/incsearch * mouse * some more options * preview * remaining bool options * fix more options that can change list of files * Add applyLocalBoolOpt * Use applyLocalBoolOpt * Add position and loadfile fixes
This commit is contained in:
1 parent
8bbcbdd0ea
commit
8374080815
2 files changed
+272
-796
No files matched your search
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -537,3 +538,73 @@ func TestSplitKeys(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestApplyBoolOpt(t *testing.T) {
|
||||
tests := []struct {
|
||||
opt bool
|
||||
e setExpr
|
||||
exp bool
|
||||
}{
|
||||
{true, setExpr{"feature", ""}, true},
|
||||
{true, setExpr{"feature", "true"}, true},
|
||||
{true, setExpr{"feature", "false"}, false},
|
||||
{false, setExpr{"feature", ""}, true},
|
||||
{false, setExpr{"feature", "true"}, true},
|
||||
{false, setExpr{"feature", "false"}, false},
|
||||
{true, setExpr{"nofeature", ""}, false},
|
||||
{false, setExpr{"nofeature", ""}, false},
|
||||
{true, setExpr{"feature!", ""}, false},
|
||||
{false, setExpr{"feature!", ""}, true},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
testStr := fmt.Sprintf("%v", test)
|
||||
if err := applyBoolOpt(&test.opt, &test.e); err != nil {
|
||||
t.Errorf("at test '%s' expected '%t' but got an error '%s'", testStr, test.exp, err)
|
||||
continue
|
||||
}
|
||||
if test.opt != test.exp {
|
||||
t.Errorf("at test '%s' expected '%t' but got '%t'", testStr, test.exp, test.opt)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestApplyLocalBoolOpt(t *testing.T) {
|
||||
tests := []struct {
|
||||
localOpt map[string]bool
|
||||
globalOpt bool
|
||||
e setLocalExpr
|
||||
exp bool
|
||||
}{
|
||||
{map[string]bool{}, false, setLocalExpr{"/", "feature", ""}, true},
|
||||
{map[string]bool{}, false, setLocalExpr{"/", "feature", "true"}, true},
|
||||
{map[string]bool{}, false, setLocalExpr{"/", "feature", "false"}, false},
|
||||
{map[string]bool{}, false, setLocalExpr{"/", "nofeature", ""}, false},
|
||||
{map[string]bool{}, true, setLocalExpr{"/", "feature!", ""}, false},
|
||||
{map[string]bool{}, false, setLocalExpr{"/", "feature!", ""}, true},
|
||||
{map[string]bool{"/": true}, false, setLocalExpr{"/", "feature", ""}, true},
|
||||
{map[string]bool{"/": true}, false, setLocalExpr{"/", "feature", "true"}, true},
|
||||
{map[string]bool{"/": true}, false, setLocalExpr{"/", "feature", "false"}, false},
|
||||
{map[string]bool{"/": true}, false, setLocalExpr{"/", "nofeature", ""}, false},
|
||||
{map[string]bool{"/": true}, true, setLocalExpr{"/", "feature!", ""}, false},
|
||||
{map[string]bool{"/": true}, false, setLocalExpr{"/", "feature!", ""}, false},
|
||||
{map[string]bool{"/": false}, false, setLocalExpr{"/", "feature", ""}, true},
|
||||
{map[string]bool{"/": false}, false, setLocalExpr{"/", "feature", "true"}, true},
|
||||
{map[string]bool{"/": false}, false, setLocalExpr{"/", "feature", "false"}, false},
|
||||
{map[string]bool{"/": false}, false, setLocalExpr{"/", "nofeature", ""}, false},
|
||||
{map[string]bool{"/": false}, true, setLocalExpr{"/", "feature!", ""}, true},
|
||||
{map[string]bool{"/": false}, false, setLocalExpr{"/", "feature!", ""}, true},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
testStr := fmt.Sprintf("%v", test)
|
||||
if err := applyLocalBoolOpt(test.localOpt, test.globalOpt, &test.e); err != nil {
|
||||
t.Errorf("at test '%s' expected '%t' but got an error '%s'", testStr, test.exp, err)
|
||||
continue
|
||||
}
|
||||
result := test.localOpt[test.e.path]
|
||||
if result != test.exp {
|
||||
t.Errorf("at test '%s' expected '%t' but got '%t'", testStr, test.exp, result)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user