use of cz.habarta.typescript.generator.ext.EnumConstantsExtension in project typescript-generator by vojtechhabarta.
the class EnumConstantsExtensionTest method testSorting.
@Test
public void testSorting() {
final Settings settings = TestUtils.settings();
settings.sortDeclarations = false;
settings.newline = "\n";
settings.outputFileType = TypeScriptFileType.implementationFile;
settings.outputKind = TypeScriptOutputKind.global;
settings.jsonLibrary = JsonLibrary.jackson2;
settings.extensions.add(new EnumConstantsExtension());
Assert.assertNotEquals(new TypeScriptGenerator(settings).generateTypeScript(Input.from(Emotions.class, Direction.class)), new TypeScriptGenerator(settings).generateTypeScript(Input.from(Direction.class, Emotions.class)));
settings.sortDeclarations = true;
Assert.assertEquals(new TypeScriptGenerator(settings).generateTypeScript(Input.from(Emotions.class, Direction.class)), new TypeScriptGenerator(settings).generateTypeScript(Input.from(Direction.class, Emotions.class)));
}
use of cz.habarta.typescript.generator.ext.EnumConstantsExtension in project typescript-generator by vojtechhabarta.
the class EnumConstantsExtensionTest method testInTypeScriptGenerator.
@Test
public void testInTypeScriptGenerator() {
final Settings settings = new Settings();
settings.newline = "\n";
settings.outputFileType = TypeScriptFileType.implementationFile;
settings.outputKind = TypeScriptOutputKind.global;
settings.jsonLibrary = JsonLibrary.jackson2;
settings.extensions.add(new EnumConstantsExtension());
final String actual = new TypeScriptGenerator(settings).generateTypeScript(Input.from(Direction.class));
Assert.assertTrue(actual.contains("const Direction"));
Assert.assertTrue(actual.contains("North"));
}
use of cz.habarta.typescript.generator.ext.EnumConstantsExtension in project typescript-generator by vojtechhabarta.
the class EnumConstantsExtensionTest method basicTest.
@Test
public void basicTest() {
final List<String> lines = new ArrayList<>();
final EmitterExtension.Writer writer = new EmitterExtension.Writer() {
@Override
public void writeIndentedLine(String line) {
lines.add(line);
}
};
final Settings settings = new Settings();
settings.sortDeclarations = true;
final TypeProcessor typeProcessor = new DefaultTypeProcessor();
final Model model = new Jackson2Parser(settings, typeProcessor).parseModel(Direction.class);
final TsModel tsModel = new ModelCompiler(settings, typeProcessor).javaToTypeScript(model);
new EnumConstantsExtension().emitElements(writer, settings, false, tsModel);
String indent = settings.indentString;
Assert.assertEquals(7, lines.size());
Assert.assertEquals("", lines.get(0));
Assert.assertEquals("const Direction = {", lines.get(1));
Assert.assertEquals(indent + "North: <Direction>\"North\",", lines.get(2));
Assert.assertEquals(indent + "East: <Direction>\"East\",", lines.get(3));
Assert.assertEquals(indent + "South: <Direction>\"South\",", lines.get(4));
Assert.assertEquals(indent + "West: <Direction>\"West\",", lines.get(5));
Assert.assertEquals("}", lines.get(6));
}
Aggregations