diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2011-12-03 02:17:34 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2011-12-03 02:17:34 +0000 |
commit | 2fd401c8f190f1fe43e51a7f726f6ed6119a1f96 (patch) | |
tree | 7f76eff391f37fe6467ff4ffbc0c582c9959ea30 /libgo/go/old/template | |
parent | 02e9018f1616b23f1276151797216717b3564202 (diff) | |
download | gcc-2fd401c8f190f1fe43e51a7f726f6ed6119a1f96.tar.gz |
libgo: Update to weekly.2011-11-02.
From-SVN: r181964
Diffstat (limited to 'libgo/go/old/template')
-rw-r--r-- | libgo/go/old/template/parse.go | 21 | ||||
-rw-r--r-- | libgo/go/old/template/template_test.go | 19 |
2 files changed, 19 insertions, 21 deletions
diff --git a/libgo/go/old/template/parse.go b/libgo/go/old/template/parse.go index 9f8d1eba338..fc9885feef7 100644 --- a/libgo/go/old/template/parse.go +++ b/libgo/go/old/template/parse.go @@ -10,7 +10,6 @@ import ( "fmt" "io" "io/ioutil" - "os" "reflect" "strconv" "strings" @@ -25,11 +24,11 @@ type Error struct { Msg string } -func (e *Error) String() string { return fmt.Sprintf("line %d: %s", e.Line, e.Msg) } +func (e *Error) Error() string { return fmt.Sprintf("line %d: %s", e.Line, e.Msg) } // checkError is a deferred function to turn a panic with type *Error into a plain error return. // Other panics are unexpected and so are re-enabled. -func checkError(error *os.Error) { +func checkError(error *error) { if v := recover(); v != nil { if e, ok := v.(*Error); ok { *error = e @@ -414,7 +413,7 @@ func (t *Template) newVariable(words []string) *variableElement { // Build argument list, processing any literals for i, word := range words { - var lerr os.Error + var lerr error switch word[0] { case '"', '`', '\'': v, err := strconv.Unquote(word) @@ -650,7 +649,7 @@ func (t *Template) parse() { // Parse initializes a Template by parsing its definition. The string // s contains the template text. If any errors occur, Parse returns // the error. -func (t *Template) Parse(s string) (err os.Error) { +func (t *Template) Parse(s string) (err error) { if t.elems == nil { return &Error{1, "template not allocated with New"} } @@ -667,7 +666,7 @@ func (t *Template) Parse(s string) (err os.Error) { // ParseFile is like Parse but reads the template definition from the // named file. -func (t *Template) ParseFile(filename string) (err os.Error) { +func (t *Template) ParseFile(filename string) (err error) { b, err := ioutil.ReadFile(filename) if err != nil { return err @@ -677,7 +676,7 @@ func (t *Template) ParseFile(filename string) (err os.Error) { // Execute applies a parsed template to the specified data object, // generating output to wr. -func (t *Template) Execute(wr io.Writer, data interface{}) (err os.Error) { +func (t *Template) Execute(wr io.Writer, data interface{}) (err error) { // Extract the driver data. val := reflect.ValueOf(data) defer checkError(&err) @@ -701,7 +700,7 @@ func (t *Template) SetDelims(left, right string) { // the formatter map fmap, which may be nil, defines auxiliary functions // for formatting variables. The template is returned. If any errors // occur, err will be non-nil. -func Parse(s string, fmap FormatterMap) (t *Template, err os.Error) { +func Parse(s string, fmap FormatterMap) (t *Template, err error) { t = New(fmap) err = t.Parse(s) if err != nil { @@ -715,7 +714,7 @@ func Parse(s string, fmap FormatterMap) (t *Template, err os.Error) { // a file containing the template text, while the formatter map fmap, which // may be nil, defines auxiliary functions for formatting variables. // The template is returned. If any errors occur, err will be non-nil. -func ParseFile(filename string, fmap FormatterMap) (t *Template, err os.Error) { +func ParseFile(filename string, fmap FormatterMap) (t *Template, err error) { b, err := ioutil.ReadFile(filename) if err != nil { return nil, err @@ -727,7 +726,7 @@ func ParseFile(filename string, fmap FormatterMap) (t *Template, err os.Error) { func MustParse(s string, fmap FormatterMap) *Template { t, err := Parse(s, fmap) if err != nil { - panic("template.MustParse error: " + err.String()) + panic("template.MustParse error: " + err.Error()) } return t } @@ -737,7 +736,7 @@ func MustParse(s string, fmap FormatterMap) *Template { func MustParseFile(filename string, fmap FormatterMap) *Template { b, err := ioutil.ReadFile(filename) if err != nil { - panic("template.MustParseFile error: " + err.String()) + panic("template.MustParseFile error: " + err.Error()) } return MustParse(string(b), fmap) } diff --git a/libgo/go/old/template/template_test.go b/libgo/go/old/template/template_test.go index 9595eb189b3..c88346995a8 100644 --- a/libgo/go/old/template/template_test.go +++ b/libgo/go/old/template/template_test.go @@ -10,7 +10,6 @@ import ( "io" "io/ioutil" "json" - "os" "strings" "testing" ) @@ -462,9 +461,9 @@ var tests = []*Test{ func TestAll(t *testing.T) { // Parse - testAll(t, func(test *Test) (*Template, os.Error) { return Parse(test.in, formatters) }) + testAll(t, func(test *Test) (*Template, error) { return Parse(test.in, formatters) }) // ParseFile - testAll(t, func(test *Test) (*Template, os.Error) { + testAll(t, func(test *Test) (*Template, error) { err := ioutil.WriteFile("_test/test.tmpl", []byte(test.in), 0600) if err != nil { t.Error("unexpected write error:", err) @@ -473,7 +472,7 @@ func TestAll(t *testing.T) { return ParseFile("_test/test.tmpl", formatters) }) // tmpl.ParseFile - testAll(t, func(test *Test) (*Template, os.Error) { + testAll(t, func(test *Test) (*Template, error) { err := ioutil.WriteFile("_test/test.tmpl", []byte(test.in), 0600) if err != nil { t.Error("unexpected write error:", err) @@ -484,7 +483,7 @@ func TestAll(t *testing.T) { }) } -func testAll(t *testing.T, parseFunc func(*Test) (*Template, os.Error)) { +func testAll(t *testing.T, parseFunc func(*Test) (*Template, error)) { s := new(S) // initialized by hand for clarity. s.Header = "Header" @@ -530,8 +529,8 @@ func testAll(t *testing.T, parseFunc func(*Test) (*Template, os.Error)) { } else { if err == nil { t.Errorf("expected execute error %q, got nil", test.err) - } else if err.String() != test.err { - t.Errorf("expected execute error %q, got %q", test.err, err.String()) + } else if err.Error() != test.err { + t.Errorf("expected execute error %q, got %q", test.err, err.Error()) } } if buf.String() != test.out { @@ -703,7 +702,7 @@ func TestReferenceToUnexported(t *testing.T) { if err == nil { t.Fatal("expected execute error, got none") } - if strings.Index(err.String(), "not exported") < 0 { + if strings.Index(err.Error(), "not exported") < 0 { t.Fatal("expected unexported error; got", err) } } @@ -777,8 +776,8 @@ func TestFormatters(t *testing.T) { t.Error("unexpected parse error:", err) continue } - if strings.Index(err.String(), c.err) < 0 { - t.Errorf("unexpected error: expected %q, got %q", c.err, err.String()) + if strings.Index(err.Error(), c.err) < 0 { + t.Errorf("unexpected error: expected %q, got %q", c.err, err.Error()) continue } } else { |