Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
alingse committed Nov 29, 2024
1 parent a84544a commit 508df23
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 26 deletions.
27 changes: 4 additions & 23 deletions java/src/main/java/thriftlabs/thriftparser/Thrift.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.ParserRuleContext;

import thriftlabs.thriftparser.*;

public class Thrift {
public static final int CommentChannel = 2; // 定义评论通道的常量
Expand All @@ -27,27 +24,11 @@ public static ParserResult parse(String content) {
return new ParserResult(lexer, tokens, parser, document);
}

public static class ThriftData {
private CommonTokenStream tokens;
private ThriftParser.DocumentContext document;

public ThriftData(CharStream inputStream) {
ParserResult result = parse(inputStream);
this.tokens = result.tokens;
this.document = result.document;
}

public static ThriftData fromString(String data) {
CharStream inputStream = CharStreams.fromString(data);
return new ThriftData(inputStream);
}
}

public static class ParserResult {
ThriftLexer lexer;
CommonTokenStream tokens;
ThriftParser parser;
ThriftParser.DocumentContext document;
public ThriftLexer lexer;
public CommonTokenStream tokens;
public ThriftParser parser;
public ThriftParser.DocumentContext document;

public ParserResult(ThriftLexer lexer, CommonTokenStream tokens, ThriftParser parser,
ThriftParser.DocumentContext document) {
Expand Down
3 changes: 0 additions & 3 deletions java/src/test/java/thriftlabs/thriftparser/ParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@

import java.util.List;

import thriftlabs.thriftparser.ThriftLexer;
import thriftlabs.thriftparser.ThriftParser;

public class ParserTest {

public static String content = "include \"./other.thrift\" \n" +
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package thriftlabs.thriftparser.integration;

import java.util.List;

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

import thriftlabs.thriftparser.Thrift;
import thriftlabs.thriftparser.ThriftParser;

public class ParseIntegrationTest {

public static String content = "include \"./other.thrift\" \n" +
"namespace py demo_thrift\n" +
"namespace go demo_thrift\n" +
"namespace java thriftlabs.thriftxx.demo_thrift\n" +
"\n" +
"const string __VERSION__ = \"0.0.8\"\n" +
"\n" +
"struct DemoStruct {" +
"1: required string x1;" +
"}";

@Test
public void testThrift() {
Thrift.ParserResult td = Thrift.parse(content);
List<ThriftParser.HeaderContext> headers = td.document.header();
assertEquals(headers.size(), 4);
}
}

0 comments on commit 508df23

Please sign in to comment.