本文整理汇总了Golang中github.com/quarnster/completion/util.Diff函数的典型用法代码示例。如果您正苦于以下问题:Golang Diff函数的具体用法?Golang Diff怎么用?Golang Diff使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Diff函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestScopes
func TestScopes(t *testing.T) {
tests := []struct {
in string
}{
{"../../clang/testdata/hello.cpp"},
{"../../net/testdata/CompleteSharp.cs"},
}
for _, test := range tests {
if d, err := ioutil.ReadFile(test.in); err != nil {
t.Error(err)
} else {
var p SCOPES
if !p.Parse(string(d)) {
t.Errorf("Failed to parse: %s\n%v", p.Error(), p.RootNode())
continue
}
ex := "testdata/" + filepath.Base(test.in) + ".exp"
cmp := p.RootNode().String()
if exp, err := ioutil.ReadFile(ex); err != nil {
t.Logf("Couldn't read the expected output file %s (%s); it'll be created", ex, err)
if err := ioutil.WriteFile(ex, []byte(cmp), 0644); err != nil {
t.Error(err)
}
} else if d := util.Diff(string(exp), cmp); len(d) != 0 {
t.Error(d)
}
}
}
}
示例2: 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)
}
}
}
}
}
示例3: TestParse
func TestParse(t *testing.T) {
if f, err := os.Open(testdata); err != nil {
t.Fatal(err)
} else if fi, err := f.Readdir(-1); err != nil {
t.Fatal(err)
} else {
for i := range fi {
if n := testdata + fi[i].Name(); strings.HasSuffix(n, ".cs") {
var p CSHARP
if d, err := ioutil.ReadFile(n); err != nil {
t.Error(err)
} else if !p.Parse(string(d)) {
t.Errorf("%s: %s", n, p.Error())
} else {
back := p.RootNode().Children[len(p.RootNode().Children)-1]
if back.Name != "EndOfFile" {
t.Log(p.RootNode())
t.Errorf("Didn't finish parsing %s: %s", n, p.Error())
}
root := p.RootNode()
root.Simplify()
res := root.String()
if exp, err := ioutil.ReadFile(n + ".pt"); err != nil {
t.Logf("Expected result for parsing %s does not exist and will be created", n)
ioutil.WriteFile(n+".pt", []byte(res), 0644)
} else if d := util.Diff(string(exp), res); len(d) > 0 {
t.Error(d)
}
}
}
}
}
}
示例4: TestParseResult
func TestParseResult(t *testing.T) {
var tests = make(map[string][]string)
if dir, err := os.Open("./testdata"); err != nil {
t.Fatal(err)
} else if fi, err := dir.Readdir(0); err != nil {
t.Fatal(err)
} else {
for _, f := range fi {
if strings.HasSuffix(f.Name(), ".in") {
path := "./testdata/" + f.Name()
if input, err := ioutil.ReadFile(path); err != nil {
t.Fatal(err)
} else {
data, err := ioutil.ReadFile(path + ".res")
if err != nil {
t.Logf("Error reading test data: %s. Testdata will be created", err)
}
tests[path] = []string{string(input), string(data)}
}
}
}
}
for k, data := range tests {
if !strings.HasSuffix(k, "j.in") {
continue
}
s := time.Now()
input, expected := data[0], data[1]
res := ""
if cmp, err := parseresult(input); err != nil {
t.Error(err)
continue
} else {
res = fmt.Sprintf("%s", cmp)
}
e := time.Now()
t.Logf("Parse %s %s", k, e.Sub(s))
if len(expected) <= 1 {
// Just if we want to add new tests, this will spit out the newly added
// test data
fn := k + ".res"
t.Logf("Creating new test data: %s", fn)
if err := ioutil.WriteFile(fn, []byte(res), 0644); err != nil {
t.Errorf("Couldn't write test data to %s: %s", fn, err)
}
continue
}
s = time.Now()
if d := util.Diff(expected, res); len(d) != 0 {
t.Error(d)
}
e = time.Now()
t.Logf("Diff %s %s", k, e.Sub(s))
}
}
示例5: TestClangUnsaved
func TestClangUnsaved(t *testing.T) {
if skip {
t.Skipf("Clang not installed, skipping")
}
var (
a content.CompleteAtArgs
b content.CompletionResult
c Clang
expected string
)
a.Location.File.Name = "test.cpp"
a.Location.File.Contents = `
class Test {
public:
int A;
int B;
int C;
};
void main() {
Test t;
t.
}
`
a.Location.Line = 11
a.Location.Column = 4
if err := c.CompleteAt(&a, &b); err == nil {
// Need to provide -xc++ or similar, so it should complain about this if we didn't
t.Error("Expected an error, but didn't get one")
}
a.SessionOverrides.Set("compiler_flags", []string{"-x", "c++", "-fno-exceptions"})
if err := c.CompleteAt(&a, &b); err != nil {
t.Errorf("Unexpected error: %s", err)
} else if strings.Index(b.Messages, "void main") == -1 {
t.Errorf("Expected an error about main returning void but got: \"%s\"", b.Messages)
}
res := fmt.Sprintf("%s", b)
fn := "./testdata/unsaved.cpp.res"
if data, err := ioutil.ReadFile(fn); err != nil {
t.Logf("Error reading test data: %s. Testdata will be created", err)
} else {
expected = string(data)
}
if len(expected) <= 1 {
// Just if we want to add new tests, this will spit out the newly added
// test data
t.Logf("Creating new test data: %s", fn)
if err := ioutil.WriteFile(fn, []byte(res), 0644); err != nil {
t.Errorf("Couldn't write test data to %s: %s", fn, err)
}
} else if d := util.Diff(expected, res); len(d) != 0 {
t.Error(d)
}
}
示例6: TestNet
func TestNet(t *testing.T) {
paths := DefaultPaths()
if len(paths) == 0 {
t.Skip("Neither mono nor Windows .NET Framework paths were possible to get")
}
var (
n Net
args content.CompleteAtArgs
cmp content.CompletionResult
)
tests := []struct {
InFile string
Line, Column uint
}{
// TODO: this test is not platform independent as it depends on whatever framework you happen
// to have installed
{"./testdata/CompleteSharp.cs", 40, 27},
{"./testdata/CompleteSharp.cs", 40, 41},
{"./testdata/CompleteSharp.cs", 47, 47},
//{"./testdata/CompleteSharp.cs", 28, 14},
{"./testdata/CompleteSharp.cs", 211, 46},
{"./testdata/CompleteSharp.cs", 761, 83},
{"./testdata/CompleteSharp.cs", 761, 27},
{"./testdata/CompleteSharp.cs", 857, 29},
{"./testdata/CompleteSharp.cs", 737, 15},
{"./testdata/CompleteSharp.cs", 95, 38},
{"./testdata/CompleteSharp.cs", 95, 45},
{"./testdata/CompleteSharp.cs", 776, 39},
{"./testdata/NamespaceTest.cs", 4, 15},
{"./testdata/NamespaceTest.cs", 6, 15},
}
args.SessionId = "a"
args.Settings().Set("net_paths", []string{"./testdata/"})
args.Settings().Set("net_assemblies", []string{"CompleteSharp.exe"})
for _, test := range tests {
args.Location.File.Name = test.InFile
args.Location.Line = test.Line
args.Location.Column = test.Column
ex := fmt.Sprintf("%s-%d-%d.cmp", test.InFile, test.Line, test.Column)
if err := n.CompleteAt(&args, &cmp); err != nil {
t.Errorf("Unable to complete %v: %s", test, err)
} else if exp, err := ioutil.ReadFile(ex); err != nil {
t.Logf("Couldn't read the expected output file %s (%s); it'll be created", ex, err)
if err := ioutil.WriteFile(ex, []byte(cmp.String()), 0644); err != nil {
t.Error(err)
}
} else if d := util.Diff(string(exp), cmp.String()); len(d) != 0 {
t.Error(d)
}
}
}
示例7: TestClangUnsaved
func TestClangUnsaved(t *testing.T) {
if skip {
t.Skipf("Clang not installed, skipping")
}
var (
a content.CompleteAtArgs
b content.CompletionResult
c Clang
expected string
)
a.Location.File.Name = "test.cpp"
a.Location.File.Contents = `
class Test {
public:
int A;
int B;
int C;
};
void main() {
Test t;
t.
}
`
a.Location.Line = 11
a.Location.Column = 4
a.SessionOverrides.Set("compiler_flags", []string{"-x", "c++", "-fno-exceptions"})
if err := c.CompleteAt(&a, &b); err != nil {
t.Error(err)
}
res := fmt.Sprintf("%s", b)
fn := "./testdata/unsaved.cpp.res"
if data, err := ioutil.ReadFile(fn); err != nil {
t.Logf("Error reading test data: %s. Testdata will be created", err)
} else {
expected = string(data)
}
if len(expected) <= 1 {
// Just if we want to add new tests, this will spit out the newly added
// test data
t.Logf("Creating new test data: %s", fn)
if err := ioutil.WriteFile(fn, []byte(res), 0644); err != nil {
t.Errorf("Couldn't write test data to %s: %s", fn, err)
}
} else if d := util.Diff(expected, res); len(d) != 0 {
t.Error(d)
}
}
示例8: TestScopeName
// This is not 100% what ST3 does, but IMO ST3 is wrong
func TestScopeName(t *testing.T) {
var (
w Window
v = w.NewFile()
)
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)
}
}
}
示例9: TestLine
func TestLine(t *testing.T) {
for _, test := range []string{"./testdata/8", "./testdata/hello", "./testdata/game.bz2", "./testdata/listener.o.bz2", "./testdata/completion.bz2", "./testdata/hello4"} {
rf, err := readFile(test)
if err != nil {
t.Error(err)
continue
}
f, err := newSectionReader(rf)
if err != nil {
t.Error(err)
continue
}
defer f.Close()
bri := f.Reader("debug_line")
res := ""
for {
var v lineHeader
if err := bri.ReadInterface(&v); err != nil {
if err == io.EOF {
break
}
t.Error(err)
}
res += fmt.Sprintf("%s\n", v)
}
expected := ""
fn := test + ".line"
if data, err := ioutil.ReadFile(fn); err == nil {
expected = string(data)
}
if len(expected) <= 1 {
t.Logf("Creating new test data: %s", fn)
if err := ioutil.WriteFile(fn, []byte(res), 0644); err != nil {
t.Errorf("Couldn't write test data to %s: %s", fn, err)
}
} else if d := util.Diff(expected, res); len(d) != 0 {
t.Error(d)
}
}
}
示例10: TestString
func TestString(t *testing.T) {
if cmp, err := loadData(); err != nil {
t.Fatal(err)
} else {
expfile := "./testdata/big.json.gz.in"
expected := ""
if d, err := ioutil.ReadFile(expfile); err != nil {
t.Log("Expected result file doesn't exist and will be created")
} else {
expected = string(d)
}
res := cmp.String()
if len(expected) <= 1 {
t.Logf("Creating new test data: %s", expfile)
if err := ioutil.WriteFile(expfile, []byte(res), 0644); err != nil {
t.Errorf("Couldn't write test data to %s: %s", expfile, err)
}
} else if d := util.Diff(expected, res); len(d) != 0 {
t.Error(d)
}
}
}
示例11: TestExtractScope
// This is not 100% what ST3 does
func TestExtractScope(t *testing.T) {
var (
w Window
v = w.NewFile()
)
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 := Region{-1, -1}
str := ""
nr := Region{0, 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)
}
}
}
示例12: TestCompleteGame
func TestCompleteGame(t *testing.T) {
testfile := "./testdata/game.bz2"
tests := []string{
"asCObjectType",
"asCScriptFunction",
}
if r, err := readFile(testfile); err != nil {
t.Error(err)
} else if dh, err := NewDWARFHelper(testfile, r); err != nil {
t.Error(err)
} else {
res := ""
expected := ""
if data, err := ioutil.ReadFile(testfile + ".res"); err == nil {
expected = string(data)
}
for _, test := range tests {
res += test + "\n"
if cmp, err := dh.Complete(content.FullyQualifiedName{Relative: test}); err != nil {
t.Error(err)
} else {
res += cmp.String()
}
}
if len(expected) <= 1 {
fn := testfile + ".res"
t.Logf("Creating new test data: %s", fn)
if err := ioutil.WriteFile(fn, []byte(res), 0644); err != nil {
t.Errorf("Couldn't write test data to %s: %s", fn, err)
}
} else if d := util.Diff(expected, res); len(d) != 0 {
t.Error(d)
}
}
}
示例13: TestSublime
//.........这里部分代码省略.........
}
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(primitives.Region{0, v.Buffer().Size()}), "FAILED") != -1 {
t.Error(v.Buffer())
}
}
}
log4go.Debug("After")
l.Lock()
gr.Base().CallFunctionObjArgs()
l.Unlock()
var v *backend.View
for _, v2 := range w.Views() {
if v == nil || v2.Buffer().Size() > v.Buffer().Size() {
v = v2
}
}
// log4go.Debug("Before")
// gr.Base().CallFunctionObjArgs()
// for i := 0; i < 500; i++ {
// ed.CommandHandler().RunTextCommand(v, "set_motion", backend.Args{"motion": "vi_j"})
// }
// for i := 0; i < 500; i++ {
// ed.CommandHandler().RunTextCommand(v, "set_motion", backend.Args{"motion": "vi_k"})
// }
// log4go.Debug("After")
// gr.Base().CallFunctionObjArgs()
}
示例14: TestLoadAssembly
//.........这里部分代码省略.........
if err != nil {
t.Fatalf("Failed to open %s: %s", testdata_path, err)
}
defer testdata.Close()
fi, err := testdata.Readdir(0)
if err != nil {
t.Errorf("Failed to fully read %s: %s. Got %d useable entries.", testdata_path, err, len(fi))
}
for i := range fi {
if strings.HasSuffix(fi[i].Name(), ".exe") || strings.HasSuffix(fi[i].Name(), ".dll") {
path := testdata_path + fi[i].Name()
data, err := ioutil.ReadFile(path + ".asm")
if err != nil {
t.Logf("Error reading test data: %s. Testdata will be created", err)
}
tests[path] = string(data)
}
}
for k, v := range tests {
t.Log("Testing", k)
f, err := os.Open(k)
if err != nil {
t.Error(err)
continue
}
defer f.Close()
if asm, err := LoadAssembly(f); err != nil {
t.Error(err)
continue
} else {
var res string
for i := range asm.Tables {
if asm.Tables[i].Rows == 0 {
continue
}
td := asm.Tables[i]
res += fmt.Sprintln(td.RowType.Name())
row := reflect.New(td.RowType).Interface()
for i := uint32(0); i < td.Rows; i++ {
data, err := td.Index(i + 1)
if err != nil {
t.Error(err)
continue
}
if err := asm.Create(&binary.BinaryReader{Reader: bytes.NewReader(data), Endianess: binary.LittleEndian}, row); err != nil {
t.Error(err)
} else {
res += fmt.Sprintf("\t%+v\n", row)
}
}
}
if types, err := asm.Types(); err != nil {
t.Error(err)
} else {
for i := range types {
res += fmt.Sprintf("\t%s\n", types[i])
}
}
var idx = &ConcreteTableIndex{metadataUtil: &asm.MetadataUtil, index: 0, table: id_TypeDef}
tdTable := asm.Tables[id_TypeDef]
//ty := reflect.New(td.RowType).Interface().(*TypeDefRow)
for i := uint32(0); i < tdTable.Rows; i++ {
idx.index = i + 1
td, err := TypeDefFromIndex(idx)
if err != nil {
t.Error(err)
continue
} else if n := td.Name(); check(&n, n) != nil {
continue
}
if ct, err := td.ToContentType(); err != nil {
t.Error(err)
continue
} else {
res += fmt.Sprintln(ct)
}
}
if len(v) <= 1 {
// Just if we want to add new tests, this will spit out the newly added
// test data
fn := k + ".asm"
t.Logf("Creating new test data: %s", fn)
if err := ioutil.WriteFile(fn, []byte(res), 0644); err != nil {
t.Errorf("Couldn't write test data to %s: %s", fn, err)
}
continue
}
if d := util.Diff(v, res); len(d) != 0 {
t.Error(d)
}
}
}
}
示例15: TestInfo
//.........这里部分代码省略.........
continue
}
f, err := newSectionReader(rf)
if err != nil {
t.Error(err)
continue
}
defer f.Close()
bri := f.Reader("debug_info")
bra := f.Reader("debug_abbrev")
brs := f.Reader("debug_str")
var ih InfoHeader
nextHeader, _ := bri.Seek(0, 1)
var abbr_entries []AbbrevEntry
buf := bytes.NewBuffer(nil)
var indent = ""
for {
off, _ := bri.Seek(0, 1)
if off >= nextHeader {
if err := bri.ReadInterface(&ih); err != nil {
if err != io.EOF {
t.Error(err)
}
break
} else {
buf.WriteString(fmt.Sprintf("%+v\n", ih))
nextHeader += int64(ih.Length) + 4
abbr_entries = nil
bra.Seek(ih.DebugAbbrevOffset, 0)
for {
var abr AbbrevEntry
if err := bra.ReadInterface(&abr); err != nil {
break
} else {
abbr_entries = append(abbr_entries, abr)
}
}
}
}
var (
ie InfoEntry
)
if err := bri.ReadInterface(&ie); err != nil {
if err == io.EOF {
break
}
t.Error(err)
break
}
ie.header = &ih
if ie.id <= 0 {
indent = indent[:len(indent)-2]
continue
}
// buf.WriteString(fmt.Sprintf("%v, %d\n", ie.id, len(abbr_entries)))
ie.ae = &abbr_entries[ie.id-1]
ie.reader.Info = bri
ie.reader.Abbrev = bra
ie.reader.Str = brs
buf.WriteString(fmt.Sprintf("%s%s [%d] ", indent, ie.Tag().String(), ie.id))
if ie.ae.Children == DW_CHILDREN_yes {
buf.WriteRune('*')
}
buf.WriteRune('\n')
indent += " "
for _, attr := range ie.ae.Attributes {
pos, _ := bri.Seek(0, 1)
va := ie.Attribute(attr.Name)
switch v := va.(type) {
case uint64:
buf.WriteString(fmt.Sprintf("%s0x%08x %s 0x%08x\n", indent, pos, attr, v))
default:
buf.WriteString(fmt.Sprintf("%s0x%08x %s %v\n", indent, pos, attr, v))
}
}
if ie.ae.Children == DW_CHILDREN_no {
indent = indent[:len(indent)-2]
}
buf.WriteRune('\n')
off, _ = bri.Seek(0, 1)
// buf.WriteString(fmt.Sprintf("0x%x 0x%x", off, nextHeader))
}
res := buf.String()
expected := ""
fn := test + ".info"
if data, err := ioutil.ReadFile(fn); err == nil {
expected = string(data)
}
if len(expected) <= 1 {
t.Logf("Creating new test data: %s", fn)
if err := ioutil.WriteFile(fn, []byte(res), 0644); err != nil {
t.Errorf("Couldn't write test data to %s: %s", fn, err)
}
} else if d := util.Diff(expected, res); len(d) != 0 {
t.Error(d)
}
}
}