Skip to content

Commit

Permalink
dont allow patterns that match each other across scenarios (#51)
Browse files Browse the repository at this point in the history
* dont allow patterns that match each other across scenarios

* update version
  • Loading branch information
rvhonorato authored Feb 28, 2023
1 parent f8ab561 commit 46438f1
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
18 changes: 18 additions & 0 deletions input/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ func (inp *Input) ValidatePatterns() error {
return err
}

scenarioFnameArray := []string{}

for _, scenario := range inp.Scenarios {
// Ambig and Unambig
if scenario.Parameters.Restraints.Ambig != "" || scenario.Parameters.Restraints.Unambig != "" {
Expand Down Expand Up @@ -195,6 +197,22 @@ func (inp *Input) ValidatePatterns() error {
err := errors.New("duplicated patterns in `" + m + "` modules' `fname` parameters")
return err
}

// Check if there are patterns that match each other
scenarioFnameArray = append(scenarioFnameArray, fnameArr...)
}
// Check if there are patterns that match each other
for i := 0; i < len(scenarioFnameArray); i++ {
for j := i + 1; j < len(scenarioFnameArray); j++ {

patternA := regexp.MustCompile(scenarioFnameArray[i])
patternB := regexp.MustCompile(scenarioFnameArray[j])

if scenarioFnameArray[i] != scenarioFnameArray[j] && (patternA.MatchString(scenarioFnameArray[j]) || patternB.MatchString(scenarioFnameArray[i])) {
err := errors.New("patterns `" + scenarioFnameArray[i] + "` and `" + scenarioFnameArray[j] + "` match each other, please rename them")
return err
}
}
}

}
Expand Down
33 changes: 33 additions & 0 deletions input/input_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,39 @@ func TestInput_ValidatePatterns(t *testing.T) {
},
wantErr: true,
},
{
name: "invalid-fnames-match-each-other",
fields: fields{
General: GeneralStruct{
ReceptorSuffix: "_r_u",
},
Scenarios: []Scenario{
{
Name: "",
Parameters: ParametersStruct{
Modules: ModuleParams{
Order: []string{"rigidbody"},
Rigidbody: map[string]any{
"something_fname": "_ti",
},
},
},
},
{
Name: "",
Parameters: ParametersStruct{
Modules: ModuleParams{
Order: []string{"rigidbody"},
Rigidbody: map[string]any{
"something_fname": "_ti_something",
},
},
},
},
},
},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/golang/glog"
)

const version = "v1.5.0"
const version = "v1.5.1"

func init() {
var versionPrint bool
Expand Down

0 comments on commit 46438f1

Please sign in to comment.