Skip to content

Commit

Permalink
Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
t0yv0 committed Jan 23, 2025
1 parent bc7f7dd commit 718f2d7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
9 changes: 4 additions & 5 deletions unstable/difft/difft.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,13 @@ func (edits Edits[T]) apply(xs []T, equals func(T, T) bool) ([]T, error) {
return output, nil
}

type DiffTOptions[T any] struct {
type DiffOptions[T any] struct {
Equals func(T, T) bool
}

func DiffT[T any](xs, ys []T, opts DiffTOptions[T]) Edits[T] {
eq := opts.Equals
if eq == nil {
eq = func(x T, y T) bool {
func DiffT[T any](xs, ys []T, opts DiffOptions[T]) Edits[T] {
if opts.Equals == nil {
opts.Equals = func(x T, y T) bool {
return any(x) == any(y)
}
}
Expand Down
6 changes: 4 additions & 2 deletions unstable/difft/difft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ import (
)

func TestDiffAppliesCorrectly(t *testing.T) {
t.Parallel()
rapid.Check(t, func(t *rapid.T) {
s1 := rapid.StringMatching(`^[abc]{0,5}`).Draw(t, "s1")
s2 := rapid.StringMatching(`^[abc]{0,5}`).Draw(t, "s2")

eq := func(b1, b2 byte) bool {
return b1 == b2
}
edits := DiffT([]byte(s1), []byte(s2), DiffTOptions[byte]{
edits := DiffT([]byte(s1), []byte(s2), DiffOptions[byte]{
Equals: eq,
})

Expand All @@ -50,11 +51,12 @@ func TestDiffAppliesCorrectly(t *testing.T) {
}

func TestDiff(t *testing.T) {
t.Parallel()
eq := func(a, b byte) bool {
return a == b
}
input := []byte(`mario`)
dd := DiffT(input, []byte(`darius`), DiffTOptions[byte]{Equals: eq})
dd := DiffT(input, []byte(`darius`), DiffOptions[byte]{Equals: eq})
assert.Equal(t, Remove, dd[0].Change)
assert.Equal(t, Insert, dd[1].Change)
assert.Equal(t, Keep, dd[2].Change)
Expand Down
1 change: 1 addition & 0 deletions unstable/difft/matrix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
)

func TestMatrix(t *testing.T) {
t.Parallel()
m := newMatrix(3, 3)
m.set(1, 1, 42)
assert.Equal(t, 42, m.get(1, 1))
Expand Down

0 comments on commit 718f2d7

Please sign in to comment.