-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathelement_test.go
More file actions
70 lines (58 loc) · 1.64 KB
/
element_test.go
File metadata and controls
70 lines (58 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package diffx
import "testing"
func TestStringElement_Equal(t *testing.T) {
a := StringElement("hello")
b := StringElement("hello")
c := StringElement("world")
if !a.Equal(b) {
t.Error("Expected a.Equal(b) to be true")
}
if a.Equal(c) {
t.Error("Expected a.Equal(c) to be false")
}
}
func TestStringElement_Hash(t *testing.T) {
a := StringElement("hello")
b := StringElement("hello")
c := StringElement("world")
if a.Hash() != b.Hash() {
t.Error("Expected equal elements to have equal hashes")
}
if a.Hash() == c.Hash() {
t.Error("Expected different elements to have different hashes (collision unlikely)")
}
}
func TestStringElement_EqualDifferentType(t *testing.T) {
a := StringElement("hello")
// Create a mock element that's not a StringElement
type otherElement struct{}
// StringElement.Equal should return false for non-StringElement types
// We can't directly test this without implementing Element interface,
// but we verify the type assertion logic works correctly
if a.Equal(StringElement("hello")) != true {
t.Error("Same string should be equal")
}
}
func TestToElements(t *testing.T) {
strs := []string{"a", "b", "c"}
elems := toElements(strs)
if len(elems) != 3 {
t.Fatalf("expected 3 elements, got %d", len(elems))
}
for i, elem := range elems {
se, ok := elem.(StringElement)
if !ok {
t.Errorf("element %d is not StringElement", i)
continue
}
if string(se) != strs[i] {
t.Errorf("element %d: expected %q, got %q", i, strs[i], se)
}
}
}
func TestToElements_Empty(t *testing.T) {
elems := toElements([]string{})
if len(elems) != 0 {
t.Errorf("expected 0 elements, got %d", len(elems))
}
}