-
Notifications
You must be signed in to change notification settings - Fork 3
/
types_test.go
43 lines (38 loc) · 1.15 KB
/
types_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package brigodier
import (
"github.com/stretchr/testify/require"
"testing"
)
func TestStringType_Parse(t *testing.T) {
r := &StringReader{String: `"hello world"`}
s, err := String.Parse(r)
require.NoError(t, err)
require.Equal(t, "hello world", s)
require.Equal(t, "", r.Remaining())
r = &StringReader{String: `hello world`}
s, err = String.Parse(r)
require.NoError(t, err)
require.Equal(t, "hello", s)
require.Equal(t, " world", r.Remaining())
}
func TestStringType_Parse_Word(t *testing.T) {
r := &StringReader{String: "hello world"}
s, err := StringWord.Parse(r)
require.NoError(t, err)
require.Equal(t, "hello", s)
require.Equal(t, " world", r.Remaining())
}
func TestStringType_Parse_Phrase(t *testing.T) {
r := &StringReader{String: "Hello world! This is a test."}
s, err := StringPhrase.Parse(r)
require.NoError(t, err)
require.Equal(t, "Hello world! This is a test.", s)
}
func TestBoolType_Parse(t *testing.T) {
parse, err := Bool.Parse(&StringReader{String: "true"})
require.NoError(t, err)
require.Equal(t, true, parse)
parse, err = Bool.Parse(&StringReader{String: "false"})
require.NoError(t, err)
require.Equal(t, false, parse)
}