| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
package org.mozilla.javascript.testing; |
| 6 |
|
| 7 |
import org.mozilla.javascript.ErrorReporter; |
| 8 |
import org.mozilla.javascript.EvaluatorException; |
| 9 |
|
| 10 |
import junit.framework.Assert; |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
public class TestErrorReporter extends Assert implements ErrorReporter { |
| 27 |
private final String[] errors; |
| 28 |
private final String[] warnings; |
| 29 |
private int errorsIndex = 0; |
| 30 |
private int warningsIndex = 0; |
| 31 |
|
| 32 |
public TestErrorReporter(String[] errors, String[] warnings) { |
| 33 |
this.errors = errors; |
| 34 |
this.warnings = warnings; |
| 35 |
} |
| 36 |
|
| 37 |
public void error(String message, String sourceName, int line, |
| 38 |
String lineSource, int lineOffset) { |
| 39 |
if (errors != null && errorsIndex < errors.length) { |
| 40 |
assertEquals(errors[errorsIndex++], message); |
| 41 |
} else { |
| 42 |
fail("extra error: " + message); |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
public void warning(String message, String sourceName, int line, |
| 47 |
String lineSource, int lineOffset) { |
| 48 |
if (warnings != null && warningsIndex < warnings.length) { |
| 49 |
assertEquals(warnings[warningsIndex++], message); |
| 50 |
} else { |
| 51 |
fail("extra warning: " + message); |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
public EvaluatorException runtimeError( |
| 56 |
String message, String sourceName, int line, String lineSource, |
| 57 |
int lineOffset) { |
| 58 |
throw new UnsupportedOperationException(); |
| 59 |
} |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
public boolean hasEncounteredAllWarnings() { |
| 65 |
return (warnings == null) ? |
| 66 |
warningsIndex == 0 : |
| 67 |
warnings.length == warningsIndex; |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
public boolean hasEncounteredAllErrors() { |
| 74 |
return (errors == null) ? |
| 75 |
errorsIndex == 0 : |
| 76 |
errors.length == errorsIndex; |
| 77 |
} |
| 78 |
} |