當前位置: 首頁>>代碼示例>>Golang>>正文


Golang difflib.GetUnifiedDiffString函數代碼示例

本文整理匯總了Golang中github.com/pmezard/go-difflib/difflib.GetUnifiedDiffString函數的典型用法代碼示例。如果您正苦於以下問題:Golang GetUnifiedDiffString函數的具體用法?Golang GetUnifiedDiffString怎麽用?Golang GetUnifiedDiffString使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了GetUnifiedDiffString函數的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: DumpDiff

func DumpDiff(expectedObj, actualObj interface{}) {
	expected := pretty.Sprintf("%# v\n", expectedObj)
	actual := pretty.Sprintf("%# v\n", actualObj)
	diff := difflib.UnifiedDiff{
		A:        difflib.SplitLines(expected),
		B:        difflib.SplitLines(actual),
		FromFile: "expected",
		ToFile:   "actual",
		Context:  3,
	}
	text, _ := difflib.GetUnifiedDiffString(diff)
	fmt.Print(text)
}
開發者ID:flimzy,項目名稱:go-pouchdb,代碼行數:13,代碼來源:find_test.go

示例2: diff

// diff returns a diff of both values as long as both are of the same type and
// are a struct, map, slice or array. Otherwise it returns an empty string.
func diff(expected interface{}, actual interface{}) string {
	if expected == nil || actual == nil {
		return ""
	}

	et, ek := typeAndKind(expected)
	at, _ := typeAndKind(actual)

	if et != at {
		return ""
	}

	if ek != reflect.Struct && ek != reflect.Map && ek != reflect.Slice && ek != reflect.Array {
		return ""
	}

	e := spew.Sdump(expected)
	a := spew.Sdump(actual)

	diff, _ := difflib.GetUnifiedDiffString(difflib.UnifiedDiff{
		A:        difflib.SplitLines(e),
		B:        difflib.SplitLines(a),
		FromFile: "Expected",
		FromDate: "",
		ToFile:   "Actual",
		ToDate:   "",
		Context:  1,
	})

	return "\n\nDiff:\n" + diff
}
開發者ID:ClearcodeHQ,項目名稱:Go-Forward,代碼行數:33,代碼來源:assertions.go

示例3: UnifiedOutput

func UnifiedOutput(diffTargets []string) (int, error) {
	tmp, err := ioutil.TempFile(os.TempDir(), "rsyncdiff")
	if err != nil {
		return 1, err
	}
	defer os.Remove(tmp.Name())

	for _, target := range diffTargets {
		diffInfo, err := NewDiffInfo(target)
		if err != nil {
			return 1, err
		}
		diff := difflib.UnifiedDiff{
			A:        diffInfo.A,
			B:        diffInfo.B,
			FromFile: diffInfo.FromFile,
			ToFile:   diffInfo.ToFile,
		}
		result, err := difflib.GetUnifiedDiffString(diff)
		if err != nil {
			return 1, err
		}
		_, err = tmp.WriteString(result)
		if err != nil {
			return 1, err
		}
		tmp.Sync()
	}

	cmd := &Command{}
	cmd.Command = "cat"
	cmd.Options = []string{tmp.Name()}
	return cmd.Run()
}
開發者ID:kaneda-t,項目名稱:rsyncdiff,代碼行數:34,代碼來源:output.go

示例4: TestOptionMerge

func TestOptionMerge(t *testing.T) {
	InitLogging()
	logging.SetLevel(logging.DEBUG, "")
	cli := &TestCli{*New("test")}

	cli.SetDefaults(map[string]interface{}{
		"a": 1,
		"b": 2,
		"hash": map[string]interface{}{
			"a": 1,
			"b": 2,
			"hoh": map[string]interface{}{
				"a": 1,
				"b": 2,
			},
			"hol": map[string]interface{}{
				"a": []interface{}{1, 2},
				"b": []interface{}{3, 4},
			},
		},
		"list": []interface{}{
			"a",
			"b",
		},
		"lol": []interface{}{
			[]interface{}{"a", "b", "c"},
			[]interface{}{"d", "e", "f"},
		},
	})

	os.Args = []string{os.Args[0]}

	ProcessAllOptions(cli)
	log.Debugf("processed: %#v", cli.GetOptions())
	options := cli.GetOptions()
	if !reflect.DeepEqual(options, TestOptionMergeExpected) {
		log.Debugf("processed: %#v", options)
		got, err := json.MarshalIndent(options, "", "    ")
		if err != nil {
			log.Errorf("Failed to marshal json: %s", err)
		}
		log.Debugf("got: %#v", string(got))
		log.Debugf("processed: %#v", options)
		got, err = json.MarshalIndent(options, "", "    ")
		log.Debugf("got: %#v", string(got))
		expected, _ := json.MarshalIndent(TestOptionMergeExpected, "", "    ")

		diff := difflib.UnifiedDiff{
			A:        difflib.SplitLines(string(expected)),
			B:        difflib.SplitLines(string(got)),
			FromFile: "Expected",
			ToFile:   "Got",
			Context:  3,
		}
		result, _ := difflib.GetUnifiedDiffString(diff)
		log.Errorf("Diff:\n%s", result)
		t.Fail()
	}
}
開發者ID:coryb,項目名稱:cliby,代碼行數:59,代碼來源:cli_test.go

示例5: Unified

// Unified compares two strings and output the differences.
func Unified(a, b string) (string, error) {
	diff := difflib.UnifiedDiff{
		A:        difflib.SplitLines(a),
		B:        difflib.SplitLines(b),
		FromFile: "Original",
		ToFile:   "Current",
		Context:  1,
	}
	return difflib.GetUnifiedDiffString(diff)
}
開發者ID:joao-parana,項目名稱:csfw,代碼行數:11,代碼來源:diff.go

示例6: RawDiff

// RawDiff returns a contextual diff of the running rule configuration
// against the provided configuration. This contextual diff library
// does not guarantee that the generated unified diff can be applied
// so this is only used for human consumption and verifying that the diff
// has not change since an edit request was issued
func (c *Conf) RawDiff(rawConf string) (string, error) {
	diff := difflib.UnifiedDiff{
		A:        difflib.SplitLines(c.RawText),
		B:        difflib.SplitLines(rawConf),
		FromFile: c.Name,
		ToFile:   c.Name,
		Context:  3,
	}
	return difflib.GetUnifiedDiffString(diff)
}
開發者ID:nicollet,項目名稱:bosun,代碼行數:15,代碼來源:modify.go

示例7: Diff

// Diff diff diff
func Diff(want, have interface{}) string {
	text, _ := difflib.GetUnifiedDiffString(difflib.UnifiedDiff{
		A:        difflib.SplitLines(spew.Sdump(want)),
		B:        difflib.SplitLines(spew.Sdump(have)),
		FromFile: "want",
		ToFile:   "have",
		Context:  3,
	})
	return "\n" + text
}
開發者ID:davkal,項目名稱:scope,代碼行數:11,代碼來源:diff.go

示例8: GenerateDiff

func GenerateDiff(prevName, prevStr, currName, currStr string) (string, error) {
	diff := difflib.UnifiedDiff{
		A:        difflib.SplitLines(prevStr),
		B:        difflib.SplitLines(currStr),
		FromFile: prevName,
		ToFile:   currName,
		Context:  0,
	}
	return difflib.GetUnifiedDiffString(diff)
}
開發者ID:vindalu,項目名稱:vindalu,代碼行數:10,代碼來源:version_diff.go

示例9: godiff

func godiff(a, b string) string {
	diff := difflib.UnifiedDiff{
		A:        difflib.SplitLines(a),
		B:        difflib.SplitLines(b),
		FromFile: "File A",
		ToFile:   "File B",
		Context:  3,
	}
	text, err := difflib.GetUnifiedDiffString(diff)
	if err != nil {
		log.Fatal(err)
	}
	return text
}
開發者ID:anykao,項目名稱:p,代碼行數:14,代碼來源:diffjar.go

示例10: TestOptionMergeSubdir

func TestOptionMergeSubdir(t *testing.T) {
	os.Chdir("subdir")
	InitLogging()
	logging.SetLevel(logging.DEBUG, "")
	cli := &TestCli{*New("test")}
	cli.SetDefaults(map[string]interface{}{
		"a": 1,
		"b": 2,
		"hash": map[string]interface{}{
			"a": 1,
			"b": 2,
			"hoh": map[string]interface{}{
				"a": 1,
				"b": 2,
			},
			"hol": map[string]interface{}{
				"a": []interface{}{1, 2},
				"b": []interface{}{3, 4},
			},
		},
		"list": []interface{}{
			"a",
			"b",
		},
		"lol": []interface{}{
			[]interface{}{"a", "b", "c"},
			[]interface{}{"d", "e", "f"},
		},
	})

	ProcessAllOptions(cli)
	if !reflect.DeepEqual(cli.GetOptions(), TestOptionMergeSubdirExpected) {
		got, _ := json.MarshalIndent(cli.GetOptions(), "", "    ")
		expected, _ := json.MarshalIndent(TestOptionMergeSubdirExpected, "", "    ")

		diff := difflib.UnifiedDiff{
			A:        difflib.SplitLines(string(expected)),
			B:        difflib.SplitLines(string(got)),
			FromFile: "Expected",
			ToFile:   "Got",
			Context:  3,
		}
		result, _ := difflib.GetUnifiedDiffString(diff)
		log.Errorf("Diff:\n%s", result)
		t.Fail()
	}
}
開發者ID:coryb,項目名稱:cliby,代碼行數:47,代碼來源:cli_test.go

示例11: Diff

// Diff returns the difference between the textual representation of two deployments
func (d *Deployment) Diff(other *Deployment) string {
	if other == nil {
		return "other was nil"
	}
	diff := difflib.UnifiedDiff{
		A:        difflib.SplitLines(d.String()),
		B:        difflib.SplitLines(other.String()),
		FromFile: "ThisDeployment",
		ToFile:   "OtherDeployment",
	}

	out, err := difflib.GetUnifiedDiffString(diff)
	if err != nil {
		panic(err)
	}

	return out
}
開發者ID:redspread,項目名稱:spread,代碼行數:19,代碼來源:deployment.go

示例12: diffDeployment

func diffDeployment(currRaw, newRaw string) (string, error) {
	curr, err := prettifyJSON(currRaw)
	if err != nil {
		return "", err
	}
	new, err := prettifyJSON(newRaw)
	if err != nil {
		return "", err
	}

	diff := difflib.UnifiedDiff{
		A:        difflib.SplitLines(curr),
		B:        difflib.SplitLines(new),
		FromFile: "Current",
		ToFile:   "Proposed",
		Context:  3,
	}
	return difflib.GetUnifiedDiffString(diff)
}
開發者ID:NetSys,項目名稱:quilt,代碼行數:19,代碼來源:run.go

示例13: diffStr

// diffStr returns a unified diff string of two Godeps.
func diffStr(a, b *Godeps) (string, error) {
	var ab, bb bytes.Buffer

	_, err := a.WriteTo(&ab)
	if err != nil {
		log.Fatalln(err)
	}

	_, err = b.WriteTo(&bb)
	if err != nil {
		log.Fatalln(err)
	}

	diff := difflib.UnifiedDiff{
		A:        difflib.SplitLines(ab.String()),
		B:        difflib.SplitLines(bb.String()),
		FromFile: "Godeps",
		ToFile:   "$GOPATH",
		Context:  10,
	}
	return difflib.GetUnifiedDiffString(diff)
}
開發者ID:roger2000hk,項目名稱:godep,代碼行數:23,代碼來源:diff.go


注:本文中的github.com/pmezard/go-difflib/difflib.GetUnifiedDiffString函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。