本文整理汇总了Golang中lime/backend/loaders.LoadJSON函数的典型用法代码示例。如果您正苦于以下问题:Golang LoadJSON函数的具体用法?Golang LoadJSON怎么用?Golang LoadJSON使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了LoadJSON函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestVintageous
func TestVintageous(t *testing.T) {
fn := "testdata/Vintageous.sublime-keymap"
ed := GetEditor()
w := ed.NewWindow()
v := w.NewFile()
v.Settings().Set("command_mode", true)
OnQueryContext.Add(func(v *View, key string, op Op, operand interface{}, match_all bool) QueryContextReturn {
if key == "vi_has_action" {
return True
}
return Unknown
})
if d, err := ioutil.ReadFile(fn); err != nil {
t.Errorf("Couldn't load file %s: %s", fn, err)
} else {
var bindings KeyBindings
if err := loaders.LoadJSON(d, &bindings); err != nil {
t.Error(err)
}
t.Log(bindings)
b2 := bindings.Filter(KeyPress{Key: 'g'})
if a := b2.Action(v); a == nil || a.Command != "set_action" {
t.Error(a)
}
b2 = b2.Filter(KeyPress{Key: 'g'})
if a := b2.Action(v); a == nil || a.Command != "set_motion" {
t.Error(a)
}
}
}
示例2: TestKeyFilter2
func TestKeyFilter2(t *testing.T) {
ed := GetEditor()
w := ed.NewWindow()
v := w.NewFile()
enable := "test1"
OnQueryContext.Add(func(v *View, key string, operator Op, operand interface{}, match_all bool) QueryContextReturn {
t.Log("Querying for", key)
if key == enable {
return True
}
return Unknown
})
fn := "testdata/Default.sublime-keymap"
if d, err := ioutil.ReadFile(fn); err != nil {
t.Errorf("Couldn't load file %s: %s", fn, err)
} else {
var bindings KeyBindings
if err := loaders.LoadJSON(d, &bindings); err != nil {
t.Error(err)
}
b2 := bindings.Filter(KeyPress{Key: 'i'})
a := b2.Action(v)
if a.Context[0].Key != enable {
t.Error(b2, a)
}
}
}
示例3: loadSetting
func (e *Editor) loadSetting(fn string) {
if d, err := ioutil.ReadFile(fn); err != nil {
log4go.Error("Couldn't load file %s: %s", fn, err)
} else {
if err := loaders.LoadJSON(d, e.Settings()); err != nil {
log4go.Error(err)
} else {
log4go.Info("Loaded %s", fn)
}
}
}
示例4: loadSetting
func (e *Editor) loadSetting(path string) {
d, err := ioutil.ReadFile(path)
if err != nil {
log4go.Error("Couldn't load file %s: %s", path, err)
}
if err := loaders.LoadJSON(d, e.Settings()); err != nil {
log4go.Error(err)
} else {
log4go.Info("Loaded %s", path)
}
}
示例5: loadKeybinding
func (e *Editor) loadKeybinding(fn string) {
if d, err := ioutil.ReadFile(fn); err != nil {
log4go.Error("Couldn't load file %s: %s", fn, err)
} else {
var bindings KeyBindings
if err := loaders.LoadJSON(d, &bindings); err != nil {
log4go.Error(err)
} else {
log4go.Info("Loaded %s", fn)
}
e.keyBindings.merge(&bindings)
}
}
示例6: TestKeyFilter
func TestKeyFilter(t *testing.T) {
fn := "loaders/json/testdata/Default (OSX).sublime-keymap"
if d, err := ioutil.ReadFile(fn); err != nil {
t.Errorf("Couldn't load file %s: %s", fn, err)
} else {
var bindings KeyBindings
if err := loaders.LoadJSON(d, &bindings); err != nil {
t.Error(err)
}
if b2 := bindings.Filter(KeyPress{Key: 'j', Ctrl: true}); b2.Len() != 3 {
t.Errorf("Not of the expected length: %d, %s", 3, b2)
} else if b3 := b2.Filter(KeyPress{Key: 's'}); b3.Len() != 1 {
t.Errorf("Not of the expected length: %d, %s", 1, b3)
}
}
}
示例7: TestLoadKeyBindings
func TestLoadKeyBindings(t *testing.T) {
tests := []string{
"loaders/json/testdata/Default (OSX).sublime-keymap",
}
for i, fn := range tests {
if d, err := ioutil.ReadFile(fn); err != nil {
if i == 0 {
t.Errorf("Couldn't load file %s: %s", fn, err)
}
} else {
var bindings KeyBindings
if err := loaders.LoadJSON(d, &bindings); err != nil {
t.Error(err)
}
}
}
}
示例8: TestLoadKeyBindings
func TestLoadKeyBindings(t *testing.T) {
tests := []string{
"loaders/json/testdata/Default (OSX).sublime-keymap",
// "/Users/quarnster/Library/Application Support/Sublime Text 3/Packages/Default/Default (Linux).sublime-keymap",
// "/Users/quarnster/Library/Application Support/Sublime Text 3/Packages/Default/Default (OSX).sublime-keymap",
// "/Users/quarnster/Library/Application Support/Sublime Text 3/Packages/Default/Default (Windows).sublime-keymap",
}
for i, fn := range tests {
if d, err := ioutil.ReadFile(fn); err != nil {
if i == 0 {
t.Errorf("Couldn't load file %s: %s", fn, err)
} else {
t.Logf("Skipping: Couldn't load file %s: %s", fn, err)
}
} else {
var bindings KeyBindings
if err := loaders.LoadJSON(d, &bindings); err != nil {
t.Error(err)
}
}
}
}