Skip to content

Commit 0165530

Browse files
committed
added test for writing SDL
1 parent c556ee5 commit 0165530

File tree

1 file changed

+40
-3
lines changed

1 file changed

+40
-3
lines changed

src/test/java/com/domain/SdlangTest.java

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package com.domain;
22

3-
import com.singingbush.sdl.Parser;
4-
import com.singingbush.sdl.SDLParseException;
5-
import com.singingbush.sdl.Tag;
3+
import com.singingbush.sdl.*;
64
import org.junit.Test;
75

86
import java.io.IOException;
97
import java.io.Reader;
108
import java.io.StringReader;
9+
import java.time.LocalDate;
10+
import java.time.LocalDateTime;
11+
import java.util.Arrays;
1112
import java.util.List;
1213

1314
import static org.junit.Assert.assertEquals;
@@ -50,4 +51,40 @@ public void testParserConstructorWithString() throws IOException, SDLParseExcept
5051
assertEquals(3, tag.getChildren().get(0).getValues().size());
5152
assertEquals(3, tag.getChildren().get(1).getValues().size());
5253
}
54+
55+
@Test
56+
public void testWritingSdl() {
57+
final LocalDateTime dateTime = LocalDateTime.now();
58+
59+
final Tag child = new Tag("child");
60+
child.addValue(SDL.value(dateTime));
61+
child.addValue(SDL.value(541L));
62+
63+
final Tag t = new Tag("my", "thing");
64+
t.addValue(SDL.value('g'));
65+
t.addChild(child);
66+
t.setAttribute("flt", SDL.value(0.0f));
67+
t.setAttribute("lng", SDL.value(1_000L));
68+
69+
// Create a Tag the new way
70+
Tag tag = SDL.tag("thing")
71+
.withNamespace("my")
72+
.withComment("some comment that is only available\nwhen serialised using pretty print")
73+
.withValue(SDL.value('g'))
74+
.withChild(SDL.tag("child")
75+
.withComment("some line comment")
76+
.withValues(SDL.value(dateTime), SDL.value(541L))
77+
.build()
78+
)
79+
.withAttribute("flt", SDL.value(0.0f))
80+
.withAttribute("lng", SDL.value(1_000L))
81+
.build();
82+
83+
assertEquals("content should be same regardless of the new style allowing comments", t, tag);
84+
85+
assertEquals(1, tag.getValues().size());
86+
assertEquals(Character.class, tag.getValues().get(0).getClass());
87+
assertEquals(1, tag.getChildren().size());
88+
assertEquals(2, tag.getAttributes().size());
89+
}
5390
}

0 commit comments

Comments
 (0)