package org.panda_lang.panda.framework.language.interpreter.pattern.token;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.panda_lang.panda.framework.design.interpreter.token.TokenizedSource;
import org.panda_lang.panda.framework.language.interpreter.lexer.PandaLexer;
import org.panda_lang.panda.framework.language.interpreter.pattern.lexical.elements.LexicalPatternElement;
import org.panda_lang.panda.framework.language.interpreter.pattern.token.extractor.TokenExtractorResult;
import org.panda_lang.panda.framework.language.interpreter.source.PandaSource;
import org.panda_lang.panda.framework.language.resource.PandaSyntax;

class TokenPatternTest {

    private static final String CONTENT = "method void test(15, 25) { Console.print('test') }";
    private static final TokenizedSource SOURCE = new PandaLexer(PandaSyntax.getInstance(), new PandaSource("Test", CONTENT)).convert();

    @Test
    public void testTokenPattern() {
        TokenPattern pattern = TokenPattern.builder()
                .compile("(method|hidden|local) [static] <return-type> <name> \\(<*parameters>\\) \\{ <*body> \\}[;]")
                .build();

        LexicalPatternElement content = pattern.getPatternContent();
        Assertions.assertNotNull(content);

        TokenExtractorResult result = pattern.extract(SOURCE);
        Assertions.assertNotNull(result);

        if (result.hasErrorMessage()) {
            System.out.println("Error message: " + result.getErrorMessage());
        }

        System.out.println(result.isMatched());
        Assertions.assertTrue(result.isMatched());

        Assertions.assertEquals("void", result.getWildcards().get(0).asString());
        Assertions.assertEquals("test", result.getWildcards().get(1).asString());
        Assertions.assertEquals("15,25", result.getWildcards().get(2).asString());
        Assertions.assertEquals("Console.print(test)", result.getWildcards().get(3).asString());
    }

}

package org.panda_lang.panda.framework.language.interpreter.pattern.token;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.panda_lang.panda.framework.design.interpreter.token.TokenizedSource;
import org.panda_lang.panda.framework.language.interpreter.lexer.PandaLexer;
import org.panda_lang.panda.framework.language.interpreter.pattern.lexical.elements.LexicalPatternElement;
import org.panda_lang.panda.framework.language.interpreter.pattern.token.extractor.TokenExtractorResult;
import org.panda_lang.panda.framework.language.interpreter.source.PandaSource;
import org.panda_lang.panda.framework.language.resource.PandaSyntax;

class TokenPatternTest {

    private static final String CONTENT = "method void test(15, 25) { Console.print('test') }";
    private static final TokenizedSource SOURCE = new PandaLexer(PandaSyntax.getInstance(), new PandaSource("Test", CONTENT)).convert();

    @Test
    public void testTokenPattern() {
        TokenPattern pattern = TokenPattern.builder()
                .compile("(method|hidden|local) [static] <return-type> <name> \\(<*parameters>\\) \\{ <*body> \\}[;]")
                .build();

        LexicalPatternElement content = pattern.getPatternContent();
        Assertions.assertNotNull(content);

        TokenExtractorResult result = pattern.extract(SOURCE);
        Assertions.assertNotNull(result);

        if (result.hasErrorMessage()) {
            System.out.println("Error message: " + result.getErrorMessage());
        }

        System.out.println(result.isMatched());
        Assertions.assertTrue(result.isMatched());

        Assertions.assertNotNull(result.getWildcards());
        Assertions.assertEquals("void", result.getWildcards().get(0).asString());
        Assertions.assertEquals("test", result.getWildcards().get(1).asString());
        Assertions.assertEquals("15,25", result.getWildcards().get(2).asString());
        Assertions.assertEquals("Console.print(test)", result.getWildcards().get(3).asString());
    }

}

Add null check to TokenPattern unit test