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 | 3d25b0827e2e3ec50f26209a1c43894f6fe1ff40 (patch) | |
tree | cf7526d0549ee03d48e782a0d21eb565d1b0d2e1 /test/switch.go | |
parent | 6d4af3d1b5cd81a4c864298e0bf85b9840fdb689 (diff) | |
download | go-3d25b0827e2e3ec50f26209a1c43894f6fe1ff40.tar.gz |
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://codereview.appspot.com/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 fd8748b9b..c6a0ebc74 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) } } |