diff options
author | Alan Donovan <adonovan@google.com> | 2013-02-11 18:20:52 -0500 |
---|---|---|
committer | Alan Donovan <adonovan@google.com> | 2013-02-11 18:20:52 -0500 |
commit | 1c1096ea31ed50f3553382ebb81a6a16396e56ec (patch) | |
tree | e5694fb132d8aae3f55a8d340d14b173467a2193 /test/switch.go | |
parent | d282532901c02e3f2dde4ed3f2258bcb7a61d510 (diff) | |
download | go-1c1096ea31ed50f3553382ebb81a6a16396e56ec.tar.gz go-1c1096ea31ed50f3553382ebb81a6a16396e56ec.zip |
test: a number of fixes.
Details:
- reorder.go: delete p8.
(Once expectation is changed per b/4627 it is identical to p1.)
- switch.go: added some more (degenerate) switches.
- range.go: improved error messages in a few cases.
- method.go: added tests of calls to promoted methods.
R=iant
CC=golang-dev
https://golang.org/cl/7306087
Diffstat (limited to 'test/switch.go')
-rw-r--r-- | test/switch.go | 59 |
1 files changed, 52 insertions, 7 deletions
diff --git a/test/switch.go b/test/switch.go index fd8748b9bc..c6a0ebc74a 100644 --- a/test/switch.go +++ b/test/switch.go @@ -307,9 +307,9 @@ func main() { // switch on array. switch ar := [3]int{1, 2, 3}; ar { - case [3]int{1,2,3}: + case [3]int{1, 2, 3}: assert(true, "[1 2 3]") - case [3]int{4,5,6}: + case [3]int{4, 5, 6}: assert(false, "ar should be [1 2 3]") default: assert(false, "ar should be [1 2 3]") @@ -327,12 +327,57 @@ func main() { assert(false, "c1 did not match itself") } + // empty switch + switch { + } + + // empty switch with default case. + fired = false + switch { + default: + fired = true + } + assert(fired, "fail") + + // Default and fallthrough. + count = 0 + switch { + default: + count++ + fallthrough + case false: + count++ + } + assert(count == 2, "fail") + + // fallthrough to default, which is not at end. + count = 0 + switch i5 { + case 5: + count++ + fallthrough + default: + count++ + case 6: + count++ + } + assert(count == 2, "fail") + + // fallthrough in final case. + count = 0 + switch i5 { + case 5: + count++ + fallthrough + } + assert(count == 1, "fail") + i := 0 switch x := 5; { - case i < x: - os.Exit(0) - case i == x: - case i > x: - os.Exit(1) + case i < x: + os.Exit(0) + case i == x: + case i > x: + os.Exit(1) } } |