]> Cypherpunks repositories - gostls13.git/commitdiff
exp/template: make -0 be an unsigned int.
authorRob Pike <r@golang.org>
Thu, 23 Jun 2011 00:19:29 +0000 (10:19 +1000)
committerRob Pike <r@golang.org>
Thu, 23 Jun 2011 00:19:29 +0000 (10:19 +1000)
Fix (inconsequential) type error in list initializer.

R=rsc
CC=golang-dev
https://golang.org/cl/4638058

src/pkg/exp/template/parse.go
src/pkg/exp/template/parse_test.go

index 74d4b1df2f0bb4c509a098530d000fa35a7b315f..57ddb0084fa6a5f225a68b0f79f38607e4a188f7 100644 (file)
@@ -68,6 +68,7 @@ const (
        nodeEnd
        nodeField
        nodeIdentifier
+       nodeList
        nodeNumber
        nodeRange
        nodeString
@@ -82,7 +83,7 @@ type listNode struct {
 }
 
 func newList() *listNode {
-       return &listNode{nodeType: nodeText}
+       return &listNode{nodeType: nodeList}
 }
 
 func (l *listNode) append(n node) {
@@ -178,8 +179,7 @@ func (f *fieldNode) String() string {
 }
 
 // numberNode holds a number, signed or unsigned, integer, floating, or imaginary.
-// The value is parsed and stored under all the types that can represent the value
-// (although for simplicity -0 is not considered a valid unsigned integer).
+// The value is parsed and stored under all the types that can represent the value.
 // This simulates in a small amount of code the behavior of Go's ideal constants.
 // TODO: booleans, complex numbers.
 type numberNode struct {
@@ -207,7 +207,7 @@ func newNumber(text string) (*numberNode, os.Error) {
                }
        }
        // Do integer test first so we get 0x123 etc.
-       u, err := strconv.Btoui64(text, 0) // will fail for -0; tough.
+       u, err := strconv.Btoui64(text, 0) // will fail for -0; fixed below.
        if err == nil {
                n.isUint = true
                n.uint64 = u
@@ -216,6 +216,10 @@ func newNumber(text string) (*numberNode, os.Error) {
        if err == nil {
                n.isInt = true
                n.int64 = i
+               if i == 0 {
+                       n.isUint = true // in case of -0.
+                       n.uint64 = u
+               }
        }
        // If an integer extraction succeeded, promote the float.
        if n.isInt {
index 5c694f256a54053d9068602ba755930dd21dfb4b..f89eaa6ce3cfbc8b08c80dec0aea51e52005bd3b 100644 (file)
@@ -25,6 +25,7 @@ type numberTest struct {
 var numberTests = []numberTest{
        // basics
        {"0", true, true, true, false, 0, 0, 0},
+       {"-0", true, true, true, false, 0, 0, 0}, // check that -0 is a uint.
        {"73", true, true, true, false, 73, 73, 73},
        {"-73", true, false, true, false, -73, 0, -73},
        {"+73", true, false, true, false, 73, 0, 73},
@@ -37,7 +38,7 @@ var numberTests = []numberTest{
        {"4i", false, false, true, true, 0, 0, 4},
        // funny bases
        {"0123", true, true, true, false, 0123, 0123, 0123},
-       {"-0x0", true, false, true, false, 0, 0, 0},
+       {"-0x0", true, true, true, false, 0, 0, 0},
        {"0xdeadbeef", true, true, true, false, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef},
        // some broken syntax
        {text: "+-2"},