aboutsummaryrefslogtreecommitdiffhomepage
path: root/cgo/const_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'cgo/const_test.go')
-rw-r--r--cgo/const_test.go30
1 files changed, 22 insertions, 8 deletions
diff --git a/cgo/const_test.go b/cgo/const_test.go
index 27ed8b772..235a7117b 100644
--- a/cgo/const_test.go
+++ b/cgo/const_test.go
@@ -4,6 +4,7 @@ import (
"bytes"
"go/format"
"go/token"
+ "strings"
"testing"
)
@@ -14,20 +15,33 @@ func TestParseConst(t *testing.T) {
Go string
}{
{`5`, `5`},
- {`(5)`, `5`},
- {`(((5)))`, `5`},
+ {`(5)`, `(5)`},
+ {`(((5)))`, `(5)`},
+ {`)`, `error: 1:1: unexpected token )`},
+ {`5)`, `error: 1:2: unexpected token )`},
+ {" \t)", `error: 1:4: unexpected token )`},
{`5.8f`, `5.8`},
- {`foo`, `<invalid>`}, // identifiers unimplemented
- {``, `<invalid>`}, // empty constants not allowed in Go
+ {`foo`, `error: 1:1: unexpected token ILLEGAL`}, // identifiers unimplemented
+ {``, `error: 1:1: empty constant`}, // empty constants not allowed in Go
{`"foo"`, `"foo"`},
+ {`"a\\n"`, `"a\\n"`},
+ {`"a\n"`, `"a\n"`},
+ {`"a\""`, `"a\""`},
{`'a'`, `'a'`},
- {`0b10`, `<invalid>`}, // binary number literals unimplemented
+ {`0b10`, `0b10`},
+ {`0x1234_5678`, `0x1234_5678`},
} {
fset := token.NewFileSet()
- startPos := fset.AddFile("test.c", -1, 1000).Pos(0)
- expr := parseConst(startPos, tc.C)
+ startPos := fset.AddFile("", -1, 1000).Pos(0)
+ expr, err := parseConst(startPos, fset, tc.C)
s := "<invalid>"
- if expr != nil {
+ if err != nil {
+ if !strings.HasPrefix(tc.Go, "error: ") {
+ t.Errorf("expected value %#v for C constant %#v but got error %#v", tc.Go, tc.C, err.Error())
+ continue
+ }
+ s = "error: " + err.Error()
+ } else if expr != nil {
// Serialize the Go constant to a string, for more readable test
// cases.
buf := &bytes.Buffer{}