本文整理汇总了Golang中github.com/limetext/lime/backend/util.Diff函数的典型用法代码示例。如果您正苦于以下问题:Golang Diff函数的具体用法?Golang Diff怎么用?Golang Diff使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Diff函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestLoadTheme
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)
}
}
}
}
}
开发者ID:RandomWalkEagle,项目名称:lime,代码行数:32,代码来源:theme_test.go
示例2: TestScopeName
// This is not 100% what ST3 does, but IMO ST3 is wrong
func TestScopeName(t *testing.T) {
w := GetEditor().NewWindow()
defer w.Close()
v := w.NewFile()
defer func() {
v.SetScratch(true)
v.Close()
}()
const (
in = "textmate/testdata/main.go"
expfile = "testdata/scopename.res"
syntax = "textmate/testdata/Go.tmLanguage"
)
v.Settings().Set("syntax", syntax)
if d, err := ioutil.ReadFile(in); err != nil {
t.Fatal(err)
} else {
// v.rootNode = nil
e := v.BeginEdit()
v.Insert(e, 0, string(d))
v.EndEdit(e)
last := ""
str := ""
lasti := 0
for v.ScopeName(1) == "" {
time.Sleep(250 * time.Millisecond)
}
for i := 0; i < v.buffer.Size(); i++ {
if name := v.ScopeName(i); name != last {
if last != "" {
str += fmt.Sprintf("%d-%d: %s\n", lasti, i, last)
lasti = i
}
last = name
}
}
if i := v.Buffer().Size(); lasti != i {
str += fmt.Sprintf("%d-%d: %s\n", lasti, i, last)
}
if d, err := ioutil.ReadFile(expfile); err != nil {
if err := ioutil.WriteFile(expfile, []byte(str), 0644); err != nil {
t.Error(err)
}
} else if diff := util.Diff(string(d), str); diff != "" {
t.Error(diff)
}
}
}
开发者ID:hanshenu,项目名称:lime,代码行数:51,代码来源:view_test.go
示例3: TestExtractScope
// This is not 100% what ST3 does
func TestExtractScope(t *testing.T) {
w := GetEditor().NewWindow()
defer w.Close()
v := w.NewFile()
defer func() {
v.SetScratch(true)
v.Close()
}()
const (
in = "textmate/testdata/main.go"
expfile = "testdata/scoperange.res"
syntax = "textmate/testdata/Go.tmLanguage"
)
v.Settings().Set("syntax", syntax)
if d, err := ioutil.ReadFile(in); err != nil {
t.Fatal(err)
} else {
// v.rootNode = nil
e := v.BeginEdit()
v.Insert(e, 0, string(d))
v.EndEdit(e)
last := text.Region{A: -1, B: -1}
str := ""
nr := text.Region{A: 0, B: 0}
for v.ExtractScope(1) == nr {
time.Sleep(time.Millisecond)
}
for i := 0; i < v.buffer.Size(); i++ {
if r := v.ExtractScope(i); r != last {
str += fmt.Sprintf("%d (%d, %d)\n", i, r.A, r.B)
last = r
}
}
if d, err := ioutil.ReadFile(expfile); err != nil {
if err := ioutil.WriteFile(expfile, []byte(str), 0644); err != nil {
t.Error(err)
}
} else if diff := util.Diff(string(d), str); diff != "" {
t.Error(diff)
}
}
}
开发者ID:hanshenu,项目名称:lime,代码行数:45,代码来源:view_test.go
示例4: TestSublime
//.........这里部分代码省略.........
assert v.substr(sublime.Region(0, v.size())) == "Tada"
except:
traceback.print_exc()
raise
`)
time.Sleep(time.Millisecond * 10)
if err := ioutil.WriteFile("testdata/reload_test.py", data, 0644); err != nil {
t.Fatalf("Couldn't write file: %s", err)
}
log4go.Debug("Running %s", "reload_test.py")
if _, err := py.Import("reload_test"); err != nil {
log4go.Error(err)
t.Error(err)
} else {
log4go.Debug("Ran %s", "reload_test.py")
}
os.Remove("testdata/plugins/reload.py")
os.Remove("testdata/reload_test.py")
var f func(indent string, v py.Object, buf *bytes.Buffer)
f = func(indent string, v py.Object, buf *bytes.Buffer) {
b := v.Base()
if dir, err := b.Dir(); err != nil {
t.Error(err)
} else {
if l, ok := dir.(*py.List); ok {
sl := l.Slice()
if indent == "" {
for _, v2 := range sl {
if item, err := b.GetAttr(v2); err != nil {
t.Error(err)
} else {
ty := item.Type()
line := fmt.Sprintf("%s%s\n", indent, v2)
buf.WriteString(line)
if ty == py.TypeType {
f(indent+"\t", item, buf)
}
item.Decref()
}
}
} else {
for _, v2 := range sl {
buf.WriteString(fmt.Sprintf("%s%s\n", indent, v2))
}
}
} else {
ty := dir.Type()
t.Error("Unexpected type:", ty)
}
dir.Decref()
}
}
buf := bytes.NewBuffer(nil)
f("", subl, buf)
l.Unlock()
const expfile = "testdata/api.txt"
if d, err := ioutil.ReadFile(expfile); err != nil {
if err := ioutil.WriteFile(expfile, buf.Bytes(), 0644); err != nil {
t.Error(err)
}
} else if diff := util.Diff(string(d), buf.String()); diff != "" {
t.Error(diff)
}
ed.LogCommands(true)
tests := []string{
"state",
"registers",
"settings",
"constants",
"registers",
"cmd_data",
"marks",
}
for _, test := range tests {
ed.CommandHandler().RunWindowCommand(w, "vintage_ex_run_data_file_based_tests", backend.Args{"suite_name": test})
}
for _, w := range ed.Windows() {
for _, v := range w.Views() {
if strings.HasSuffix(v.Buffer().FileName(), "sample.txt") {
continue
}
if strings.Index(v.Buffer().Substr(text.Region{0, v.Buffer().Size()}), "FAILED") != -1 {
t.Error(v.Buffer())
}
}
}
var v *backend.View
for _, v2 := range w.Views() {
if v == nil || v2.Buffer().Size() > v.Buffer().Size() {
v = v2
}
}
}
开发者ID:EDi-nabi,项目名称:lime,代码行数:101,代码来源:sublime_test.go
示例5: TestSublime
func TestSublime(t *testing.T) {
ed := backend.GetEditor()
ed.Console().Buffer().AddCallback(func(b text.Buffer, pos, delta int) {
t.Logf("%s", b.Substr(text.Region{pos, pos + delta}))
})
w := ed.NewWindow()
Init()
l := py.NewLock()
py.AddToPath("testdata")
py.AddToPath("testdata/plugins")
if m, err := py.Import("sublime_plugin"); err != nil {
t.Fatal(err)
} else {
scanpath("testdata/", m)
}
subl, err := py.Import("sublime")
if err != nil {
t.Fatal(err)
}
if w, err := _windowClass.Alloc(1); err != nil {
t.Fatal(err)
} else {
(w.(*Window)).data = &backend.Window{}
subl.AddObject("test_window", w)
}
if dir, err := os.Open("testdata"); err != nil {
t.Error(err)
} else if files, err := dir.Readdirnames(0); err != nil {
t.Error(err)
} else {
for _, fn := range files {
if filepath.Ext(fn) == ".py" {
log4go.Debug("Running %s", fn)
if _, err := py.Import(fn[:len(fn)-3]); err != nil {
log4go.Error(err)
t.Error(err)
} else {
log4go.Debug("Ran %s", fn)
}
}
}
}
var f func(indent string, v py.Object, buf *bytes.Buffer)
f = func(indent string, v py.Object, buf *bytes.Buffer) {
b := v.Base()
if dir, err := b.Dir(); err != nil {
t.Error(err)
} else {
if l, ok := dir.(*py.List); ok {
sl := l.Slice()
if indent == "" {
for _, v2 := range sl {
if item, err := b.GetAttr(v2); err != nil {
t.Error(err)
} else {
ty := item.Type()
line := fmt.Sprintf("%s%s\n", indent, v2)
buf.WriteString(line)
if ty == py.TypeType {
f(indent+"\t", item, buf)
}
item.Decref()
}
}
} else {
for _, v2 := range sl {
buf.WriteString(fmt.Sprintf("%s%s\n", indent, v2))
}
}
} else {
ty := dir.Type()
t.Error("Unexpected type:", ty)
}
dir.Decref()
}
}
buf := bytes.NewBuffer(nil)
f("", subl, buf)
l.Unlock()
const expfile = "testdata/api.txt"
if d, err := ioutil.ReadFile(expfile); err != nil {
if err := ioutil.WriteFile(expfile, buf.Bytes(), 0644); err != nil {
t.Error(err)
}
} else if diff := util.Diff(string(d), buf.String()); diff != "" {
t.Error(diff)
}
ed.LogCommands(true)
tests := []string{
"state",
"registers",
"settings",
//.........这里部分代码省略.........
开发者ID:jlneder,项目名称:lime,代码行数:101,代码来源:sublime_test.go
示例6: TestTmLanguage
func TestTmLanguage(t *testing.T) {
files := []string{
"testdata/Property List (XML).tmLanguage",
"testdata/XML.plist",
"testdata/Go.tmLanguage",
}
for _, fn := range files {
if _, err := Provider.LanguageFromFile(fn); err != nil {
t.Fatal(err)
}
}
type test struct {
in string
out string
syn string
}
tests := []test{
{
"testdata/plist2.tmlang",
"testdata/plist2.tmlang.res",
"text.xml.plist",
},
{
"testdata/Property List (XML).tmLanguage",
"testdata/plist.tmlang.res",
"text.xml.plist",
},
{
"testdata/main.go",
"testdata/main.go.res",
"source.go",
},
{
"testdata/go2.go",
"testdata/go2.go.res",
"source.go",
},
{
"testdata/utf.go",
"testdata/utf.go.res",
"source.go",
},
}
for _, t3 := range tests {
var d0 string
if d, err := ioutil.ReadFile(t3.in); err != nil {
t.Errorf("Couldn't load file %s: %s", t3.in, err)
continue
} else {
d0 = string(d)
}
if lp, err := NewLanguageParser(t3.syn, d0); err != nil {
t.Error(err)
} else if root, err := lp.Parse(); err != nil {
t.Error(err)
} else {
// fmt.Println(lp.RootNode())
str := fmt.Sprintf("%s", root)
if d, err := ioutil.ReadFile(t3.out); err != nil {
if err := ioutil.WriteFile(t3.out, []byte(str), 0644); err != nil {
t.Error(err)
}
} else if diff := util.Diff(string(d), str); diff != "" {
t.Error(diff)
}
}
}
}
开发者ID:ericcapricorn,项目名称:lime,代码行数:71,代码来源:language_test.go
注:本文中的github.com/limetext/lime/backend/util.Diff函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论