MCPcopy Create free account
hub / github.com/expr-lang/expr / TestAbs_UnsignedIntegers

Function TestAbs_UnsignedIntegers

builtin/builtin_test.go:873–904  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

871}
872
873func TestAbs_UnsignedIntegers(t *testing.T) {
874 // Test that abs() correctly handles unsigned integers
875 // Unsigned integers are always non-negative, so abs() should return them unchanged
876 tests := []struct {
877 name string
878 env map[string]any
879 expr string
880 want any
881 }{
882 {"uint", map[string]any{"x": uint(42)}, "abs(x)", uint(42)},
883 {"uint8", map[string]any{"x": uint8(42)}, "abs(x)", uint8(42)},
884 {"uint16", map[string]any{"x": uint16(42)}, "abs(x)", uint16(42)},
885 {"uint32", map[string]any{"x": uint32(42)}, "abs(x)", uint32(42)},
886 {"uint64", map[string]any{"x": uint64(42)}, "abs(x)", uint64(42)},
887 {"uint zero", map[string]any{"x": uint(0)}, "abs(x)", uint(0)},
888 {"uint8 zero", map[string]any{"x": uint8(0)}, "abs(x)", uint8(0)},
889 {"uint16 zero", map[string]any{"x": uint16(0)}, "abs(x)", uint16(0)},
890 {"uint32 zero", map[string]any{"x": uint32(0)}, "abs(x)", uint32(0)},
891 {"uint64 zero", map[string]any{"x": uint64(0)}, "abs(x)", uint64(0)},
892 }
893
894 for _, tt := range tests {
895 t.Run(tt.name, func(t *testing.T) {
896 program, err := expr.Compile(tt.expr, expr.Env(tt.env))
897 require.NoError(t, err)
898
899 result, err := expr.Run(program, tt.env)
900 require.NoError(t, err)
901 assert.Equal(t, tt.want, result)
902 })
903 }
904}

Callers

nothing calls this directly

Calls 6

CompileFunction · 0.92
EnvStruct · 0.92
NoErrorFunction · 0.92
RunFunction · 0.92
EqualFunction · 0.92
RunMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…