package com.github.rschmitt.dynamicobject;

import static com.github.rschmitt.dynamicobject.DynamicObject.newInstance;
import static com.github.rschmitt.dynamicobject.DynamicObject.registerTag;
import static com.github.rschmitt.dynamicobject.DynamicObject.serialize;
import static org.junit.Assert.assertEquals;

import org.junit.BeforeClass;
import org.junit.Test;

public class PrintingTest {
    static Tagged emptyTagged;
    static Untagged emptyUntagged;
    static Tagged nestedTagged;
    static Untagged nestedUntagged;

    @BeforeClass
    public static void setup() {
        registerTag(Tagged.class, "Tagged");
        emptyTagged = newInstance(Tagged.class);
        emptyUntagged = newInstance(Untagged.class);

        nestedTagged = emptyTagged.tagged(emptyTagged).untagged(emptyUntagged);
        nestedUntagged = emptyUntagged.tagged(emptyTagged).untagged(emptyUntagged);
    }

    @Test
    public void toStringTest() {
        assertEquals("#Tagged{}", emptyTagged.toString());
        assertEquals("{}", emptyUntagged.toString());
        assertEquals("#Tagged{:untagged {}, :tagged #Tagged{}}", nestedTagged.toString());
        assertEquals("{:untagged {}, :tagged #Tagged{}}", nestedUntagged.toString());
    }

    @Test
    public void toFormattedStringTest() {
        assertEquals("#Tagged{}\n", emptyTagged.toFormattedString());
        assertEquals("{}\n", emptyUntagged.toFormattedString());
        assertEquals("#Tagged{:untagged {}, :tagged #Tagged{}}\n", nestedTagged.toFormattedString());
        assertEquals("{:untagged {}, :tagged #Tagged{}}\n", nestedUntagged.toFormattedString());
    }

    @Test
    public void serializeTest() {
        assertEquals("#Tagged{}", serialize(emptyTagged));
        assertEquals("{}", serialize(emptyUntagged));
        assertEquals("#Tagged{:untagged {}, :tagged #Tagged{}}", serialize(nestedTagged));
        assertEquals("{:untagged {}, :tagged #Tagged{}}", serialize(nestedUntagged));
    }
}

interface Tagged extends DynamicObject<Tagged> {
    @Key(":tagged") Tagged tagged(Tagged tagged);
    @Key(":untagged") Tagged untagged(Untagged untagged);
}

interface Untagged extends DynamicObject<Untagged> {
    @Key(":tagged") Untagged tagged(Tagged tagged);
    @Key(":untagged") Untagged untagged(Untagged untagged);
}

@@ -48,75 +48,54 @@
 ort 
-static com.github.rschmitt.dynamicobject.DynamicObject.newInstance;
+org.junit.BeforeClass;%0Aimport org.junit.Test;%0A
 %0Aimp
@@ -153,27 +153,17 @@
 cObject.
-registerTag
+*
 ;%0Aimport
@@ -174,164 +174,76 @@
 tic 
-com.github.rschmitt.dynamicobject.DynamicObject.serialize;%0Aimport static org.junit.Assert.assertEquals;%0A%0Aimport org.junit.BeforeClass;%0Aimport org.junit.Test
+java.lang.String.format;%0Aimport static org.junit.Assert.assertEquals
 ;%0A%0Ap
@@ -1178,32 +1178,39 @@
    assertEquals(
+format(
 %22#Tagged%7B%7D%5Cn%22, e
@@ -1203,19 +1203,20 @@
 Tagged%7B%7D
-%5C
+%25
 n%22
+)
 , emptyT
@@ -1268,14 +1268,22 @@
 als(
+format(
 %22%7B%7D
-%5C
+%25
 n%22
+)
 , em
@@ -1329,32 +1329,39 @@
    assertEquals(
+format(
 %22#Tagged%7B:untagg
@@ -1377,35 +1377,36 @@
 agged #Tagged%7B%7D%7D
-%5C
+%25
 n%22
+)
 , nestedTagged.t
@@ -1439,32 +1439,39 @@
    assertEquals(
+format(
 %22%7B:untagged %7B%7D, 
@@ -1492,11 +1492,12 @@
 d%7B%7D%7D
-%5C
+%25
 n%22
+)
 , ne

Fix toFormattedStringTest on Windows