diff --git a/src/pokedex/pokedex.go b/src/pokedex/pokedex.go index 6c0c05e0..1f9a2064 100644 --- a/src/pokedex/pokedex.go +++ b/src/pokedex/pokedex.go @@ -132,10 +132,9 @@ func Decompress(data []byte) []byte { func CreateNameMetadata(idx string, key string, name PokemonName, rootDir string, fpaths []string) *PokemonMetadata { entryCategories := make(map[int][][]string, 0) - for i, fpath := range fpaths { basename := strings.TrimPrefix(fpath, rootDir) - if strings.Contains(basename, strings.ToLower(name.Slug)) { + if strings.Contains(basename, "/"+strings.ToLower(name.Slug)+"-") || strings.Contains(basename, "/"+strings.ToLower(name.Slug)+".") { data, err := os.ReadFile(fpath) Check(err) cats := createCategories(strings.TrimPrefix(fpath, rootDir), data) @@ -173,6 +172,17 @@ func createCategories(fpath string, data []byte) []string { parts := strings.Split(fpath, "/") height := sizeCategory(len(strings.Split(string(data), "\n"))) + extra := []string{"hisui", "galar", "totem", "gmax", "alola", "mega"} + + nameParts := strings.Split( + strings.TrimSuffix(parts[len(parts)-1], ".cow"), + "-", + ) + for _, ex := range extra { + if nameParts[len(nameParts)-1] == ex { + return append([]string{height, ex}, parts[0:len(parts)-1]...) + } + } return append([]string{height}, parts[0:len(parts)-1]...) } diff --git a/test/data/cows/similar_names/gen7x/mew.cow b/test/data/cows/similar_names/gen7x/mew.cow new file mode 100644 index 00000000..9ba242fc --- /dev/null +++ b/test/data/cows/similar_names/gen7x/mew.cow @@ -0,0 +1,13 @@ +  ▄▄▄▄▄▄▄ + ▄▄▄▄▄ ▄▄▄▀ + ▄▄▄▄▄▀▀▀▀▀▀ +  ▄▄▀ ▄▄ + ▀▄▄▄▄▄▄▄▄▄▄▄▄ + ▀▀ ▄ ▄ ▄ ▄▄▄ +   ▄  ▄▄  ▄▄▄▄▄▄▄▄ +  ▄ ▄▄▄▄▄▄▄▀▀▀▄▄  + ▀▄▄▀ ▄▄▄▄▄▄▀     +       ▄▄▄▄▄▄▄▀ +  ▄ ▄▄▄▄▄▄▄▀▀ + ▀▀  ▄▄  + ▀▀ diff --git a/test/data/cows/similar_names/gen7x/mewtwo.cow b/test/data/cows/similar_names/gen7x/mewtwo.cow new file mode 100644 index 00000000..e45766b9 --- /dev/null +++ b/test/data/cows/similar_names/gen7x/mewtwo.cow @@ -0,0 +1,12 @@ +  ▄▄  ▄▄ ▄▄ + ▄▄▄▄▄▄▄ ▄  ▄▄   + ▄▄ ▄▄ ▄  ▄▄ ▄▀ + ▀▄   ▄▄  ▄▄     +  ▄▄ ▄▄▄▄▀▄▄   ▄  + ▄▄▄▄▄  ▄▄▄▄▀ ▀▄ ▄▄ +   ▄▄▄▄▄▄▄ ▄ ▄▄▄▄▄   +    ▄ ▄▄   ▄▄  ▄▀ + ▄▄ ▄▄▄▄▄▄▄▄▄▄▄▀▀ + ▀▄▄▄▀ ▀▄▄▄▄ +  ▄▄▄▄  + ▀▀▀▀ diff --git a/test/data/cows/similar_names/gen8/eternatus-eternamax.cow b/test/data/cows/similar_names/gen8/eternatus-eternamax.cow new file mode 100644 index 00000000..9ee8e4d0 --- /dev/null +++ b/test/data/cows/similar_names/gen8/eternatus-eternamax.cow @@ -0,0 +1,28 @@ +  ▄ ▄▄▄▄▄ ▄▄▄▄▄ ▄▄ + ▄▄   ▄▄▄ ▄▄▄▄▄▄ ▄▄▄▄▄   + ▄▄  ▄▄▄ ▄▄▄▄▄▄▄▄▄▀▀▄▄▄▄▄▄▄ ▄▄▄▄ + ▄▄ ▄▄▄▄▀▀▀▀ ▄▄▄▄▄▄▄▄▄▄▄▄▄▄ ▀▀▀▀▀ +  ▄▄▄ ▄▄ ▄▄▀▀▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ + ▀▄ ▄▄▄ ▄▀▄▄▄▄ ▄▄▄▄▄ ▄▄▄▄ + ▀▄ ▄▀▄▄ ▄▄▄▄▄▀▀▀▀▀▀▀▀▀ ▄ ▄▀▀▀▀▀▄▄▄▄▄ ▄▀ + ▀▄  ▄▄ ▄▀▀ ▄▄   ▄▄▄▄▄▄▄ ▄ ▄▄▄▄▄▄▄ ▄▄ ▀▀▀▄▄ ▄▄ + ▄▄▄    ▄▄ ▄▄ ▄▄▄▄  ▄▄ ▄▄ ▄▄▄ ▄▄▄▄▄▄▄▄▄ ▀▄ ▄▄▄ + ▀▄ ▄▄ ▄▄▄ ▄▄▄▄▄▄ ▄▄▄▄▄ ▄▄▄▀▀▀▀▀ ▄▄▄ ▄ ▄▄▄   ▄▄ + ▀▀▄▄ ▄   ▄▄▄▄ ▄▄  ▄▄▄▄▄▀ ▄▄▄▄ ▄▀ ▀▄ ▄ ▄▄▀ + ▄▄   ▄▄▄▄▄▄ ▄ ▄▄  ▄▄▄  ▄▄▄▄ ▄ ▄▄▄▄▄▄▄▄ ▄▀▄   +   ▄▄ ▄ ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄ ▄▄ ▄▄ ▄▄▄ ▄ ▄ ▄▀▀▀▄▄ ▄▀ + ▄▄▄▄▄▄▄▄▄▄▄▄ ▄▄ ▄▄▄▄▄▄ ▄ ▄▄ ▄▄ ▄▄▄▄ ▄▄ ▄▄▄▄▀▀ ▄▄   + ▄▄▄▄▄ ▄▄ ▄▄▄▄▄▄▄▄▄ ▄▄▄ ▄▄   ▄▄▄▄▄  ▄▀▀ ▄▄▄▄ ▄▀▀▀ + ▄▄▄▄▄ ▄▀▀▄▄▄ ▄▀▄▄  ▄ ▄ ▄▄▄▄▄▄ ▄ ▄▄▄▄  ▄   ▄▄▄▄▄▄ ▄ ▄▀ + ▄▄▄▄▄▀▀       ▄   ▄▄ ▄▄▄▄▄▄ ▄▄ ▄▄   ▀▄▄▄▄▀▄▄▀ ▀▀ + ▀▀ ▄ ▀▄ ▄▄  ▄ ▄ ▄▄ ▄ ▄ ▄▄    ▄▀ +   ▄▄ ▄▄ ▄ ▄▄▄▄▄▄ ▄▄ ▄▄▄ ▄  ▀ +  ▄▄   ▄▄▄▄  ▄▀▀▄ ▄▄▄▄▄     ▄▄▄ +   ▄▄▄▄▄ ▄▄▀▀▀ ▀▀▄ ▄▀▀▄▄▄▄ ▄    + ▄▄▄▄ ▄▀▀ ▀   ▄   ▄▀ +  ▄▄▄▀   ▄▄▄ ▄  +  ▄▀▀  ▄▄▄  ▄▀ +    ▄▄ +    ▄▄▀ +   ▄▀ + ▀▄▀ diff --git a/test/data/cows/similar_names/gen8/eternatus.cow b/test/data/cows/similar_names/gen8/eternatus.cow new file mode 100644 index 00000000..f18e461b --- /dev/null +++ b/test/data/cows/similar_names/gen8/eternatus.cow @@ -0,0 +1,25 @@ +  ▄▄▄▄ + ▄▄▄ ▄▄▄▄▄ + ▄▄▄▄▄▀▀▄▄▄▄▄ ▄ + ▄▄▄  ▄▄▄▄ ▄▄▄▄▀ ▀▀ ▄ ▄▄▄ ▄▄▄▄ + ▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄  ▄▄▄▄   ▄▄▄▄▀▀▄▄▄▄ + ▄ ▄▄▄▄▄▄▄ ▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▀ ▄▄▄▄ ▄▄▀ ▀▄▄▀ +   ▄▄▄  ▄▄▄▄ ▄▀▄▄▄ ▄▄▀▀ ▄▄ ▄▄▀▀     + ▄ ▄   ▄▄▄▄  ▄▄▄▄▄▄▄▀ ▄▄▄▄ ▄ ▄▄ ▄▀ ▀ + ▄▄▄▄    ▄ ▄ ▄▄▄ ▄▄▀ ▄▄▄▄ ▄▄▄▀   ▄    +   ▄▄▄▄▄▄▄ ▄▄▄▄▄▄ ▄▄▄▄▄▄▄ ▄▄▀ ▄▄▄ ▄▄▀ ▄ +  ▄▄▄ ▄▄▄▄▄▄ ▄▄▄▄▄ ▄▄ ▄▀▀    ▄▀ ▄▄▄ ▄▄▄▄▄▄▄ +  ▄▄  ▄▄ ▄ ▄▄ ▄▄▄▄▄▀▄▄   ▄▄  ▄ ▄▄▄   ▄▄▄▄▄▄▄▄▄▀ +  ▄▄  ▄ ▄▄▄▄▄▄▄▄▄▀▄ ▄ ▄▄▄▄▄▄   ▄▄  ▄▄▄  ▄▄▄▄▄▄▄▀▀ +  ▄▄▀▄▄▄▄▄ ▄ ▄▄▀▄   ▄▄▄▄ ▄▄▄▄▄▄▄▀▄▄▄ ▄▄▄▄▄▄ ▄▀ ▄▄▄▄▄▄▄ + ▀▀▀▀▄▄▀▀▄▀ ▀▄▄▄▄▄▄▄ ▄▄▄▄▄  ▄  ▄▄▄▄▄ ▄▄▄▄▄▄▄▀ + ▄▄▄▄▄▄ ▄▄▄▄▄▄  ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▀▀▄ ▄▄▄▄▄▄▄▄▄▀ + ▄▄▄▄▄ ▄▄▄▄▄▄ ▄▄▄▄▄▄▄ ▄ ▄▄ ▄▄▄▄ ▄▄▄▄▄  ▀▄▄▀ ▀▄▀▄▀ + ▀▀▀▄▄▄▄▄ ▄▄▄▄ ▀▄ ▄▄▄▄▄▄▄▄ ▄▄ ▄ ▄▄▀ + ▄▄▄▄▄ ▄▄ ▄▄  ▀▀▄▄▄▄▄▄▄▄▄ ▄ ▄▄▄ + ▀▀▀▄▄▄▄▄▄▄▀▀ ▀▀▄ ▄ ▄▄▄▄▄▄▄▄ + ▀▄▄▄▀▀ ▄▄▄▄▄▄▀▀▄▄▄ ▄▄▄  + ▀▄▄▀▀ ▄▄▄ ▄▄▄ ▄▀ + ▄▄▄▄▀▄▄▄▄▀ +  ▄▀▀▄▄▄▀▀ + ▀▀ diff --git a/test/data/cows/similar_names/gen8/natu.cow b/test/data/cows/similar_names/gen8/natu.cow new file mode 100644 index 00000000..cfddd175 --- /dev/null +++ b/test/data/cows/similar_names/gen8/natu.cow @@ -0,0 +1,9 @@ +  ▄▄▄▄ + ▄▄▄▄▀ + ▄▄▄▄▄▄▄▄ +  ▄▄ ▄▄▄▄ +   ▄▄ ▄▄▄ ▄▄ ▄  + ▄▄▄▄▄▄▄    ▄ ▄  + ▀▄▄▄▄▄ ▄▄▄▄▄▄  + ▀▄▄▄▄▄▄▄▄▀▀▀ + ▀▀  ▄▀ diff --git a/test/pokedex_test.go b/test/pokedex_test.go index a988aeec..3f9ebf81 100644 --- a/test/pokedex_test.go +++ b/test/pokedex_test.go @@ -2,6 +2,7 @@ package test import ( "embed" + "fmt" "os" "testing" @@ -53,3 +54,75 @@ func TestReadMetadataFromEmbedded(test *testing.T) { Assert(expected, result, test) } + +func TestCreateNameMetadataMew(test *testing.T) { + result := pokedex.CreateNameMetadata( + fmt.Sprintf("%04d", 0), + "mew", + pokedex.PokemonName{English: "Mew", Japanese: "ミュウ", JapanesePhonetic: "myuu", Slug: "mew"}, + "data/cows/similar_names/", + []string{"data/cows/similar_names/gen7x/mew.cow", "data/cows/similar_names/gen7x/mewtwo.cow"}, + ) + expected := &pokedex.PokemonMetadata{ + Idx: "0000", + Name: "Mew", + JapaneseName: "ミュウ", + JapanesePhonetic: "myuu", + Entries: []pokedex.PokemonEntryMapping{ + {EntryIndex: 0, Categories: []string{"medium", "gen7x"}}, + }, + } + + Assert(expected, result, test) +} + +func TestCreateNameMetadataNatu(test *testing.T) { + result := pokedex.CreateNameMetadata( + fmt.Sprintf("%04d", 0), + "natu", + pokedex.PokemonName{English: "Natu", Japanese: "ネイティ", JapanesePhonetic: "neiti", Slug: "natu"}, + "data/cows/similar_names/", + []string{ + "data/cows/similar_names/gen8/natu.cow", + "data/cows/similar_names/gen8/eternatus.cow", + "data/cows/similar_names/gen8/eternatus-eternamax.cow", + }, + ) + expected := &pokedex.PokemonMetadata{ + Idx: "0000", + Name: "Natu", + JapaneseName: "ネイティ", + JapanesePhonetic: "neiti", + Entries: []pokedex.PokemonEntryMapping{ + {EntryIndex: 0, Categories: []string{"small", "gen8"}}, + }, + } + + Assert(expected, result, test) +} + +func TestCreateNameMetadataEternatus(test *testing.T) { + result := pokedex.CreateNameMetadata( + fmt.Sprintf("%04d", 0), + "eternatus", + pokedex.PokemonName{English: "Eternatus", Japanese: "ムゲンダイナ", JapanesePhonetic: "mugendaina", Slug: "eternatus"}, + "data/cows/similar_names/", + []string{ + "data/cows/similar_names/gen8/natu.cow", + "data/cows/similar_names/gen8/eternatus.cow", + "data/cows/similar_names/gen8/eternatus-eternamax.cow", + }, + ) + expected := &pokedex.PokemonMetadata{ + Idx: "0000", + Name: "Eternatus", + JapaneseName: "ムゲンダイナ", + JapanesePhonetic: "mugendaina", + Entries: []pokedex.PokemonEntryMapping{ + {EntryIndex: 1, Categories: []string{"big", "gen8"}}, + {EntryIndex: 2, Categories: []string{"big", "gen8"}}, + }, + } + + Assert(expected, result, test) +} \ No newline at end of file