Skip to content

Commit a513604

Browse files
author
Bob Garner
committed
Updated code formatting test.
1 parent 9bc47cf commit a513604

File tree

4 files changed

+115
-320
lines changed

4 files changed

+115
-320
lines changed

test/java/org/entityc/compiler/EntityCompilerTest.java

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
package org.entityc.compiler;
22

33
import org.apache.commons.io.FileUtils;
4+
import org.entityc.compiler.model.MTCodeFormat;
5+
import org.entityc.compiler.transform.template.formatter.TemplateFormatController;
6+
import org.entityc.compiler.util.ECLog;
47
import org.junit.jupiter.api.Test;
58

9+
import javax.json.Json;
10+
import javax.json.JsonObjectBuilder;
611
import java.io.File;
712
import java.io.IOException;
813

@@ -63,17 +68,42 @@ void templateDocumentation() throws IOException {
6368
runTemplateTest(TestName);
6469
}
6570

66-
//@Test
71+
@Test
6772
void templateFormatting() throws IOException {
6873
final String testName = "TemplateCodeFormatting";
6974
final String TestResourceDir = BASE_RESOURCE_DIR + "/" + testName;
7075
String strTmp = System.getProperty("java.io.tmpdir");
7176
String sourceFile = TestResourceDir + "/" + testName + ".eml";
72-
String destFile = TestResourceDir + "/" + testName + "_formatted.eml";
73-
EntityCompiler.main(new String[]{TestResourceDir + "/" + "TestFormat.edl", "-tp", TestResourceDir, "-tf", testName, "-tfout", destFile});
74-
assertTrue(true);
75-
// String actual = FileUtils.readFileToString(new File(strTmp + File.separator + testName + ".txt"));
76-
// String expected = FileUtils.readFileToString(new File(TestResourceDir + "/" + testName + "Expected.txt"));
77-
// assertEquals(actual, expected);
77+
String expectedFile = TestResourceDir + "/" + testName + "Expected.eml";
78+
79+
JsonObjectBuilder jsonObjectBuilder = Json.createObjectBuilder();
80+
jsonObjectBuilder.add("Element.ExpressionOperator.spaceBefore", true);
81+
jsonObjectBuilder.add("Element.ExpressionOperator.spaceAfter", true);
82+
jsonObjectBuilder.add("Element.ExpressionOperatorEquals.spaceBefore", true);
83+
jsonObjectBuilder.add("Element.ExpressionOperatorEquals.spaceAfter", true);
84+
jsonObjectBuilder.add("Element.FilterName.spaceAfter", false);
85+
jsonObjectBuilder.add("Instruction.outlet.suppressIndent", true);
86+
jsonObjectBuilder.add("Instruction.receive.suppressIndent", true);
87+
jsonObjectBuilder.add("Instruction.send.suppressIndent", true);
88+
jsonObjectBuilder.add("Element.Description.alignTo.InstructionName", true);
89+
jsonObjectBuilder.add("Element.FunctionOpenParen.alignTo.InstructionName", true);
90+
jsonObjectBuilder.add("Element.FunctionArgName.alignTo.FunctionArgName", true);
91+
jsonObjectBuilder.add("Element.FunctionCloseParen.alignTo.FunctionOpenParen", true);
92+
jsonObjectBuilder.add("Element.Description.alignTo.FunctionArgName", true);
93+
// jsonObjectBuilder.add("Element.FunctionCallOpenParen.alignTo.InstructionName", true);
94+
// jsonObjectBuilder.add("Element.FunctionCallArgName.alignTo.FunctionCallArgName", true);
95+
// jsonObjectBuilder.add("Element.FunctionCallCloseParen.alignTo.FunctionCallOpenParen", true);
96+
jsonObjectBuilder.add("Element.FunctionCallArgDelim.spaceAfter", true); // TODO: broken when used with above three
97+
jsonObjectBuilder.add("Element.FunctionCallDelim.spaceAfter", true);
98+
jsonObjectBuilder.add("Element.InstructionBlockStartSuffix.alignTo.InstructionBlockStartPrefix.if.Description", true);
99+
jsonObjectBuilder.add("Element.InstructionSuffix.alignTo.InstructionPrefix.if.Description", true);
100+
101+
MTCodeFormat codeFormat = new MTCodeFormat(null, "Default", jsonObjectBuilder.build());
102+
ECLog.SetExitOnFatal(false);
103+
String inputText = FileUtils.readFileToString(new File(sourceFile));
104+
105+
final String actual = TemplateFormatController.FormatCodeAsString(inputText, codeFormat);
106+
String expected = FileUtils.readFileToString(new File(expectedFile));
107+
assertEquals(expected, actual);
78108
}
79109
}
Lines changed: 36 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -1,150 +1,42 @@
1-
$[D summary,main "This template contains the author that is responsible for generating the create object service methods."]
2-
$[D "**Create**"]
3-
$[D ""]
4-
$[D "The create method is called by create endpoints implemented in the controller class. This method"]
5-
$[D "in turn calls a create method in the repository class however before that it will assign"]
6-
$[D "a UUID primary key. This is also where it places some of the in-memory caching code. It will"]
7-
$[D "also set relationships associated with the logged in (principle) user."]
1+
$[log]
2+
$[foreach typedef in space.typedefs]
83

9-
$[D summary, main "Generates the Spring Boot Service classes for all entities in your project space."]
10-
$[D main, summary ""]
11-
$[D main, summary "Generates the Spring Boot Service classes for all entities in your project space."]
12-
$[D "
13-
When your application involves release and version management of some entity, this template has functions that can be useful. The template is centered around the support of a particular structure of entities that have specific relationships between eachother.
14-
15-
The entities involved in the pattern shown below are as follows:
16-
17-
| Entity | Description |
18-
|:------:|-------------|
19-
| O | **Object** - This is the main entity you are trying to manage in terms of versioning and release management. For instance, lets say your entity is called Widget. This would be the non-versioned Widget.|
20-
| V | **Version** - This represents a entity that tracks versions of the O entity. It would have attributes that need to be under version control. In our example, this would be a version of a Widget so might be named WidgetVersion.|
21-
| VR | **Version Release** - This entity binds our O and V entities to a release. So |
22-
| R | **Release** - This represents a release of one or more O,V pairs. |
23-
| P | **Parent** - This is an *optional* entity that defines a context for the R entity (as a parent entity to it). |
24-
25-
26-
```
27-
+-------+ +-------+ +--------+ +-------+ +-------+
28-
| P +---<| R +-----<| VR |>-------+ V |>---------+ O |>--+
29-
+----+--+ +-------+ +--------+ +-------+ +----+--+ |
30-
| Y | |
31-
| +-----------------------------------+ |
32-
+-----------------------------------------------------------------------+
33-
Tag-> release:top release:binder release:version release:object
34-
35-
```
36-
37-
These functions help support the detection of this pattern not just in terms of the tags but also the relationships between the entities.
38-
"
39-
]
40-
$[D "easily expanded to support many other features."]
41-
$[let something = !otherthing]
42-
$[capture parentId]${relationship|domain: Model|wrap:("hello") cache blah:"asdf"}Id$[/capture]
43-
package ${domain.namespace};
44-
45-
$[receive distinct imports]
46-
47-
$[import "service/authors/ServiceBaseAuthor"]
48-
$[import "service/authors/ServiceCRUDAuthors"]
49-
$[*import "service/authors/ServiceCacheAuthor"*]
50-
$[import "service/authors/ServiceUploadAuthor"]
51-
52-
$[foreach space.modules]
53-
${module.name} is one of the modules.
4+
Typedef: ${typedef.name}
545
$[/foreach]
6+
$[foreach enum in space.enums]
557

56-
$[function abc D "this is a description of this function" (argument1 D "description for arg 1 that can be pretty long because it has a lot to say about this argument for some reason so it just keeps rambling on and on aobut it.", argument2 D "another description this time for arg 2")]
57-
$[/function]
58-
59-
$[function xyz
60-
D main, summary "this is a description of this function"
61-
(argumentA D "description for arg 1 that can be pretty long because it has a lot to say about this argument for some reason so it just keeps rambling on and on aobut it.",argumentHLM D "another description this time for arg 2"
62-
)
63-
]
64-
$[/function]
65-
$[call xyz ( argumentA:"", argumentHLM:5 )]
66-
67-
$[publisher org.entitycompiler.springboot.service
68-
D "This publisher ultimately builds the Service classes for the Spring Boot application but it relies on many"
69-
D "authors to fill it out with methods required to implement the application."
70-
]
71-
$[language java]
72-
$[domain Service]
73-
$[switch track]
74-
$[case justin]laskdjf;askljdf
75-
$[case hard] qwerqwer
76-
$[default]do this
8+
Enum: ${enum.name}
9+
$[/foreach]
10+
$[foreach entity in space.entities]
11+
12+
$[let qualifier = entity.isSecondary ? "Secondary " : ""]
13+
${qualifier}Entity: ${entity.name}
14+
$[foreach attribute in entity.attributes]
15+
$[switch attribute.type]
16+
$[case uuid]
17+
$[let typeLongName="Unique Identifier - 128 bits"]
18+
$[case int32]
19+
$[let typeLongName="32-bit Integer"]
20+
$[case int64]
21+
$[let typeLongName="64-bit Integer"]
22+
$[case float]
23+
$[let typeLongName="32-bit Floating Point"]
24+
$[case double]
25+
$[let typeLongName="64-bit Floating Point"]
26+
$[case string]
27+
$[let typeLongName="String of characters"]
28+
$[case enum]
29+
$[let typeLongName="Enum named " + attribute.type.name]
30+
$[case typedef]
31+
$[let typeLongName="Typedef named " + attribute.type.name]
32+
$[case entity]
33+
$[let typeLongName="Entity named " + attribute.type.name]
34+
$[default]
35+
$[let typeLongName="Unknown"]
7736
$[/switch]
78-
$[foreach module in space.modules]
79-
$[if module.isIncluded]$[continue]$[/if]
80-
$[outlet moduleLoopTop
81-
D "This is just inside the module foreach. An author could use this to filter out modules, for instance."]
82-
$[/outlet]
83-
$[foreach module.entities as entity]
84-
$[if !(entity.isSecondary || entity.isImplicit|| entity.isExtern || entity.isTransient)+5*(4+xyz*efv)]xx$[continue]$[/if]
85-
$[outlet entityLoopTop
86-
D "This is just inside the entity foreach. An author could use this to filter out entities, for instance."]
87-
$[/outlet]
88-
$[file domain.namespace|path entity|domain|name "java"]
89-
$[outlet commentHeader
90-
D "This outlet simply allows you to place comments at the top of the source file."
91-
]$[/outlet]
92-
93-
$[foreach ab in bc]
94-
${ab.name}dude$[let this=that]wer
37+
Attribute
38+
Name: ${attribute.name}
39+
Type: ${typeLongName}
9540
$[/foreach]
96-
97-
package ${domain.namespace};
98-
99-
$[receive distinct imports D "This will receive Java import statements."]
100-
$[send imports]
101-
import org.springframework.stereotype.Service;
102-
import org.springframework.transaction.annotation.Transactional;
103-
$[/send]
104-
105-
@Service
106-
@Transactional
107-
$[outlet classAnnotation
108-
D "This allows an author to add an annotation to the class definition."
109-
]$[/outlet]
110-
public class ${className} {
111-
112-
$[receive distinct memberDecl]
113-
$[receive distinct caches]
114-
115-
$[outlet members
116-
D "This is the top section of the class where member variables typically are placed."
117-
]
118-
// no members
119-
$[/outlet]
120-
121-
$[outlet constructor
122-
D "The constructor outlet lets you replace the simple constructor with one that supports other functions such as"
123-
D "auto wired objects."
124-
]
125-
public ${className}() {}
126-
$[/outlet]
127-
128-
$[outlet methods
129-
D "This outlet is where authors place the build of generated code. Some of these authors may also be publishers"
130-
D "to give access to specific methods."
131-
]
132-
// no methods
133-
$[/outlet]
134-
}
135-
$[/file]
136-
$[/foreach]
13741
$[/foreach]
138-
$[/publisher]
139-
$[file domain.namespace|path "README" "md"]
140-
# Service Classes
141-
142-
The classes in this directory are Service classes as part of the Spring Framework.
143-
144-
## Generated by
145-
146-
Entity Compiler v${compiler.version}
147-
148-
Template: `${template.name}`
149-
150-
$[/file]
42+
$[/log]
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
$[log]
2+
$[foreach typedef in space.typedefs]
3+
4+
Typedef: ${typedef.name}
5+
$[/foreach]
6+
$[foreach enum in space.enums]
7+
8+
Enum: ${enum.name}
9+
$[/foreach]
10+
$[foreach entity in space.entities]
11+
12+
$[let qualifier = entity.isSecondary ? "Secondary ":""]
13+
${qualifier}Entity: ${entity.name}
14+
$[foreach attribute in entity.attributes]
15+
$[switch attribute.type]
16+
$[case string]
17+
$[let typeLongName = "String of characters"]
18+
$[case int32]
19+
$[let typeLongName = "32-bit Integer"]
20+
$[case int64]
21+
$[let typeLongName = "64-bit Integer"]
22+
$[case double]
23+
$[let typeLongName = "64-bit Floating Point"]
24+
$[case float]
25+
$[let typeLongName = "32-bit Floating Point"]
26+
$[case uuid]
27+
$[let typeLongName = "Unique Identifier - 128 bits"]
28+
$[case typedef]
29+
$[let typeLongName = "Typedef named " + attribute.type.name]
30+
$[case enum]
31+
$[let typeLongName = "Enum named " + attribute.type.name]
32+
$[case entity]
33+
$[let typeLongName = "Entity named " + attribute.type.name]
34+
$[default]
35+
$[let typeLongName = "Unknown"]
36+
$[/switch]
37+
Attribute
38+
Name: ${attribute.name}
39+
Type: ${typeLongName}
40+
$[/foreach]
41+
$[/foreach]
42+
$[/log]

0 commit comments

Comments
 (0)