diff --git a/error_template_test.go b/error_template_test.go index 327609d..2eea9fd 100644 --- a/error_template_test.go +++ b/error_template_test.go @@ -229,6 +229,50 @@ func TestExtractVariables(t *testing.T) { t.Fatalf("expected %v, got %v", exp, variables) } }) + + t.Run("Multiple", func(t *testing.T) { + inputs := []string{ + "invalid input '123abc'\nin main at /home/user/main.py:123\nin main at /home/user/main.py:1", + "invalid input 'shouldNotBeIncluded'\nin main at /home/user/main.py:123\nin main at /home/user/main.py:1", + } + input := strings.Join(inputs, "\n\n") + if !tmp.Match(input) { + t.Fatalf("expected template to match input, got false instead") + } + + variables := tmp.ExtractVariables(input) + exp := map[string]string{ + "stacktrace": "\nin main at /home/user/main.py:123\nin main at /home/user/main.py:1", + "input": "123abc", + } + + fmt.Printf("%q\n", variables) + if !reflect.DeepEqual(variables, exp) { + t.Fatalf("expected %v, got %v", exp, variables) + } + }) + + t.Run("Multiple no stack trace", func(t *testing.T) { + inputs := []string{ + "invalid input '123abc'", + "invalid input 'shouldNotBeIncluded'", + } + input := strings.Join(inputs, "\n\n") + if !tmp.Match(input) { + t.Fatalf("expected template to match input, got false instead") + } + + variables := tmp.ExtractVariables(input) + exp := map[string]string{ + "stacktrace": "\nin main at /home/user/main.py:123\nin main at /home/user/main.py:1", + "input": "123abc", + } + + fmt.Printf("%q\n", variables) + if !reflect.DeepEqual(variables, exp) { + t.Fatalf("expected %v, got %v", exp, variables) + } + }) } func TestExtractStackTrace(t *testing.T) {