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.
87 lines
1.8 KiB
Go
87 lines
1.8 KiB
Go
package shell
|
|
|
|
import (
|
|
"bufio"
|
|
"io"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
)
|
|
|
|
type WordTest struct {
|
|
suite.Suite
|
|
}
|
|
|
|
func (t *WordTest) TestSupports() {
|
|
p := &WordParameters{}
|
|
|
|
noChars := []rune{}
|
|
t.True(p.Supports(noChars, 'a'))
|
|
t.True(p.Supports(noChars, '-'))
|
|
t.True(p.Supports(noChars, 'A'))
|
|
t.True(p.Supports(noChars, '0'))
|
|
t.True(p.Supports(noChars, '.'))
|
|
}
|
|
|
|
func (t *WordTest) TestShouldLeave() {
|
|
p := &WordParameters{}
|
|
|
|
noChars := []rune{}
|
|
t.True(p.ShouldLeave(noChars, ' '))
|
|
t.True(p.ShouldLeave(noChars, '\t'))
|
|
t.True(p.ShouldLeave(noChars, '\n'))
|
|
}
|
|
func (t *WordTest) TestAddToken() {
|
|
word := NewWord("")
|
|
|
|
word.AddToken(Char('a'))
|
|
|
|
t.Equal("a", word.String())
|
|
}
|
|
|
|
func (t *WordTest) TestParse() {
|
|
parser := &BaseParser{&WordParameters{}}
|
|
reader := bufio.NewReader(strings.NewReader("word1 word2 word\\ 3"))
|
|
|
|
iterator, err := NewCharIterator(reader)
|
|
t.NoError(err)
|
|
|
|
token, err := parser.Parse(iterator, &CharCollection{})
|
|
t.NoError(err)
|
|
t.Equal("word1", token.String())
|
|
|
|
iterator.Next()
|
|
token, err = parser.Parse(iterator, &CharCollection{})
|
|
t.NoError(err)
|
|
t.Equal("", token.String())
|
|
|
|
iterator.Next()
|
|
iterator.Next()
|
|
token, err = parser.Parse(iterator, &CharCollection{})
|
|
t.NoError(err)
|
|
t.Equal("word2", token.String())
|
|
|
|
iterator.Next()
|
|
iterator.Next()
|
|
token, err = parser.Parse(iterator, &CharCollection{})
|
|
t.ErrorIs(err, io.EOF)
|
|
t.Equal("word 3", token.String())
|
|
}
|
|
|
|
func (t *WordTest) TestParseBackslash() {
|
|
parser := &BaseParser{&WordParameters{}}
|
|
reader := bufio.NewReader(strings.NewReader("w\\\\\\\\\\o=rd1\\ \\$wo\\\\rd2\\\\\\ word\\ 3"))
|
|
|
|
iterator, err := NewCharIterator(reader)
|
|
t.NoError(err)
|
|
|
|
token, err := parser.Parse(iterator, &CharCollection{})
|
|
t.ErrorIs(err, io.EOF)
|
|
t.Equal("w\\\\\\\\o=rd1 $wo\\\\rd2\\\\ word 3", token.String())
|
|
}
|
|
|
|
func TestWordTest(t *testing.T) {
|
|
suite.Run(t, new(WordTest))
|
|
}
|