|
21 | 21 |
|
22 | 22 | package com.igormaznitsa.jcp.directives; |
23 | 23 |
|
| 24 | +import static org.junit.Assert.assertEquals; |
| 25 | +import static org.junit.Assert.assertNotNull; |
| 26 | +import static org.junit.Assert.assertTrue; |
| 27 | +import static org.junit.Assert.fail; |
| 28 | + |
| 29 | +import com.igormaznitsa.jcp.containers.FileInfoContainer; |
| 30 | +import com.igormaznitsa.jcp.context.CommentTextProcessor; |
| 31 | +import com.igormaznitsa.jcp.context.PreprocessingState; |
| 32 | +import com.igormaznitsa.jcp.context.PreprocessorContext; |
| 33 | +import java.util.concurrent.atomic.AtomicBoolean; |
| 34 | + |
24 | 35 | // This test checks work of //$$, //$ and /*-*/ |
25 | 36 | // Those directives are very specific and they don't have any distinguished handler |
26 | 37 | public class SpecialDirectivesTest extends AbstractDirectiveHandlerAcceptanceTest { |
27 | 38 |
|
28 | 39 | @Override |
29 | 40 | public void testExecution() throws Exception { |
30 | | - assertFilePreprocessing("directive_special.txt", false, null, null); |
| 41 | + final StringBuilder calledForText = new StringBuilder(); |
| 42 | + |
| 43 | + final AtomicBoolean started = new AtomicBoolean(); |
| 44 | + final AtomicBoolean stopped = new AtomicBoolean(); |
| 45 | + |
| 46 | + final CommentTextProcessor testProcessor = new CommentTextProcessor() { |
| 47 | + @Override |
| 48 | + public void onContextStarted(PreprocessorContext context) { |
| 49 | + if (!started.compareAndSet(false, true)) { |
| 50 | + fail(); |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | + @Override |
| 55 | + public void onContextStopped(PreprocessorContext context, Throwable error) { |
| 56 | + if (!stopped.compareAndSet(false, true)) { |
| 57 | + fail(); |
| 58 | + } |
| 59 | + } |
| 60 | + |
| 61 | + @Override |
| 62 | + public String onUncommentText(String text, FileInfoContainer fileInfoContainer, |
| 63 | + PreprocessorContext context, PreprocessingState state) { |
| 64 | + assertNotNull(text); |
| 65 | + assertNotNull(fileInfoContainer); |
| 66 | + assertNotNull(context); |
| 67 | + assertNotNull(state); |
| 68 | + |
| 69 | + calledForText.append("...\n").append(text); |
| 70 | + |
| 71 | + return text; |
| 72 | + } |
| 73 | + }; |
| 74 | + |
| 75 | + assertFilePreprocessing("directive_special.txt", false, false, null, null, |
| 76 | + c -> c.addCommentTextProcessor(testProcessor)); |
| 77 | + assertTrue(started.get()); |
| 78 | + assertTrue(stopped.get()); |
| 79 | + assertEquals("...\n" + |
| 80 | + "hello 223 world\n" + |
| 81 | + "...\n" + |
| 82 | + "hello /*$111+112$*/ world\n" + |
| 83 | + "...\n" + |
| 84 | + "\"\"\"hello 223 world\n" + |
| 85 | + "...\n" + |
| 86 | + "\"\"\"hello /*$111+112$*/ world\n", calledForText.toString()); |
31 | 87 | } |
32 | 88 |
|
33 | 89 | @Override |
|
0 commit comments