MCPcopy
hub / github.com/TomWright/dasel / TestValue_Compare

Function TestValue_Compare

model/value_comparison_test.go:705–803  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

703}
704
705func TestValue_Compare(t *testing.T) {
706 run := func(a *model.Value, b *model.Value, exp int) func(t *testing.T) {
707 return func(t *testing.T) {
708 got, err := a.Compare(b)
709 if err != nil {
710 t.Errorf("unexpected error: %s", err)
711 return
712 }
713 if got != exp {
714 t.Errorf("expected %d, got %d", exp, got)
715 }
716 }
717 }
718 t.Run("int", func(t *testing.T) {
719 t.Run("less", run(
720 model.NewIntValue(1),
721 model.NewIntValue(2),
722 -1,
723 ))
724 t.Run("greater", run(
725 model.NewIntValue(2),
726 model.NewIntValue(1),
727 1,
728 ))
729 t.Run("equal", run(
730 model.NewIntValue(1),
731 model.NewIntValue(1),
732 0,
733 ))
734 })
735 t.Run("float", func(t *testing.T) {
736 t.Run("less", run(
737 model.NewFloatValue(1.1),
738 model.NewFloatValue(1.2),
739 -1,
740 ))
741 t.Run("greater", run(
742 model.NewFloatValue(1.2),
743 model.NewFloatValue(1.1),
744 1,
745 ))
746 t.Run("equal", run(
747 model.NewFloatValue(1.1),
748 model.NewFloatValue(1.1),
749 0,
750 ))
751 })
752 t.Run("int float", func(t *testing.T) {
753 t.Run("less", run(
754 model.NewIntValue(1),
755 model.NewFloatValue(2),
756 -1,
757 ))
758 t.Run("greater", run(
759 model.NewIntValue(2),
760 model.NewFloatValue(1),
761 1,
762 ))

Callers

nothing calls this directly

Calls 6

NewIntValueFunction · 0.92
NewFloatValueFunction · 0.92
NewStringValueFunction · 0.92
runFunction · 0.85
CompareMethod · 0.80
RunMethod · 0.45

Tested by

no test coverage detected