MCPcopy Index your code
hub / github.com/httprunner/httprunner / TestParseDataStringWithFunctions

Function TestParseDataStringWithFunctions

hrp/parser_test.go:587–633  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

585}
586
587func TestParseDataStringWithFunctions(t *testing.T) {
588 variablesMapping := map[string]interface{}{
589 "n": 5,
590 "a": 12.3,
591 "b": 3.45,
592 }
593
594 testData1 := []struct {
595 expr string
596 expect interface{}
597 }{
598 {"${gen_random_string(5)}", 5},
599 {"${gen_random_string($n)}", 5},
600 {"123${gen_random_string(5)}abc", 11},
601 {"123${gen_random_string($n)}abc", 11},
602 }
603
604 parser := newParser()
605 for _, data := range testData1 {
606 value, err := parser.Parse(data.expr, variablesMapping)
607 if !assert.NoError(t, err) {
608 t.Fatal()
609 }
610 if !assert.Equal(t, data.expect, len(value.(string))) {
611 t.Fatal()
612 }
613 }
614
615 testData2 := []struct {
616 expr string
617 expect interface{}
618 }{
619 {"${max($a, $b)}", 12.3},
620 {"abc${max($a, $b)}123", "abc12.3123"},
621 {"abc${max($a, 3.45)}123", "abc12.3123"},
622 }
623
624 for _, data := range testData2 {
625 value, err := parser.Parse(data.expr, variablesMapping)
626 if !assert.NoError(t, err) {
627 t.Fatal()
628 }
629 if !assert.Equal(t, data.expect, value) {
630 t.Fatal()
631 }
632 }
633}
634
635func TestConvertString(t *testing.T) {
636 testData := []struct {

Callers

nothing calls this directly

Calls 2

newParserFunction · 0.85
ParseMethod · 0.80

Tested by

no test coverage detected