Skip to content

Commit

Permalink
pkg/eval/vals: Test that structmaps are treated like maps by CmpTotal.
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaq committed Aug 23, 2023
1 parent 4ceb919 commit a15f0f7
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion pkg/eval/vals/cmp_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
package vals

import "testing"
import (
"testing"

"src.elv.sh/pkg/tt"
)

func TestCmp(t *testing.T) {
// Cmp is tested by tests of the Elvish compare command.
}

func TestCmpTotal_StructMap(t *testing.T) {
// CmpTotal should pretend that structmaps are maps too. Since maps don't
// have an internal ordering, comparing a structmap to another structmap or
// to a map should always return CmpEqual, like comparing two maps.
//
// This is not covered by tests of the Elvish compare command because Elvish
// code are not supposed to know which values are actually structmaps.
x := testStructMap{}
y := testStructMap2{}
z := EmptyMap
tt.Test(t, tt.Fn("CmpTotal", CmpTotal), tt.Table{
tt.Args(x, y).Rets(CmpEqual),
tt.Args(x, z).Rets(CmpEqual),
})
}

0 comments on commit a15f0f7

Please sign in to comment.