提交 9e01ec60 编写于 作者: chai2010's avatar chai2010

添加 errors 标准库

上级 6b54f4f2
// 版权 @2023 凹语言 作者。保留所有权利。
func New(text: string) => error {
return &errorString{text}
}
type errorString struct {
s :string
}
func errorString.Error => string {
return this.s
}
// 版权 @2023 凹语言 作者。保留所有权利。
func TestNewEqual {
// Different allocations should not be equal.
if New("abc") == New("abc") {
assert(false, `New("abc") == New("abc")`)
}
if New("abc") == New("xyz") {
assert(false, `New("abc") == New("xyz")`)
}
// Same allocation should be equal to itself (not crash).
err := New("jkl")
if err != err {
assert(false, `err != err`)
}
}
func TestErrorMethod {
err := New("abc")
if err.Error() != "abc" {
assert(false, `New("abc").Error() = "` + err.Error() + `", want "abc"`)
}
}
func ExampleNew() {
err := New("emit macho dwarf: elf header corrupted")
if err != nil {
print(err)
}
// Output: emit macho dwarf: elf header corrupted
}
......@@ -71,6 +71,7 @@ func IsStdPkg(pkgpath string) bool {
var stdPkgs = []string{
"arduino",
"errors",
"fmt",
"math",
"os",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册