package org.panda_lang.panda.interpreter.parser.implementation.general.expression;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

class PandaPatternTest {

    private static final String METHOD = "[<instance:reader expression exclude method, field> .] <name> `( [<*arguments>] `) [;]";
    private static final String VARIABLE = "([<type>] <name:condition token {type:unknown}>|<name:reader expression include field>) [= <assignation:reader expression>][;]";

    @Test
    public void testMethod() {
        PandaPatternTester.test(
                METHOD,

                "Console.print('var');",

                PandaPatternTester.Wildcard.of("instance", "Console"),
                PandaPatternTester.Wildcard.of("name", "print"),
                PandaPatternTester.Wildcard.of("*arguments", "var")
        );
    }

    @Test
    public void testConstructor() {
        Assertions.assertFalse(PandaPatternTester.build(METHOD, "Test test = new Test('Constructor');").isMatched());
    }

    @Test
    public void testFieldAsVariable() {
        Assertions.assertFalse(PandaPatternTester.build(
                "[<type>] <name:condition token {type:unknown}> [= <assignation:reader expression>][;]",
                "this.testField = this;"
        ).isMatched());
    }

    @Test
    public void testVariable() {
        PandaPatternTester.test(
                VARIABLE,

                "String variable = 'Test';",

                PandaPatternTester.Wildcard.of("type", "String"),
                PandaPatternTester.Wildcard.of("name", "variable"),
                PandaPatternTester.Wildcard.of("assignation", "Test")
        );
    }

}

@@ -1674,10 +1674,328 @@
 %0A    %7D%0A%0A
+    @Test%0A    public void testFieldBasedVariable() %7B%0A        PandaPatternTester.test(%0A                VARIABLE,%0A%0A                %22this.variable = 'Test';%22,%0A%0A                PandaPatternTester.Wildcard.of(%22name%22, %22this.variable%22),%0A                PandaPatternTester.Wildcard.of(%22assignation%22, %22Test%22)%0A        );%0A    %7D%0A%0A
 %7D%0A

Add field based variable unit test