Example #1
0
func TestShorterThanExpectedString(t *testing.T) {
	s1 := "one\ntwo\nthree\nfour\n"
	s2 := "one\ntwo\nthree\n"
	a, b := bytes.NewBufferString(s1), bytes.NewBufferString(s2)

	diffs, err := text.Compare(a, b)

	if err != nil {
		t.Error(err)
	}

	if len(diffs) != 1 {
		t.Errorf("Expected 1 diffs, got %d", len(diffs))
		for _, d := range diffs {
			t.Errorf(d.String())
		}
	}

	if len(diffs) > 0 {
		ed := core.Diff{Expected: "four", Actual: nil, Pos: []string{"4"}}
		ad := diffs[0]

		if !ad.Equals(ed) {
			t.Errorf("Expected %s but got %s", ed, ad)
		}
	}
}
Example #2
0
func TestDifferentStrings(t *testing.T) {
	s1 := "one\ntwo\nthree\nfour\n"
	s2 := "one\nTwo\nthree\nfore\n"
	a, b := bytes.NewBufferString(s1), bytes.NewBufferString(s2)

	diffs, err := text.Compare(a, b)

	if err != nil {
		t.Error(err)
	}
	if len(diffs) != 2 {
		t.Errorf("Expected 2 diffs, got %d", len(diffs))
	}

	if len(diffs) > 0 {
		ed := core.Diff{Expected: "two", Actual: "Two", Pos: []string{"2"}}
		ad := diffs[0]

		if !ad.Equals(ed) {
			t.Errorf("Expected %s but got %s", ed, ad)
		}
	}

	if len(diffs) > 1 {
		ed := core.Diff{Expected: "four", Actual: "fore", Pos: []string{"4"}}
		ad := diffs[1]

		if !ad.Equals(ed) {
			t.Errorf("Expected %s but got %s", ed, ad)
		}
	}
}
Example #3
0
func TestSimilarStrings(t *testing.T) {
	s := "one\ntwo\nthree\nfour\n"
	a, b := bytes.NewBufferString(s), bytes.NewBufferString(s)

	diffs, err := text.Compare(a, b)

	if err != nil {
		t.Error(err)
	}
	for _, diff := range diffs {
		t.Errorf(diff.String())
	}
}
Example #4
0
func (t textEvidence) Check(approved io.Reader) ([]core.Diff, error) {
	return text.Compare(approved, t.Reader)
}
Example #5
0
func (x *xmlEvidence) Check(approved io.Reader) ([]core.Diff, error) {
	return text.Compare(approved, &x.Buffer)
}