Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions menu/idx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,22 @@ func TestGetStructIdxMap(t *testing.T) {
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
rType := reflect.TypeOf(tt.input)
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
rType := reflect.TypeOf(tc.input)
tags, err := getStructIdxMap(rType)
if (err != nil) != tt.wantErr {
if (err != nil) != tc.wantErr {
t.Errorf("got unexpected error: %s", err)
}
if !maps.Equal(tags, tt.expected) {
t.Errorf("expected: %v, got: %v", tt.expected, tags)
if !maps.Equal(tags, tc.expected) {
t.Errorf("expected: %v, got: %v", tc.expected, tags)
}
})
}
}

func TestIDXMemoryLayout(t *testing.T) {
type explicitOrderForm struct {
type inoptimalOrderForm struct {
string1 string //nolint
bool1 bool //nolint
string2 string //nolint
Expand All @@ -110,13 +110,13 @@ func TestIDXMemoryLayout(t *testing.T) {
bool2 bool `idx:"3"` //nolint
}

expType := reflect.TypeFor[explicitOrderForm]()
expType := reflect.TypeFor[inoptimalOrderForm]()
idxType := reflect.TypeFor[idxOrderForm]()
expTSize := expType.Size()
t.Logf("explicitly ordered struct is %d bytes\n", expTSize)
inopTSize := expType.Size()
idxTSize := idxType.Size()
t.Logf("idx tag-ordered struct is %d bytes\n", idxTSize)
if idxTSize > expTSize {
t.Errorf("expected size of form ordered by idx tags (%d) to be of lower size than explicit counterpart (%d)", idxTSize, expTSize)
if idxTSize > inopTSize {
t.Errorf("expected size of form ordered by idx tags (%d) to be of lower size than explicit counterpart (%d)", idxTSize, inopTSize)
} else {
t.Logf("idx-tagged struct (%d bytes) < inoptimal struct (%d bytes)", idxTSize, inopTSize)
}
}