Skip to content

Commit 025afa2

Browse files
committed
improved test
1 parent a277169 commit 025afa2

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

jcp/src/test/java/com/igormaznitsa/jcp/directives/SpecialDirectivesTest.java

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,69 @@
2121

2222
package com.igormaznitsa.jcp.directives;
2323

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+
2435
// This test checks work of //$$, //$ and /*-*/
2536
// Those directives are very specific and they don't have any distinguished handler
2637
public class SpecialDirectivesTest extends AbstractDirectiveHandlerAcceptanceTest {
2738

2839
@Override
2940
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());
3187
}
3288

3389
@Override
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
//$hello /*$111+112$*/ world
22
//$$hello /*$111+112$*/ world
3+
//$"""hello /*$111+112$*/ world
4+
//$$"""hello /*$111+112$*/ world
35
hello/*-*/world
46
---START_ETALON---
57
hello 223 world
68
hello /*$111+112$*/ world
9+
"""hello 223 world
10+
"""hello /*$111+112$*/ world
711
hello

0 commit comments

Comments
 (0)