1 // Copyright 2013 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // golang.org/issue/6612
6 // Test new scheme for deciding whether C.name is an expression, type, constant.
7 // Clang silences some warnings when the name is a #defined macro, so test those too
8 // (even though we now use errors exclusively, not warnings).
15 const char *mytext = "abcdef";
21 #define myfunc_def myfunc
22 #define myvar_def myvar
23 #define mytext_def mytext
24 #define mytype_def mytype
25 #define myenum_def myenum
26 #define myint_def 12345
27 #define myfloat_def 1.5
28 #define mystring_def "hello"
34 func testNaming(t
*testing
.T
) {
37 if v
:= C
.myvar
; v
!= 5 {
38 t
.Errorf("C.myvar = %d, want 5", v
)
40 if v
:= C
.myvar_def
; v
!= 5 {
41 t
.Errorf("C.myvar_def = %d, want 5", v
)
43 if s
:= C
.GoString(C
.mytext
); s
!= "abcdef" {
44 t
.Errorf("C.mytext = %q, want %q", s
, "abcdef")
46 if s
:= C
.GoString(C
.mytext_def
); s
!= "abcdef" {
47 t
.Errorf("C.mytext_def = %q, want %q", s
, "abcdef")
49 if c
:= C
.myenum
; c
!= 1234 {
50 t
.Errorf("C.myenum = %v, want 1234", c
)
52 if c
:= C
.myenum_def
; c
!= 1234 {
53 t
.Errorf("C.myenum_def = %v, want 1234", c
)
58 t
.Errorf("C.myenum as const = %v, want 1234", c
)
62 const c
= C
.myenum_def
64 t
.Errorf("C.myenum as const = %v, want 1234", c
)
67 if c
:= C
.myint_def
; c
!= 12345 {
68 t
.Errorf("C.myint_def = %v, want 12345", c
)
73 t
.Errorf("C.myint as const = %v, want 12345", c
)
77 if c
:= C
.myfloat_def
; c
!= 1.5 {
78 t
.Errorf("C.myint_def = %v, want 1.5", c
)
81 const c
= C
.myfloat_def
83 t
.Errorf("C.myint as const = %v, want 1.5", c
)
87 if s
:= C
.mystring_def
; s
!= "hello" {
88 t
.Errorf("C.mystring_def = %q, want %q", s
, "hello")