package br.com.agneresteves.ef.core.transformer.parser.scope;

import br.com.agneresteves.ef.core.processor.Processor;
import br.com.agneresteves.ef.core.transformer.parser.ElasticFormatParser;
import br.com.agneresteves.ef.core.transformer.parser.ReferenceParser;
import br.com.agneresteves.ef.core.transformer.processor.scope.RootScopeProcessor;
import br.com.agneresteves.ef.core.transformer.processor.tag.TagShowValueProcessor;
import br.com.agneresteves.ef.core.transformer.processor.text.AnyTextProcessor;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

/**
 * RootScopeParserTest
 * I
 *
 * @author Agner Esteves Ballejo
 * @since 18/11/2017
 */
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class RootScopeParserTest {

    @Test
    public void T01_parseAnyText() {
        ElasticFormatParser efParser = new ElasticFormatParser(ReferenceParser.ROOT_SCOPE.getRefName());

        Processor processor = efParser.parse("any text").get();
        assertTrue(processor instanceof RootScopeProcessor);

        RootScopeProcessor rootScopeProcessor = (RootScopeProcessor) processor;

        assertEquals(1, rootScopeProcessor.getChildrens().size());
        assertTrue(rootScopeProcessor.getChildrens().get(0) instanceof AnyTextProcessor);
    }

    @Test
    public void T02_parseAnyTextAndTagShowValue() {
        ElasticFormatParser efParser = new ElasticFormatParser(ReferenceParser.ROOT_SCOPE.getRefName());

        Processor processor = efParser.parse("any text<!=var!>").get();
        assertTrue(processor instanceof RootScopeProcessor);

        RootScopeProcessor rootScopeProcessor = (RootScopeProcessor) processor;

        assertEquals(2, rootScopeProcessor.getChildrens().size());
        assertTrue(rootScopeProcessor.getChildrens().get(0) instanceof AnyTextProcessor);
        assertTrue(rootScopeProcessor.getChildrens().get(1) instanceof TagShowValueProcessor);
    }

    @Test
    public void T03_parseAnyTextAndTagShowValueAndFinishWithText() {
        ElasticFormatParser efParser = new ElasticFormatParser(ReferenceParser.ROOT_SCOPE.getRefName());

        Processor processor = efParser.parse("any text<!=var!>another text").get();
        assertTrue(processor instanceof RootScopeProcessor);

        RootScopeProcessor rootScopeProcessor = (RootScopeProcessor) processor;

        assertEquals(3, rootScopeProcessor.getChildrens().size());
        assertTrue(rootScopeProcessor.getChildrens().get(0) instanceof AnyTextProcessor);
        assertTrue(rootScopeProcessor.getChildrens().get(1) instanceof TagShowValueProcessor);
        assertTrue(rootScopeProcessor.getChildrens().get(2) instanceof AnyTextProcessor);
    }

}
