]> Cypherpunks repositories - gostls13.git/commitdiff
debug/macho: make Type implements fmt.(Go)Stringer interfaces
authorHiroshi Ioka <hirochachacha@gmail.com>
Mon, 14 Aug 2017 08:26:22 +0000 (17:26 +0900)
committerIan Lance Taylor <iant@golang.org>
Tue, 15 Aug 2017 00:13:36 +0000 (00:13 +0000)
Fixes #21436

Change-Id: I56f43e2852696c28edbcc772a54125a9a9c32497
Reviewed-on: https://go-review.googlesource.com/55262
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/debug/macho/file_test.go
src/debug/macho/macho.go

index 71896d1b2e738ad97c536ecc1982a317a3da8ed5..fa84064fa9b5b56b6ada5c248365dc1dccb2ef38 100644 (file)
@@ -217,3 +217,12 @@ func TestRelocTypeString(t *testing.T) {
                t.Errorf("got %v, want %v", X86_64_RELOC_BRANCH.GoString(), "macho.X86_64_RELOC_BRANCH")
        }
 }
+
+func TestTypeString(t *testing.T) {
+       if TypeExec.String() != "Exec" {
+               t.Errorf("got %v, want %v", TypeExec.String(), "Exec")
+       }
+       if TypeExec.GoString() != "macho.Exec" {
+               t.Errorf("got %v, want %v", TypeExec.GoString(), "macho.Exec")
+       }
+}
index 366ce205dfb3ac83c9003cdf6acc7b7ee586fc6c..6535ba787b055f320a9421203f232c28bf4c68ac 100644 (file)
@@ -41,6 +41,16 @@ const (
        TypeBundle Type = 8
 )
 
+var typeStrings = []intName{
+       {uint32(TypeObj), "Obj"},
+       {uint32(TypeExec), "Exec"},
+       {uint32(TypeDylib), "Dylib"},
+       {uint32(TypeBundle), "Bundle"},
+}
+
+func (t Type) String() string   { return stringName(uint32(t), typeStrings, false) }
+func (t Type) GoString() string { return stringName(uint32(t), typeStrings, true) }
+
 // A Cpu is a Mach-O cpu type.
 type Cpu uint32