You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
843 B
Go
45 lines
843 B
Go
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))
|
|
}
|