|
1 | 1 | package com.domain; |
2 | 2 |
|
3 | | -import com.singingbush.sdl.Parser; |
4 | | -import com.singingbush.sdl.SDLParseException; |
5 | | -import com.singingbush.sdl.Tag; |
| 3 | +import com.singingbush.sdl.*; |
6 | 4 | import org.junit.Test; |
7 | 5 |
|
8 | 6 | import java.io.IOException; |
9 | 7 | import java.io.Reader; |
10 | 8 | import java.io.StringReader; |
| 9 | +import java.time.LocalDate; |
| 10 | +import java.time.LocalDateTime; |
| 11 | +import java.util.Arrays; |
11 | 12 | import java.util.List; |
12 | 13 |
|
13 | 14 | import static org.junit.Assert.assertEquals; |
@@ -50,4 +51,40 @@ public void testParserConstructorWithString() throws IOException, SDLParseExcept |
50 | 51 | assertEquals(3, tag.getChildren().get(0).getValues().size()); |
51 | 52 | assertEquals(3, tag.getChildren().get(1).getValues().size()); |
52 | 53 | } |
| 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 | + } |
53 | 90 | } |
0 commit comments