Skip to content

Commit 5258e3c

Browse files
committed
Update tests and add markdown description Model
1 parent e7be12e commit 5258e3c

File tree

3 files changed

+115
-83
lines changed

3 files changed

+115
-83
lines changed

core/esmf-aspect-meta-model-java/src/test/java/org/eclipse/esmf/aspectmodel/utils/DescriptionsUtilsTest.java

Lines changed: 63 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -5,54 +5,64 @@
55
import static org.junit.jupiter.api.Assertions.assertTrue;
66

77
import java.util.List;
8+
import java.util.Locale;
89

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;
916
import org.junit.jupiter.api.Test;
1017

1118
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+
1229
@Test
1330
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 );
1632
assertThat( notes ).hasSize( 1 );
17-
assertEquals( "This is a note.\nContinued on the next line.", notes.get( 0 ) );
33+
assertEquals( "This is a note block.\nIt supports multiple lines.\nHere's a second line of the note.", notes.get( 0 ) );
1834
}
1935

2036
@Test
2137
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 );
3039

3140
assertEquals( 2, examples.size() );
32-
assertEquals( "First example.\nMore detail.", examples.get( 0 ) );
33-
assertEquals( "Second example.", examples.get( 1 ) );
41+
assertEquals( "This is the first example block.\nIt can span several lines, and supports *italic* and **bold** text.",
42+
examples.get( 0 ) );
43+
assertEquals( "This is the second example.\nAlso 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.\nIt can span several lines, and supports <em>italic</em> and <strong>bold</strong> text." );
3452
}
3553

3654
@Test
3755
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 );
4057
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)." );
4259
}
4360

4461
@Test
4562
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() );
5666
}
5767

5868
@Test
@@ -65,44 +75,37 @@ void testNoBlocks() {
6575

6676
@Test
6777
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 );
8695

8796
assertThat( html ).contains( "<div class=\"note\">" );
88-
assertThat( html ).contains( "This is a note." );
97+
assertThat( html ).contains( "This is a note block.\nIt supports multiple lines.\nHere's a second line of the note." );
8998
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.\nIt can span several lines, and supports <em>italic</em> and <strong>bold</strong> text." );
91101
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\nwith an inline <a href=\"https://www.example.com/spec\">link</a>." );
94103
assertThat( html ).contains( "<ol>" );
95104
}
96105

97106
@Test
98107
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 );
106109
assertThat( html ).contains( "<ul>" );
107110
assertThat( html ).contains( "<li>Item A</li>" );
108111
assertThat( html ).contains( "<li>Item B</li>" );
@@ -111,45 +114,22 @@ void testMarkdownRenderingBulletList() {
111114

112115
@Test
113116
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 );
121118
assertThat( html ).contains( "<ol>" );
122119
assertThat( html ).contains( "<li>First</li>" );
123120
assertThat( html ).contains( "<li>Second</li>" );
124121
assertThat( html ).contains( "<li>Third</li>" );
125122
}
126123

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-
140124
@Test
141125
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>" );
146128
}
147129

148130
@Test
149131
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)" );
154134
}
155135
}

core/esmf-test-aspect-models/src/main/java/org/eclipse/esmf/test/TestAspect.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ public enum TestAspect implements TestModel {
116116
ASPECT_WITH_LIST_AND_ELEMENT_CONSTRAINT,
117117
ASPECT_WITH_LIST_ENTITY_ENUMERATION,
118118
ASPECT_WITH_LIST_WITH_LENGTH_CONSTRAINT,
119+
ASPECT_WITH_MARKDOWN_DESCRIPTION,
119120
ASPECT_WITH_MEASUREMENT,
120121
ASPECT_WITH_MEASUREMENT_WITH_UNIT,
121122
ASPECT_WITH_MULTILANGUAGE_EXAMPLE_VALUE,
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Copyright (c) 2025 Robert Bosch Manufacturing Solutions GmbH
2+
#
3+
# See the AUTHORS file(s) distributed with this work for additional
4+
# information regarding authorship.
5+
#
6+
# This Source Code Form is subject to the terms of the Mozilla Public
7+
# License, v. 2.0. If a copy of the MPL was not distributed with this
8+
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
9+
#
10+
# SPDX-License-Identifier: MPL-2.0
11+
12+
@prefix : <urn:samm:org.eclipse.esmf.test:1.0.0#> .
13+
@prefix samm: <urn:samm:org.eclipse.esmf.samm:meta-model:2.2.0#> .
14+
@prefix samm-c: <urn:samm:org.eclipse.esmf.samm:characteristic:2.2.0#> .
15+
16+
:AspectWithMarkdownDescription a samm:Aspect ;
17+
samm:properties ( :myProperty ) ;
18+
samm:operations ( ) .
19+
20+
:myProperty a samm:Property ;
21+
samm:description """
22+
This is a sample concept demonstrating **Markdown** support in samm:description.
23+
24+
> NOTE: This is a note block.
25+
> It supports multiple lines.
26+
> Here's a second line of the note.
27+
28+
> EXAMPLE 1: This is the first example block.
29+
> It can span several lines, and supports *italic* and **bold** text.
30+
31+
> EXAMPLE 2: This is the second example.
32+
> Also multiline, for testing multiple example entries.
33+
34+
> SOURCE: ISO 12345:2023, section 4.2.1
35+
> with an inline [link](https://www.example.com/spec).
36+
37+
Unordered list:
38+
* Item A
39+
* Item B
40+
* Item C
41+
42+
Ordered list:
43+
1. First
44+
2. Second
45+
3. Third
46+
47+
You can also include inline links like [Visit Example](https://example.com).
48+
49+
Another paragraph after a blank line to simulate text flow and paragraph breaks.
50+
"""@en ;
51+
samm:characteristic samm-c:Text .

0 commit comments

Comments
 (0)