package us.bpsm.edn.examples;

import org.junit.Assert;
import org.junit.Test;
import us.bpsm.edn.parser.Parser;
import us.bpsm.edn.parser.Parsers;
import us.bpsm.edn.printer.Printers;

public class PrintingExamples {
    @Test
    public void printCompactly() {
        Assert.assertEquals(
                EXPECTED_COMPACT_RENDERING,
                Printers.printString(
                        Printers.defaultPrinterProtocol(), VALUE_TO_PRINT));
    }

    @Test
    public void printPretty() {
        Assert.assertEquals(
                EXPECTED_PRETTY_RENDERING,
                Printers.printString(
                        Printers.prettyPrinterProtocol(), VALUE_TO_PRINT));
    }

    static final Object VALUE_TO_PRINT;
    static {
        Parser parser = Parsers.newParser(Parsers.defaultConfiguration());
        VALUE_TO_PRINT = parser.nextValue(Parsers.newParseable(
                "{:a [1 2 3],\n" +
                " [x/y] 3.14159}\n"));
    }

    static final String EXPECTED_COMPACT_RENDERING =
            "{:a[1 2 3][x/y]3.14159}";

    static final String EXPECTED_PRETTY_RENDERING =
            "{"           + "\n" +
            "  :a ["      + "\n" +
            "    1"       + "\n" +
            "    2"       + "\n" +
            "    3"       + "\n" +
            "  ]"         + "\n" +
            "  ["         + "\n" +
            "    x/y"     + "\n" +
            "  ] 3.14159" + "\n" +
            "}";
}

@@ -24,16 +24,50 @@
 mples;%0A%0A
+import org.hamcrest.CoreMatchers;%0A
 import o
@@ -213,16 +213,65 @@
 nters;%0A%0A
+import java.util.Arrays;%0Aimport java.util.List;%0A%0A
 public c
@@ -364,40 +364,23 @@
 sert
-Equals(%0A                EXPECTED
+That(ACCEPTABLE
 _COM
@@ -385,32 +385,33 @@
 OMPACT_RENDERING
+S
 ,%0A              
@@ -404,32 +404,53 @@
                 
+CoreMatchers.hasItem(
 Printers.printSt
@@ -505,32 +505,56 @@
 interProtocol(),
+%0A                       
  VALUE_TO_PRINT)
@@ -546,32 +546,33 @@
 VALUE_TO_PRINT))
+)
 ;%0A    %7D%0A%0A    @Te
@@ -631,40 +631,23 @@
 sert
-Equals(%0A                EXPECTED
+That(ACCEPTABLE
 _PRE
@@ -659,16 +659,17 @@
 ENDERING
+S
 ,%0A      
@@ -670,32 +670,53 @@
                 
+CoreMatchers.hasItem(
 Printers.printSt
@@ -778,16 +778,40 @@
 tocol(),
+%0A                       
  VALUE_T
@@ -819,16 +819,17 @@
 _PRINT))
+)
 ;%0A    %7D%0A
@@ -1119,31 +1119,39 @@
 c final 
+List%3C
 String
- EXPECTED
+%3E ACCEPTABLE
 _COMPACT
@@ -1152,34 +1152,50 @@
 OMPACT_RENDERING
+S
  =
+ Arrays.asList(
 %0A            %22%7B:
@@ -1216,16 +1216,62 @@
 .14159%7D%22
+,%0A            %22%7B%5Bx/y%5D3.14159 :a%5B1 2 3%5D%7D%22%0A    )
 ;%0A%0A    s
@@ -1286,23 +1286,31 @@
 nal 
+List%3C
 String
- EXPECTED
+%3E ACCEPTABLE
 _PRE
@@ -1322,18 +1322,34 @@
 ENDERING
+S
  =
+ Arrays.asList(
 %0A       
@@ -1671,12 +1671,350 @@
      %22%7D%22
+,%0A            %22%7B%22           + %22%5Cn%22 +%0A            %22  %5B%22         + %22%5Cn%22 +%0A            %22    x/y%22     + %22%5Cn%22 +%0A            %22  %5D 3.14159%22 + %22%5Cn%22 +%0A            %22  :a %5B%22      + %22%5Cn%22 +%0A            %22    1%22       + %22%5Cn%22 +%0A            %22    2%22       + %22%5Cn%22 +%0A            %22    3%22       + %22%5Cn%22 +%0A            %22  %5D%22         + %22%5Cn%22 +%0A            %22%7D%22%0A    )
 ;%0A%7D%0A

make PrintingExamples insenstive to hash ordering