Make go get to install work.

This commit is contained in:
Vikram Rangnekar
2020-04-16 00:26:32 -04:00
parent 40c99e9ef3
commit 09d6460a13
99 changed files with 240 additions and 73 deletions

View File

@ -1,12 +1,17 @@
package qcode
func GetQType(gql string) QType {
ic := false
for i := range gql {
b := gql[i]
if b == '{' {
switch {
case b == '#':
ic = true
case b == '\n':
ic = false
case !ic && b == '{':
return QTQuery
}
if al(b) {
case !ic && al(b):
switch b {
case 'm', 'M':
return QTMutation

View File

@ -0,0 +1,50 @@
package qcode
import "testing"
func TestGetQType(t *testing.T) {
type args struct {
gql string
}
type ts struct {
name string
args args
want QType
}
tests := []ts{
ts{
name: "query",
args: args{gql: " query {"},
want: QTQuery,
},
ts{
name: "mutation",
args: args{gql: " mutation {"},
want: QTMutation,
},
ts{
name: "default query",
args: args{gql: " {"},
want: QTQuery,
},
ts{
name: "default query with comment",
args: args{gql: `# query is good
{`},
want: QTQuery,
},
ts{
name: "failed query with comment",
args: args{gql: `# query is good query {`},
want: -1,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := GetQType(tt.args.gql); got != tt.want {
t.Errorf("GetQType() = %v, want %v", got, tt.want)
}
})
}
}