From 333b6bc91b2f7dbfa4af1e740cded2e978593c89 Mon Sep 17 00:00:00 2001 From: CorentinGS Date: Wed, 18 Dec 2024 17:57:41 +0100 Subject: [PATCH 1/4] fix: Use errors.Is for EOF error comparison in tests closes #12 --- polyglot_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/polyglot_test.go b/polyglot_test.go index e5be5e4..01a867c 100644 --- a/polyglot_test.go +++ b/polyglot_test.go @@ -3,6 +3,7 @@ package chess import ( "bytes" "encoding/binary" + "errors" "io" "os" "path/filepath" @@ -60,7 +61,7 @@ func TestBytesBookSource(t *testing.T) { // Test EOF source.index = 32 n, err = source.Read(buf) - if err != io.EOF { + if !errors.Is(err, io.EOF) { t.Errorf("Read() error = %v, want EOF", err) } } From 52dd184cfa8846e21e2a83a1a34178a94f356a88 Mon Sep 17 00:00:00 2001 From: CorentinGS Date: Wed, 18 Dec 2024 17:58:45 +0100 Subject: [PATCH 2/4] fix: error variable naming in loop for clarity. closes #11 --- polyglot.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/polyglot.go b/polyglot.go index af56927..ae6f2ed 100644 --- a/polyglot.go +++ b/polyglot.go @@ -194,12 +194,12 @@ func LoadFromSource(source BookSource) (*PolyglotBook, error) { buf := make([]byte, 16) for { - _, err := source.Read(buf) - if err == io.EOF { + _, readErr := source.Read(buf) + if readErr == io.EOF { break } - if err != nil { - return nil, err + if readErr != nil { + return nil, readErr } entry := PolyglotEntry{ From 5d47fd2d41bfb0f28823bdc1a0d552b3704e8a6a Mon Sep 17 00:00:00 2001 From: CorentinGS Date: Wed, 18 Dec 2024 18:00:35 +0100 Subject: [PATCH 3/4] fix: potential nil pointer closes: #8 --- pgn.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pgn.go b/pgn.go index e9fa8ea..5947e9d 100644 --- a/pgn.go +++ b/pgn.go @@ -519,7 +519,7 @@ func (p *Parser) parseVariation() error { // the last move before the variation start variationParent = parentMove.parent // Reset position to where the variation starts - if variationParent.parent != nil { + if variationParent.parent != nil && variationParent.parent.position != nil { p.game.pos = variationParent.parent.position.copy() if newPos := p.game.pos.Update(variationParent); newPos != nil { p.game.pos = newPos From 878381046c88e6ee16234e4d07d73b9d4f4df448 Mon Sep 17 00:00:00 2001 From: CorentinGS Date: Wed, 18 Dec 2024 18:01:52 +0100 Subject: [PATCH 4/4] fix: Add "Undefined" token type to lexer closes #6 --- lexer.go | 1 + 1 file changed, 1 insertion(+) diff --git a/lexer.go b/lexer.go index 63ae242..a3057c4 100644 --- a/lexer.go +++ b/lexer.go @@ -44,6 +44,7 @@ const ( func (t TokenType) String() string { types := []string{ "EOF", + "Undefined", "TagStart", "TagEnd", "TagKey",