示例#1
0
func TestLoadTheme(t *testing.T) {
	type Test struct {
		in  string
		out string
	}
	tests := []Test{
		{
			"testdata/Monokai.tmTheme",
			"testdata/Monokai.tmTheme.res",
		},
	}
	for _, test := range tests {
		if d, err := ioutil.ReadFile(test.in); err != nil {
			t.Logf("Couldn't load file %s: %s", test.in, err)
		} else {
			var theme Theme
			if err := loaders.LoadPlist(d, &theme); err != nil {
				t.Error(err)
			} else {
				str := fmt.Sprintf("%s", theme)
				if d, err := ioutil.ReadFile(test.out); err != nil {
					if err := ioutil.WriteFile(test.out, []byte(str), 0644); err != nil {
						t.Error(err)
					}
				} else if diff := util.Diff(string(d), str); diff != "" {
					t.Error(diff)
				}

			}
		}
	}
}
示例#2
0
func LoadTheme(filename string) (*Theme, error) {
	var scheme Theme
	if d, err := ioutil.ReadFile(filename); err != nil {
		return nil, fmt.Errorf("Unable to load colorscheme definition: %s", err)
	} else if err := loaders.LoadPlist(d, &scheme); err != nil {
		return nil, fmt.Errorf("Unable to load colorscheme definition: %s", err)
	}

	return &scheme, nil
}
示例#3
0
func (t *LanguageProvider) LanguageFromFile(fn string) (*Language, error) {
	d, err := ioutil.ReadFile(fn)
	if err != nil {
		return nil, fmt.Errorf("Couldn't load file %s: %s", fn, err)
	}
	var l Language
	if err := loaders.LoadPlist(d, &l); err != nil {
		return nil, err
	}
	t.Lock()
	defer t.Unlock()
	t.scope[l.ScopeName] = fn
	return &l, nil
}