parse_test.go 1.26 KB
Newer Older
1 2 3 4 5
package cli

import (
  //"fmt"
  "testing"
Matt Bell's avatar
Matt Bell committed
6 7

  "github.com/jbenet/go-ipfs/commands"
8 9 10
)

func TestOptionParsing(t *testing.T) {
11 12 13 14 15
  cmd := &commands.Command{
    Options: []commands.Option{
      commands.Option{ []string{"b"}, commands.String },
    },
  }
16 17
  cmd.Register("test", &commands.Command{})

18
  opts, input, err := parseOptions([]string{ "--beep", "--boop=\"5", "lol\"", "test2", "-cVb", "beep" },
19
    []string{"test"}, cmd)
20 21 22 23 24 25 26
  /*for k, v := range opts {
    fmt.Printf("%s: %s\n", k, v)
  }
  fmt.Printf("%s\n", input)*/
  if err != nil {
    t.Error("Should have passed")
  }
27
  if len(opts) != 5 || opts["c"] != "" || opts["V"] != "" || opts["beep"] != "" || opts["boop"] != "5 lol" || opts["b"] != "beep" {
28 29
    t.Error("Returned options were defferent than expected: %v", opts)
  }
30
  if len(input) != 1 || input[0] != "test2" {
31 32
    t.Error("Returned input was different than expected: %v", input)
  }
Matt Bell's avatar
Matt Bell committed
33

34
  path, args, err := parsePath([]string{ "test", "beep", "boop" }, cmd)
Matt Bell's avatar
Matt Bell committed
35 36 37 38 39 40 41 42 43
  if err != nil {
    t.Error("Should have passed")
  }
  if len(path) != 1 || path[0] != "test" {
    t.Error("Returned path was defferent than expected: %v", path)
  }
  if len(args) != 2 || args[0] != "beep" || args[1] != "boop" {
    t.Error("Returned args were different than expected: %v", args)
  }
44
}