config/name_values: fix index out of range in looksLikeSentences
This commit is contained in:
parent
023454a3a6
commit
5dfc266da9
|
@ -399,7 +399,7 @@ func looksLikeSentences(s string) bool {
|
|||
}
|
||||
runes := []rune(s) // HCL guarantees that all strings are valid UTF-8
|
||||
first := runes[0]
|
||||
last := runes[len(s)-1]
|
||||
last := runes[len(runes)-1]
|
||||
|
||||
// If the first rune is a letter then it must be an uppercase letter.
|
||||
// (This will only see the first rune in a multi-rune combining sequence,
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
package configs
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func Test_looksLikeSentences(t *testing.T) {
|
||||
tests := map[string]struct {
|
||||
args string
|
||||
want bool
|
||||
}{
|
||||
"empty sentence": {
|
||||
args: "",
|
||||
want: false,
|
||||
},
|
||||
"valid sentence": {
|
||||
args: "A valid sentence.",
|
||||
want: true,
|
||||
},
|
||||
"valid sentence with an accent": {
|
||||
args: `A Valid sentence with an accent "é".`,
|
||||
want: true,
|
||||
},
|
||||
}
|
||||
|
||||
for name, tt := range tests {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
if got := looksLikeSentences(tt.args); got != tt.want {
|
||||
t.Errorf("looksLikeSentences() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue