Documentation ¶
Index ¶
- func CallerInfo() []string
- func Contains(t TestingT, s, contains interface{}, msgAndArgs ...interface{}) bool
- func Containsf(t TestingT, s interface{}, contains interface{}, msg string, ...) bool
- func DifferentAddressRanges(t TestingT, a, b []byte) (ok bool)
- func ElementsMatch(t TestingT, listA, listB interface{}, msgAndArgs ...interface{}) (ok bool)
- func ElementsMatchf(t TestingT, listA interface{}, listB interface{}, msg string, ...) bool
- func Equal(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool
- func EqualBSON(t TestingT, expected, actual interface{}) bool
- func EqualError(t TestingT, theError error, errString string, msgAndArgs ...interface{}) bool
- func EqualErrorf(t TestingT, theError error, errString string, msg string, args ...interface{}) bool
- func EqualValues(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool
- func EqualValuesf(t TestingT, expected interface{}, actual interface{}, msg string, ...) bool
- func Equalf(t TestingT, expected interface{}, actual interface{}, msg string, ...) bool
- func Error(t TestingT, err error, msgAndArgs ...interface{}) bool
- func ErrorContains(t TestingT, theError error, contains string, msgAndArgs ...interface{}) bool
- func ErrorContainsf(t TestingT, theError error, contains string, msg string, args ...interface{}) bool
- func ErrorIs(t TestingT, err, target error, msgAndArgs ...interface{}) bool
- func Errorf(t TestingT, err error, msg string, args ...interface{}) bool
- func Eventually(t TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, ...) bool
- func Eventuallyf(t TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, ...) bool
- func Fail(t TestingT, failureMessage string, msgAndArgs ...interface{}) bool
- func FailNow(t TestingT, failureMessage string, msgAndArgs ...interface{}) bool
- func FailNowf(t TestingT, failureMessage string, msg string, args ...interface{}) bool
- func Failf(t TestingT, failureMessage string, msg string, args ...interface{}) bool
- func False(t TestingT, value bool, msgAndArgs ...interface{}) bool
- func Falsef(t TestingT, value bool, msg string, args ...interface{}) bool
- func GetContextDiffString(diff ContextDiff) (string, error)
- func GetUnifiedDiffString(diff UnifiedDiff) (string, error)
- func Greater(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) bool
- func GreaterOrEqual(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) bool
- func GreaterOrEqualf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) bool
- func Greaterf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) bool
- func InDelta(t TestingT, expected, actual interface{}, delta float64, ...) bool
- func InDeltaf(t TestingT, expected interface{}, actual interface{}, delta float64, ...) bool
- func IsType(t TestingT, expectedType interface{}, object interface{}, ...) bool
- func IsTypef(t TestingT, expectedType interface{}, object interface{}, msg string, ...) bool
- func Len(t TestingT, object interface{}, length int, msgAndArgs ...interface{}) bool
- func Lenf(t TestingT, object interface{}, length int, msg string, args ...interface{}) bool
- func Less(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) bool
- func LessOrEqual(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) bool
- func LessOrEqualf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) bool
- func Lessf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) bool
- func Negative(t TestingT, e interface{}, msgAndArgs ...interface{}) bool
- func Negativef(t TestingT, e interface{}, msg string, args ...interface{}) bool
- func Nil(t TestingT, object interface{}, msgAndArgs ...interface{}) bool
- func Nilf(t TestingT, object interface{}, msg string, args ...interface{}) bool
- func NoError(t TestingT, err error, msgAndArgs ...interface{}) bool
- func NoErrorf(t TestingT, err error, msg string, args ...interface{}) bool
- func NotContains(t TestingT, s, contains interface{}, msgAndArgs ...interface{}) bool
- func NotContainsf(t TestingT, s interface{}, contains interface{}, msg string, ...) bool
- func NotEqual(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool
- func NotEqualValues(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool
- func NotEqualValuesf(t TestingT, expected interface{}, actual interface{}, msg string, ...) bool
- func NotEqualf(t TestingT, expected interface{}, actual interface{}, msg string, ...) bool
- func NotNil(t TestingT, object interface{}, msgAndArgs ...interface{}) bool
- func NotNilf(t TestingT, object interface{}, msg string, args ...interface{}) bool
- func ObjectsAreEqual(expected, actual interface{}) bool
- func ObjectsAreEqualValues(expected, actual interface{}) bool
- func Positive(t TestingT, e interface{}, msgAndArgs ...interface{}) bool
- func Positivef(t TestingT, e interface{}, msg string, args ...interface{}) bool
- func Soon(t TestingT, callback func(ctx context.Context), timeout time.Duration)deprecated
- func SplitLines(s string) []string
- func True(t TestingT, value bool, msgAndArgs ...interface{}) bool
- func Truef(t TestingT, value bool, msg string, args ...interface{}) bool
- func WithinDuration(t TestingT, expected, actual time.Time, delta time.Duration, ...) bool
- func WithinDurationf(t TestingT, expected time.Time, actual time.Time, delta time.Duration, ...) bool
- func WriteContextDiff(writer io.Writer, diff ContextDiff) error
- func WriteUnifiedDiff(writer io.Writer, diff UnifiedDiff) error
- type CompareType
- type ContextDiff
- type Match
- type OpCode
- type SequenceMatcher
- func (m *SequenceMatcher) GetGroupedOpCodes(n int) [][]OpCode
- func (m *SequenceMatcher) GetMatchingBlocks() []Match
- func (m *SequenceMatcher) GetOpCodes() []OpCode
- func (m *SequenceMatcher) QuickRatio() float64
- func (m *SequenceMatcher) Ratio() float64
- func (m *SequenceMatcher) RealQuickRatio() float64
- func (m *SequenceMatcher) SetSeq1(a []string)
- func (m *SequenceMatcher) SetSeq2(b []string)
- func (m *SequenceMatcher) SetSeqs(a, b []string)
- type TestingT
- type UnifiedDiff
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CallerInfo ¶
func CallerInfo() []string
CallerInfo returns an array of strings containing the file and line number of each stack frame leading from the current test to the assert call that failed.
func Contains ¶
Contains asserts that the specified string, list(array, slice...) or map contains the specified substring or element.
assert.Contains(t, "Hello World", "World") assert.Contains(t, ["Hello", "World"], "World") assert.Contains(t, {"Hello": "World"}, "Hello")
func Containsf ¶
func Containsf(t TestingT, s interface{}, contains interface{}, msg string, args ...interface{}) bool
Containsf asserts that the specified string, list(array, slice...) or map contains the specified substring or element.
assert.Containsf(t, "Hello World", "World", "error message %s", "formatted") assert.Containsf(t, ["Hello", "World"], "World", "error message %s", "formatted") assert.Containsf(t, {"Hello": "World"}, "Hello", "error message %s", "formatted")
func DifferentAddressRanges ¶
DifferentAddressRanges asserts that two byte slices reference distinct memory address ranges, meaning they reference different underlying byte arrays.
func ElementsMatch ¶
ElementsMatch asserts that the specified listA(array, slice...) is equal to specified listB(array, slice...) ignoring the order of the elements. If there are duplicate elements, the number of appearances of each of them in both lists should match.
assert.ElementsMatch(t, [1, 3, 2, 3], [1, 3, 3, 2])
func ElementsMatchf ¶
func ElementsMatchf(t TestingT, listA interface{}, listB interface{}, msg string, args ...interface{}) bool
ElementsMatchf asserts that the specified listA(array, slice...) is equal to specified listB(array, slice...) ignoring the order of the elements. If there are duplicate elements, the number of appearances of each of them in both lists should match.
assert.ElementsMatchf(t, [1, 3, 2, 3], [1, 3, 3, 2], "error message %s", "formatted")
func Equal ¶
Equal asserts that two objects are equal.
assert.Equal(t, 123, 123)
Pointer variable equality is determined based on the equality of the referenced values (as opposed to the memory addresses). Function equality cannot be determined and will always fail.
func EqualBSON ¶
EqualBSON asserts that the expected and actual BSON binary values are equal. If the values are not equal, it prints both the binary and Extended JSON diff of the BSON values. The provided BSON value types must implement the fmt.Stringer interface.
func EqualError ¶
EqualError asserts that a function returned an error (i.e. not `nil`) and that it is equal to the provided error.
actualObj, err := SomeFunction() assert.EqualError(t, err, expectedErrorString)
func EqualErrorf ¶
func EqualErrorf(t TestingT, theError error, errString string, msg string, args ...interface{}) bool
EqualErrorf asserts that a function returned an error (i.e. not `nil`) and that it is equal to the provided error.
actualObj, err := SomeFunction() assert.EqualErrorf(t, err, expectedErrorString, "error message %s", "formatted")
func EqualValues ¶
EqualValues asserts that two objects are equal or convertible to the same types and equal.
assert.EqualValues(t, uint32(123), int32(123))
func EqualValuesf ¶
func EqualValuesf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) bool
EqualValuesf asserts that two objects are equal or convertible to the same types and equal.
assert.EqualValuesf(t, uint32(123), int32(123), "error message %s", "formatted")
func Equalf ¶
func Equalf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) bool
Equalf asserts that two objects are equal.
assert.Equalf(t, 123, 123, "error message %s", "formatted")
Pointer variable equality is determined based on the equality of the referenced values (as opposed to the memory addresses). Function equality cannot be determined and will always fail.
func Error ¶
Error asserts that a function returned an error (i.e. not `nil`).
actualObj, err := SomeFunction() if assert.Error(t, err) { assert.Equal(t, expectedError, err) }
func ErrorContains ¶
ErrorContains asserts that a function returned an error (i.e. not `nil`) and that the error contains the specified substring.
actualObj, err := SomeFunction() assert.ErrorContains(t, err, expectedErrorSubString)
func ErrorContainsf ¶
func ErrorContainsf(t TestingT, theError error, contains string, msg string, args ...interface{}) bool
ErrorContainsf asserts that a function returned an error (i.e. not `nil`) and that the error contains the specified substring.
actualObj, err := SomeFunction() assert.ErrorContainsf(t, err, expectedErrorSubString, "error message %s", "formatted")
func ErrorIs ¶ added in v1.13.0
ErrorIs asserts that at least one of the errors in err's chain matches target. This is a wrapper for errors.Is.
func Errorf ¶
Errorf asserts that a function returned an error (i.e. not `nil`).
actualObj, err := SomeFunction() if assert.Errorf(t, err, "error message %s", "formatted") { assert.Equal(t, expectedErrorf, err) }
func Eventually ¶
func Eventually(t TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, msgAndArgs ...interface{}) bool
Eventually asserts that given condition will be met in waitFor time, periodically checking target function each tick.
assert.Eventually(t, func() bool { return true; }, time.Second, 10*time.Millisecond)
func Eventuallyf ¶
func Eventuallyf(t TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, msg string, args ...interface{}) bool
Eventuallyf asserts that given condition will be met in waitFor time, periodically checking target function each tick.
assert.Eventuallyf(t, func() bool { return true; }, time.Second, 10*time.Millisecond, "error message %s", "formatted")
func Falsef ¶
Falsef asserts that the specified value is false.
assert.Falsef(t, myBool, "error message %s", "formatted")
func GetContextDiffString ¶
func GetContextDiffString(diff ContextDiff) (string, error)
GetContextDiffString is like WriteContextDiff but returns the diff as a string.
func GetUnifiedDiffString ¶
func GetUnifiedDiffString(diff UnifiedDiff) (string, error)
GetUnifiedDiffString is like WriteUnifiedDiff but returns the diff as a string.
func Greater ¶
Greater asserts that the first element is greater than the second
assert.Greater(t, 2, 1) assert.Greater(t, float64(2), float64(1)) assert.Greater(t, "b", "a")
func GreaterOrEqual ¶
GreaterOrEqual asserts that the first element is greater than or equal to the second
assert.GreaterOrEqual(t, 2, 1) assert.GreaterOrEqual(t, 2, 2) assert.GreaterOrEqual(t, "b", "a") assert.GreaterOrEqual(t, "b", "b")
func GreaterOrEqualf ¶
func GreaterOrEqualf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) bool
GreaterOrEqualf asserts that the first element is greater than or equal to the second
assert.GreaterOrEqualf(t, 2, 1, "error message %s", "formatted") assert.GreaterOrEqualf(t, 2, 2, "error message %s", "formatted") assert.GreaterOrEqualf(t, "b", "a", "error message %s", "formatted") assert.GreaterOrEqualf(t, "b", "b", "error message %s", "formatted")
func Greaterf ¶
Greaterf asserts that the first element is greater than the second
assert.Greaterf(t, 2, 1, "error message %s", "formatted") assert.Greaterf(t, float64(2), float64(1), "error message %s", "formatted") assert.Greaterf(t, "b", "a", "error message %s", "formatted")
func InDelta ¶
func InDelta(t TestingT, expected, actual interface{}, delta float64, msgAndArgs ...interface{}) bool
InDelta asserts that the two numerals are within delta of each other.
assert.InDelta(t, math.Pi, 22/7.0, 0.01)
func InDeltaf ¶
func InDeltaf(t TestingT, expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) bool
InDeltaf asserts that the two numerals are within delta of each other.
assert.InDeltaf(t, math.Pi, 22/7.0, 0.01, "error message %s", "formatted")
func IsType ¶
func IsType(t TestingT, expectedType interface{}, object interface{}, msgAndArgs ...interface{}) bool
IsType asserts that the specified objects are of the same type.
func IsTypef ¶
func IsTypef(t TestingT, expectedType interface{}, object interface{}, msg string, args ...interface{}) bool
IsTypef asserts that the specified objects are of the same type.
func Len ¶
Len asserts that the specified object has specific length. Len also fails if the object has a type that len() not accept.
assert.Len(t, mySlice, 3)
func Lenf ¶
Lenf asserts that the specified object has specific length. Lenf also fails if the object has a type that len() not accept.
assert.Lenf(t, mySlice, 3, "error message %s", "formatted")
func Less ¶
Less asserts that the first element is less than the second
assert.Less(t, 1, 2) assert.Less(t, float64(1), float64(2)) assert.Less(t, "a", "b")
func LessOrEqual ¶
LessOrEqual asserts that the first element is less than or equal to the second
assert.LessOrEqual(t, 1, 2) assert.LessOrEqual(t, 2, 2) assert.LessOrEqual(t, "a", "b") assert.LessOrEqual(t, "b", "b")
func LessOrEqualf ¶
LessOrEqualf asserts that the first element is less than or equal to the second
assert.LessOrEqualf(t, 1, 2, "error message %s", "formatted") assert.LessOrEqualf(t, 2, 2, "error message %s", "formatted") assert.LessOrEqualf(t, "a", "b", "error message %s", "formatted") assert.LessOrEqualf(t, "b", "b", "error message %s", "formatted")
func Lessf ¶
Lessf asserts that the first element is less than the second
assert.Lessf(t, 1, 2, "error message %s", "formatted") assert.Lessf(t, float64(1), float64(2), "error message %s", "formatted") assert.Lessf(t, "a", "b", "error message %s", "formatted")
func Negative ¶
Negative asserts that the specified element is negative
assert.Negative(t, -1) assert.Negative(t, -1.23)
func Negativef ¶
Negativef asserts that the specified element is negative
assert.Negativef(t, -1, "error message %s", "formatted") assert.Negativef(t, -1.23, "error message %s", "formatted")
func Nilf ¶
Nilf asserts that the specified object is nil.
assert.Nilf(t, err, "error message %s", "formatted")
func NoError ¶
NoError asserts that a function returned no error (i.e. `nil`).
actualObj, err := SomeFunction() if assert.NoError(t, err) { assert.Equal(t, expectedObj, actualObj) }
func NoErrorf ¶
NoErrorf asserts that a function returned no error (i.e. `nil`).
actualObj, err := SomeFunction() if assert.NoErrorf(t, err, "error message %s", "formatted") { assert.Equal(t, expectedObj, actualObj) }
func NotContains ¶
NotContains asserts that the specified string, list(array, slice...) or map does NOT contain the specified substring or element.
assert.NotContains(t, "Hello World", "Earth") assert.NotContains(t, ["Hello", "World"], "Earth") assert.NotContains(t, {"Hello": "World"}, "Earth")
func NotContainsf ¶
func NotContainsf(t TestingT, s interface{}, contains interface{}, msg string, args ...interface{}) bool
NotContainsf asserts that the specified string, list(array, slice...) or map does NOT contain the specified substring or element.
assert.NotContainsf(t, "Hello World", "Earth", "error message %s", "formatted") assert.NotContainsf(t, ["Hello", "World"], "Earth", "error message %s", "formatted") assert.NotContainsf(t, {"Hello": "World"}, "Earth", "error message %s", "formatted")
func NotEqual ¶
NotEqual asserts that the specified values are NOT equal.
assert.NotEqual(t, obj1, obj2)
Pointer variable equality is determined based on the equality of the referenced values (as opposed to the memory addresses).
func NotEqualValues ¶
NotEqualValues asserts that two objects are not equal even when converted to the same type
assert.NotEqualValues(t, obj1, obj2)
func NotEqualValuesf ¶
func NotEqualValuesf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) bool
NotEqualValuesf asserts that two objects are not equal even when converted to the same type
assert.NotEqualValuesf(t, obj1, obj2, "error message %s", "formatted")
func NotEqualf ¶
func NotEqualf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) bool
NotEqualf asserts that the specified values are NOT equal.
assert.NotEqualf(t, obj1, obj2, "error message %s", "formatted")
Pointer variable equality is determined based on the equality of the referenced values (as opposed to the memory addresses).
func NotNilf ¶
NotNilf asserts that the specified object is not nil.
assert.NotNilf(t, err, "error message %s", "formatted")
func ObjectsAreEqual ¶
func ObjectsAreEqual(expected, actual interface{}) bool
ObjectsAreEqual determines if two objects are considered equal.
This function does no assertion of any kind.
func ObjectsAreEqualValues ¶
func ObjectsAreEqualValues(expected, actual interface{}) bool
ObjectsAreEqualValues gets whether two objects are equal, or if their values are equal.
func Positive ¶
Positive asserts that the specified element is positive
assert.Positive(t, 1) assert.Positive(t, 1.23)
func Positivef ¶
Positivef asserts that the specified element is positive
assert.Positivef(t, 1, "error message %s", "formatted") assert.Positivef(t, 1.23, "error message %s", "formatted")
func Soon
deprecated
added in
v1.12.2
Soon runs the provided callback and fails the passed-in test if the callback does not complete within timeout. The provided callback should respect the passed-in context and cease execution when it has expired.
Deprecated: This function will be removed with GODRIVER-2667, use assert.Eventually instead.
func SplitLines ¶
SplitLines splits a string on "\n" while preserving them. The output can be used as input for UnifiedDiff and ContextDiff structures.
func Truef ¶
Truef asserts that the specified value is true.
assert.Truef(t, myBool, "error message %s", "formatted")
func WithinDuration ¶
func WithinDuration(t TestingT, expected, actual time.Time, delta time.Duration, msgAndArgs ...interface{}) bool
WithinDuration asserts that the two times are within duration delta of each other.
assert.WithinDuration(t, time.Now(), time.Now(), 10*time.Second)
func WithinDurationf ¶
func WithinDurationf(t TestingT, expected time.Time, actual time.Time, delta time.Duration, msg string, args ...interface{}) bool
WithinDurationf asserts that the two times are within duration delta of each other.
assert.WithinDurationf(t, time.Now(), time.Now(), 10*time.Second, "error message %s", "formatted")
func WriteContextDiff ¶
func WriteContextDiff(writer io.Writer, diff ContextDiff) error
WriteContextDiff compares two sequences of lines; generates the delta as a context diff.
Context diffs are a compact way of showing line changes and a few lines of context. The number of context lines is set by diff.Context which defaults to three.
By default, the diff control lines (those with *** or ---) are created with a trailing newline.
For inputs that do not have trailing newlines, set the diff.Eol argument to "" so that the output will be uniformly newline free.
The context diff format normally has a header for filenames and modification times. Any or all of these may be specified using strings for diff.FromFile, diff.ToFile, diff.FromDate, diff.ToDate. The modification times are normally expressed in the ISO 8601 format. If not specified, the strings default to blanks.
func WriteUnifiedDiff ¶
func WriteUnifiedDiff(writer io.Writer, diff UnifiedDiff) error
WriteUnifiedDiff compares two sequences of lines; generates the delta as a unified diff.
Unified diffs are a compact way of showing line changes and a few lines of context. The number of context lines is set by 'n' which defaults to three.
By default, the diff control lines (those with ---, +++, or @@) are created with a trailing newline. This is helpful so that inputs created from file.readlines() result in diffs that are suitable for file.writelines() since both the inputs and outputs have trailing newlines.
For inputs that do not have trailing newlines, set the lineterm argument to "" so that the output will be uniformly newline free.
The unidiff format normally has a header for filenames and modification times. Any or all of these may be specified using strings for 'fromfile', 'tofile', 'fromfiledate', and 'tofiledate'. The modification times are normally expressed in the ISO 8601 format.
Types ¶
type CompareType ¶
type CompareType int
type ContextDiff ¶
type ContextDiff UnifiedDiff
type SequenceMatcher ¶
SequenceMatcher compares sequence of strings. The basic algorithm predates, and is a little fancier than, an algorithm published in the late 1980's by Ratcliff and Obershelp under the hyperbolic name "gestalt pattern matching". The basic idea is to find the longest contiguous matching subsequence that contains no "junk" elements (R-O doesn't address junk). The same idea is then applied recursively to the pieces of the sequences to the left and to the right of the matching subsequence. This does not yield minimal edit sequences, but does tend to yield matches that "look right" to people.
SequenceMatcher tries to compute a "human-friendly diff" between two sequences. Unlike e.g. UNIX(tm) diff, the fundamental notion is the longest *contiguous* & junk-free matching subsequence. That's what catches peoples' eyes. The Windows(tm) windiff has another interesting notion, pairing up elements that appear uniquely in each sequence. That, and the method here, appear to yield more intuitive difference reports than does diff. This method appears to be the least vulnerable to syncing up on blocks of "junk lines", though (like blank lines in ordinary text files, or maybe "<P>" lines in HTML files). That may be because this is the only method of the 3 that has a *concept* of "junk" <wink>.
Timing: Basic R-O is cubic time worst case and quadratic time expected case. SequenceMatcher is quadratic time for the worst case and has expected-case behavior dependent in a complicated way on how many elements the sequences have in common; best case time is linear.
func NewMatcher ¶
func NewMatcher(a, b []string) *SequenceMatcher
func NewMatcherWithJunk ¶
func NewMatcherWithJunk(a, b []string, autoJunk bool, isJunk func(string) bool) *SequenceMatcher
func (*SequenceMatcher) GetGroupedOpCodes ¶
func (m *SequenceMatcher) GetGroupedOpCodes(n int) [][]OpCode
GetGroupedOpCodes isolates change clusters by eliminating ranges with no changes.
Returns a generator of groups with up to n lines of context. Each group is in the same format as returned by GetOpCodes().
func (*SequenceMatcher) GetMatchingBlocks ¶
func (m *SequenceMatcher) GetMatchingBlocks() []Match
GetMatchingBlocks returns list of triples describing matching subsequences.
Each triple is of the form (i, j, n), and means that a[i:i+n] == b[j:j+n]. The triples are monotonically increasing in i and in j. It's also guaranteed that if (i, j, n) and (i', j', n') are adjacent triples in the list, and the second is not the last triple in the list, then i+n != i' or j+n != j'. IOW, adjacent triples never describe adjacent equal blocks.
The last triple is a dummy, (len(a), len(b), 0), and is the only triple with n==0.
func (*SequenceMatcher) GetOpCodes ¶
func (m *SequenceMatcher) GetOpCodes() []OpCode
GetOpCodes returns a list of 5-tuples describing how to turn a into b.
Each tuple is of the form (tag, i1, i2, j1, j2). The first tuple has i1 == j1 == 0, and remaining tuples have i1 == the i2 from the tuple preceding it, and likewise for j1 == the previous j2.
The tags are characters, with these meanings:
'r' (replace): a[i1:i2] should be replaced by b[j1:j2]
'd' (delete): a[i1:i2] should be deleted, j1==j2 in this case.
'i' (insert): b[j1:j2] should be inserted at a[i1:i1], i1==i2 in this case.
'e' (equal): a[i1:i2] == b[j1:j2]
func (*SequenceMatcher) QuickRatio ¶
func (m *SequenceMatcher) QuickRatio() float64
QuickRatio returns an upper bound on ratio() relatively quickly.
This isn't defined beyond that it is an upper bound on .Ratio(), and is faster to compute.
func (*SequenceMatcher) Ratio ¶
func (m *SequenceMatcher) Ratio() float64
Ratio returns a measure of the sequences' similarity (float in [0,1]).
Where T is the total number of elements in both sequences, and M is the number of matches, this is 2.0*M / T. Note that this is 1 if the sequences are identical, and 0 if they have nothing in common.
.Ratio() is expensive to compute if you haven't already computed .GetMatchingBlocks() or .GetOpCodes(), in which case you may want to try .QuickRatio() or .RealQuickRation() first to get an upper bound.
func (*SequenceMatcher) RealQuickRatio ¶
func (m *SequenceMatcher) RealQuickRatio() float64
RealQuickRatio returns an upper bound on ratio() very quickly.
This isn't defined beyond that it is an upper bound on .Ratio(), and is faster to compute than either .Ratio() or .QuickRatio().
func (*SequenceMatcher) SetSeq1 ¶
func (m *SequenceMatcher) SetSeq1(a []string)
SetSeq1 sets the first sequence to be compared. The second sequence to be compared is not changed.
SequenceMatcher computes and caches detailed information about the second sequence, so if you want to compare one sequence S against many sequences, use .SetSeq2(s) once and call .SetSeq1(x) repeatedly for each of the other sequences.
See also SetSeqs() and SetSeq2().
func (*SequenceMatcher) SetSeq2 ¶
func (m *SequenceMatcher) SetSeq2(b []string)
SetSeq2 sets the second sequence to be compared. The first sequence to be compared is not changed.
func (*SequenceMatcher) SetSeqs ¶
func (m *SequenceMatcher) SetSeqs(a, b []string)
SetSeqs sets the two sequences to be compared.
type TestingT ¶
type TestingT interface {
Errorf(format string, args ...interface{})
}
TestingT is an interface wrapper around *testing.T
type UnifiedDiff ¶
type UnifiedDiff struct { A []string // First sequence lines FromFile string // First file name FromDate string // First file time B []string // Second sequence lines ToFile string // Second file name ToDate string // Second file time Eol string // Headers end of line, defaults to LF Context int // Number of context lines }
UnifiedDiff represents the unified diff parameters.