improve mapping template regex to allow for some extra spaces and associated test upgrade

This commit is contained in:
jnmoyne
2022-03-10 11:30:51 -08:00
parent 1d37629d95
commit 6818a232f7
2 changed files with 25 additions and 2 deletions

View File

@@ -164,8 +164,8 @@ const (
)
var commaSeparatorRegEx = regexp.MustCompile(`,\s*`)
var partitionMappingFunctionRegEx = regexp.MustCompile(`{{partition *\((.*)\)}}`)
var wildcardMappingFunctionRegEx = regexp.MustCompile(`{{wildcard *\((.*)\)}}`)
var partitionMappingFunctionRegEx = regexp.MustCompile(`{{\s*partition\s*\((.*)\)\s*}}`)
var wildcardMappingFunctionRegEx = regexp.MustCompile(`{{\s*wildcard\s*\((.*)\)\s*}}`)
// String helper.
func (rt ServiceRespType) String() string {

View File

@@ -63,12 +63,35 @@ func TestPlaceHolderIndex(t *testing.T) {
t.Fatalf("Error parsing %s", testString)
}
testString = "{{ partition(10,1,2,3) }}"
indexes, nbPartitions, err = placeHolderIndex(testString)
if err != nil || !reflect.DeepEqual(indexes, []int{1, 2, 3}) || nbPartitions != 10 {
t.Fatalf("Error parsing %s", testString)
}
testString = "{{partition (10,1,2,3)}}"
indexes, nbPartitions, err = placeHolderIndex(testString)
if err != nil || !reflect.DeepEqual(indexes, []int{1, 2, 3}) || nbPartitions != 10 {
t.Fatalf("Error parsing %s", testString)
}
testString = "{{wildcard(2)}}"
indexes, nbPartitions, err = placeHolderIndex(testString)
if err != nil || len(indexes) != 1 || indexes[0] != 2 || nbPartitions != -1 {
t.Fatalf("Error parsing %s", testString)
}
testString = "{{ wildcard (2) }}"
indexes, nbPartitions, err = placeHolderIndex(testString)
if err != nil || len(indexes) != 1 || indexes[0] != 2 || nbPartitions != -1 {
t.Fatalf("Error parsing %s", testString)
}
}
func TestRegisterDuplicateAccounts(t *testing.T) {