5
5
import static org .junit .jupiter .api .Assertions .assertTrue ;
6
6
7
7
import java .util .List ;
8
+ import java .util .Locale ;
8
9
10
+ import org .eclipse .esmf .aspectmodel .AspectModelFile ;
11
+ import org .eclipse .esmf .metamodel .AspectModel ;
12
+ import org .eclipse .esmf .test .TestAspect ;
13
+ import org .eclipse .esmf .test .TestResources ;
14
+
15
+ import org .junit .jupiter .api .BeforeAll ;
9
16
import org .junit .jupiter .api .Test ;
10
17
11
18
class DescriptionsUtilsTest {
19
+
20
+ private static String testDescription ;
21
+
22
+ @ BeforeAll
23
+ public static void init () {
24
+ final AspectModel aspectModel = TestResources .load ( TestAspect .ASPECT_WITH_MARKDOWN_DESCRIPTION );
25
+ final AspectModelFile originalFile = aspectModel .files ().iterator ().next ();
26
+ testDescription = originalFile .elements ().getFirst ().getDescription ( Locale .ENGLISH );
27
+ }
28
+
12
29
@ Test
13
30
void testExtractNotesSingleNote () {
14
- final String description = "> NOTE: This is a note.\n > Continued on the next line." ;
15
- final List <String > notes = DescriptionsUtils .notes ( description );
31
+ final List <String > notes = DescriptionsUtils .notes ( testDescription );
16
32
assertThat ( notes ).hasSize ( 1 );
17
- assertEquals ( "This is a note. \n Continued on the next line." , notes .get ( 0 ) );
33
+ assertEquals ( "This is a note block. \n It supports multiple lines. \n Here's a second line of the note ." , notes .get ( 0 ) );
18
34
}
19
35
20
36
@ Test
21
37
void testExtractExamplesMultipleExamples () {
22
- final String description =
23
- """
24
- > EXAMPLE 1: First example.
25
- > More detail.
26
-
27
- > EXAMPLE 2: Second example.
28
- """ ;
29
- final List <String > examples = DescriptionsUtils .examples ( description );
38
+ final List <String > examples = DescriptionsUtils .examples ( testDescription );
30
39
31
40
assertEquals ( 2 , examples .size () );
32
- assertEquals ( "First example.\n More detail." , examples .get ( 0 ) );
33
- assertEquals ( "Second example." , examples .get ( 1 ) );
41
+ assertEquals ( "This is the first example block.\n It can span several lines, and supports *italic* and **bold** text." ,
42
+ examples .get ( 0 ) );
43
+ assertEquals ( "This is the second example.\n Also multiline, for testing multiple example entries." , examples .get ( 1 ) );
44
+ }
45
+
46
+ @ Test
47
+ void testExtractExamplesMultipleExamplesWithBoldAndItalicText () {
48
+ final String html = DescriptionsUtils .toHtml ( testDescription );
49
+
50
+ assertThat ( html ).contains (
51
+ "This is the first example block.\n It can span several lines, and supports <em>italic</em> and <strong>bold</strong> text." );
34
52
}
35
53
36
54
@ Test
37
55
void testExtractSourcesWithLink () {
38
- final String description = "> SOURCE: Source with [link](https://example.com)" ;
39
- final List <String > sources = DescriptionsUtils .sources ( description );
56
+ final List <String > sources = DescriptionsUtils .sources ( testDescription );
40
57
assertEquals ( 1 , sources .size () );
41
- assertThat ( sources .get ( 0 ) ).contains ( "[link](https://example.com) " );
58
+ assertThat ( sources .get ( 0 ) ).contains ( "ISO 12345:2023, section 4.2.1 \n " + "with an inline [link](https://www. example.com/spec). " );
42
59
}
43
60
44
61
@ Test
45
62
void testMixedBlockTypes () {
46
- final String description =
47
- """
48
- > NOTE: A note block.
49
- > EXAMPLE: An example block.
50
-
51
- > SOURCE: A source block.
52
- """ ;
53
- assertEquals ( 1 , DescriptionsUtils .notes ( description ).size () );
54
- assertEquals ( 1 , DescriptionsUtils .examples ( description ).size () );
55
- assertEquals ( 1 , DescriptionsUtils .sources ( description ).size () );
63
+ assertEquals ( 1 , DescriptionsUtils .notes ( testDescription ).size () );
64
+ assertEquals ( 2 , DescriptionsUtils .examples ( testDescription ).size () );
65
+ assertEquals ( 1 , DescriptionsUtils .sources ( testDescription ).size () );
56
66
}
57
67
58
68
@ Test
@@ -65,44 +75,37 @@ void testNoBlocks() {
65
75
66
76
@ Test
67
77
void testToHtmlWithAllBlockTypes () {
68
- final String description =
69
- """
70
- > NOTE: This is a note.
71
- > With multiple lines.
72
-
73
- > EXAMPLE 1: First example.
74
- > Additional example content.
75
-
76
- > EXAMPLE 2: Second example.
77
-
78
- > SOURCE: Source information here.
79
-
80
- Some **markdown** content here.
81
- 1. Ordered
82
- 2. List
83
- """ ;
84
-
85
- final String html = DescriptionsUtils .toHtml ( description );
78
+ final String description = """
79
+ > NOTE: This is a note.
80
+ > With multiple lines.
81
+
82
+ > EXAMPLE 1: First example.
83
+ > Additional example content.
84
+
85
+ > EXAMPLE 2: Second example.
86
+
87
+ > SOURCE: Source information here.
88
+
89
+ Some **markdown** content here.
90
+ 1. Ordered
91
+ 2. List
92
+ """ ;
93
+
94
+ final String html = DescriptionsUtils .toHtml ( testDescription );
86
95
87
96
assertThat ( html ).contains ( "<div class=\" note\" >" );
88
- assertThat ( html ).contains ( "This is a note." );
97
+ assertThat ( html ).contains ( "This is a note block. \n It supports multiple lines. \n Here's a second line of the note ." );
89
98
assertTrue ( html .contains ( "<ul class=\" example-list\" >" ) || html .contains ( "<div class=\" example\" >" ) );
90
- assertThat ( html ).contains ( "First example." );
99
+ assertThat ( html ).contains (
100
+ "This is the first example block.\n It can span several lines, and supports <em>italic</em> and <strong>bold</strong> text." );
91
101
assertThat ( html ).contains ( "<div class=\" source\" >" );
92
- assertThat ( html ).contains ( "Source information here." );
93
- assertThat ( html ).contains ( "<strong>markdown</strong>" );
102
+ assertThat ( html ).contains ( "ISO 12345:2023, section 4.2.1\n with an inline <a href=\" https://www.example.com/spec\" >link</a>." );
94
103
assertThat ( html ).contains ( "<ol>" );
95
104
}
96
105
97
106
@ Test
98
107
void testMarkdownRenderingBulletList () {
99
- String description = """
100
- This is a list:
101
- * Item A
102
- * Item B
103
- * Item C
104
- """ ;
105
- String html = DescriptionsUtils .toHtml ( description );
108
+ String html = DescriptionsUtils .toHtml ( testDescription );
106
109
assertThat ( html ).contains ( "<ul>" );
107
110
assertThat ( html ).contains ( "<li>Item A</li>" );
108
111
assertThat ( html ).contains ( "<li>Item B</li>" );
@@ -111,45 +114,22 @@ void testMarkdownRenderingBulletList() {
111
114
112
115
@ Test
113
116
void testMarkdownRenderingOrderedList () {
114
- String description = """
115
- Steps:
116
- 1. First
117
- 2. Second
118
- 3. Third
119
- """ ;
120
- String html = DescriptionsUtils .toHtml ( description );
117
+ String html = DescriptionsUtils .toHtml ( testDescription );
121
118
assertThat ( html ).contains ( "<ol>" );
122
119
assertThat ( html ).contains ( "<li>First</li>" );
123
120
assertThat ( html ).contains ( "<li>Second</li>" );
124
121
assertThat ( html ).contains ( "<li>Third</li>" );
125
122
}
126
123
127
- @ Test
128
- void testMarkdownRenderingSpecialBlock () {
129
- String description =
130
- """
131
- > NOTE: This is a note.
132
- > Continued here.
133
- """ ;
134
- String html = DescriptionsUtils .toHtml ( description );
135
- assertThat ( html ).contains ( "<div class=\" note\" >" );
136
- assertThat ( html ).contains ( "This is a note." );
137
- assertThat ( html ).contains ( "Continued here." );
138
- }
139
-
140
124
@ Test
141
125
void testMarkdownRenderingWithLink () {
142
- String description =
143
- "Here is a [link](https://example.com) in the text." ;
144
- String html = DescriptionsUtils .toHtml ( description );
145
- assertThat ( html ).contains ( "<a href=\" https://example.com\" >link</a>" );
126
+ String html = DescriptionsUtils .toHtml ( testDescription );
127
+ assertThat ( html ).contains ( "<a href=\" https://example.com\" >Visit Example</a>" );
146
128
}
147
129
148
130
@ Test
149
131
void testHtmlOutputDoesNotContainMarkdownSyntax () {
150
- String description =
151
- "This is a [link](https://example.com)." ;
152
- String html = DescriptionsUtils .toHtml ( description );
153
- assertThat ( html ).doesNotContain ( "[link](https://example.com)" );
132
+ String html = DescriptionsUtils .toHtml ( testDescription );
133
+ assertThat ( html ).doesNotContain ( "[Visit Example](https://example.com)" );
154
134
}
155
135
}
0 commit comments