Skip to content
This repository has been archived by the owner on Sep 19, 2022. It is now read-only.

Commit

Permalink
Command parser fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
FeodorFitsner committed Nov 25, 2020
1 parent 0b36c13 commit ac574e7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
7 changes: 6 additions & 1 deletion internal/page/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func Parse(cmdText string) (*Command, error) {

tok := s.TokenText()

//fmt.Printf("%s: %s\n", s.Position, tok)
fmt.Printf("%s: %s\n", s.Position, tok)

if tok == "=" {
if prevLit == "" || prevToken == "=" {
Expand Down Expand Up @@ -112,6 +112,11 @@ func Parse(cmdText string) (*Command, error) {
prevToken = tok
}

// consume last token collected
if prevLit != "" {
command.Values = append(command.Values, prevLit)
}

return command, nil
}

Expand Down
20 changes: 20 additions & 0 deletions internal/page/command/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,23 @@ func TestParse2(t *testing.T) {
t.Errorf("command values[0] is %s, want %s", cmd.Values[0], expValue)
}
}

func TestParseClean(t *testing.T) {
cmd, err := Parse(`clean page`)

if err != nil {
t.Fatal(err)
}

// visualize command
log.Printf("%s", utils.ToJSON(cmd))

if len(cmd.Values) != 1 {
t.Errorf("the number of values is %d, want %d", len(cmd.Values), 1)
}

expValue := "page"
if cmd.Values[0] != expValue {
t.Errorf("command values[0] is %s, want %s", cmd.Values[0], expValue)
}
}

0 comments on commit ac574e7

Please sign in to comment.