当前位置: 首页>>代码示例>>Golang>>正文


Golang loaders.LoadJSON函数代码示例

本文整理汇总了Golang中github.com/limetext/lime/backend/loaders.LoadJSON函数的典型用法代码示例。如果您正苦于以下问题:Golang LoadJSON函数的具体用法?Golang LoadJSON怎么用?Golang LoadJSON使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了LoadJSON函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestParent

func TestParent(t *testing.T) {
	fn := "testdata/Default.sublime-keymap"
	fnp := "testdata/test.sublime-keymap"
	var (
		bd KeyBindings
		p  HasKeyBindings
	)

	d, err := ioutil.ReadFile(fn)
	if err != nil {
		t.Fatalf("Couldn't read %s: %s", fn, err)
	}
	if err = loaders.LoadJSON(d, &bd); err != nil {
		t.Fatalf("Error loading json: %s", err)
	}

	d, err = ioutil.ReadFile(fnp)
	if err != nil {
		t.Fatalf("Couldn't read %s: %s", fn, err)
	}
	if err = loaders.LoadJSON(d, p.KeyBindings()); err != nil {
		t.Fatalf("Error loading json: %s", err)
	}

	bd.SetParent(&p)

	if cmd := bd.Parent().KeyBindings().Bindings[0].Command; cmd != "t2" {
		t.Errorf("Expected Command %s, but got %s", "t2", cmd)
	}
}
开发者ID:rokite,项目名称:lime,代码行数:30,代码来源:keybinding_test.go

示例2: TestKeyBindingsAction

func TestKeyBindingsAction(t *testing.T) {
	tests := []struct {
		kp     KeyPress
		retNil bool
		ck     string
	}{
		{
			KeyPress{Key: 'i'},
			false,
			"test3",
		},
		{
			KeyPress{Key: 'p'},
			false,
			"t2",
		},
		{
			KeyPress{Key: 'i', Ctrl: true},
			true,
			"",
		},
		{
			KeyPress{Key: 'c'},
			false,
			"t5",
		},
	}

	if d, err := ioutil.ReadFile("testdata/Default.sublime-keymap"); err != nil {
		t.Fatal(err)
	} else {
		var (
			bindings KeyBindings
			p        HasKeyBindings
		)
		loaders.LoadJSON(d, &bindings)

		if d, err = ioutil.ReadFile("testdata/test.sublime-keymap"); err != nil {
			t.Fatal(err)
		}
		loaders.LoadJSON(d, p.KeyBindings())
		bindings.SetParent(&p)

		for i, test := range tests {
			qc := func(key string, operator util.Op, operand interface{}, match_all bool) bool {
				return key == test.ck
			}
			b := bindings.Filter(test.kp)
			if a := b.Action(qc); test.retNil {
				if a != nil {
					t.Errorf("Test %d: Expected action to be nil but got %v", i, a)
				}
			} else if a.Context[0].Key != test.ck {
				t.Errorf("Test %d: Expected %s, but got %s", i, test.ck, a.Context[0].Key)
			}
		}
	}
}
开发者ID:rokite,项目名称:lime,代码行数:58,代码来源:keybinding_test.go

示例3: TestKeyBindingsFilter

func TestKeyBindingsFilter(t *testing.T) {
	tests := []struct {
		kp    KeyPress
		count int
	}{
		{
			KeyPress{Key: 'i', Ctrl: true},
			2,
		},
		{
			KeyPress{Key: 'i'},
			1,
		},
	}

	if d, err := ioutil.ReadFile("testdata/Default.sublime-keymap"); err == nil {
		var bindings KeyBindings
		loaders.LoadJSON(d, &bindings)

		for i, test := range tests {
			if b := bindings.Filter(test.kp); b.Len() != test.count {
				t.Errorf("Test %d: Expected %d bindings, but got %d", i, test.count, b.Len())
			}
		}
	}
}
开发者ID:ericcapricorn,项目名称:lime,代码行数:26,代码来源:keybinding_test.go

示例4: 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)
		}

		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)
		}
	}
}
开发者ID:EDi-nabi,项目名称:lime,代码行数:32,代码来源:key_test.go

示例5: 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 {
		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)
		}
	}
}
开发者ID:EDi-nabi,项目名称:lime,代码行数:26,代码来源:key_test.go

示例6: TestKeyBindingsAction

func TestKeyBindingsAction(t *testing.T) {
	tests := []struct {
		kp KeyPress
		ck string
	}{
		{
			KeyPress{Key: 'i'},
			"test3",
		},
	}

	if d, err := ioutil.ReadFile("testdata/Default.sublime-keymap"); err == nil {
		var bindings KeyBindings
		loaders.LoadJSON(d, &bindings)

		for i, test := range tests {
			qc := func(key string, operator util.Op, operand interface{}, match_all bool) bool {
				return key == test.ck
			}
			b := bindings.Filter(test.kp)
			if a := b.Action(qc); a.Context[0].Key != test.ck {
				t.Errorf("Test %d: Expected %s, but got %s", i, test.ck, a.Context[0].Key)
			}
		}
	}
}
开发者ID:ericcapricorn,项目名称:lime,代码行数:26,代码来源:keybinding_test.go

示例7: loadSetting

func (e *Editor) loadSetting(pkg *packet) {
	if err := loaders.LoadJSON(pkg.Get().([]byte), e.Settings()); err != nil {
		log4go.Error(err)
	} else {
		log4go.Info("Loaded %s", pkg.Name())
		e.Watch(NewWatchedPackage(pkg))
	}
}
开发者ID:rikipy,项目名称:lime,代码行数:8,代码来源:editor.go

示例8: loadKeyBinding

func (e *Editor) loadKeyBinding(pkg *packet) {
	if err := loaders.LoadJSON(pkg.Get().([]byte), pkg); err != nil {
		log4go.Error(err)
	} else {
		log4go.Info("Loaded %s", pkg.Name())
		e.Watch(NewWatchedPackage(pkg))
	}
	e.keyBindings.merge(pkg.marshalTo.(*KeyBindings))
}
开发者ID:EDi-nabi,项目名称:lime,代码行数:9,代码来源:editor.go

示例9: TestSetParent

func TestSetParent(t *testing.T) {
	fn := "testdata/Default.sublime-keymap"
	fnp := "testdata/test.sublime-keymap"
	var (
		bd KeyBindings
		p  HasKeyBindings
	)

	d, err := ioutil.ReadFile(fn)
	if err != nil {
		t.Fatalf("Couldn't read %s: %s", fn, err)
	}
	if err = loaders.LoadJSON(d, &bd); err != nil {
		t.Fatalf("Error loading json: %s", err)
	}
	d, err = ioutil.ReadFile(fnp)
	if err != nil {
		t.Fatalf("Couldn't read %s: %s", fn, err)
	}
	if err = loaders.LoadJSON(d, p.KeyBindings()); err != nil {
		t.Fatalf("Error loading json: %s", err)
	}

	p.KeyBindings().seqIndex = 10
	bd.SetParent(&p)
	if bd.seqIndex != p.KeyBindings().seqIndex {
		t.Fatalf("Expected parent and child seqIndex be equal %d != %d", p.KeyBindings().seqIndex, bd.seqIndex)
	}

	ret := bd.Filter(KeyPress{Key: 'd', Ctrl: true})
	if ret.Len() != 1 {
		t.Fatalf("Expected ret keyBindings len %d, but got %d", 1, ret.Len())
	}
	if ret.parent.KeyBindings().Len() != 1 {
		t.Fatalf("Expected ret parent keyBindings len %d, but got %d", 1, ret.parent.KeyBindings().Len())
	}
	if cmd := ret.Bindings[0].Command; cmd != "test4" {
		t.Errorf("Expected Command %s, but got %s", "test4", cmd)
	}
	if cmd := ret.parent.KeyBindings().Bindings[0].Command; cmd != "t1" {
		t.Errorf("Expected Command %s, but got %s", "t1", cmd)
	}
}
开发者ID:rokite,项目名称:lime,代码行数:43,代码来源:keybinding_test.go

示例10: 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)
	}
}
开发者ID:jlneder,项目名称:lime,代码行数:11,代码来源:editor.go

示例11: loadKeybinding

func (e *Editor) loadKeybinding(fn string) {
	d, err := ioutil.ReadFile(fn)
	if err != nil {
		log4go.Error("Couldn't load file %s: %s", fn, err)
	}
	var bindings KeyBindings
	if err := loaders.LoadJSON(d, &bindings); err != nil {
		log4go.Error(err)
	} else {
		log4go.Info("Loaded %s", fn)
	}
	e.keyBindings.merge(&bindings)
}
开发者ID:jlneder,项目名称:lime,代码行数:13,代码来源:editor.go

示例12: TestLoadKeyBindingsFromJSON

func TestLoadKeyBindingsFromJSON(t *testing.T) {
	tests := []string{
		"testdata/Default.sublime-keymap",
	}
	for i, fn := range tests {
		if d, err := ioutil.ReadFile(fn); err != nil {
			t.Errorf("Test %d: Couldn't load file %s: %s", i, fn, err)
		} else {
			var bindings KeyBindings
			if err := loaders.LoadJSON(d, &bindings); err != nil {
				t.Errorf("Test %d: Error on LoadJSON: %s", i, err)
			}
		}
	}
}
开发者ID:rokite,项目名称:lime,代码行数:15,代码来源:keybinding_test.go

示例13: TestDropLessEqualKeys

func TestDropLessEqualKeys(t *testing.T) {
	fn := "testdata/Default.sublime-keymap"
	d, err := ioutil.ReadFile(fn)
	if err != nil {
		t.Fatalf("Couldn't read %s: %s", fn, err)
	}

	var bd KeyBindings
	if err = loaders.LoadJSON(d, &bd); err != nil {
		t.Fatalf("Error loading json: %s", err)
	}
	bd.DropLessEqualKeys(1)
	if cmd := bd.Bindings[0].Command; cmd != "test2" {
		t.Errorf("Expected Command %s, but got %s", "test2", cmd)
	}
}
开发者ID:rokite,项目名称:lime,代码行数:16,代码来源:keybinding_test.go

示例14: 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)
		}
	}
}
开发者ID:EDi-nabi,项目名称:lime,代码行数:17,代码来源:key_test.go

示例15: TestLoadKeyBindingsFromJSON

func TestLoadKeyBindingsFromJSON(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)
			}
		}
	}
}
开发者ID:EDi-nabi,项目名称:lime,代码行数:17,代码来源:key_test.go


注:本文中的github.com/limetext/lime/backend/loaders.LoadJSON函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。