Files
forge/modules/util/diff_slice_test.go
zeekayandHanzo Dev 9a07b4d089 legal: Hanzo AI, Inc. copyright above the upstream notices
2978 files. The fork is 2026-07-15 (rebrand: gitea.dev -> github.com/hanzoai/git),
so 2026 is the year, and "Copyright 2026 Hanzo AI, Inc." was already the form
used by the handful of files that had ours.

Shape is now:

	// Copyright 2026 Hanzo AI, Inc. All rights reserved.
	// Copyright 2015 The Gogs Authors. All rights reserved.
	// Copyright 2019 The Gitea Authors. All rights reserved.
	// SPDX-License-Identifier: MIT

Ours on top, theirs retained verbatim. Retained because MIT requires it, and
separately because they are true — those authors did write that code.

Not renamed to "The Git Authors": Git is a different project under a different
license, and putting its name here would attribute this code to people who have
nothing to do with it. Adding our line is the fix; overwriting theirs would have
been both a licence violation and a false statement.

gofmt still reports import-order drift in some of these files. It predates this
change (verified against a stash) and is left alone rather than burying a
one-line-per-file legal change under 3000 files of unrelated reordering.

Build clean.

Co-authored-by: Hanzo Dev <[email protected]>
2026-07-27 13:49:52 -07:00

76 lines
2.1 KiB
Go

// Copyright 2026 Hanzo AI, Inc. All rights reserved.
// Copyright 2026 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package util
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestDiffSliceBasic(t *testing.T) {
// Typical integer cases
t.Run("additions", func(t *testing.T) {
added, removed := DiffSlice([]int{1, 2}, []int{1, 2, 3})
assert.Equal(t, []int{3}, added)
assert.Empty(t, removed)
})
t.Run("removals", func(t *testing.T) {
added, removed := DiffSlice([]int{1, 2, 3}, []int{1, 2})
assert.Empty(t, added)
assert.Equal(t, []int{3}, removed)
})
t.Run("no changes", func(t *testing.T) {
added, removed := DiffSlice([]int{1, 2}, []int{1, 2})
assert.Empty(t, added)
assert.Empty(t, removed)
})
t.Run("empty slices", func(t *testing.T) {
added, removed := DiffSlice([]int{}, []int{})
assert.Empty(t, added)
assert.Empty(t, removed)
})
t.Run("overlapping elements", func(t *testing.T) {
added, removed := DiffSlice([]int{1, 2, 4}, []int{2, 3, 4})
assert.Equal(t, []int{3}, added)
assert.Equal(t, []int{1}, removed)
})
}
func TestDiffSliceOrderAndDuplicates(t *testing.T) {
oldSlice := []int{1, 2, 2, 3}
newSlice := []int{2, 4, 2, 5}
added, removed := DiffSlice(oldSlice, newSlice)
assert.Equal(t, []int{4, 5}, added)
assert.Equal(t, []int{1, 3}, removed)
}
func TestDiffSliceDeduplicatesOutput(t *testing.T) {
// Test case from issue: newSlice contains [4, 4, 5] and oldSlice is [1]
// added should return [4, 5], not [4, 4, 5]
t.Run("deduplicates added", func(t *testing.T) {
added, removed := DiffSlice([]int{1}, []int{4, 4, 5})
assert.Equal(t, []int{4, 5}, added)
assert.Equal(t, []int{1}, removed)
})
t.Run("deduplicates removed", func(t *testing.T) {
added, removed := DiffSlice([]int{1, 1, 2}, []int{3})
assert.Equal(t, []int{3}, added)
assert.Equal(t, []int{1, 2}, removed)
})
t.Run("deduplicates both", func(t *testing.T) {
added, removed := DiffSlice([]int{1, 1, 2, 2}, []int{3, 3, 4, 4})
assert.Equal(t, []int{3, 4}, added)
assert.Equal(t, []int{1, 2}, removed)
})
}