package org.ficum.visitor;

import java.util.Deque;

import org.ficum.node.Builder;
import org.ficum.node.Node;
import org.ficum.parser.ConstraintParser;
import org.ficum.parser.ExpressionParser;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.parboiled.Parboiled;
import org.parboiled.parserunners.BasicParseRunner;
import org.parboiled.support.ParsingResult;

public class QueryPrinterVistorTest {
    private BasicParseRunner<Deque<Object>> parseRunner;

    @Before
    public void setUp() {
        String[] allowedPaths = { "first", "second", "third", "fourth", "fifth" };
        ConstraintParser parser = Parboiled.createParser(ExpressionParser.class, (Object) allowedPaths);

        parseRunner = new BasicParseRunner<Deque<Object>>(parser.root());
    }

    @Test
    public void testDate() {
        String input = "first==2015-12-29";
        ParsingResult<Deque<Object>> result = parseRunner.run(input);
        Node node = Builder.build(result.resultValue);

        String actual = new QueryPrinterVisitor().start(node);

        Assert.assertEquals(input, actual);
    }

    @Test
    public void testDateBC() {
        String input = "first==-0650-12-29";
        ParsingResult<Deque<Object>> result = parseRunner.run(input);
        Node node = Builder.build(result.resultValue);

        String actual = new QueryPrinterVisitor().start(node);

        Assert.assertEquals(input, actual);
    }

    @Test
    public void testNaturalOrder() {
        String input = "first==1l,second=gt='two';third=le=3.0";
        ParsingResult<Deque<Object>> result = parseRunner.run(input);
        Node node = Builder.build(result.resultValue);

        String actual = new QueryPrinterVisitor().start(node);

        Assert.assertEquals(input, actual);
    }

    @Test
    public void testNestedPreceded() {
        String input = "first==1l,((second=gt='two';third=le=3.0);fourth=lt='five')";
        ParsingResult<Deque<Object>> result = parseRunner.run(input);
        Node node = Builder.build(result.resultValue);

        String actual = new QueryPrinterVisitor().start(node);

        Assert.assertEquals(input, actual);
    }

    @Test
    public void testPrecededOrder() {
        String input = "(first==1l;second=gt='two'),(third=le=3.0;fourth=lt='five')";
        ParsingResult<Deque<Object>> result = parseRunner.run(input);
        Node node = Builder.build(result.resultValue);

        String actual = new QueryPrinterVisitor().start(node);

        Assert.assertEquals(input, actual);
    }

    @Test
    public void testTimestampBC() {
        String input = "first==-0456-03-19T18:34:12.000Z";
        ParsingResult<Deque<Object>> result = parseRunner.run(input);
        Node node = Builder.build(result.resultValue);

        String actual = new QueryPrinterVisitor().start(node);

        Assert.assertEquals(input, actual);
    }

    @Test
    public void testTimestampZoneOffset() {
        String input = "first==2015-12-29T18:34:12.000+05:00";
        ParsingResult<Deque<Object>> result = parseRunner.run(input);
        Node node = Builder.build(result.resultValue);

        String actual = new QueryPrinterVisitor().start(node);

        Assert.assertEquals(input, actual);
    }

    @Test
    public void testTimestampZulu() {
        String input = "first==2015-12-29T18:34:12.000Z";
        ParsingResult<Deque<Object>> result = parseRunner.run(input);
        Node node = Builder.build(result.resultValue);

        String actual = new QueryPrinterVisitor().start(node);

        Assert.assertEquals(input, actual);
    }

}

@@ -32,512 +32,164 @@
 ort 
-java.util.Deque;%0A%0Aimport org.ficum.node.Builder;%0Aimport org.ficum.node.Node;%0Aimport org.ficum.parser.ConstraintParser;%0Aimport org.ficum.parser.ExpressionParser;%0Aimport org.junit.Assert;%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0Aimport org.parboiled.Parboiled;%0Aimport org.parboiled.parserunners.BasicParseRunner;%0Aimport org.parboiled.support.ParsingResult;%0A%0Apublic class QueryPrinterVistorTest %7B%0A    private BasicParseRunner%3CDeque%3CObject%3E%3E parseRunner;%0A%0A    @Before%0A    public void setUp() %7B%0A       
+org.ficum.node.Node;%0Aimport org.ficum.parser.ParseHelper;%0Aimport org.junit.Assert;%0Aimport org.junit.Test;%0A%0Apublic class QueryPrinterVistorTest %7B%0A    private
  Str
@@ -201,20 +201,28 @@
  allowed
-Path
+SelectorName
 s = %7B %22f
@@ -271,194 +271,8 @@
 %22 %7D;
-%0A        ConstraintParser parser = Parboiled.createParser(ExpressionParser.class, (Object) allowedPaths);%0A%0A        parseRunner = new BasicParseRunner%3CDeque%3CObject%3E%3E(parser.root());%0A    %7D
 %0A%0A  
@@ -364,126 +364,68 @@
     
-ParsingResult%3CDeque%3CObject%3E%3E result = p
+Node node = P
 arse
-Runner.run(input);%0A        Node node = Builder.build(result.resultValue
+Helper.parse(input, allowedSelectorNames
 );%0A
-%0A
     
@@ -633,126 +633,68 @@
     
-ParsingResult%3CDeque%3CObject%3E%3E result = p
+Node node = P
 arse
-Runner.run(input);%0A        Node node = Builder.build(result.resultValue
+Helper.parse(input, allowedSelectorNames
 );%0A
-%0A
     
@@ -928,126 +928,68 @@
     
-ParsingResult%3CDeque%3CObject%3E%3E result = p
+Node node = P
 arse
-Runner.run(input);%0A        Node node = Builder.build(result.resultValue
+Helper.parse(input, allowedSelectorNames
 );%0A
-%0A
     
@@ -1246,126 +1246,68 @@
     
-ParsingResult%3CDeque%3CObject%3E%3E result = p
+Node node = P
 arse
-Runner.run(input);%0A        Node node = Builder.build(result.resultValue
+Helper.parse(input, allowedSelectorNames
 );%0A
-%0A
     
@@ -1563,126 +1563,68 @@
     
-ParsingResult%3CDeque%3CObject%3E%3E result = p
+Node node = P
 arse
-Runner.run(input);%0A        Node node = Builder.build(result.resultValue
+Helper.parse(input, allowedSelectorNames
 );%0A
-%0A
     
@@ -1851,126 +1851,68 @@
     
-ParsingResult%3CDeque%3CObject%3E%3E result = p
+Node node = P
 arse
-Runner.run(input);%0A        Node node = Builder.build(result.resultValue
+Helper.parse(input, allowedSelectorNames
 );%0A
-%0A
     
@@ -2151,126 +2151,68 @@
     
-ParsingResult%3CDeque%3CObject%3E%3E result = p
+Node node = P
 arse
-Runner.run(input);%0A        Node node = Builder.build(result.resultValue
+Helper.parse(input, allowedSelectorNames
 );%0A
-%0A
     
@@ -2440,126 +2440,68 @@
     
-ParsingResult%3CDeque%3CObject%3E%3E result = p
+Node node = P
 arse
-Runner.run(input);%0A        Node node = Builder.build(result.resultValue
+Helper.parse(input, allowedSelectorNames
 );%0A
-%0A
     

use ParseHelper