Package cz.juzna.latte.lexer

Source Code of cz.juzna.latte.lexer.AbstractLexerTest

package cz.juzna.latte.lexer;

import com.intellij.ide.plugins.PluginManager;
import com.intellij.lexer.Lexer;
import com.intellij.openapi.application.PluginPathManager;
import com.intellij.openapi.application.ex.PathManagerEx;
import com.intellij.psi.tree.IElementType;
import com.intellij.testFramework.PlatformLiteFixture;

import java.util.ArrayList;


public abstract class AbstractLexerTest extends PlatformLiteFixture {
    Lexer lexer;

  protected String getTestDataPath() {
    return "tests/data";
  }

    protected void assertToken(LexerToken token, IElementType type, String content) {
        if(type != null) assertEquals(type, token.type);
        if(content != null) assertEquals(content, token.content);
    }

    protected LexerToken[] lex(String str) {
        ArrayList<LexerToken> tokens = new ArrayList<LexerToken>();
        IElementType el;

        lexer.start(str);

        while((el = lexer.getTokenType()) != null) {
            tokens.add(new LexerToken(el, lexer.getTokenStart(), lexer.getTokenEnd(), lexer.getTokenText()));
            lexer.advance();
        }

        return tokens.toArray(new LexerToken[tokens.size()]);
    }
}
TOP

Related Classes of cz.juzna.latte.lexer.AbstractLexerTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.