File: errors_test.go

package info (click to toggle)
golang-github-spf13-pflag 1.0.10-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid
  • size: 612 kB
  • sloc: sh: 80; makefile: 2
file content (67 lines) | stat: -rw-r--r-- 1,771 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package pflag

import (
	"errors"
	"testing"
)

func TestNotExistError(t *testing.T) {
	err := &NotExistError{
		name:                "foo",
		specifiedShorthands: "bar",
	}

	if err.GetSpecifiedName() != "foo" {
		t.Errorf("Expected GetSpecifiedName to return %q, got %q", "foo", err.GetSpecifiedName())
	}
	if err.GetSpecifiedShortnames() != "bar" {
		t.Errorf("Expected GetSpecifiedShortnames to return %q, got %q", "bar", err.GetSpecifiedShortnames())
	}
}

func TestValueRequiredError(t *testing.T) {
	err := &ValueRequiredError{
		flag:                &Flag{},
		specifiedName:       "foo",
		specifiedShorthands: "bar",
	}

	if err.GetFlag() == nil {
		t.Error("Expected GetSpecifiedName to return its flag field, but got nil")
	}
	if err.GetSpecifiedName() != "foo" {
		t.Errorf("Expected GetSpecifiedName to return %q, got %q", "foo", err.GetSpecifiedName())
	}
	if err.GetSpecifiedShortnames() != "bar" {
		t.Errorf("Expected GetSpecifiedShortnames to return %q, got %q", "bar", err.GetSpecifiedShortnames())
	}
}

func TestInvalidValueError(t *testing.T) {
	expectedCause := errors.New("error")
	err := &InvalidValueError{
		flag:  &Flag{},
		value: "foo",
		cause: expectedCause,
	}

	if err.GetFlag() == nil {
		t.Error("Expected GetSpecifiedName to return its flag field, but got nil")
	}
	if err.GetValue() != "foo" {
		t.Errorf("Expected GetValue to return %q, got %q", "foo", err.GetValue())
	}
	if err.Unwrap() != expectedCause {
		t.Errorf("Expected Unwrwap to return %q, got %q", expectedCause, err.Unwrap())
	}
}

func TestInvalidSyntaxError(t *testing.T) {
	err := &InvalidSyntaxError{
		specifiedFlag: "--=",
	}

	if err.GetSpecifiedFlag() != "--=" {
		t.Errorf("Expected GetSpecifiedFlag to return %q, got %q", "--=", err.GetSpecifiedFlag())
	}
}