Skip to content

Commit 8dcac1d

Browse files
committed
0.23.1 - additional unit tests
1 parent 7cf3562 commit 8dcac1d

7 files changed

+146
-23
lines changed

CHANGELOG.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@ This project does its best to adhere to [Semantic Versioning](http://semver.org/
44

55

66
--------
7-
### [0.23.0](N/A) - 2021-06-28
7+
### [0.23.1](N/A) - 2021-08-14
8+
#### Changed
9+
* Expanded C# and Java field parsing tests
10+
11+
12+
--------
13+
### [0.23.0](https://github.com/TeamworkGuy2/JParseCode/commit/7cf3562bbeace52d7ff816251f106de2b2c64d05) - 2021-06-28
814
#### Added
915
* Lots of additional unit tests
1016
* `TypeExtractor.isSimpleLiteral()` used to determine whether a `FieldDef.initializer` should be serialized as a literal value `"initializer"` or an `"initializerExpression"`

bin/jparse_code-with-tests.jar

3.4 KB
Binary file not shown.

bin/jparse_code.jar

3.2 KB
Binary file not shown.

package-lib.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version" : "0.23.0",
2+
"version" : "0.23.1",
33
"name" : "jparse-code",
44
"description" : "An in-progress suite of parsing/transpilation tools for C#, Java, and TypeScript code. Generates simple JSON ASTs.",
55
"homepage" : "https://github.com/TeamworkGuy2/JParseCode",

test/twg2/parser/codeParser/test/CsFieldsParseTest.java

+20-20
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import org.junit.Test;
1313
import org.junit.runners.Parameterized.Parameter;
1414

15-
import twg2.ast.interm.annotation.AnnotationSig;
1615
import twg2.ast.interm.classes.ClassAst;
1716
import twg2.ast.interm.field.FieldDef;
1817
import twg2.parser.codeParser.AccessModifierEnum;
@@ -40,8 +39,8 @@ public class CsFieldsParseTest {
4039
" [DefaultValue(-1)]",
4140
" private int mod = -1;",
4241
"",
43-
" /// <value>The name.</value>",
44-
" private string name;",
42+
" // The lower and upper.",
43+
" private string lower;private string upper ;",
4544
"",
4645
" /// <value>The names.</value>",
4746
" public IList<string> Names { get; set; } = DEFAULT_NAMES;",
@@ -58,7 +57,7 @@ public class CsFieldsParseTest {
5857
" /// <value>The access timestamps.</value>",
5958
" public DateTime[] accesses { set { this.mod++; this.accesses = value; } }",
6059
"",
61-
" public string name { get { this.mod++; return this.name != null ? this._name : \"\"; } set { this.mod++; this._name = value; } } = \"functional\";",
60+
" public string Name { get { this.mod++; return this.name != null ? this._name : \"\"; } set { this.mod++; this._name = value; } } = \"functional\";",
6261
" public TrackInfo TrackInfo { get; }",
6362
" }",
6463
"",
@@ -80,7 +79,7 @@ public void simpleCsParseTest() {
8079
String fullClassName = simpleCs.fullClassName;
8180
Assert.assertEquals(1, blocks.size());
8281
ClassAst.SimpleImpl<CsBlock> clas = blocks.get(0).parsedClass;
83-
Assert.assertEquals(9, clas.getFields().size());
82+
Assert.assertEquals(10, clas.getFields().size());
8483

8584
Assert.assertEquals(fullClassName, NameUtil.joinFqName(clas.getSignature().getFullName()));
8685
Assert.assertEquals(AccessModifierEnum.PUBLIC, clas.getSignature().getAccessModifier());
@@ -89,27 +88,28 @@ public void simpleCsParseTest() {
8988
List<FieldDef> fields = clas.getFields();
9089
assertField(fields, 0, fullClassName + ".mod", "int", "-1");
9190
Assert.assertEquals(ls(" <value>The modification count.</value>\n"), fields.get(0).getComments());
92-
List<AnnotationSig> as = fields.get(0).getAnnotations();
93-
// annotation: DefaultValue(-1)
94-
assertAnnotation(as, 0, "DefaultValue", new String[] { "value" }, "-1");
91+
assertAnnotation(fields.get(0).getAnnotations(), 0, "DefaultValue", new String[] { "value" }, "-1");
9592
Assert.assertArrayEquals(ary(CsKeyword.PRIVATE), fields.get(0).getAccessModifiers().toArray());
9693

97-
assertField(fields, 1, fullClassName + ".name", "string");
94+
assertField(fields, 1, fullClassName + ".lower", "string");
95+
Assert.assertEquals(ls(" The lower and upper.\n"), fields.get(1).getComments());
9896
Assert.assertArrayEquals(ary(CsKeyword.PRIVATE), fields.get(1).getAccessModifiers().toArray());
99-
assertField(fields, 2, fullClassName + ".Names", ary("IList", ary("string")), "DEFAULT_NAMES");
100-
Assert.assertArrayEquals(ary(CsKeyword.PUBLIC), fields.get(2).getAccessModifiers().toArray());
101-
assertField(fields, 3, fullClassName + ".Count", "int", "1");
97+
assertField(fields, 2, fullClassName + ".upper", "string");
98+
Assert.assertArrayEquals(ary(CsKeyword.PRIVATE), fields.get(2).getAccessModifiers().toArray());
99+
assertField(fields, 3, fullClassName + ".Names", ary("IList", ary("string")), "DEFAULT_NAMES");
102100
Assert.assertArrayEquals(ary(CsKeyword.PUBLIC), fields.get(3).getAccessModifiers().toArray());
103-
assertField(fields, 4, fullClassName + ".C2", "float", "3.141592f");
104-
Assert.assertArrayEquals(ary(CsKeyword.PROTECTED), fields.get(4).getAccessModifiers().toArray());
105-
assertField(fields, 5, fullClassName + ".C3", "decimal", "(decimal)1.23456789");
106-
Assert.assertArrayEquals(ary(CsKeyword.PROTECTED, CsKeyword.INTERNAL), fields.get(5).getAccessModifiers().toArray());
107-
assertField(fields, 6, fullClassName + ".accesses", "DateTime[]");
108-
Assert.assertArrayEquals(ary(CsKeyword.PUBLIC), fields.get(6).getAccessModifiers().toArray());
109-
assertField(fields, 7, fullClassName + ".name", "string");
101+
assertField(fields, 4, fullClassName + ".Count", "int", "1");
102+
Assert.assertArrayEquals(ary(CsKeyword.PUBLIC), fields.get(4).getAccessModifiers().toArray());
103+
assertField(fields, 5, fullClassName + ".C2", "float", "3.141592f");
104+
Assert.assertArrayEquals(ary(CsKeyword.PROTECTED), fields.get(5).getAccessModifiers().toArray());
105+
assertField(fields, 6, fullClassName + ".C3", "decimal", "(decimal)1.23456789");
106+
Assert.assertArrayEquals(ary(CsKeyword.PROTECTED, CsKeyword.INTERNAL), fields.get(6).getAccessModifiers().toArray());
107+
assertField(fields, 7, fullClassName + ".accesses", "DateTime[]");
110108
Assert.assertArrayEquals(ary(CsKeyword.PUBLIC), fields.get(7).getAccessModifiers().toArray());
111-
assertField(fields, 8, fullClassName + ".TrackInfo", "TrackInfo");
109+
assertField(fields, 8, fullClassName + ".Name", "string");
112110
Assert.assertArrayEquals(ary(CsKeyword.PUBLIC), fields.get(8).getAccessModifiers().toArray());
111+
assertField(fields, 9, fullClassName + ".TrackInfo", "TrackInfo");
112+
Assert.assertArrayEquals(ary(CsKeyword.PUBLIC), fields.get(9).getAccessModifiers().toArray());
113113
}
114114

115115
}

test/twg2/parser/codeParser/test/JavaEnumParseTest.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class JavaEnumParseTest {
3535
" /** The classes enum */",
3636
" Classes(4) {",
3737
" @Override",
38-
" public String toString() { return \"classic\"; }",
38+
" public String toString() { return \"classic\"; }",
3939
" };",
4040
"",
4141
" int secret;",
@@ -67,13 +67,16 @@ public void simpleEnumCsParseTest() {
6767

6868
FieldDef f = enums.get(0);
6969
Assert.assertEquals(fullClassName + ".Fields", NameUtil.joinFqName(f.getFullName()));
70+
Assert.assertEquals("SimpleEnumJava", f.getFieldType().getTypeName());
7071
Assert.assertEquals(ls(" The fields enum\n"), f.getComments());
7172

7273
f = enums.get(1);
7374
Assert.assertEquals(fullClassName + ".Methods", NameUtil.joinFqName(f.getFullName()));
75+
Assert.assertEquals("SimpleEnumJava", f.getFieldType().getTypeName());
7476

7577
f = enums.get(2);
7678
Assert.assertEquals(fullClassName + ".Classes", NameUtil.joinFqName(f.getFullName()));
79+
Assert.assertEquals("SimpleEnumJava", f.getFieldType().getTypeName());
7780
Assert.assertEquals(ls(" The classes enum "), f.getComments());
7881
}
7982

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
package twg2.parser.codeParser.test;
2+
3+
import static twg2.parser.test.utils.AnnotationAssert.assertAnnotation;
4+
import static twg2.parser.test.utils.FieldAssert.assertField;
5+
import static twg2.parser.test.utils.TypeAssert.ary;
6+
import static twg2.parser.test.utils.TypeAssert.ls;
7+
8+
import java.io.IOException;
9+
import java.util.List;
10+
11+
import org.junit.Assert;
12+
import org.junit.Test;
13+
import org.junit.runners.Parameterized.Parameter;
14+
15+
import twg2.ast.interm.classes.ClassAst;
16+
import twg2.ast.interm.field.FieldDef;
17+
import twg2.parser.codeParser.AccessModifierEnum;
18+
import twg2.parser.codeParser.java.JavaBlock;
19+
import twg2.parser.codeParser.java.JavaKeyword;
20+
import twg2.parser.codeParser.tools.NameUtil;
21+
import twg2.parser.language.CodeLanguageOptions;
22+
import twg2.parser.test.utils.CodeFileAndAst;
23+
import twg2.parser.workflow.CodeFileParsed;
24+
25+
/**
26+
* @author TeamworkGuy2
27+
* @since 2021-08-14
28+
*/
29+
public class JavaFieldsParseTest {
30+
private static List<String> srcLines = ls(
31+
"package ParserExamples.Fields;",
32+
"",
33+
"/** A simple class to test field parsing.",
34+
" * @since 2021-8-14",
35+
" */",
36+
"public class FieldsJava {",
37+
"",
38+
" /** The modification count. */",
39+
" @DefaultValue(-1)",
40+
" private int mod = -1;",
41+
"",
42+
" // The lower and upper.",
43+
" private String lower;private String upper ;",
44+
"",
45+
" /** The names. */",
46+
" public List<String> Names = DEFAULT_NAMES;",
47+
"",
48+
" /** The number of Names. */",
49+
" public int Count = 1;",
50+
"",
51+
" /** The number of names. */",
52+
" protected float C2 = 3.141592f;",
53+
"",
54+
" /** The number of names. */",
55+
" protected double C3 = (double)1.23456789D;",
56+
"",
57+
" /** The access timestamps. */",
58+
" public ZonedDateTime[] accesses;",
59+
"",
60+
" public String name = \"functional\";",
61+
" public TrackInfo TrackInfo;",
62+
"",
63+
"}"
64+
);
65+
66+
@Parameter
67+
private CodeFileAndAst<JavaBlock> simpleJava;
68+
69+
70+
public JavaFieldsParseTest() throws IOException {
71+
simpleJava = CodeFileAndAst.<JavaBlock>parse(CodeLanguageOptions.JAVA, "FieldsJava.java", "ParserExamples.Fields.FieldsJava", true, srcLines);
72+
}
73+
74+
75+
@Test
76+
public void simpleJavaParseTest() {
77+
List<CodeFileParsed.Simple<JavaBlock>> blocks = simpleJava.parsedBlocks;
78+
String fullClassName = simpleJava.fullClassName;
79+
Assert.assertEquals(1, blocks.size());
80+
ClassAst.SimpleImpl<JavaBlock> clas = blocks.get(0).parsedClass;
81+
Assert.assertEquals(10, clas.getFields().size());
82+
83+
Assert.assertEquals(fullClassName, NameUtil.joinFqName(clas.getSignature().getFullName()));
84+
Assert.assertEquals(AccessModifierEnum.PUBLIC, clas.getSignature().getAccessModifier());
85+
Assert.assertEquals("class", clas.getSignature().getDeclarationType());
86+
87+
List<FieldDef> fields = clas.getFields();
88+
assertField(fields, 0, fullClassName + ".mod", "int", "-1");
89+
Assert.assertEquals(ls(" The modification count. "), fields.get(0).getComments());
90+
assertAnnotation(fields.get(0).getAnnotations(), 0, "DefaultValue", new String[] { "value" }, "-1");
91+
Assert.assertArrayEquals(ary(JavaKeyword.PRIVATE), fields.get(0).getAccessModifiers().toArray());
92+
93+
assertField(fields, 1, fullClassName + ".lower", "String");
94+
Assert.assertEquals(ls(" The lower and upper.\n"), fields.get(1).getComments());
95+
Assert.assertArrayEquals(ary(JavaKeyword.PRIVATE), fields.get(1).getAccessModifiers().toArray());
96+
assertField(fields, 2, fullClassName + ".upper", "String");
97+
Assert.assertArrayEquals(ary(JavaKeyword.PRIVATE), fields.get(2).getAccessModifiers().toArray());
98+
assertField(fields, 3, fullClassName + ".Names", ary("List", ary("String")), "DEFAULT_NAMES");
99+
Assert.assertArrayEquals(ary(JavaKeyword.PUBLIC), fields.get(3).getAccessModifiers().toArray());
100+
assertField(fields, 4, fullClassName + ".Count", "int", "1");
101+
Assert.assertArrayEquals(ary(JavaKeyword.PUBLIC), fields.get(4).getAccessModifiers().toArray());
102+
assertField(fields, 5, fullClassName + ".C2", "float", "3.141592f");
103+
Assert.assertArrayEquals(ary(JavaKeyword.PROTECTED), fields.get(5).getAccessModifiers().toArray());
104+
assertField(fields, 6, fullClassName + ".C3", "double", "(double)1.23456789D");
105+
Assert.assertArrayEquals(ary(JavaKeyword.PROTECTED), fields.get(6).getAccessModifiers().toArray());
106+
assertField(fields, 7, fullClassName + ".accesses", "ZonedDateTime[]");
107+
Assert.assertArrayEquals(ary(JavaKeyword.PUBLIC), fields.get(7).getAccessModifiers().toArray());
108+
assertField(fields, 8, fullClassName + ".name", "String");
109+
Assert.assertArrayEquals(ary(JavaKeyword.PUBLIC), fields.get(8).getAccessModifiers().toArray());
110+
assertField(fields, 9, fullClassName + ".TrackInfo", "TrackInfo");
111+
Assert.assertArrayEquals(ary(JavaKeyword.PUBLIC), fields.get(9).getAccessModifiers().toArray());
112+
}
113+
114+
}

0 commit comments

Comments
 (0)