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


Golang diff.Diff函数代码示例

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


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

示例1: TestPretty

func TestPretty(t *testing.T) {
	var b bytes.Buffer
	for i, inout := range [][2]string{
		{"{}", "{}"},
		{`{"a":1}`, `{"a": 1
}`},
		{`{"m":{"a":1,"c":"b","b":[3,2,1]}}`, `{"m": {"a": 1,
    "b": [3,2,1],
    "c": "b"
  }
}`},
	} {
		m := make(map[string]interface{})
		if err := json.Unmarshal([]byte(inout[0]), &m); err != nil {
			t.Fatalf("%d. cannot unmarshal test input string: %v", i, err)
		}
		b.Reset()
		if err := Pretty(&b, m, ""); err != nil {
			t.Errorf("%d. Pretty: %v", i, err)
			continue
		}
		if inout[1] != b.String() {
			t.Errorf("%d. got %s\n\tawaited\n%s\n\tdiff\n%s", i, b.String(), inout[1],
				diff.Diff(inout[1], b.String()))
		}
	}
}
开发者ID:xingskycn,项目名称:go,代码行数:27,代码来源:jsondiff_test.go

示例2: TestConvertMainModuleToTemplate

func TestConvertMainModuleToTemplate(t *testing.T) {
	mod := intMainModule{
		Vars: []intVar{
			{"ch", "HandshakeChannel0"},
			{"__pid0_ch", "HandshakeChannel0Proxy(ch)"},
			{"proc1", "__pid0_ProcA(__pid0_ch)"},
		},
	}
	expected := []tmplModule{
		{
			Name: "main",
			Args: []string{},
			Vars: []tmplVar{
				{"ch", "HandshakeChannel0"},
				{"__pid0_ch", "HandshakeChannel0Proxy(ch)"},
				{"proc1", "__pid0_ProcA(__pid0_ch)"},
			},
		},
	}
	err, tmplMods := convertMainModuleToTemplate(mod)
	if err != nil {
		t.Fatalf("Unexpected error: %s", err)
	}
	expectPP := pp.PP(expected)
	actualPP := pp.PP(tmplMods)
	if expectPP != actualPP {
		t.Errorf("Unmatched\n%s\n", diff.Diff(expectPP, actualPP))
	}
}
开发者ID:psg-titech,项目名称:sandal,代码行数:29,代码来源:intermediate2template_test.go

示例3: Compare

// Compare returns a string containing a line-by-line unified diff of the
// values in got and want.  Compare includes unexported fields.
//
// Each line in the output is prefixed with '+', '-', or ' ' to indicate if it
// should be added to, removed from, or is correct for the "got" value with
// respect to the "want" value.
func Compare(got, want interface{}) string {
	diffOpt := &Config{
		Diffable:          true,
		IncludeUnexported: true,
	}

	return diff.Diff(diffOpt.Sprint(got), diffOpt.Sprint(want))
}
开发者ID:pwaller,项目名称:godebug,代码行数:14,代码来源:public.go

示例4: Diff

// Diff returns the line diff of the two JSON map[string]interface{}s.
func Diff(a map[string]interface{}, b map[string]interface{}) string {
	var bA, bB bytes.Buffer
	if err := Pretty(&bA, a, ""); err != nil {
		return "ERROR(a): " + err.Error()
	}
	if err := Pretty(&bB, b, ""); err != nil {
		return "ERROR(b): " + err.Error()
	}
	return diff.Diff(bA.String(), bB.String())
}
开发者ID:xingskycn,项目名称:go,代码行数:11,代码来源:jsondiff.go

示例5: TestConvertASTToNuSMV2

func TestConvertASTToNuSMV2(t *testing.T) {
	defs := []Def{
		ProcDef{
			Name: "ProcA",
			Parameters: []Parameter{
				{
					Name: "ch0",
					Type: BufferedChannelType{
						BufferSize: NumberExpr{Pos{}, "3"},
						Elems:      []Type{NamedType{"bool"}},
					},
				},
			},
			Stmts: []Stmt{
				VarDeclStmt{
					Name: "b",
					Type: NamedType{"int"},
				},
				SendStmt{
					Channel: IdentifierExpr{Pos{}, "ch0"},
					Args: []Expr{
						TrueExpr{Pos{}},
					},
				},
			},
		},
		InitBlock{
			Vars: []InitVar{
				ChannelVar{
					Name: "ch",
					Type: BufferedChannelType{
						BufferSize: NumberExpr{Pos{}, "3"},
						Elems:      []Type{NamedType{"bool"}},
					},
				},
				InstanceVar{
					Name:        "proc1",
					ProcDefName: "ProcA",
					Args: []Expr{
						IdentifierExpr{Pos{}, "ch"},
					},
				},
			},
		},
	}
	mod, err := ConvertASTToNuSMV(defs)
	if err != nil {
		t.Fatalf("Unexpected error: %s", err)
	}
	if mod != expectedResult2 {
		t.Errorf("Unmatched\n%s\n", diff.Diff(expectedResult2, mod))
	}
}
开发者ID:psg-titech,项目名称:sandal2,代码行数:53,代码来源:driver_test.go

示例6: TestNewApproach

func TestNewApproach(test *testing.T) {
	prep, _ := vfmd.QuickPrep(strings.NewReader(newApproach_input))
	result, err := QuickParse(bytes.NewReader(prep), BlocksAndSpans, nil, nil)
	if err != nil {
		test.Fatal(err)
	}
	expected := newApproach_flatOutput
	if !reflect.DeepEqual(result, expected) {
		// TODO(akavel): spew.Dump?
		test.Errorf("expected vs. got DIFF:\n%s",
			diff.Diff(spew.Sdump(expected), spew.Sdump(result)))
	}
}
开发者ID:akavel,项目名称:vfmd,代码行数:13,代码来源:block_deep_test.go

示例7: TestMapToSlice

func TestMapToSlice(t *testing.T) {
	for i, tc := range []struct {
		in, await string
	}{
		{`SELECT NVL(MAX(F_dazon), :dazon) FROM T_spl_level
	         WHERE (F_spl_azon = :lev_azon OR
			        F_ssz = 0 AND F_lev_azon = :lev_azon)`,
			`SELECT NVL(MAX(F_dazon), :1) FROM T_spl_level
	         WHERE (F_spl_azon = :2 OR
			        F_ssz = 0 AND F_lev_azon = :3)`},
		{`DECLARE
  i1 PLS_INTEGER;
  i2 PLS_INTEGER;
  v001 BRUNO.DB_WEB_ELEKTR.KOTVENY_REC_TYP;

BEGIN
  v001.dijkod := :p002#dijkod;

  DB_web.sendpreoffer_31101(p_kotveny=>v001);

  :p002#dijkod := v001.dijkod;

END;
`,
			`DECLARE
  i1 PLS_INTEGER;
  i2 PLS_INTEGER;
  v001 BRUNO.DB_WEB_ELEKTR.KOTVENY_REC_TYP;

BEGIN
  v001.dijkod := :1;

  DB_web.sendpreoffer_31101(p_kotveny=>v001);

  :2 := v001.dijkod;

END;
`},
	} {

		got, _ := MapToSlice(tc.in, nil)
		d := diff.Diff(tc.await, got)
		if d != "" {
			t.Errorf("%d. diff:\n%s", i, d)
		}
	}
}
开发者ID:rdterner,项目名称:go-1,代码行数:47,代码来源:orahlp_test.go

示例8: TestToJSON

func TestToJSON(t *testing.T) {
	tests := []struct {
		s    Schema
		want string
	}{
		{
			s: Schema{
				Name: "UsersResponse",
				Type: "object",
				Children: []Schema{
					{
						Name: "nextPageToken",
						Type: "string",
					},
					{
						Name: "users",
						Type: "array",
						Children: []Schema{
							{
								Ref: "User",
							},
						},
					},
				},
			},
			want: "```" + `
{
    nextPageToken: string,
    users: [
        User
    ]
}
` + "```",
		},
	}

	for i, tt := range tests {
		got := tt.s.toJSON()
		if d := diff.Diff(got, tt.want); d != "" {
			t.Errorf("case %d: want != got: %s", i, d)
		}
	}
}
开发者ID:GamerockSA,项目名称:dex,代码行数:43,代码来源:markdown_test.go

示例9: TestGetFdf

func TestGetFdf(t *testing.T) {
	var err error
	if Workdir, err = ioutil.TempDir("", "agostle-"); err != nil {
		t.Fatalf("tempdir for Workdir: %v", err)
	}
	defer os.RemoveAll(Workdir)

	s := time.Now()
	fp1, err := getFdf("testdata/f1040.pdf")
	t.Logf("PDF -> FDF vanilla route: %s", time.Since(s))
	if err != nil {
		t.Errorf("getFdf: %v", err)
	}
	if len(fp1.Fields) != 214 {
		t.Errorf("getFdf: got %d, awaited %d fields.", len(fp1.Fields), 214)
	}
	var buf1 bytes.Buffer
	if _, err = fp1.WriteTo(&buf1); err != nil {
		t.Errorf("WriteTo1: %v", err)
	}

	s = time.Now()
	fp2, err := getFdf("testdata/f1040.pdf")
	t.Logf("gob -> FDF route: %s", time.Since(s))
	if err != nil {
		t.Errorf("getFdf2: %v", err)
	}
	if !reflect.DeepEqual(fp1, fp2) {
		t.Errorf("getFdf2: got %#v, awaited %#v.", fp2, fp1)
	}
	var buf2 bytes.Buffer
	if _, err = fp2.WriteTo(&buf2); err != nil {
		t.Errorf("WroteTo2: %v", err)
	}
	if df := diff.Diff(buf1.String(), buf2.String()); df != "" {
		t.Errorf("DIFF: %s", df)
	}

	out, err := exec.Command("ls", "-l", Workdir).Output()
	if err == nil {
		t.Logf("ls -l %s:\n%s", Workdir, out)
	}
}
开发者ID:thanzen,项目名称:agostle,代码行数:43,代码来源:pdf_test.go

示例10: DiffStrings

// DiffStrings json.Unmarshals the strings and diffs that.
func DiffStrings(a, b string) (string, error) {
	mA := make(map[string]interface{})
	if err := json.Unmarshal([]byte(a), &mA); err != nil {
		return "", err
	}
	var bA bytes.Buffer
	if err := Pretty(&bA, mA, ""); err != nil {
		return "", err
	}

	mB := make(map[string]interface{})
	if err := json.Unmarshal([]byte(b), &mB); err != nil {
		return "", err
	}
	var bB bytes.Buffer
	if err := Pretty(&bB, mB, ""); err != nil {
		return "", err
	}

	return diff.Diff(bA.String(), bB.String()), nil
}
开发者ID:xingskycn,项目名称:go,代码行数:22,代码来源:jsondiff.go

示例11: diffs

func diffs() {
	// func Diff(old, new string) string
	// 行级比较,同"git diff"
	// new 跟 old 比较,
	// -old
	// +new
	// 	constitution := strings.TrimSpace(`
	// We the People of the United States, in Order to form a more perfect Union,
	// establish Justice, insure domestic Tranquility, provide for the common defence,
	// promote the general Welfare, and secure the Blessings of Liberty to ourselves
	// and our Posterity, do ordain and establish this Constitution for the United
	// States of America.
	// `)

	// 	got := strings.TrimSpace(`
	// :wq
	// We the People of the United States, in Order to form a more perfect Union,
	// establish Justice, insure domestic Tranquility, provide for the common defence,
	// and secure the Blessings of Liberty to ourselves
	// and our Posterity, do ordain and establish this Constitution for the United
	// States of America.
	// `)
	// 	P(diff.Diff(got, constitution))

	P(diff.Diff("old", "new"))

	// [ `run` | done: 2.495417ms ]
	// -old
	// +new
	/*

		Error loading syntax file "Packages/GoSublime/syntax/GoSublime-Go.tmLanguage":
		 Unable to open Packages/GoSublime/syntax/GoSublime-Go.tmLanguage
	*/

}
开发者ID:zykzhang,项目名称:practice,代码行数:36,代码来源:diff.go

示例12: TestUnpackObject_blob

func TestUnpackObject_blob(t *testing.T) {
	is := is.New(t)
	tcases := []struct {
		Fname  string
		Object *Object
	}{

		// blobs
		{
			Fname: "tests/blob/1f7a7a472abf3dd9643fd615f6da379c4acb3e3a",
			Object: &Object{
				Type: BlobT,
				Size: 10,
				blob: newBlob([]byte("version 2\n")),
			},
		},
		{
			Fname: "tests/blob/d670460b4b4aece5915caf5c68d12f560a9fe3e4",
			Object: &Object{
				Type: BlobT,
				Size: 13,
				blob: newBlob([]byte("test content\n")),
			},
		},

		// trees
		{
			Fname: "tests/tree/3c4e9cd789d88d8d89c1073707c3585e41b0e614",
			Object: &Object{Type: TreeT, Size: 101,
				tree: []Tree{
					{"40000", "bak", shaFromStr("\xd82\x9f\xc1̓\x87\x80\xffݟ\x94\xe0\xd3d\xe0\xeat\xf5y")},
					{"100644", "new.txt", shaFromStr("\xfaI\xb0w\x97#\x91\xadX\x03pP\xf2\xa7_t\xe3g\x1e\x92")},
					{"100644", "test.txt", shaFromStr("\x1fzzG*\xbf=\xd9d?\xd6\x15\xf6\xda7\x9cJ\xcb>:")},
				},
			},
		},
		{
			Fname: "tests/tree/0155eb4229851634a0f03eb265b69f5a2d56f341",
			Object: &Object{Type: TreeT, Size: 71,
				tree: []Tree{
					{"100644", "new.txt", shaFromStr("\xfaI\xb0w\x97#\x91\xadX\x03pP\xf2\xa7_t\xe3g\x1e\x92")},
					{"100644", "test.txt", shaFromStr("\x1fzzG*\xbf=\xd9d?\xd6\x15\xf6\xda7\x9cJ\xcb>:")},
				},
			},
		},

		// commit
		{
			Fname: "tests/commit/de70159e4a5842aed0aae9380e3006e909c8feb4",
			Object: &Object{Type: CommitT, Size: 165,
				commit: &Commit{
					Tree:      "d8329fc1cc938780ffdd9f94e0d364e0ea74f579",
					Author:    &Stamp{Name: "Henry", Email: "[email protected]", When: time.Unix(1438988455, 0)},
					Committer: &Stamp{Name: "Henry", Email: "[email protected]", When: time.Unix(1438988455, 0)},
					Message:   "first commit",
				},
			},
		},
		{
			Fname: "tests/commit/ad8fdc888c6f6caed63af0fb08484901e4e7e41e",
			Object: &Object{Type: CommitT, Size: 165,
				commit: &Commit{
					Tree:      "d8329fc1cc938780ffdd9f94e0d364e0ea74f579",
					Author:    &Stamp{Name: "Henry", Email: "[email protected]", When: time.Unix(1438995813, 0)},
					Committer: &Stamp{Name: "Henry", Email: "[email protected]", When: time.Unix(1438995813, 0)},
					Message:   "first commit",
				},
			},
			// TODO(cryptix): add example with Parent
		},
	}

	for _, tc := range tcases {
		f, err := os.Open(tc.Fname)
		is.Nil(err)
		obj, err := DecodeObject(f)
		is.Nil(err)
		diff := diff.Diff(obj.String(), tc.Object.String())
		is.Equal(diff, "")
		is.Nil(f.Close())
	}
}
开发者ID:ralphtheninja,项目名称:git-remote-ipfs,代码行数:82,代码来源:object_test.go

示例13: TestConvertHandshakeChannelToTemplate

func TestConvertHandshakeChannelToTemplate(t *testing.T) {
	mod := intHandshakeChannel{
		Name:      "HandshakeChannel0",
		ValueType: []string{"boolean"},
		ZeroValue: []string{"FALSE"},
	}
	expected := []tmplModule{
		{
			Name: "HandshakeChannel0",
			Args: []string{},
			Vars: []tmplVar{
				{"filled", "boolean"},
				{"received", "boolean"},
				{"value_0", "boolean"},
			},
			Assigns: []tmplAssign{
				{"init(filled)", "FALSE"},
				{"init(received)", "FALSE"},
				{"init(value_0)", "FALSE"},
			},
		},
		{
			Name: "HandshakeChannel0Proxy",
			Args: []string{"ch"},
			Vars: []tmplVar{
				{"send_filled", "boolean"},
				{"send_leaving", "boolean"},
				{"recv_received", "boolean"},
				{"send_value_0", "boolean"},
			},
			Defs: []tmplAssign{
				{"ready", "ch.filled"},
				{"received", "ch.received"},
				{"value_0", "ch.value_0"},
			},
			Assigns: []tmplAssign{
				{"next(ch.filled)", strings.Join([]string{
					"case",
					"  send_filled : TRUE;",
					"  send_leaving : FALSE;",
					"  TRUE : ch.filled;",
					"esac",
				}, "\n")},
				{"next(ch.received)", strings.Join([]string{
					"case",
					"  send_filled : FALSE;",
					"  send_leaving : FALSE;",
					"  recv_received : TRUE;",
					"  TRUE : ch.received;",
					"esac",
				}, "\n")},
				{"next(ch.value_0)", strings.Join([]string{
					"case",
					"  send_filled : send_value_0;",
					"  TRUE : ch.value_0;",
					"esac",
				}, "\n")},
			},
		},
	}
	err, tmplMods := convertHandshakeChannelToTemplate(mod)
	if err != nil {
		t.Fatalf("Unexpected error: %s", err)
	}
	expectPP := pp.PP(expected)
	actualPP := pp.PP(tmplMods)
	if expectPP != actualPP {
		t.Errorf("Unmatched\n%s\n", diff.Diff(expectPP, actualPP))
	}
}
开发者ID:psg-titech,项目名称:sandal,代码行数:70,代码来源:intermediate2template_test.go

示例14: TestConvertProcModuleToTemplate

func TestConvertProcModuleToTemplate(t *testing.T) {
	mod := intProcModule{
		Name: "__pid0_ProcA",
		Args: []string{"ch0"},
		Vars: []intVar{
			{"b", "0..8"},
		},
		InitState: intState("state0"),
		Trans: []intTransition{
			{
				FromState: "state0",
				NextState: "state1",
				Condition: "",
			},
			{
				FromState: "state1",
				NextState: "state2",
				Condition: "!ch0.ready",
				Actions: []intAssign{
					{"ch0.send_filled", "TRUE"},
					{"ch0.send_value_0", "TRUE"},
				},
			},
		},
		Defaults: map[string]string{
			"ch0.send_filled":   "FALSE",
			"ch0.recv_received": "FALSE",
			"ch0.send_value_0":  "ch0.value_0",
		},
		Defs: []intAssign{},
	}
	expected := []tmplModule{
		{
			Name: "__pid0_ProcA",
			Args: []string{"ch0"},
			Vars: []tmplVar{
				{"state", "{state0, state1, state2}"},
				{"transition", "{notrans, trans0, trans1}"},
				{"b", "0..8"},
			},
			Trans: []string{
				"transition = trans0 -> (TRUE)",
				"transition = trans1 -> (!ch0.ready)",
			},
			Assigns: []tmplAssign{
				{"transition", strings.Join([]string{
					"case",
					"  state = state0 & ((TRUE)) : {trans0};",
					"  state = state1 & ((!ch0.ready)) : {trans1};",
					"  TRUE : notrans;",
					"esac",
				}, "\n")},
				{"init(state)", "state0"},
				{"next(state)", strings.Join([]string{
					"case",
					"  transition = trans0 : state1;",
					"  transition = trans1 : state2;",
					"  TRUE : state;",
					"esac",
				}, "\n")},
				{"ch0.send_filled", strings.Join([]string{
					"case",
					"  transition = trans1 : TRUE;",
					"  TRUE : FALSE;",
					"esac",
				}, "\n")},
				{"ch0.recv_received", strings.Join([]string{
					"case",
					"  TRUE : FALSE;",
					"esac",
				}, "\n")},
				{"ch0.send_value_0", strings.Join([]string{
					"case",
					"  transition = trans1 : TRUE;",
					"  TRUE : ch0.value_0;",
					"esac",
				}, "\n")},
			},
			Justice: "running",
		},
	}
	err, tmplMods := convertProcModuleToTemplate(mod)
	if err != nil {
		t.Fatalf("Unexpected error: %s", err)
	}
	expectPP := pp.PP(expected)
	actualPP := pp.PP(tmplMods)
	if expectPP != actualPP {
		t.Errorf("Unmatched\n%s\n", diff.Diff(expectPP, actualPP))
	}
}
开发者ID:psg-titech,项目名称:sandal,代码行数:91,代码来源:intermediate2template_test.go

示例15: TestArgs


//.........这里部分代码省略.........
						},
						[]Param{
							&PathParam{paramCommon{name: "src"}, str("/tmp/hello")},
							&PathParam{paramCommon{name: "dst"}, str("/var/hello")},
						},
					},
				},
			},
		},
		{
			name: "list of key values",
			cfg: `{
                 "params": [
                     {
                         "type": "List",
                         "name": "mounts",
                         "spec": {
                            "name": "volume",
                            "type": "KeyVal",
                            "spec": {
                              "keys": [
                                  {"name": "src", "type":"Path"},
                                  {"name": "dst", "type":"Path"}
                              ]
                            }
                        }
                     }
                  ]
               }`,
			args: []string{"--volume", "/tmp/hello:/var/hello"},
			vars: map[string]string{"VOLUME": "/tmp/hello:/var/hello"},
			expect: &Config{
				Params: []Param{
					&ListParam{
						paramCommon{name: "mounts"},
						&KVParam{
							paramCommon{name: "volume"},
							"",
							[]Param{
								&PathParam{paramCommon{name: "src"}, nil},
								&PathParam{paramCommon{name: "dst"}, nil},
							},
							nil,
						},
						[]Param{
							&KVParam{
								paramCommon{name: "volume"},
								"",
								[]Param{
									&PathParam{paramCommon{name: "src"}, nil},
									&PathParam{paramCommon{name: "dst"}, nil},
								},
								[]Param{
									&PathParam{paramCommon{name: "src"}, str("/tmp/hello")},
									&PathParam{paramCommon{name: "dst"}, str("/var/hello")},
								},
							},
						},
					},
				},
			},
		},
	}
	for i, tc := range tcs {
		comment := Commentf(
			"test #%d (%v) cfg=%v, args=%v", i+1, tc.name, tc.cfg, tc.args)
		cfg, err := ParseJSON(strings.NewReader(tc.cfg))
		c.Assert(err, IsNil, comment)

		if tc.expectErr {
			c.Assert(cfg.ParseArgs(tc.args), NotNil)
			continue
		}

		// make sure all the values have been parsed
		c.Assert(cfg.ParseArgs(tc.args), IsNil)
		c.Assert(len(cfg.Params), Equals, len(tc.expect.Params))
		for i, _ := range cfg.Params {
			comment := Commentf(
				"test #%d (%v) cfg=%v, args=%v\n%v",
				i+1, tc.name, tc.cfg, tc.args,
				diff.Diff(
					fmt.Sprintf("%# v", pretty.Formatter(cfg.Params[i])),
					fmt.Sprintf("%# v", pretty.Formatter(tc.expect.Params[i]))),
			)
			c.Assert(cfg.Params[i], DeepEquals, tc.expect.Params[i], comment)
		}

		// make sure args are equivalent to the passed arguments
		if len(tc.args) != 0 {
			args := cfg.Args()
			c.Assert(args, DeepEquals, tc.args, comment)
		}

		// make sure vars are what we expect them to be
		if len(tc.vars) != 0 {
			c.Assert(cfg.EnvVars(), DeepEquals, tc.vars, comment)
		}
	}
}
开发者ID:gravitational,项目名称:configure,代码行数:101,代码来源:schema_test.go


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