Skip to content

Commit

Permalink
Alpha release v0.0.5 with handmade expression parser
Browse files Browse the repository at this point in the history
  • Loading branch information
rasteric committed Feb 2, 2019
1 parent 9e8f9c9 commit 303b43a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
grammar:
java org.antlr.v4.Tool -Dlanguage=Go -o parser Mdb.g4
java org.antlr.v4.Tool -Dlanguage=Go -o parser MdbParser.g4

compile:
go build -v && go test && go vet
Expand Down
12 changes: 12 additions & 0 deletions commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const (
CmdListBlob
CmdListDate
CmdSetDateStr
CmdFieldIsEmpty
)

// A database that has been opened.
Expand Down Expand Up @@ -278,6 +279,8 @@ func Exec(cmd *Command) *Result {
r.Strings[0] = s
case CmdFieldIsNull:
r.Bool = theDB.FieldIsNull(cmd.StrArgs[0], cmd.ItemArg, cmd.StrArgs[1])
case CmdFieldIsEmpty:
r.Bool = theDB.FieldIsEmpty(cmd.StrArgs[0], cmd.ItemArg, cmd.StrArgs[1])
case CmdFieldExists:
r.Bool = theDB.FieldExists(cmd.StrArgs[0], cmd.StrArgs[1])
case CmdGetFields:
Expand Down Expand Up @@ -395,6 +398,15 @@ func FieldIsNullCommand(db CommandDB, item Item, field string) *Command {
}
}

func FieldIsEmptyCommand(db CommandDB, item Item, field string) *Command {
return &Command{
ID: CmdFieldIsEmpty,
DB: db,
StrArgs: []string{field},
ItemArg: item,
}
}

func FindCommand(db CommandDB, query *Query, limit int64) *Command {
return &Command{
ID: CmdFind,
Expand Down
19 changes: 10 additions & 9 deletions minidb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -562,13 +562,14 @@ func TestMDB(t *testing.T) {
}

func TestParseQuery(t *testing.T) {
queries := []string{`test Name=r% OR Name=John`,
"Person Name=Smith OR NOT Name=John",
"Person Age=47 AND Name=John%",
queries := []string{`test Name=r% or Name=John`,
"Person Name=Smith or not Name=John",
"Person Age=47 and Name=John%",
`Person Name="John"`,
`Person Email="[email protected]" AND Name="%r%"`,
`Person Email="[email protected]" and Name="%r%"`,
`Person every Name=%e%`,
`Person no Name=John`,
`Person not every Name=John`,
}
for _, query := range queries {
_, err := ParseQuery(query)
Expand Down Expand Up @@ -794,15 +795,15 @@ func TestFindTest(t *testing.T) {
}
}
// Data blob list field
for j := range v.Blobs {
query := `test Data="` + v.Blobs[j] + `"`
for j, _ := range v.Blobs {
query := fmt.Sprintf("test Data=%s", v.Blobs[j])
q, err := ParseQuery(query)
if err != nil {
t.Errorf(`ParseQuery("%s") failed: %s`, query, err)
}
results, err := db.Find(q, 200)
if err != nil {
t.Errorf(`MDB.Find() failed for query "%s", should have succeeded`, query)
t.Errorf(`MDB.Find() failed for query "%s", should have succeeded: %s`, query, err)
}
found := false
for k := range results {
Expand Down Expand Up @@ -831,7 +832,7 @@ func TestFindTest(t *testing.T) {
}
}
if !found {
t.Errorf(`MDB.Find() failed to find Blob for query "%s", should have succeeded`, query)
t.Errorf(`MDB.Find() failed to find single Blob for query "%s", should have succeeded`, query)
}
}

Expand Down Expand Up @@ -877,7 +878,7 @@ func teardown() {
db.Close()
}
if tmpfile != nil {
// os.Remove(tmpfile.Name())
os.Remove(tmpfile.Name())
}
}

Expand Down

0 comments on commit 303b43a

Please sign in to comment.