From 46438f1b0ede82c044e32b034116f0bb26499338 Mon Sep 17 00:00:00 2001 From: Rodrigo V Honorato Date: Tue, 28 Feb 2023 15:05:18 +0100 Subject: [PATCH] dont allow patterns that match each other across scenarios (#51) * dont allow patterns that match each other across scenarios * update version --- input/input.go | 18 ++++++++++++++++++ input/input_test.go | 33 +++++++++++++++++++++++++++++++++ main.go | 2 +- 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/input/input.go b/input/input.go index a0b4368..5f5daab 100644 --- a/input/input.go +++ b/input/input.go @@ -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 != "" { @@ -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 + } + } } } diff --git a/input/input_test.go b/input/input_test.go index afe6c37..d3bc49f 100644 --- a/input/input_test.go +++ b/input/input_test.go @@ -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) { diff --git a/main.go b/main.go index 6c7d913..a3aef64 100644 --- a/main.go +++ b/main.go @@ -14,7 +14,7 @@ import ( "github.com/golang/glog" ) -const version = "v1.5.0" +const version = "v1.5.1" func init() { var versionPrint bool