package com.wizzardo.tools.evaluation;

import org.junit.Assert;
import org.junit.Test;

import java.util.Map;

/**
 * Created by wizzardo on 26.12.15.
 */
public class ConfigTest {

    @Test
    public void test_1() {
        String s = "key = 'value'";

        Expression expression = EvalTools.prepare(s);

        Config config = new Config();

        expression.get(config);

        Assert.assertEquals(1, config.size());
        Assert.assertEquals("value", config.get("key"));
    }

    @Test
    public void test_2() {
        String s = "a.b = 'value'\n" +
                "a.c = 'value 2'";

        Expression expression = EvalTools.prepare(s);

        Config config = new Config();

        expression.get(config);

        Assert.assertEquals(1, config.size());
        Assert.assertEquals("value", ((Map) config.get("a")).get("b"));
        Assert.assertEquals("value 2", ((Map) config.get("a")).get("c"));
    }

    @Test
    public void test_3() {
        String s = "a { b = 'value' }";

        Expression expression = EvalTools.prepare(s);

        Config config = new Config();

        expression.get(config);

        Assert.assertEquals(1, config.size());
        Assert.assertEquals("value", ((Map) config.get("a")).get("b"));
    }

    @Test
    public void test_4() {
        String s = "a { b { c = 'value'} }";

        Expression expression = EvalTools.prepare(s);

        Config config = new Config();

        expression.get(config);

        Assert.assertEquals(1, config.size());
        Assert.assertEquals("value", ((Map) ((Map) config.get("a")).get("b")).get("c"));
    }

    @Test
    public void test_5() {
        String s = "a { b = 'value'; c = 'value 2' }";

        Expression expression = EvalTools.prepare(s);

        Config config = new Config();

        expression.get(config);

        Assert.assertEquals(1, config.size());
        Assert.assertEquals("value", ((Map) config.get("a")).get("b"));
        Assert.assertEquals("value 2", ((Map) config.get("a")).get("c"));
    }
}

@@ -2029,11 +2029,607 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void test_6() %7B%0A        String s = %22a %7B %5B'user', 'password'%5D.each %7B%5Cn%22 +%0A//                %22this.%5C%22$%7Bit%7D%5C%22 = 'secret'%5Cn%22 + // not implemented dynamic filed name yet%0A                %22this%5B%5C%22$%7Bit%7D%5C%22%5D = 'secret'%5Cn%22 +%0A                %22%7D %7D%22;%0A%0A        Expression expression = EvalTools.prepare(s);%0A%0A        Config config = new Config();%0A%0A        expression.get(config);%0A%0A        Assert.assertEquals(1, config.size());%0A        Assert.assertEquals(%22secret%22, ((Map) config.get(%22a%22)).get(%22user%22));%0A        Assert.assertEquals(%22secret%22, ((Map) config.get(%22a%22)).get(%22password%22));%0A    %7D
 %0A%7D%0A

add test for config with closure