当前位置: 首页>>代码示例>>Golang>>正文


Golang difflib.SplitLines函数代码示例

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


在下文中一共展示了SplitLines函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: NewDiffInfo

func NewDiffInfo(target string) (*DiffInfo, error) {
	from := path.Join(rsyncFrom, target)
	to := path.Join(rsyncTo, target)
	fromExist := isFileExist(from)
	fromIsDiffTarget := isDiffTarget(from)
	toExist := isFileExist(to)
	toIsDiffTarget := isDiffTarget(to)
	fromLines := ""
	if fromExist && fromIsDiffTarget {
		bytes, err := ioutil.ReadFile(from)
		if err != nil {
			return nil, err
		}
		fromLines = string(bytes)
	}
	toLines := ""
	if toExist && toIsDiffTarget {
		bytes, err := ioutil.ReadFile(to)
		if err != nil {
			return nil, err
		}
		toLines = string(bytes)
	}

	info := &DiffInfo{}
	info.A = difflib.SplitLines(toLines)
	info.B = difflib.SplitLines(fromLines)
	info.FromFile = from
	info.ToFile = to
	return info, nil
}
开发者ID:kaneda-t,项目名称:rsyncdiff,代码行数:31,代码来源: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: formatFile

func formatFile(filepath string, runWrite, runDiff bool) error {
	format, _ := fzp.GetFormat(filepath)

	if format != fzp.FormatFzp {
		return errors.New("at the moment only fzp format supported")
	}

	fzpFile, fzpBytes, err := fzp.ReadFzp(filepath)
	if err != nil {
		fmt.Println(err)
		return err
	}

	formattedXML, err := fzpFile.ToXML()
	if err != nil {
		fmt.Println(err)
		return err
	}

	if runWrite {
		err := ioutil.WriteFile(filepath, formattedXML, 0755)
		if err != nil {
			fmt.Println("Error", err)
			os.Exit(127)
		}
		return nil
	}

	// diff
	if runDiff {
		diff := difflib.ContextDiff{
			A:        difflib.SplitLines(string(fzpBytes)),
			B:        difflib.SplitLines(string(formattedXML)),
			FromFile: filepath,
			ToFile:   "Current",
			Context:  3,
			Eol:      "\n",
		}
		result, _ := difflib.GetContextDiffString(diff)
		fmt.Printf(strings.Replace(result, "\t", " ", -1))
		return nil
	}

	fmt.Println(string(formattedXML))
	return nil
}
开发者ID:fritzing,项目名称:fzp,代码行数:46,代码来源:command-format.go

示例12: 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

示例13: Diff

// Diff consumes the entire reader streams into memory before generating a diff
// which then gets filled into the buffer. This implementation stores and
// manipulates all three values in memory.
func (diff *differ) Diff(out io.Writer, a io.ReadSeeker, b io.ReadSeeker) error {
	var src, dst []byte
	var err error

	if src, err = ioutil.ReadAll(a); err != nil {
		return err
	}
	if dst, err = ioutil.ReadAll(b); err != nil {
		return err
	}

	d := difflib.UnifiedDiff{
		A:       difflib.SplitLines(string(src)),
		B:       difflib.SplitLines(string(dst)),
		Context: 3,
	}

	return difflib.WriteUnifiedDiff(out, d)
}
开发者ID:shazow,项目名称:go-diff,代码行数:22,代码来源:differ.go

示例14: 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

示例15: 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.SplitLines函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。