From 12c425616a076bf2023b98da97abd2836558708b Mon Sep 17 00:00:00 2001 From: Tom McKeesick Date: Tue, 10 May 2022 17:54:12 +1000 Subject: [PATCH 01/12] Create a height category when building assets --- pokesay.go | 2 ++ src/pokedex/convert.go | 17 ++++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/pokesay.go b/pokesay.go index b5a09f0a..1fa48dab 100644 --- a/pokesay.go +++ b/pokesay.go @@ -83,6 +83,8 @@ func printSpeechBubble(scanner *bufio.Scanner, args Args) { func printPokemon(index int, name string, categoryKeys []string) { d, _ := GOBCowData.ReadFile(pokedex.EntryFpath("build/assets/cows", index)) + lines := strings.Split(string(pokedex.Decompress(d)), "\n") + fmt.Println(len(lines), pokedex.SizeCategory(len(lines))) fmt.Printf( "%s%s: %s | %s: %s\n", pokedex.Decompress(d), diff --git a/src/pokedex/convert.go b/src/pokedex/convert.go index ed4179fd..c6110bfb 100644 --- a/src/pokedex/convert.go +++ b/src/pokedex/convert.go @@ -130,7 +130,7 @@ func CreateMetadata(rootDir string, fpaths []string, debug bool) (PokemonTrie, [ data, err := os.ReadFile(fpath) check(err) - cats := createCategories(strings.TrimPrefix(fpath, rootDir)) + cats := createCategories(strings.TrimPrefix(fpath, rootDir), data) name := createName(fpath) categories.Insert( @@ -147,9 +147,20 @@ func createName(fpath string) string { return strings.Split(parts[len(parts)-1], ".")[0] } -func createCategories(fpath string) []string { +func SizeCategory(height int) string { + if height <= 13 { + return "small" + } else if height <= 19 { + return "medium" + } + return "big" +} + +func createCategories(fpath string, data []byte) []string { parts := strings.Split(fpath, "/") - return parts[0 : len(parts)-1] + height := SizeCategory(len(strings.Split(string(data), "\n"))) + + return append(parts[0:len(parts)-1], []string{height}...) } // Strips the leading "./" from a path e.g. "./cows/ -> cows/" From 4e2591b0bed2c4865cb7477b5eb31a8545d81084 Mon Sep 17 00:00:00 2001 From: Tom McKeesick Date: Tue, 17 May 2022 19:58:18 +1000 Subject: [PATCH 02/12] update bind-mounted paths --- build/Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/build/Makefile b/build/Makefile index ae3973d8..91f93404 100644 --- a/build/Makefile +++ b/build/Makefile @@ -24,18 +24,18 @@ build/cows: # generate embedded bin files for category/metadata/the actual pokemon build/assets: docker run \ - -v $(PWD)/build/assets:/usr/local/src/build/assets \ + -v $(PWD)/assets:/usr/local/src/build/assets \ --rm --name pokesay \ $(DOCKER_IMAGE) \ build/scripts/build_assets.sh build/release: build/assets docker run \ - -v $(PWD)/build/bin:/usr/local/src/build/bin \ - -v $(PWD)/build/assets:/usr/local/src/build/assets \ + -v $(PWD)/bin:/usr/local/src/build/bin \ + -v $(PWD)/assets:/usr/local/src/build/assets \ --rm --name pokesay \ $(DOCKER_IMAGE) \ build/scripts/build.sh - tree $(PWD)/build/bin/ + tree $(PWD)/bin/ .PHONY: all build/docker build/cows build/assets build/release From b5826e6222deb3db9781921c5d77ee59f0cc6237 Mon Sep 17 00:00:00 2001 From: Tom McKeesick Date: Tue, 17 May 2022 19:58:58 +1000 Subject: [PATCH 03/12] Add extra error guards and checks --- pokesay.go | 4 ++++ src/pokedex/entries.go | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/pokesay.go b/pokesay.go index 1fa48dab..b4e3216f 100644 --- a/pokesay.go +++ b/pokesay.go @@ -11,6 +11,7 @@ import ( "strconv" "strings" "time" + "errors" "github.com/fatih/color" "github.com/tmck-code/pokesay/src/pokedex" @@ -41,6 +42,9 @@ func check(e error) { } func randomInt(n int) int { + if n <= 0 { + log.Fatal(errors.New("randomInt arg must be >0")) + } return rand.New(Rand).Intn(n) } diff --git a/src/pokedex/entries.go b/src/pokedex/entries.go index a1c94fd7..793ae813 100644 --- a/src/pokedex/entries.go +++ b/src/pokedex/entries.go @@ -128,16 +128,22 @@ func (t PokemonTrie) GetCategoryPaths(s string) ([][]string, error) { func (t PokemonTrie) GetCategory(s []string) ([]*PokemonEntry, error) { current := t.Root matches := make([]*PokemonEntry, 0) + found := false for _, char := range s { - if _, ok := current.Children[char]; ok { + if _, ok := current.Children[char]; ok || found { + found = true current = current.Children[char] for _, p := range current.Children { + fmt.Println(p) matches = append(matches, p.Data...) } } else { return nil, errors.New(fmt.Sprintf("Could not find category: %s", s)) } } + if len(matches) == 0 { + return nil, errors.New(fmt.Sprintf("Could not find category: %s", s)) + } return matches, nil } From 4b88cd94261274289896495edc96af473b4d38b1 Mon Sep 17 00:00:00 2001 From: Tom McKeesick Date: Tue, 17 May 2022 19:59:31 +1000 Subject: [PATCH 04/12] Remove debug printing, add tostring method --- pokesay.go | 2 -- src/pokedex/entries.go | 5 +++++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/pokesay.go b/pokesay.go index b4e3216f..03dd5097 100644 --- a/pokesay.go +++ b/pokesay.go @@ -87,8 +87,6 @@ func printSpeechBubble(scanner *bufio.Scanner, args Args) { func printPokemon(index int, name string, categoryKeys []string) { d, _ := GOBCowData.ReadFile(pokedex.EntryFpath("build/assets/cows", index)) - lines := strings.Split(string(pokedex.Decompress(d)), "\n") - fmt.Println(len(lines), pokedex.SizeCategory(len(lines))) fmt.Printf( "%s%s: %s | %s: %s\n", pokedex.Decompress(d), diff --git a/src/pokedex/entries.go b/src/pokedex/entries.go index 793ae813..fb46099a 100644 --- a/src/pokedex/entries.go +++ b/src/pokedex/entries.go @@ -24,6 +24,11 @@ type PokemonEntry struct { Index int } +func (p PokemonEntry) String() string { + return fmt.Sprintf("{Index: %d, Name: %s}", p.Index, p.Name) +} + + type Node struct { Children map[string]*Node Data []*PokemonEntry From 196cc879eb9e88373ceabc2712a287d0144a1aff Mon Sep 17 00:00:00 2001 From: Tom McKeesick Date: Tue, 17 May 2022 19:59:42 +1000 Subject: [PATCH 05/12] Make "size" the top-level category This means that any big/medium/small category will also match all categories underneath it in the tree. Conversely, it prevents categories like "big" matching on other sizes. Supplying a category like "big" will search all category lines for a random matching one, e.g. "pokemon-gen7x / regular / big", and then will go down the tree searching for a match. Currently, as soon as it hits "regular" it will start accumulating matches from all big/medium/small groups --- src/pokedex/convert.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pokedex/convert.go b/src/pokedex/convert.go index c6110bfb..28bca714 100644 --- a/src/pokedex/convert.go +++ b/src/pokedex/convert.go @@ -160,7 +160,7 @@ func createCategories(fpath string, data []byte) []string { parts := strings.Split(fpath, "/") height := SizeCategory(len(strings.Split(string(data), "\n"))) - return append(parts[0:len(parts)-1], []string{height}...) + return append([]string{height}, parts[0:len(parts)-1]...) } // Strips the leading "./" from a path e.g. "./cows/ -> cows/" From 722a91b9fd39b45b8434e2ad73b9287cb686dcde Mon Sep 17 00:00:00 2001 From: Tom McKeesick Date: Tue, 17 May 2022 20:01:45 +1000 Subject: [PATCH 06/12] Add a basic unit test file There's some weirdness going on in the Trie selection, going to make unit tests to make everything rock-solid --- entries_test.go | 61 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 entries_test.go diff --git a/entries_test.go b/entries_test.go new file mode 100644 index 00000000..beb9f76f --- /dev/null +++ b/entries_test.go @@ -0,0 +1,61 @@ +package main + +import ( + "testing" + "fmt" + "github.com/tmck-code/pokesay/src/pokedex" +) + +func assert(expected interface{}, result interface{}, obj interface{}, test *testing.T) { + if expected != result { + test.Fatalf(`expected = %+v, result = %+v, obj = %+v`, expected, result, obj) + } +} + +func TestNewPokemonEntry(test *testing.T) { + p := pokedex.NewPokemonEntry(1, "yo") + assert(1, p.Index, p, test) +} + +func TestTrieInsert(test *testing.T) { + t := pokedex.NewTrie() + t.Insert( + []string{"pokemon", "gen1", "regular"}, + pokedex.NewPokemonEntry(0, "pikachu"), + ) + t.Insert( + []string{"pokemon", "gen1", "regular"}, + pokedex.NewPokemonEntry(1, "bulbasaur"), + ) + + result, err := t.GetCategory([]string{"pokemon", "gen1"}) + check(err) + + assert(2, len(result), result, test) + assert( + "[{Index: 0, Name: pikachu} {Index: 1, Name: bulbasaur}]", + fmt.Sprintf("%s", result), + result, test, + ) +} +func TestTrieInsert2(test *testing.T) { + t := pokedex.NewTrie() + t.Insert( + []string{"pokemon", "gen1", "regular"}, + pokedex.NewPokemonEntry(0, "pikachu"), + ) + t.Insert( + []string{"pokemon", "gen1", "other"}, + pokedex.NewPokemonEntry(1, "bulbasaur"), + ) + + result, err := t.GetCategory([]string{"pokemon", "gen1"}) + check(err) + + assert(2, len(result), result, test) + assert( + "[{Index: 0, Name: pikachu} {Index: 1, Name: bulbasaur}]", + fmt.Sprintf("%s", result), + result, test, + ) +} From 62031b24558db1193e4ab1504a75fc59825704c8 Mon Sep 17 00:00:00 2001 From: Tom McKeesick Date: Tue, 17 May 2022 20:15:29 +1000 Subject: [PATCH 07/12] some test updates --- entries_test.go | 37 ++++++++++++++++++++++++++----------- src/pokedex/entries.go | 5 +---- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/entries_test.go b/entries_test.go index beb9f76f..f44ea0c7 100644 --- a/entries_test.go +++ b/entries_test.go @@ -7,7 +7,7 @@ import ( ) func assert(expected interface{}, result interface{}, obj interface{}, test *testing.T) { - if expected != result { + if fmt.Sprintf("%v", expected) != fmt.Sprintf("%v", result) { test.Fatalf(`expected = %+v, result = %+v, obj = %+v`, expected, result, obj) } } @@ -38,24 +38,39 @@ func TestTrieInsert(test *testing.T) { result, test, ) } -func TestTrieInsert2(test *testing.T) { +func TestCategoryPaths(test *testing.T) { t := pokedex.NewTrie() t.Insert( - []string{"pokemon", "gen1", "regular"}, + []string{"small", "gen1", "regular"}, pokedex.NewPokemonEntry(0, "pikachu"), ) t.Insert( - []string{"pokemon", "gen1", "other"}, + []string{"small", "gen1", "other"}, pokedex.NewPokemonEntry(1, "bulbasaur"), ) + t.Insert( + []string{"medium", "gen1", "other"}, + pokedex.NewPokemonEntry(2, "bulbasaur"), + ) + t.Insert( + []string{"big", "gen1", "other"}, + pokedex.NewPokemonEntry(3, "bulbasaur"), + ) + t.Insert( + []string{"big", "gen1"}, + pokedex.NewPokemonEntry(4, "charmander"), + ) - result, err := t.GetCategory([]string{"pokemon", "gen1"}) + result, err := t.GetCategoryPaths("big") check(err) - assert(2, len(result), result, test) - assert( - "[{Index: 0, Name: pikachu} {Index: 1, Name: bulbasaur}]", - fmt.Sprintf("%s", result), - result, test, - ) + expected := [][]string{ + []string{"small", "gen1", "regular"}, + []string{"small", "gen1", "other"}, + []string{"medium", "gen1", "other"}, + []string{"big", "gen1", "other"}, + []string{"big", "gen1"}, + } + assert(expected, t.Keys, t, test) + assert("", result, result, test) } diff --git a/src/pokedex/entries.go b/src/pokedex/entries.go index fb46099a..6f969bdd 100644 --- a/src/pokedex/entries.go +++ b/src/pokedex/entries.go @@ -133,13 +133,10 @@ func (t PokemonTrie) GetCategoryPaths(s string) ([][]string, error) { func (t PokemonTrie) GetCategory(s []string) ([]*PokemonEntry, error) { current := t.Root matches := make([]*PokemonEntry, 0) - found := false for _, char := range s { - if _, ok := current.Children[char]; ok || found { - found = true + if _, ok := current.Children[char]; ok { current = current.Children[char] for _, p := range current.Children { - fmt.Println(p) matches = append(matches, p.Data...) } } else { From 098b7e396ce156a6b718f9a098d9763729c9e570 Mon Sep 17 00:00:00 2001 From: Tom McKeesick Date: Tue, 17 May 2022 20:31:31 +1000 Subject: [PATCH 08/12] Create test for getting "big" category paths This is a test case that asserts what is failing during development --- entries_test.go | 37 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/entries_test.go b/entries_test.go index f44ea0c7..adb48e4f 100644 --- a/entries_test.go +++ b/entries_test.go @@ -40,37 +40,26 @@ func TestTrieInsert(test *testing.T) { } func TestCategoryPaths(test *testing.T) { t := pokedex.NewTrie() - t.Insert( + t.Insert([]string{"small", "gen1", "regular"}, pokedex.NewPokemonEntry(0, "pikachu")) + t.Insert([]string{"small", "gen1", "other"}, pokedex.NewPokemonEntry(1, "bulbasaur")) + t.Insert([]string{"medium", "gen1", "other"}, pokedex.NewPokemonEntry(2, "bulbasaur")) + t.Insert([]string{"big", "gen1", "other"}, pokedex.NewPokemonEntry(3, "bulbasaur")) + t.Insert([]string{"big", "gen1"}, pokedex.NewPokemonEntry(4, "charmander")) + + expected := [][]string{ []string{"small", "gen1", "regular"}, - pokedex.NewPokemonEntry(0, "pikachu"), - ) - t.Insert( []string{"small", "gen1", "other"}, - pokedex.NewPokemonEntry(1, "bulbasaur"), - ) - t.Insert( []string{"medium", "gen1", "other"}, - pokedex.NewPokemonEntry(2, "bulbasaur"), - ) - t.Insert( []string{"big", "gen1", "other"}, - pokedex.NewPokemonEntry(3, "bulbasaur"), - ) - t.Insert( []string{"big", "gen1"}, - pokedex.NewPokemonEntry(4, "charmander"), - ) - - result, err := t.GetCategoryPaths("big") - check(err) + } + assert(expected, t.Keys, t, test) - expected := [][]string{ - []string{"small", "gen1", "regular"}, - []string{"small", "gen1", "other"}, - []string{"medium", "gen1", "other"}, + expected = [][]string{ []string{"big", "gen1", "other"}, []string{"big", "gen1"}, } - assert(expected, t.Keys, t, test) - assert("", result, result, test) + result, err := t.GetCategoryPaths("big") + check(err) + assert(expected, result, result, test) } From 85edba37ac56c48b6e4fcf53714e878a0c29f2fc Mon Sep 17 00:00:00 2001 From: Tom McKeesick Date: Tue, 17 May 2022 20:32:37 +1000 Subject: [PATCH 09/12] Always return full category path when matching --- src/pokedex/entries.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/pokedex/entries.go b/src/pokedex/entries.go index 6f969bdd..1473143f 100644 --- a/src/pokedex/entries.go +++ b/src/pokedex/entries.go @@ -114,13 +114,9 @@ func (t *PokemonTrie) Insert(s []string, data *PokemonEntry) { func (t PokemonTrie) GetCategoryPaths(s string) ([][]string, error) { matches := [][]string{} for _, k := range t.Keys { - for i, el := range k { + for _, el := range k { if el == s { - if i == 0 { - matches = append(matches, []string{s}) - } else { - matches = append(matches, k) - } + matches = append(matches, k) } } } From f8830fe2116966a74d32306e65ba5c562cfa8beb Mon Sep 17 00:00:00 2001 From: Tom McKeesick Date: Tue, 17 May 2022 21:37:25 +1000 Subject: [PATCH 10/12] Add test & sort behaviour for listing categories --- entries_test.go | 65 ------------------------------------------ pokesay.go | 14 ++++++--- pokesay_test.go | 75 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+), 69 deletions(-) delete mode 100644 entries_test.go create mode 100644 pokesay_test.go diff --git a/entries_test.go b/entries_test.go deleted file mode 100644 index adb48e4f..00000000 --- a/entries_test.go +++ /dev/null @@ -1,65 +0,0 @@ -package main - -import ( - "testing" - "fmt" - "github.com/tmck-code/pokesay/src/pokedex" -) - -func assert(expected interface{}, result interface{}, obj interface{}, test *testing.T) { - if fmt.Sprintf("%v", expected) != fmt.Sprintf("%v", result) { - test.Fatalf(`expected = %+v, result = %+v, obj = %+v`, expected, result, obj) - } -} - -func TestNewPokemonEntry(test *testing.T) { - p := pokedex.NewPokemonEntry(1, "yo") - assert(1, p.Index, p, test) -} - -func TestTrieInsert(test *testing.T) { - t := pokedex.NewTrie() - t.Insert( - []string{"pokemon", "gen1", "regular"}, - pokedex.NewPokemonEntry(0, "pikachu"), - ) - t.Insert( - []string{"pokemon", "gen1", "regular"}, - pokedex.NewPokemonEntry(1, "bulbasaur"), - ) - - result, err := t.GetCategory([]string{"pokemon", "gen1"}) - check(err) - - assert(2, len(result), result, test) - assert( - "[{Index: 0, Name: pikachu} {Index: 1, Name: bulbasaur}]", - fmt.Sprintf("%s", result), - result, test, - ) -} -func TestCategoryPaths(test *testing.T) { - t := pokedex.NewTrie() - t.Insert([]string{"small", "gen1", "regular"}, pokedex.NewPokemonEntry(0, "pikachu")) - t.Insert([]string{"small", "gen1", "other"}, pokedex.NewPokemonEntry(1, "bulbasaur")) - t.Insert([]string{"medium", "gen1", "other"}, pokedex.NewPokemonEntry(2, "bulbasaur")) - t.Insert([]string{"big", "gen1", "other"}, pokedex.NewPokemonEntry(3, "bulbasaur")) - t.Insert([]string{"big", "gen1"}, pokedex.NewPokemonEntry(4, "charmander")) - - expected := [][]string{ - []string{"small", "gen1", "regular"}, - []string{"small", "gen1", "other"}, - []string{"medium", "gen1", "other"}, - []string{"big", "gen1", "other"}, - []string{"big", "gen1"}, - } - assert(expected, t.Keys, t, test) - - expected = [][]string{ - []string{"big", "gen1", "other"}, - []string{"big", "gen1"}, - } - result, err := t.GetCategoryPaths("big") - check(err) - assert(expected, result, result, test) -} diff --git a/pokesay.go b/pokesay.go index 03dd5097..d214bfc5 100644 --- a/pokesay.go +++ b/pokesay.go @@ -3,15 +3,16 @@ package main import ( "bufio" "embed" + "errors" "flag" "fmt" "log" "math/rand" "os" + "sort" "strconv" "strings" "time" - "errors" "github.com/fatih/color" "github.com/tmck-code/pokesay/src/pokedex" @@ -149,7 +150,7 @@ func parseFlags() Args { return args } -func runListCategories(categories pokedex.PokemonTrie) { +func ListCategories(categories pokedex.PokemonTrie) []string { ukm := map[string]bool{} for _, v := range categories.Keys { for _, k := range v { @@ -162,8 +163,13 @@ func runListCategories(categories pokedex.PokemonTrie) { keys[i] = k i++ } - fmt.Println(strings.Join(keys, " ")) - fmt.Printf("\n%d %s\n", len(keys), "total names") + sort.Strings(keys) + return keys +} + +func runListCategories(categories pokedex.PokemonTrie) { + keys := fmt.Sprintf(strings.Join(ListCategories(categories), " ")) + fmt.Printf("%s\n%d %s\n", keys, len(keys), "total names") } func runListNames() { diff --git a/pokesay_test.go b/pokesay_test.go new file mode 100644 index 00000000..7bd955a9 --- /dev/null +++ b/pokesay_test.go @@ -0,0 +1,75 @@ +package main + +import ( + "fmt" + "testing" + + "github.com/tmck-code/pokesay/src/pokedex" +) + +// Made my own basic test helper. Takes in an expected & result object of any type, and asserts +// that their Go syntax representations (%#v) are the same +func assert(expected interface{}, result interface{}, obj interface{}, test *testing.T) { + if fmt.Sprintf("%#v", expected) != fmt.Sprintf("%#v", result) { + test.Fatalf(`expected = %#v, result = %#v, obj = %#v`, expected, result, obj) + } +} + +func TestNewPokemonEntry(test *testing.T) { + p := pokedex.NewPokemonEntry(1, "yo") + assert(1, p.Index, p, test) +} + +func TestTrieInsert(test *testing.T) { + t := pokedex.NewTrie() + t.Insert([]string{"p", "g1", "r"}, pokedex.NewPokemonEntry(0, "pikachu")) + t.Insert([]string{"p", "g1", "r"}, pokedex.NewPokemonEntry(1, "bulbasaur")) + + result, err := t.GetCategory([]string{"p", "g1"}) + check(err) + + assert(2, len(result), result, test) + assert( + "[{Index: 0, Name: pikachu} {Index: 1, Name: bulbasaur}]", + fmt.Sprintf("%s", result), + result, test, + ) +} + +func TestCategoryPaths(test *testing.T) { + t := pokedex.NewTrie() + t.Insert([]string{"small", "g1", "r"}, pokedex.NewPokemonEntry(0, "pikachu")) + t.Insert([]string{"small", "g1", "o"}, pokedex.NewPokemonEntry(1, "bulbasaur")) + t.Insert([]string{"medium", "g1", "o"}, pokedex.NewPokemonEntry(2, "bulbasaur")) + t.Insert([]string{"big", "g1", "o"}, pokedex.NewPokemonEntry(3, "bulbasaur")) + t.Insert([]string{"big", "g1"}, pokedex.NewPokemonEntry(4, "charmander")) + + expected := [][]string{ + []string{"small", "g1", "r"}, + []string{"small", "g1", "o"}, + []string{"medium", "g1", "o"}, + []string{"big", "g1", "o"}, + []string{"big", "g1"}, + } + assert(expected, t.Keys, t, test) + + expected = [][]string{ + []string{"big", "g1", "o"}, + []string{"big", "g1"}, + } + result, err := t.GetCategoryPaths("big") + check(err) + assert(expected, result, result, test) +} + +func TestListCategories(test *testing.T) { + t := pokedex.NewTrie() + t.Insert([]string{"small", "g1", "r"}, pokedex.NewPokemonEntry(0, "pikachu")) + t.Insert([]string{"small", "g1", "o"}, pokedex.NewPokemonEntry(1, "bulbasaur")) + t.Insert([]string{"medium", "g1", "o"}, pokedex.NewPokemonEntry(2, "bulbasaur")) + t.Insert([]string{"big", "g1", "o"}, pokedex.NewPokemonEntry(3, "bulbasaur")) + t.Insert([]string{"big", "g1"}, pokedex.NewPokemonEntry(4, "charmander")) + + result := ListCategories(*t) + assert([]string{"big", "g1", "medium", "o", "r", "small"}, result, result, test) +} From cf2963178e6626a535c4b3c159cc9fb838c56e8a Mon Sep 17 00:00:00 2001 From: Tom McKeesick Date: Tue, 17 May 2022 21:53:59 +1000 Subject: [PATCH 11/12] update cow asset path --- build/scripts/build_assets.sh | 5 +++-- pokesay.go | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/build/scripts/build_assets.sh b/build/scripts/build_assets.sh index 0c175adb..e5f73ba1 100755 --- a/build/scripts/build_assets.sh +++ b/build/scripts/build_assets.sh @@ -2,9 +2,10 @@ set -euo pipefail -tar xzf build/cows.tar.gz +FROM="${1:-/tmp/cows/}" + go run ./src/bin/pokedex/pokedex.go \ - -from ./cows/ \ + -from "${FROM}" \ -to ./build/assets/ \ -toCategoryFpath pokedex.gob \ -toDataSubDir cows/ \ diff --git a/pokesay.go b/pokesay.go index d214bfc5..a1b7239b 100644 --- a/pokesay.go +++ b/pokesay.go @@ -168,8 +168,8 @@ func ListCategories(categories pokedex.PokemonTrie) []string { } func runListCategories(categories pokedex.PokemonTrie) { - keys := fmt.Sprintf(strings.Join(ListCategories(categories), " ")) - fmt.Printf("%s\n%d %s\n", keys, len(keys), "total names") + keys := ListCategories(categories) + fmt.Printf("%s\n%d %s\n", strings.Join(keys, " "), len(keys), "total categories") } func runListNames() { From 6eccff6fb4ef4bb37ba1f3cc030dd716b1e89896 Mon Sep 17 00:00:00 2001 From: Tom McKeesick Date: Tue, 17 May 2022 21:56:12 +1000 Subject: [PATCH 12/12] Add unit tests to github actions --- .github/workflows/main.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d735bc15..2e628b00 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -22,4 +22,6 @@ jobs: run: ls -alh build/bin - name: Test build run: echo w | ./build/bin/pokesay-linux-amd64 + - name: Run unit tests + run: go test