Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(19)

Side by Side Diff: src/pkg/exp/exception/exception_test.go

Issue 857048: code review 857048: Remove exp/exception as it's no longer relevant (Closed)
Patch Set: code review 857048: Remove exp/exception as it's no longer relevant Created 14 years, 11 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/pkg/exp/exception/exception.go ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2009 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.
4
5 package exception
6
7 import "testing"
8
9 func TestNoException(t *testing.T) {
10 e := Try(func(throw Handler) {})
11 if e != nil {
12 t.Fatalf("no exception expected, found: %v", e)
13 }
14 }
15
16
17 func TestNilException(t *testing.T) {
18 e := Try(func(throw Handler) { throw(nil) })
19 if e == nil {
20 t.Fatalf("exception expected", e)
21 }
22 if e.Value != nil {
23 t.Fatalf("nil exception expected, found: %v", e)
24 }
25 }
26
27
28 func TestTry(t *testing.T) {
29 s := 0
30 for i := 1; i <= 10; i++ {
31 e := Try(func(throw Handler) {
32 if i%3 == 0 {
33 throw(i)
34 panic("throw returned")
35 }
36 })
37 if e != nil {
38 s += e.Value.(int)
39 }
40 }
41 result := 3 + 6 + 9
42 if s != result {
43 t.Fatalf("expected: %d, found: %d", result, s)
44 }
45 }
46
47
48 func TestCatch(t *testing.T) {
49 s := 0
50 for i := 1; i <= 10; i++ {
51 Try(func(throw Handler) {
52 if i%3 == 0 {
53 throw(i)
54 }
55 }).Catch(func(x interface{}) { s += x.(int) })
56 }
57 result := 3 + 6 + 9
58 if s != result {
59 t.Fatalf("expected: %d, found: %d", result, s)
60 }
61 }
OLDNEW
« no previous file with comments | « src/pkg/exp/exception/exception.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b