2016-03-01 15:57:46 -07:00
|
|
|
// Copyright 2011 The Go Authors. All rights reserved.
|
2011-11-01 19:46:59 -06:00
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package errors_test
|
|
|
|
|
|
|
|
import (
|
2012-02-17 17:48:33 -07:00
|
|
|
"errors"
|
2011-11-01 19:46:59 -06:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestNewEqual(t *testing.T) {
|
|
|
|
// Different allocations should not be equal.
|
2012-02-17 17:48:33 -07:00
|
|
|
if errors.New("abc") == errors.New("abc") {
|
2011-11-01 19:46:59 -06:00
|
|
|
t.Errorf(`New("abc") == New("abc")`)
|
|
|
|
}
|
2012-02-17 17:48:33 -07:00
|
|
|
if errors.New("abc") == errors.New("xyz") {
|
2011-11-01 19:46:59 -06:00
|
|
|
t.Errorf(`New("abc") == New("xyz")`)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Same allocation should be equal to itself (not crash).
|
2012-02-17 17:48:33 -07:00
|
|
|
err := errors.New("jkl")
|
2011-11-01 19:46:59 -06:00
|
|
|
if err != err {
|
|
|
|
t.Errorf(`err != err`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestErrorMethod(t *testing.T) {
|
2012-02-17 17:48:33 -07:00
|
|
|
err := errors.New("abc")
|
2011-11-01 19:46:59 -06:00
|
|
|
if err.Error() != "abc" {
|
|
|
|
t.Errorf(`New("abc").Error() = %q, want %q`, err.Error(), "abc")
|
|
|
|
}
|
|
|
|
}
|