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

Golang diff.Diff函数代码示例

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

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



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


示例16: TestProviderConfigMarshal


//.........这里部分代码省略.........
			// spacing must match json.MarshalIndent(cfg, "", "\t")
			want: `{
	"issuer": "https://auth.example.com",
	"authorization_endpoint": "https://auth.example.com/auth",
	"token_endpoint": "https://auth.example.com/token",
	"userinfo_endpoint": "https://auth.example.com/userinfo",
	"jwks_uri": "https://auth.example.com/jwk",
	"response_types_supported": [
		"code"
	],
	"subject_types_supported": [
		"public"
	],
	"id_token_signing_alg_values_supported": [
		"RS256"
	]
}`,
		},
		{
			cfg: ProviderConfig{
				Issuer: &url.URL{Scheme: "https", Host: "auth.example.com"},
				AuthEndpoint: &url.URL{
					Scheme: "https", Host: "auth.example.com", Path: "/auth",
				},
				TokenEndpoint: &url.URL{
					Scheme: "https", Host: "auth.example.com", Path: "/token",
				},
				UserInfoEndpoint: &url.URL{
					Scheme: "https", Host: "auth.example.com", Path: "/userinfo",
				},
				KeysEndpoint: &url.URL{
					Scheme: "https", Host: "auth.example.com", Path: "/jwk",
				},
				RegistrationEndpoint: &url.URL{
					Scheme: "https", Host: "auth.example.com", Path: "/register",
				},
				ScopesSupported:         DefaultScope,
				ResponseTypesSupported:  []string{oauth2.ResponseTypeCode},
				ResponseModesSupported:  DefaultResponseModesSupported,
				GrantTypesSupported:     []string{oauth2.GrantTypeAuthCode},
				SubjectTypesSupported:   []string{SubjectTypePublic},
				IDTokenSigningAlgValues: []string{jose.AlgRS256},
				ServiceDocs:             &url.URL{Scheme: "https", Host: "example.com", Path: "/docs"},
			},
			// spacing must match json.MarshalIndent(cfg, "", "\t")
			want: `{
	"issuer": "https://auth.example.com",
	"authorization_endpoint": "https://auth.example.com/auth",
	"token_endpoint": "https://auth.example.com/token",
	"userinfo_endpoint": "https://auth.example.com/userinfo",
	"jwks_uri": "https://auth.example.com/jwk",
	"registration_endpoint": "https://auth.example.com/register",
	"scopes_supported": [
		"openid",
		"email",
		"profile"
	],
	"response_types_supported": [
		"code"
	],
	"response_modes_supported": [
		"query",
		"fragment"
	],
	"grant_types_supported": [
		"authorization_code"
	],
	"subject_types_supported": [
		"public"
	],
	"id_token_signing_alg_values_supported": [
		"RS256"
	],
	"service_documentation": "https://example.com/docs"
}`,
		},
	}

	for i, tt := range tests {
		got, err := json.MarshalIndent(&tt.cfg, "", "\t")
		if err != nil {
			t.Errorf("case %d: failed to marshal config: %v", i, err)
			continue
		}
		if d := diff.Diff(string(got), string(tt.want)); d != "" {
			t.Errorf("case %d: expected did not match result: %s", i, d)
		}

		var cfg ProviderConfig
		if err := json.Unmarshal(got, &cfg); err != nil {
			t.Errorf("case %d: could not unmarshal marshal response: %v", i, err)
			continue
		}

		if d := pretty.Compare(tt.cfg, cfg); d != "" {
			t.Errorf("case %d: config did not survive JSON marshaling round trip: %s", i, d)
		}
	}

}
开发者ID:GamerockSA,项目名称:dex,代码行数:101,代码来源:provider_test.go


示例17: TestHTMLFiles


//.........这里部分代码省略.........
		{"span_level/link/ref_resolution_within_other_blocks.md"},
		{"span_level/link/square_brackets_in_link_or_ref.md"},
		{"span_level/link/two_consecutive_refs.md"},
		{"span_level/link/unused_ref.md"},
		{"span_level/link/url_escapes.md"},
		{"span_level/link/url_in_angle_brackets.md"},
		{"span_level/link/url_special_chars.md"},
		{"span_level/link/url_whitespace.md"},
		{"span_level/link/vs_code.md"},
		{"span_level/link/vs_emph.md"},
		{"span_level/link/vs_image.md"},

		{"text_processing/utf8/invalid_unicode.md"},
		{"text_processing/utf8/multibyte_chars.md"},
		{"text_processing/utf8/not_enough_continuation_bytes.md"},
		{"text_processing/utf8/overlong_encoding.md"},
		{"text_processing/utf8/stray_continuation_bytes.md"},
		{"text_processing/utf8_bom/code_block_with_bom.md"},
		{"text_processing/utf8_bom/eof_with_incomplete_bom.md"},
		{"text_processing/utf8_bom/list_with_bom.md"},
		{"text_processing/utf8_bom/text_with_bom.md"},
	}

	// Patches to what I believe are bugs in the original testdata, when
	// confronted with the spec.
	replacer := strings.NewReplacer(
		"'>'", "'>'",
		"'", "'",
		`"/>`, `" />`,
		// TODO(akavel): consider fixing (?) below line in our code
		""", """,
		// TODO(akavel): ...do something sensible so that this doesn't fail the diff.Diff?...
		"%5C", "%5c",
		// TODO(akavel): mitigate this somehow? or not? X|
		`<img src="url)"`, `<img src="url%29"`,
		`<img src="url("`, `<img src="url%28"`,
		`<a href="url)"`, `<a href="url%29"`,
		`<a href="url("`, `<a href="url%28"`,
		// TODO(akavel): I assume html/template has this ok, but need to verify at some point
		`<img src="url*#$%%5E&amp;%5C%7E"`, `<img src="url*#$%25%5e&amp;%5c~"`,
		`<a href="url*#$%%5E&amp;%5C%7E"`, `<a href="url*#$%25%5e&amp;%5c~"`,
		// TODO(akavel): or not TODO? HTML entities currently not supported, incl. in URLs
		`<a href="http://g&ouml;&ouml;gle.com">`, `<a href="http://g&amp;ouml;&amp;ouml;gle.com">`,
		`<img src="http://g&ouml;&ouml;gle.com"`, `<img src="http://g&amp;ouml;&amp;ouml;gle.com"`,
		// Various newline/space fixes in the testcases.
		"\n<li>\n    Parent list\n\n    <ol>", "\n<li>Parent list<ol>",
		"<code>Code block included in list\n</code>", "<code> Code block included in list\n</code>",
		"And another\n\n<p>Another para", "And another<p>Another para",
		"<li>Level 1\n<ol>", "<li>Level 1<ol>",
		"<li>Level 2\n<p>", "<li>Level 2<p>",
		"<li>Level 3\n<p>", "<li>Level 3<p>",
		"Level 4\n<ul>", "Level 4<ul>",
		"<li>Level 2\n<ol>", "<li>Level 2<ol>",
		"And another\n<p>", "And another<p>",
		"<li>Parent list\n    <ul>", "<li>Parent list<ul>",
		"<li>Third list\n<ul>", "<li>Third list<ul>",
		"<pre><code>Code block included in list</code></pre>", "<pre><code>Code block included in list\n</code></pre>",
		"<pre><code>Code block not included in list</code></pre>", "<pre><code>Code block not included in list\n</code></pre>",
		"<li>Level 1\n<ul>", "<li>Level 1<ul>",
		"<li>Level 2\n<ul>", "<li>Level 2<ul>",
	)

	for _, c := range cases {
		test.Log(c.path)
		subdir, fname := path.Split(c.path)
		fname = strings.TrimSuffix(fname, ".md")
		data, err := ioutil.ReadFile(filepath.Join(dir, c.path))
		if err != nil {
			test.Error(err)
			continue
		}
		expectedOutput, err := ioutil.ReadFile(
			filepath.Join(dir, subdir, "expected", fname+".html"))
		if err != nil {
			test.Error(err)
			continue
		}
		prep, _ := QuickPrep(bytes.NewReader(data))
		blocks, err := mdblock.QuickParse(bytes.NewReader(prep), mdblock.BlocksAndSpans, nil, nil)
		if err != nil {
			test.Errorf("case %s error: %s", c.path, err)
			continue
		}

		buf := bytes.NewBuffer(nil)
		err = QuickHTML(buf, blocks)
		if err != nil {
			test.Error(err)
			continue
		}
		html := simplifyHtml(buf.Bytes())
		expectedOutput = []byte(replacer.Replace(string(simplifyHtml(expectedOutput))))
		if !bytes.Equal(html, expectedOutput) {
			test.Errorf("case %s blocks:\n%s",
				c.path, spew.Sdump(blocks))
			test.Errorf("case %s expected vs. got DIFF:\n%s",
				c.path, diff.Diff(string(expectedOutput), string(html)))
		}
	}
}
开发者ID:akavel,项目名称:vfmd,代码行数:101,代码来源:html_test.go


示例18: TestSplitFdf


//.........这里部分代码省略.........
<<
/V ()
/T (Forgalmi rendszámRow5)
>>]
>>
>>
endobj
trailer

<<
/Root 1 0 R
>>
%%EOF
`)

	fp := splitFdf(fdf)
	if len(fp.Parts) != 64 {
		t.Errorf("wanted 64 parts, got %d", len(fp.Parts))
	}
	if len(fp.Fields) != 63 {
		t.Errorf("wanted 63 fields, got %d", len(fp.Fields))
	}
	t.Logf("splitted=%q (%d)", fp, len(fp.Parts))

	if err := fp.Set("A baleset helye", "Kiskunbürgözd"); err != nil {
		t.Errorf("Set: %v", err)
	}

	var buf bytes.Buffer
	if _, err := fp.WriteTo(&buf); err != nil {
		t.Errorf("WriteTo: %v", err)
	}

	df := diff.Diff(buf.String(), `%FDF-1.2
%âăĎÓ
1 0 obj
<<
/FDF
<<
/Fields [
<<
/V ()
/T (Forgalmi rendszámRow4)
>>
<<
/V ()
/T (Forgalmi rendszámRow3)
>>
<<
/V ()
/T (Forgalmi rendszámRow2)
>>
<<
/V ()
/T (Az Ön gépjárművének forgalmi rendszáma)
>>
<<
/V ()
/T (Forgalmi rendszámRow1)
>>
<<
/V ()
/T (neve_2)
>>
<<
/V ()
开发者ID:thanzen,项目名称:agostle,代码行数:67,代码来源:pdf_test.go


示例19: TestConvertASTToIntModuleForSend


//.........这里部分代码省略.........
			ValueType: []string{"boolean"},
			ZeroValue: []string{"FALSE"},
		},
		intProcModule{
			Name: "__pid0_SendProc",
			Args: []string{"__orig_ch"},
			Vars: []intVar{
				{"ch", "HandshakeChannel0Proxy(__orig_ch)"},
			},
			InitState: intState("state0"),
			Trans: []intTransition{
				{
					FromState: "state0",
					NextState: "state2",
					Condition: "",
					Actions:   []intAssign(nil),
				},
				{
					FromState: "state2",
					NextState: "state3",
					Condition: "!(ch.ready)",
					Actions: []intAssign{
						{"ch.send_filled", "TRUE"},
						{"ch.send_value_0", "TRUE"},
					},
				},
				{
					FromState: "state3",
					NextState: "state4",
					Condition: "(ch.ready) & (ch.received)",
					Actions: []intAssign{
						{"ch.send_leaving", "TRUE"},
					},
				},
				{
					FromState: "state4",
					NextState: "state1",
					Condition: "",
					Actions:   []intAssign(nil),
				},
				{
					FromState: "state0",
					NextState: "state5",
					Condition: "",
					Actions:   []intAssign(nil),
				},
				{
					FromState: "state5",
					NextState: "state6",
					Condition: "!(ch.ready)",
					Actions: []intAssign{
						{"ch.send_filled", "TRUE"},
						{"ch.send_value_0", "TRUE"},
					},
				},
				{
					FromState: "state6",
					NextState: "state7",
					Condition: "(ch.ready) & (ch.received)",
					Actions: []intAssign{
						{"ch.send_leaving", "TRUE"},
					},
				},
				{
					FromState: "state7",
					NextState: "state1",
					Condition: "",
					Actions:   []intAssign(nil),
				},
			},
			Defaults: map[string]string{
				"ch.send_leaving":  "FALSE",
				"ch.send_filled":   "FALSE",
				"ch.recv_received": "FALSE",
				"ch.send_value_0":  "ch.value_0",
			},
			Defs: []intAssign(nil),
		},
		intMainModule{
			Vars: []intVar{
				{"ch", "HandshakeChannel0"},
				{"sp", "process __pid0_SendProc(ch)"},
			},
		},
	}

	scanner := new(parsing.Scanner)
	scanner.Init([]rune(sendWithTagSource), 0)
	defs := parsing.Parse(scanner)

	err, intMods := astToIr1(defs)
	if err != nil {
		t.Fatalf("Unexpected error: %s", err)
	}
	actualPP := pp.PP(intMods)
	expectPP := pp.PP(expected)
	if actualPP != expectPP {
		t.Errorf("Unmatched\n%s\n", diff.Diff(expectPP, actualPP))
	}
}
开发者ID:psg-titech,项目名称:sandal2,代码行数:101,代码来源:ir1_test.go


示例20: TestConvertASTToIntModule


//.........这里部分代码省略.........
					Type: HandshakeChannelType{
						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: HandshakeChannelType{
						Elems: []Type{NamedType{"bool"}},
					},
				},
				InstanceVar{
					Name:        "proc1",
					ProcDefName: "ProcA",
					Args: []Expr{
						IdentifierExpr{Pos{}, "ch"},
					},
				},
			},
		},
	}
	expected := []intModule{
		intHandshakeChannel{
			Name:      "HandshakeChannel0",
			ValueType: []string{"boolean"},
			ZeroValue: []string{"FALSE"},
		},
		intProcModule{
			Name: "__pid0_ProcA",
			Args: []string{"__orig_ch0"},
			Vars: []intVar{
				{"ch0", "HandshakeChannel0Proxy(__orig_ch0)"},
				{"b", "0..1"},
			},
			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"},
					},
				},
				{
					FromState: "state2",
					NextState: "state3",
					Condition: "(ch0.ready) & (ch0.received)",
					Actions: []intAssign{
						{"ch0.send_leaving", "TRUE"},
					},
				},
			},
			Defaults: map[string]string{
				"ch0.send_leaving":  "FALSE",
				"ch0.send_filled":   "FALSE",
				"ch0.recv_received": "FALSE",
				"ch0.send_value_0":  "ch0.value_0",
				"next(b)":           "b",
			},
			Defs: []intAssign{},
		},
		intMainModule{
			Vars: []intVar{
				{"ch", "HandshakeChannel0"},
				{"proc1", "process __pid0_ProcA(ch)"},
			},
		},
	}
	err, intMods := astToIr1(defs)
	if err != nil {
		t.Fatalf("Unexpected error: %s", err)
	}
	expectPP := pp.PP(expected)
	actualPP := pp.PP(intMods)
	if expectPP != actualPP {
		t.Errorf("Unmatched\n%s\n", diff.Diff(expectPP, actualPP))
	}
}
开发者ID:psg-titech,项目名称:sandal2,代码行数:101,代码来源:ir1_test.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang pretty.Compare函数代码示例发布时间:2022-05-23
下一篇:
Golang webrpc.ServeMux类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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