package shell import ( "bufio" "strings" "testing" "github.com/stretchr/testify/suite" ) type CharIteratorTest struct { suite.Suite } func (t *CharIteratorTest) TestNextAndBacktrack() { charIterator, err := NewCharIterator(bufio.NewReader(strings.NewReader("abcdefg"))) t.NoError(err) t.Equal(string('a'), string(charIterator.Current())) err = charIterator.Next() t.NoError(err) t.Equal(string('b'), string(charIterator.Current())) err = charIterator.Previous() t.NoError(err) t.Equal(string('a'), string(charIterator.Current())) err = charIterator.Previous() t.Error(err) t.Equal("Chariterator can only go back once", err.Error()) err = charIterator.Next() t.NoError(err) t.Equal(string('b'), string(charIterator.Current())) } func TestCharIteratorTest(t *testing.T) { suite.Run(t, new(CharIteratorTest)) }