aboutsummaryrefslogtreecommitdiff
path: root/errors_test.go
diff options
context:
space:
mode:
authorHu Jun <[email protected]>2025-04-28 20:37:52 -0700
committerHu Jun <[email protected]>2025-04-28 20:37:52 -0700
commit2a2b77a54936c042e155dd11eaacf2159b4b6cdf (patch)
tree61329708f247bad0cc247c0257d3a66d1b522386 /errors_test.go
parentaae8e193d1d01538cb04b9768a722ea18d8aed44 (diff)
parentd661846b4df0d6611ad95577ddfb240474d21b7c (diff)
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'errors_test.go')
-rw-r--r--errors_test.go67
1 files changed, 67 insertions, 0 deletions
diff --git a/errors_test.go b/errors_test.go
new file mode 100644
index 0000000..7b4c7a4
--- /dev/null
+++ b/errors_test.go
@@ -0,0 +1,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())
+ }
+}