1
0
mirror of https://github.com/golang/go synced 2024-11-22 21:40:03 -07:00
go/src/errors/errors_test.go
fangguizhen 27b6ace2b4 errors: move example functions into example_test file
Change-Id: Ide70476698d82a51881802dd6bf05dd7abcd60e8
GitHub-Last-Rev: ddb251ded6
GitHub-Pull-Request: golang/go#57931
Reviewed-on: https://go-review.googlesource.com/c/go/+/462292
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@google.com>
2023-01-20 21:55:10 +00:00

34 lines
765 B
Go

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