-
Notifications
You must be signed in to change notification settings - Fork 1.1k
adding parsing test #200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
adding parsing test #200
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,7 +15,7 @@ | |
|
|
||
| public class GraphqlAntlrToLanguage extends GraphqlBaseVisitor<Void> { | ||
|
|
||
| Document result; | ||
| private Document result; | ||
|
|
||
| private enum ContextProperty { | ||
| OperationDefinition, | ||
|
|
@@ -109,6 +109,9 @@ private void newField(Field field) { | |
| ((SelectionSet) getFromContextStack(ContextProperty.SelectionSet)).getSelections().add(field); | ||
| } | ||
|
|
||
| Document getResult() { | ||
| return result; | ||
| } | ||
|
|
||
| @Override | ||
| public Void visitDocument(GraphqlParser.DocumentContext ctx) { | ||
|
|
@@ -688,9 +691,12 @@ private Value getValue(GraphqlParser.ValueContext ctx) { | |
| throw new ShouldNotHappenException(); | ||
| } | ||
|
|
||
| private String parseString(String string) { | ||
| static String parseString(String string) { | ||
| assert string.length() >= 2; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't use assert statements in prod code: they are turned off by default and don't have any effect. Also it is not really needed to ensure the length or that the string starts wit |
||
| StringWriter writer = new StringWriter(string.length() - 2); | ||
| int end = string.length() - 1; | ||
| assert string.charAt(0) == '"' : "string did not start with '\"'"; | ||
| assert string.charAt(end) == '"' : "string did not end with '\"'"; | ||
| for (int i = 1; i < end; i++) { | ||
| char c = string.charAt(i); | ||
| if (c != '\\') { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| package graphql.parser | ||
|
|
||
| import spock.lang.Ignore | ||
| import spock.lang.Specification | ||
| /** | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you remove this comment? We don't maintain author comments. |
||
| * Created by jiayu on 9/3/16. | ||
| */ | ||
| class GraphqlAntlrToLanguageTest extends Specification { | ||
|
|
||
| def "parsing quoted string should work"() { | ||
| given: | ||
| def input = '''"simple quoted"''' | ||
|
|
||
| when: | ||
| String parsed = GraphqlAntlrToLanguage.parseString(input) | ||
|
|
||
| then: | ||
| parsed == "simple quoted" | ||
| } | ||
|
|
||
| def "parsing escaped json should work"() { | ||
| given: | ||
| def input = '''"{\"name\": \"graphql\", \"year\": 2015}"''' | ||
|
|
||
| when: | ||
| String parsed = GraphqlAntlrToLanguage.parseString(input) | ||
|
|
||
| then: | ||
| parsed == '''{\"name\": \"graphql\", \"year\": 2015}''' | ||
| } | ||
|
|
||
| def "parsing quoted quote should work"() { | ||
| given: | ||
| def input = '''"""''' | ||
|
|
||
| when: | ||
| String parsed = GraphqlAntlrToLanguage.parseString(input) | ||
|
|
||
| then: | ||
| parsed == '''"''' | ||
| } | ||
|
|
||
| @Ignore("sadly this does not work yet") | ||
| def "parsing emoji should work"() { | ||
| given: | ||
| def input = '''"\\u1f37a"''' | ||
|
|
||
| when: | ||
| String parsed = GraphqlAntlrToLanguage.parseString(input) | ||
|
|
||
| then: | ||
| parsed == '''🍺''' | ||
| } | ||
|
|
||
| def "parsing simple unicode should work"() { | ||
| given: | ||
| def input = '''"\\u56fe"''' | ||
|
|
||
| when: | ||
| String parsed = GraphqlAntlrToLanguage.parseString(input) | ||
|
|
||
| then: | ||
| parsed == '''图''' | ||
| } | ||
|
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you revert it? This change is unrelated to the parsing.