Debian Codegraph @

test/com/google/javascript/jscomp/RemoveTryCatchTest.java

raw symbols SCIP
1 /*
2 * Copyright 2006 The Closure Compiler Authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package com.google.javascript.jscomp;
18
19
20 public class RemoveTryCatchTest extends CompilerTestCase {
21
22 public RemoveTryCatchTest() {
23 // do not compare as tree because we use synthetic blocks
24 super("", false);
25 }
26
27 @Override public CompilerPass getProcessor(Compiler compiler) {
28 return new RemoveTryCatch(compiler);
29 }
30
31 @Override public int getNumRepetitions() {
32 // Use only one repetition because test code contains JSDoc comments.
33 return 1;
34 }
35
36 public void testRemoveTryCatch() {
37 test("try{var a=1;}catch(ex){var b=2;}",
38 "var b;var a=1");
39 test("try{var a=1;var b=2}catch(ex){var c=3;var d=4;}",
40 "var d;var c;var a=1;var b=2");
41 test("try{var a=1;var b=2}catch(ex){}",
42 "var a=1;var b=2");
43 }
44
45 public void testRemoveTryFinally() {
46 test("try{var a=1;}finally{var c=3;}",
47 "var a=1;var c=3");
48 test("try{var a=1;var b=2}finally{var e=5;var f=6;}",
49 "var a=1;var b=2;var e=5;var f=6");
50 }
51
52 public void testRemoveTryCatchFinally() {
53 test("try{var a=1;}catch(ex){var b=2;}finally{var c=3;}",
54 "var b;var a=1;var c=3");
55 test("try{var a=1;var b=2}catch(ex){var c=3;var d=4;}finally{var e=5;" +
56 "var f=6;}",
57 "var d;var c;var a=1;var b=2;var e=5;var f=6");
58 }
59
60 public void testPreserveTryBlockContainingReturnStatement() {
61 testSame("function f(){var a;try{a=1;return}finally{a=2}}");
62 }
63
64 public void testPreserveAnnotatedTryBlock() {
65 test("/** @preserveTry */try{var a=1;}catch(ex){var b=2;}",
66 "try{var a=1}catch(ex){var b=2}");
67 }
68
69 public void testIfTryFinally() {
70 test("if(x)try{y}finally{z}", "if(x){y;z}");
71 }
72
73 public void testIfTryCatch() {
74 test("if(x)try{y;z}catch(e){}", "if(x){y;z}");
75 }
76 }