diff options
-rw-r--r-- | compiler/compiler_test.go | 112 | ||||
-rw-r--r-- | spec/spec.go | 12 |
2 files changed, 119 insertions, 5 deletions
diff --git a/compiler/compiler_test.go b/compiler/compiler_test.go index 2534d9f..cf1ec4d 100644 --- a/compiler/compiler_test.go +++ b/compiler/compiler_test.go @@ -77,6 +77,118 @@ func TestCompile(t *testing.T) { `, Err: true, }, + { + Caption: "don't allow kind names in the same mode to contain spelling inconsistencies", + Spec: ` +{ + "name": "test", + "entries": [ + { + "kind": "foo_1", + "pattern": "foo_1" + }, + { + "kind": "foo1", + "pattern": "foo1" + } + ] +} +`, + Err: true, + }, + { + Caption: "don't allow kind names across modes to contain spelling inconsistencies", + Spec: ` +{ + "name": "test", + "entries": [ + { + "modes": ["default"], + "kind": "foo_1", + "pattern": "foo_1" + }, + { + "modes": ["other_mode"], + "kind": "foo1", + "pattern": "foo1" + } + ] +} +`, + Err: true, + }, + { + Caption: "don't allow mode names to contain spelling inconsistencies", + Spec: ` +{ + "name": "test", + "entries": [ + { + "modes": ["foo_1"], + "kind": "a", + "pattern": "a" + }, + { + "modes": ["foo1"], + "kind": "b", + "pattern": "b" + } + ] +} +`, + Err: true, + }, + { + Caption: "allow fragment names in the same mode to contain spelling inconsistencies because fragments will not appear in output files", + Spec: ` +{ + "name": "test", + "entries": [ + { + "kind": "a", + "pattern": "a" + }, + { + "fragment": true, + "kind": "foo_1", + "pattern": "foo_1" + }, + { + "fragment": true, + "kind": "foo1", + "pattern": "foo1" + } + ] +} +`, + }, + { + Caption: "allow fragment names across modes to contain spelling inconsistencies because fragments will not appear in output files", + Spec: ` +{ + "name": "test", + "entries": [ + { + "modes": ["default"], + "kind": "a", + "pattern": "a" + }, + { + "modes": ["default"], + "fragment": true, + "kind": "foo_1", + "pattern": "foo_1" + }, + { + "modes": ["other_mode"], + "fragment": true, + "kind": "foo1", + "pattern": "foo1" + } + ] +} +`, + }, } for i, tt := range tests { t.Run(fmt.Sprintf("#%v %s", i, tt.Caption), func(t *testing.T) { diff --git a/spec/spec.go b/spec/spec.go index 3d46269..28d5abc 100644 --- a/spec/spec.go +++ b/spec/spec.go @@ -256,10 +256,12 @@ func findSpellingInconsistenciesErrors(ids []string, hook func(ids []string) err var errs []error for _, dup := range duplicated { - err := hook(dup) - if err != nil { - errs = append(errs, err) - continue + if hook != nil { + err := hook(dup) + if err != nil { + errs = append(errs, err) + continue + } } var b strings.Builder @@ -267,7 +269,7 @@ func findSpellingInconsistenciesErrors(ids []string, hook func(ids []string) err for _, id := range dup[1:] { fmt.Fprintf(&b, ", %+v", id) } - err = fmt.Errorf("these identifiers are treated as the same. please use the same spelling: %v", b.String()) + err := fmt.Errorf("these identifiers are treated as the same. please use the same spelling: %v", b.String()) errs = append(errs, err) } |