MCPcopy Index your code
hub / github.com/crowdsecurity/crowdsec / TestAtof

Function TestAtof

pkg/exprhelpers/exprlib_test.go:634–669  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

632}
633
634func TestAtof(t *testing.T) {
635 err := Init(nil)
636 require.NoError(t, err)
637
638 tests := []struct {
639 name string
640 env map[string]any
641 code string
642 result float64
643 }{
644 {
645 name: "Atof() test: basic test",
646 env: map[string]any{
647 "testFloat": "1.5",
648 },
649 code: "Atof(testFloat)",
650 result: 1.5,
651 },
652 {
653 name: "Atof() test: bad float",
654 env: map[string]any{
655 "testFloat": "1aaa.5",
656 },
657 code: "Atof(testFloat)",
658 result: 0.0,
659 },
660 }
661
662 for _, test := range tests {
663 program, err := expr.Compile(test.code, GetExprOptions(test.env)...)
664 require.NoError(t, err)
665 output, err := expr.Run(program, test.env)
666 require.NoError(t, err)
667 require.InDelta(t, test.result, output, 0.000001)
668 }
669}
670
671func TestUpper(t *testing.T) {
672 testStr := "test"

Callers

nothing calls this directly

Calls 4

InitFunction · 0.85
GetExprOptionsFunction · 0.85
RunMethod · 0.65
CompileMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…