-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavaExamplesTest.java
More file actions
43 lines (38 loc) · 1.42 KB
/
JavaExamplesTest.java
File metadata and controls
43 lines (38 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Assertions;
import org.rimumarkup.CallbackMessage;
import org.rimumarkup.RenderOptions;
import org.rimumarkup.Rimu;
/**
* Java Rimu examples.
*/
public class JavaExamplesTest {
@BeforeEach
public void before() {
// Initialize Rimu to default state.
RenderOptions options = new RenderOptions();
options.reset = true;
Rimu.render("", options);
}
@Test
public final void simpleExampleTest() {
String result = Rimu.render("Hello *Rimu*!");
Assertions.assertEquals("<p>Hello <em>Rimu</em>!</p>", result);
}
private String callbackMessage;
@Test
public final void callbackExampleTest() {
RenderOptions options = new RenderOptions();
// Capture the callback message.
options.callback = (CallbackMessage message) -> {
// NOTE: Java does not support closures and Java lambdas cannot assign variables in the method scope at runtime,
// which is why callbackMessage is outside this method.
callbackMessage = message.type + ": " + message.text;
return null;
};
String result = Rimu.render("Unknown {x}", options);
Assertions.assertEquals("<p>Unknown {x}</p>", result);
Assertions.assertEquals("error: undefined macro: {x}: Unknown {x}", callbackMessage);
}
}