OLD | NEW |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // This file contains test cases for short valid and invalid programs. | 5 // This file contains test cases for short valid and invalid programs. |
6 | 6 |
7 package parser | 7 package parser |
8 | 8 |
9 import "testing" | 9 import "testing" |
10 | 10 |
(...skipping 20 matching lines...) Expand all Loading... |
31 `package p; func f() { select { case <- c: case c <- d: case c <- <- d:
case <-c <- d: } };`, | 31 `package p; func f() { select { case <- c: case c <- d: case c <- <- d:
case <-c <- d: } };`, |
32 `package p; func f() { select { case x := (<-c): } };`, | 32 `package p; func f() { select { case x := (<-c): } };`, |
33 `package p; func f() { if ; true {} };`, | 33 `package p; func f() { if ; true {} };`, |
34 `package p; func f() { switch ; {} };`, | 34 `package p; func f() { switch ; {} };`, |
35 `package p; func f() { for _ = range "foo" + "bar" {} };`, | 35 `package p; func f() { for _ = range "foo" + "bar" {} };`, |
36 `package p; func f() { var s []int; g(s[:], s[i:], s[:j], s[i:j], s[i:j:
k], s[:j:k]) };`, | 36 `package p; func f() { var s []int; g(s[:], s[i:], s[:j], s[i:j], s[i:j:
k], s[:j:k]) };`, |
37 `package p; var ( _ = (struct {*T}).m; _ = (interface {T}).m )`, | 37 `package p; var ( _ = (struct {*T}).m; _ = (interface {T}).m )`, |
38 `package p; func ((T),) m() {}`, | 38 `package p; func ((T),) m() {}`, |
39 `package p; func ((*T),) m() {}`, | 39 `package p; func ((*T),) m() {}`, |
40 `package p; func (*(T),) m() {}`, | 40 `package p; func (*(T),) m() {}`, |
| 41 `package p; func _(x []int) { for range x {} }`, |
41 } | 42 } |
42 | 43 |
43 func TestValid(t *testing.T) { | 44 func TestValid(t *testing.T) { |
44 for _, src := range valids { | 45 for _, src := range valids { |
45 checkErrors(t, src, src) | 46 checkErrors(t, src, src) |
46 } | 47 } |
47 } | 48 } |
48 | 49 |
49 var invalids = []string{ | 50 var invalids = []string{ |
50 `foo /* ERROR "expected 'package'" */ !`, | 51 `foo /* ERROR "expected 'package'" */ !`, |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 `package p; func f() { go f /* ERROR HERE "function must be invoked" */
}`, | 93 `package p; func f() { go f /* ERROR HERE "function must be invoked" */
}`, |
93 `package p; func f() { defer func() {} /* ERROR HERE "function must be i
nvoked" */ }`, | 94 `package p; func f() { defer func() {} /* ERROR HERE "function must be i
nvoked" */ }`, |
94 `package p; func f() { go func() { func() { f(x func /* ERROR "expected
'\)'" */ (){}) } } }`, | 95 `package p; func f() { go func() { func() { f(x func /* ERROR "expected
'\)'" */ (){}) } } }`, |
95 } | 96 } |
96 | 97 |
97 func TestInvalid(t *testing.T) { | 98 func TestInvalid(t *testing.T) { |
98 for _, src := range invalids { | 99 for _, src := range invalids { |
99 checkErrors(t, src, src) | 100 checkErrors(t, src, src) |
100 } | 101 } |
101 } | 102 } |
OLD | NEW |