initial commit

This commit is contained in:
me
2024-05-23 15:45:59 +08:00
commit 70275b14e9
55 changed files with 2661 additions and 0 deletions

View File

@@ -0,0 +1,55 @@
import com.intellij.lexer.FlexAdapter;
import com.intellij.lexer.Lexer;
import com.intellij.testFramework.LexerTestCase;
import lombok.extern.slf4j.Slf4j;
import me.zhouxi.slint.lang.lexer.SlintLexer;
import org.jetbrains.annotations.NotNull;
import org.junit.Rule;
import org.junit.rules.Stopwatch;
import org.junit.runner.Description;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.concurrent.TimeUnit;
/**
* @author zhouxi 2024/4/30
*/
@Slf4j
public class LexerTest extends LexerTestCase {
@Override
protected Lexer createLexer() {
return new FlexAdapter(new SlintLexer());
}
@Override
protected String getDirPath() {
return "src/test/resources/slint";
}
public void test() throws IOException {
var source = Files.readString(Paths.get("src/test/resources/slint/main.slint"));
doTest(source);
}
protected @NotNull String getPathToTestDataFile(String extension) {
return "src/test/resources/slint/lexer/output" + extension;
}
@Rule
public Stopwatch stopwatch = new Stopwatch() {
@Override
protected void succeeded(long nanos, Description description) {
log.info("{} succeeded, time taken: {} ms", description.getMethodName(), TimeUnit.NANOSECONDS.toMillis(nanos));
}
@Override
protected void failed(long nanos, Throwable e, Description description) {
log.info("{} failed, time taken: {} ms", description.getMethodName(), TimeUnit.NANOSECONDS.toMillis(nanos));
}
};
}

View File

@@ -0,0 +1,33 @@
import com.intellij.testFramework.ParsingTestCase;
import me.zhouxi.slint.lang.SlintParserDefinition;
import org.apache.commons.lang3.time.StopWatch;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
/**
* @author zhouxi 2024/4/30
*/
public class ParserTest extends ParsingTestCase {
public ParserTest() {
super("", ".slint", new SlintParserDefinition());
}
@Override
protected @NotNull String getTestDataPath() {
return "src/test/resources/slint/parser";
}
public void test() throws IOException {
final var path = Paths.get("src/test/resources/slint/main.slint");
var source = Files.readString(path);
StopWatch started = StopWatch.createStarted();
for (int i = 0; i < 50000; i++) {
doCodeTest(source);
}
started.stop();
System.out.println(started.getNanoTime()/50000);
}
}

View File

@@ -0,0 +1,5 @@
/* dsadas */
/* dsadas */
"dasdasd\""
"dada"
"