File tree Expand file tree Collapse file tree 1 file changed +18
-4
lines changed
Expand file tree Collapse file tree 1 file changed +18
-4
lines changed Original file line number Diff line number Diff line change 11package cmd
22
33import (
4+ "regexp"
5+ "strings"
46 "testing"
57)
68
9+ func stripANSI (input string ) string {
10+ ansiEscape := regexp .MustCompile (`\x1b\[[0-9;]*m` )
11+ return ansiEscape .ReplaceAllString (input , "" )
12+ }
13+
714// TestValidatePokemonArgs tests the ValidatePokemonArgs function
815func TestValidatePokemonArgs (t * testing.T ) {
9-
10- // Test case: Too few arguments
1116 args := []string {"poke-cli" , "pokemon" }
1217 expectedError := "╭────────────────────────────────────────────────────────────╮\n " +
1318 "│Error! │\n " +
@@ -16,8 +21,17 @@ func TestValidatePokemonArgs(t *testing.T) {
1621 "│error: insufficient arguments │\n " +
1722 "╰────────────────────────────────────────────────────────────╯"
1823 err := ValidatePokemonArgs (args )
19- if err == nil || err .Error () != expectedError {
20- t .Errorf ("Expected error for too few arguments, got: %v" , err )
24+ if err == nil {
25+ t .Errorf ("Expected error for too few arguments, got nil" )
26+ return
27+ }
28+
29+ // Strip ANSI codes for comparison
30+ actualError := stripANSI (err .Error ())
31+ expectedError = strings .TrimSpace (expectedError )
32+
33+ if actualError != expectedError {
34+ t .Errorf ("Expected error:\n %s\n Got:\n %s" , expectedError , actualError )
2135 }
2236}
2337
You can’t perform that action at this time.
0 commit comments