Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

semconvgen: Add a flag for a path to a custom capitalizations file #529

Merged
57 changes: 57 additions & 0 deletions semconvgen/generator_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package main

import (
"os"
"reflect"
"testing"
)

func TestCapitalizations(t *testing.T) {
tests := []struct {
name string
capitalizations string
expected []string
pellared marked this conversation as resolved.
Show resolved Hide resolved
}{
{
name: "No additional capitalizations",
capitalizations: "",
expected: staticCapitalizations,
},
{
name: "Some additional capitalizations",
capitalizations: "ASPNETCore\nJVM",
pellared marked this conversation as resolved.
Show resolved Hide resolved
expected: append(staticCapitalizations, "ASPNETCore", "JVM"),
},
{
name: "Wrong separator for capitalizations",
capitalizations: "ASPNETCore,JVM",
expected: append(staticCapitalizations, "ASPNETCore,JVM"),
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tmpfile, err := os.CreateTemp("", "test")
if err != nil {
t.Fatal(err)
}
defer os.Remove(tmpfile.Name())

if _, err = tmpfile.Write([]byte(tt.capitalizations)); err != nil {
t.Fatal(err)
}
if err = tmpfile.Close(); err != nil {
t.Fatal(err)
}

customCapitalizations, err := capitalizations(tmpfile.Name())
if err != nil {
t.Fatal(err)
}

if !reflect.DeepEqual(customCapitalizations, tt.expected) {
t.Errorf("customCapitalizations() = %v, want %v", customCapitalizations, tt.expected)
}
})
}
}