Debian Codegraph @

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

raw symbols SCIP
1 /*
2 * Copyright 2011 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 package com.google.javascript.jscomp;
17
18 import com.google.javascript.jscomp.CheckLevel;
19 import com.google.javascript.jscomp.CompilerOptions;
20 import com.google.javascript.jscomp.DiagnosticGroups;
21
22 /**
23 * {@link CheckDebuggerStatementTest} is a unit test for
24 * {@link CheckDebuggerStatement}.
25 *
26 * @author [email protected] (Michael Bolin)
27 */
28 public class CheckDebuggerStatementTest extends CompilerTestCase {
29
30 private CheckLevel checkLevel;
31
32 @Override
33 public void tearDown() {
34 checkLevel = null;
35 }
36
37 @Override
38 protected CompilerPass getProcessor(Compiler compiler) {
39 return new CheckDebuggerStatement(compiler);
40 }
41
42 @Override
43 protected CompilerOptions getOptions() {
44 CompilerOptions options = super.getOptions();
45 if (checkLevel != null) {
46 options.setWarningLevel(
47 DiagnosticGroups.DEBUGGER_STATEMENT_PRESENT,
48 checkLevel);
49 }
50 return options;
51 }
52
53 public void testCheckDebuggerStatement() {
54 checkLevel = CheckLevel.WARNING;
55
56 testSame("debugger;", CheckDebuggerStatement.DEBUGGER_STATEMENT_PRESENT);
57 testSame("function foo() { debugger; }",
58 CheckDebuggerStatement.DEBUGGER_STATEMENT_PRESENT);
59 }
60
61 public void testCheckIsDisabledByDefault() {
62 checkLevel = null;
63
64 testSame("debugger;");
65 testSame("function foo() { debugger; }");
66 }
67
68 public void testNoWarningWhenExplicitlyDisabled() {
69 checkLevel = CheckLevel.OFF;
70
71 testSame("debugger;");
72 testSame("function foo() { debugger; }");
73 }
74
75 public void testCheckDebuggerKeywordMayAppearInComments() {
76 checkLevel = CheckLevel.WARNING;
77
78 test("// I like the debugger; it is helpful.", "");
79 }
80
81 public void testCheckDebuggerStatementInEval() {
82 checkLevel = CheckLevel.WARNING;
83
84 testSame("eval('debugger');");
85 }
86
87 }