Browse Source

Add tests for parseGuesses

tags/v1.0.0
dtluna 7 months ago
parent
commit
e8fc34b384
1 changed files with 49 additions and 0 deletions
  1. +49
    -0
      parse_test.go

+ 49
- 0
parse_test.go View File

@@ -2,6 +2,7 @@ package main

import (
"fmt"
"strings"
"testing"

"github.com/stretchr/testify/assert"
@@ -72,3 +73,51 @@ func (suite *ParseGuessSuite) TestWithCount() {
func TestParseGuessSuite(t *testing.T) {
suite.Run(t, new(ParseGuessSuite))
}

type ParseGuessesSuite struct {
suite.Suite
}

func (suite *ParseGuessesSuite) TestNoGuesses() {
t := suite.T()
reader := strings.NewReader("")
guesses, err := parseGuesses(reader)
assert.Nil(t, guesses)
assert.Error(t, err)
assert.Equal(t, ErrNoGuesses, err)
}

func (suite *ParseGuessesSuite) TestDifferentLength() {
t := suite.T()
reader := strings.NewReader("chef\njef")
guesses, err := parseGuesses(reader)
assert.Nil(t, guesses)
assert.Error(t, err)
assert.Equal(t, ErrNotSameLength, err)
}

func (suite *ParseGuessesSuite) TestBlankLine() {
t := suite.T()
reader := strings.NewReader("chef\n\njef")
guesses, err := parseGuesses(reader)
assert.Nil(t, guesses)
assert.Error(t, err)
assert.Equal(t, ErrBlankLine, err)
}

func (suite *ParseGuessesSuite) TestSuccess() {
t := suite.T()
count := uint(2)
reader := strings.NewReader("chef\njeff 2")
guesses, err := parseGuesses(reader)
assert.NotNil(t, guesses)
assert.NoError(t, err)
assert.Equal(t, []Guess{
Guess{Word: "chef"},
Guess{Word: "jeff", CorrectCount: &count},
}, guesses)
}

func TestParseGuessesSuite(t *testing.T) {
suite.Run(t, new(ParseGuessesSuite))
}

Loading…
Cancel
Save