fix: handle contents of tags properly by unquoting them when necessary

This commit is contained in:
Florian Loch
2023-01-25 09:20:43 +01:00
committed by Alec Thomas
parent 95a465b4b5
commit 37e801405f
3 changed files with 51 additions and 10 deletions
+15 -2
View File
@@ -5,17 +5,18 @@ import (
"testing"
"github.com/alecthomas/assert/v2"
"github.com/alecthomas/kong"
)
func TestDefaultValueForOptionalArg(t *testing.T) {
var cli struct {
Arg string `kong:"arg,optional,default='👌'"`
Arg string `kong:"arg,optional,default='\"\\'👌\\'\"'"`
}
p := mustNew(t, &cli)
_, err := p.Parse(nil)
assert.NoError(t, err)
assert.Equal(t, "👌", cli.Arg)
assert.Equal(t, "\"'👌'\"", cli.Arg)
}
func TestNoValueInTag(t *testing.T) {
@@ -66,6 +67,18 @@ func TestEscapedQuote(t *testing.T) {
assert.Equal(t, "i don't know", cli.DoYouKnow)
}
func TestEscapingInQuotedTags(t *testing.T) {
var cli struct {
Regex1 string `kong:"default='\\d+\n'"`
Regex2 string `default:"\\d+\n"`
}
p := mustNew(t, &cli)
_, err := p.Parse(nil)
assert.NoError(t, err)
assert.Equal(t, "\\d+\n", cli.Regex1)
assert.Equal(t, "\\d+\n", cli.Regex2)
}
func TestBareTags(t *testing.T) {
var cli struct {
Cmd struct {