5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-02 19:31:20 +08:00
wails/v2/pkg/git/git_test.go
taisei 5b091db26d
Fixed an error that occurred when an author name contains a string that is not suitable for JSON (#3638)
* fix(pkg): Fixed an issue where wails new would throw an error if the author name contained non-JSON legal characters.

* refactor(pkg): Incorporating coderabbit's suggestions

* docs: write changelog.mdx

* Escape using json package. Add tests.

* Update test.

---------

Co-authored-by: Lea O'Anthony <lea.anthony@gmail.com>
2024-07-29 21:34:19 +10:00

45 lines
747 B
Go

package git
import (
"testing"
)
func TestEscapeName1(t *testing.T) {
type args struct {
str string
}
tests := []struct {
name string
args args
want string
wantErr bool
}{
{
name: "Escape Apostrophe",
args: args{
str: `John O'Keefe`,
},
want: `John O'Keefe`,
},
{
name: "Escape backslash",
args: args{
str: `MYDOMAIN\USER`,
},
want: `MYDOMAIN\\USER`,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := EscapeName(tt.args.str)
if (err != nil) != tt.wantErr {
t.Errorf("EscapeName() error = %v, wantErr %v", err, tt.wantErr)
return
}
if got != tt.want {
t.Errorf("EscapeName() got = %v, want %v", got, tt.want)
}
})
}
}