Skip to content
This repository has been archived by the owner on Jul 24, 2023. It is now read-only.

Commit

Permalink
added some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shixzie committed Sep 18, 2017
1 parent 8c2ad72 commit fb7169b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
25 changes: 17 additions & 8 deletions nlp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func TestNL_P(t *testing.T) {
"dur {Dur}",
"string {String} int {Int}",
"string {String} time {Time}",
"need {String} since {Time}",
}

nl := New()
Expand All @@ -55,52 +56,60 @@ func TestNL_P(t *testing.T) {
expression string
want *T
}{
{
0: {
"string",
"string Hello World",
&T{String: "Hello World"},
},
{
1: {
"int",
"int 42",
&T{Int: 42},
},
{
2: {
"uint",
"uint 43",
&T{Uint: 43},
},
{
3: {
"float",
"float 44",
&T{Float: 44},
},
{
4: {
"time",
"time 05-18-1999_6:42pm",
&T{Time: tim},
},
{
5: {
"duration",
"dur 4h2m",
&T{Dur: dur},
},
{
6: {
"string int",
"string Lmao int 42",
&T{
String: "Lmao",
Int: 42,
},
},
{
7: {
"string time",
"string What's Up Boy time 05-18-1999_6:42pm",
&T{
String: "What's Up Boy",
Time: tim,
},
},
8: {
"word string time",
"Hi, I am Patrice, I need Issue#4 since 05-18-1999_6:42pm",
&T{
String: "Issue#4",
Time: tim,
},
},
}
for i, tt := range cases {
t.Run(tt.name, func(t *testing.T) {
Expand Down
18 changes: 15 additions & 3 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ func TestParseSample(t *testing.T) {
want []Token
wantErr bool
}{
{
0: {
"err: empty sample",
args{0, nil},
nil,
true,
},
{
1: {
"normal sample",
args{1, []byte("play {Name} from {Artist}")},
[]Token{
Expand All @@ -33,7 +33,7 @@ func TestParseSample(t *testing.T) {
},
false,
},
{
2: {
"spacing inside keys",
args{1, []byte("play { Name} from { Artist }")},
[]Token{
Expand All @@ -44,6 +44,18 @@ func TestParseSample(t *testing.T) {
},
false,
},
3: {
"multi word",
args{1, []byte("I need {Name} since {Since}")},
[]Token{
{Val: []byte("I")},
{Val: []byte("need")},
{Kw: true, Val: []byte("Name")},
{Val: []byte("since")},
{Kw: true, Val: []byte("Since")},
},
false,
},
}
for i, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit fb7169b

Please sign in to comment.