|
| 1 | +package de.peeeq.wurstscript.attributes; |
| 2 | + |
| 3 | +import de.peeeq.wurstscript.gui.WurstGuiCliImpl; |
| 4 | +import de.peeeq.wurstscript.parser.WPos; |
| 5 | +import org.testng.annotations.Test; |
| 6 | + |
| 7 | +import static org.testng.Assert.assertEquals; |
| 8 | +import static org.testng.Assert.assertFalse; |
| 9 | +import static org.testng.Assert.assertSame; |
| 10 | +import static org.testng.Assert.assertTrue; |
| 11 | + |
| 12 | +public class ErrorHandlerTests { |
| 13 | + @Test |
| 14 | + public void tracksErrorsWarningsAndPerFileBuckets() { |
| 15 | + WurstGuiCliImpl gui = new WurstGuiCliImpl(); |
| 16 | + ErrorHandler handler = new ErrorHandler(gui); |
| 17 | + CompileError error = new CompileError(new WPos("one.wurst", null, 1, 1), "bad"); |
| 18 | + CompileError warning = new CompileError(new WPos("one.wurst", null, 2, 1), "careful", |
| 19 | + CompileError.ErrorType.WARNING); |
| 20 | + |
| 21 | + handler.sendError(error); |
| 22 | + handler.sendError(warning); |
| 23 | + |
| 24 | + assertEquals(handler.getErrorCount(), 1); |
| 25 | + assertEquals(handler.getErrors(), java.util.List.of(error)); |
| 26 | + assertEquals(handler.getWarnings(), java.util.List.of(warning)); |
| 27 | + assertEquals(handler.getBucketForFile("one.wurst", CompileError.ErrorType.ERROR), java.util.List.of(error)); |
| 28 | + assertEquals(handler.getBucketForFile("one.wurst", CompileError.ErrorType.WARNING), java.util.List.of(warning)); |
| 29 | + assertEquals(gui.getErrorList().size(), 1); |
| 30 | + |
| 31 | + handler.removeFromGlobal(error); |
| 32 | + handler.removeFromGlobal(warning); |
| 33 | + assertTrue(handler.getErrors().isEmpty()); |
| 34 | + assertTrue(handler.getWarnings().isEmpty()); |
| 35 | + assertEquals(handler.getBucketForFile("one.wurst", CompileError.ErrorType.ERROR), null); |
| 36 | + assertEquals(handler.getBucketForFile("one.wurst", CompileError.ErrorType.WARNING), null); |
| 37 | + } |
| 38 | + |
| 39 | + @Test |
| 40 | + public void exposesGuiAndUnitTestMode() { |
| 41 | + WurstGuiCliImpl gui = new WurstGuiCliImpl(); |
| 42 | + ErrorHandler handler = new ErrorHandler(gui); |
| 43 | + |
| 44 | + assertSame(handler.getGui(), gui); |
| 45 | + assertFalse(handler.isUnitTestMode()); |
| 46 | + handler.enableUnitTestMode(); |
| 47 | + assertTrue(handler.isUnitTestMode()); |
| 48 | + assertFalse(handler.isOutputTestSource()); |
| 49 | + } |
| 50 | +} |
0 commit comments