當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。