Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
ramya-bangera committed Oct 9, 2024
1 parent 4591af6 commit 8bf181b
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func EscapeIfNeeded(str string) string {
// If the str is already unescaped or an error occurred, escape it
return url.QueryEscape(str)
}
// If the str was successfully unescaped, return it as is
// If the str was successfully unescaped and is different from the original, return the original
return str
}

Expand Down
48 changes: 48 additions & 0 deletions internal/cli/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package cli

import (
"testing"
)

func TestEscapeIfNeeded(t *testing.T) {
tests := []struct {
name string
input string
expected string
}{
{
name: "AlreadyEscaped",
input: "hello%20world",
expected: "hello%20world",
},
{
name: "Unescaped",
input: "hello world",
expected: "hello+world",
},
{
name: "PartiallyEscaped",
input: "hello%20world!",
expected: "hello%20world!",
},
{
name: "EmptyString",
input: "",
expected: "",
},
{
name: "SpecialCharacters",
input: "[email protected]",
expected: "hello%40world.com",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := EscapeIfNeeded(tt.input)
if result != tt.expected {
t.Errorf("EscapeIfNeeded(%q) actual = %q; want = %q", tt.input, result, tt.expected)
}
})
}
}

0 comments on commit 8bf181b

Please sign in to comment.