diff options
author | EuAndreh <eu@euandre.org> | 2024-11-29 10:19:45 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2024-11-29 10:19:45 -0300 |
commit | d927e9e048527d0b13d16c1ee9efbd55452f7653 (patch) | |
tree | 51dc9012af477ed873f62e06b737aedf7a8c0000 /spec/spec_test.go | |
parent | Absorb compressor/ code (diff) | |
download | tre-d927e9e048527d0b13d16c1ee9efbd55452f7653.tar.gz tre-d927e9e048527d0b13d16c1ee9efbd55452f7653.tar.xz |
Absorb spec/
Diffstat (limited to 'spec/spec_test.go')
-rw-r--r-- | spec/spec_test.go | 219 |
1 files changed, 0 insertions, 219 deletions
diff --git a/spec/spec_test.go b/spec/spec_test.go deleted file mode 100644 index e0e920e..0000000 --- a/spec/spec_test.go +++ /dev/null @@ -1,219 +0,0 @@ -package spec - -import ( - "fmt" - "testing" -) - -var idTests = []struct { - id string - invalid bool -}{ - { - id: "foo", - }, - { - id: "foo2", - }, - { - id: "foo_bar_baz", - }, - { - id: "f_o_o", - }, - { - id: "Foo", - invalid: true, - }, - { - id: "foo_Bar", - invalid: true, - }, - { - id: "2foo", - invalid: true, - }, - { - id: "_foo", - invalid: true, - }, - { - id: "foo_", - invalid: true, - }, - { - id: "foo__bar", - invalid: true, - }, -} - -func TestValidateIdentifier(t *testing.T) { - for _, tt := range idTests { - t.Run(tt.id, func(t *testing.T) { - err := validateIdentifier(tt.id) - if tt.invalid { - if err == nil { - t.Errorf("expected error didn't occur") - } - } else { - if err != nil { - t.Errorf("unexpected error occurred: %v", err) - } - } - }) - } -} - -func TestLexKindName_validate(t *testing.T) { - for _, tt := range idTests { - t.Run(tt.id, func(t *testing.T) { - err := LexKindName(tt.id).validate() - if tt.invalid { - if err == nil { - t.Errorf("expected error didn't occur") - } - } else { - if err != nil { - t.Errorf("unexpected error occurred: %v", err) - } - } - }) - } -} - -func TestLexModeName_validate(t *testing.T) { - for _, tt := range idTests { - t.Run(tt.id, func(t *testing.T) { - err := LexModeName(tt.id).validate() - if tt.invalid { - if err == nil { - t.Errorf("expected error didn't occur") - } - } else { - if err != nil { - t.Errorf("unexpected error occurred: %v", err) - } - } - }) - } -} - -func TestSnakeCaseToUpperCamelCase(t *testing.T) { - tests := []struct { - snake string - camel string - }{ - { - snake: "foo", - camel: "Foo", - }, - { - snake: "foo_bar", - camel: "FooBar", - }, - { - snake: "foo_bar_baz", - camel: "FooBarBaz", - }, - { - snake: "Foo", - camel: "Foo", - }, - { - snake: "fooBar", - camel: "FooBar", - }, - { - snake: "FOO", - camel: "FOO", - }, - { - snake: "FOO_BAR", - camel: "FOOBAR", - }, - { - snake: "_foo_bar_", - camel: "FooBar", - }, - { - snake: "___foo___bar___", - camel: "FooBar", - }, - } - for _, tt := range tests { - c := SnakeCaseToUpperCamelCase(tt.snake) - if c != tt.camel { - t.Errorf("unexpected string; want: %v, got: %v", tt.camel, c) - } - } -} - -func TestFindSpellingInconsistencies(t *testing.T) { - tests := []struct { - ids []string - duplicated [][]string - }{ - { - ids: []string{"foo", "foo"}, - duplicated: nil, - }, - { - ids: []string{"foo", "Foo"}, - duplicated: [][]string{{"Foo", "foo"}}, - }, - { - ids: []string{"foo", "foo", "Foo"}, - duplicated: [][]string{{"Foo", "foo"}}, - }, - { - ids: []string{"foo_bar_baz", "FooBarBaz"}, - duplicated: [][]string{{"FooBarBaz", "foo_bar_baz"}}, - }, - { - ids: []string{"foo", "Foo", "bar", "Bar"}, - duplicated: [][]string{{"Bar", "bar"}, {"Foo", "foo"}}, - }, - { - ids: []string{"foo", "Foo", "bar", "Bar", "baz", "bra"}, - duplicated: [][]string{{"Bar", "bar"}, {"Foo", "foo"}}, - }, - } - for i, tt := range tests { - t.Run(fmt.Sprintf("#%v", i), func(t *testing.T) { - duplicated := FindSpellingInconsistencies(tt.ids) - if len(duplicated) != len(tt.duplicated) { - t.Fatalf("unexpected IDs; want: %#v, got: %#v", tt.duplicated, duplicated) - } - for i, dupIDs := range duplicated { - if len(dupIDs) != len(tt.duplicated[i]) { - t.Fatalf("unexpected IDs; want: %#v, got: %#v", tt.duplicated[i], dupIDs) - } - for j, id := range dupIDs { - if id != tt.duplicated[i][j] { - t.Fatalf("unexpected IDs; want: %#v, got: %#v", tt.duplicated[i], dupIDs) - } - } - } - }) - } -} - -func TestLexSpec_Validate(t *testing.T) { - // We expect that the spelling inconsistency error will occur. - spec := &LexSpec{ - Entries: []*LexEntry{ - { - Modes: []LexModeName{ - // 'Default' is the spelling inconsistency because 'default' is predefined. - "Default", - }, - Kind: "foo", - Pattern: "foo", - }, - }, - } - err := spec.Validate() - if err == nil { - t.Fatalf("expected error didn't occur") - } -} |