| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 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 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 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 |
} |