• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang util.Diff函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



在下文中一共展示了Diff函数的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
			}
		}
	}
}
开发者ID:NeoTse,项目名称:completion,代码行数:29,代码来源:scopes_test.go


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

			}
		}
	}
}
开发者ID:richardfontana,项目名称:lime,代码行数:29,代码来源:theme_test.go


示例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)
					}
				}
			}
		}
	}
}
开发者ID:NeoTse,项目名称:completion,代码行数:33,代码来源:csharp_test.go


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

}
开发者ID:noname007,项目名称:completion,代码行数:57,代码来源:clang_test.go


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

}
开发者ID:noname007,项目名称:completion,代码行数:56,代码来源:clang_test.go


示例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)
		}
	}
}
开发者ID:noname007,项目名称:completion,代码行数:53,代码来源:net_test.go


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

}
开发者ID:NeoTse,项目名称:completion,代码行数:50,代码来源:clang_test.go


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

	}
}
开发者ID:richardfontana,项目名称:lime,代码行数:47,代码来源:view_test.go


示例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)
		}
	}
}
开发者ID:NeoTse,项目名称:completion,代码行数:40,代码来源:line_test.go


示例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)
		}
	}
}
开发者ID:NeoTse,项目名称:completion,代码行数:22,代码来源:strings_test.go


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


示例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)
		}
	}
}
开发者ID:NeoTse,项目名称:completion,代码行数:37,代码来源:dwarf_test.go


示例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()

}
开发者ID:richardfontana,项目名称:lime,代码行数:101,代码来源:sublime_test.go


示例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)
			}
		}
	}
}
开发者ID:noname007,项目名称:completion,代码行数:101,代码来源:assembly_test.go


示例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)
		}
	}
}
开发者ID:ksurdy,项目名称:completion,代码行数:101,代码来源:info_test.go


示例16: 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:richardfontana,项目名称:lime,代码行数:71,代码来源:language_test.go


示例17: TestSpecificClasses

func TestSpecificClasses(t *testing.T) {
	var (
		tests = make(map[Classname]string)
		err   error
	)

	classpath, err := DefaultClasspath()
	if err != nil {
		t.Skip(err)
	}

	c, err := NewCompositeArchive(classpath)
	if c == nil {
		t.Fatal(err)
	} else if err != nil {
		t.Log(err)
	}
	defer c.Close()

	testdata, err := os.Open(testdata_path)
	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(), ".class") {
			if data, err := ioutil.ReadFile(testdata_path + fi[i].Name()); err != nil {
				t.Errorf("Error reading test data: %s", err)
			} else {
				tests[Filename(strings.Replace(fi[i].Name(), "_", "/", -1)).Classname()] = string(data)
			}
		}
	}

	for k, v := range tests {
		t.Log("Testing", k)

		d, err := c.LoadClass(k)
		if err != nil {
			t.Errorf("Failed to read file contents: %s", err)
			continue
		}

		b := bytes.NewReader(d)
		c, err := NewClass(b)
		if err != nil {
			t.Errorf("Failed to create Class struct: %s", err)
			continue
		}

		ret := c.String()
		if ct, err := c.ToContentType(); err != nil {
			t.Error(err)
		} else {
			ret += fmt.Sprintf("%s\n", ct)
		}

		if len(v) <= 1 {
			// Just if we want to add new tests, this will spit out the newly added
			// test data
			fn := testdata_path + strings.Replace(string(k.Filename()), "/", "_", -1)
			t.Logf("Creating new test data: %s", fn)
			if err := ioutil.WriteFile(fn, []byte(ret), 0666); err != nil {
				t.Errorf("Couldn't write test data to %s: %s", fn, err)
			}
			continue
		}

		if d := util.Diff(v, ret); len(d) != 0 {
			t.Error(d)
		}
	}
}
开发者ID:NeoTse,项目名称:completion,代码行数:79,代码来源:class_test.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang util.BinaryReader类代码示例发布时间:2022-05-28
下一篇:
Golang csharp.CSHARP类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap