use of org.eclipse.ceylon.compiler.js.JsCompiler in project ceylon by eclipse.
the class TestMultipackages method test.
@Test
public void test() throws IOException {
// Compile module with 2 packages
System.out.println("Compiling usemulti");
TypeCheckerBuilder tcb = new TypeCheckerBuilder().usageWarnings(false);
tcb.moduleManagerFactory(new JsModuleManagerFactory("UTF-8"));
tcb.addSrcDirectory(new java.io.File("src/test/resources/multi/pass2"));
tcb.setRepositoryManager(repoman);
TypeChecker tc = tcb.getTypeChecker();
tc.process();
Options options = new Options().addRepo("build/test/test_modules").outRepo("build/test/test_modules").addSrcDir("src/test/resources/multi/pass2").verbose("");
JsCompiler compiler = new JsCompiler(tc, options);
compiler.stopOnErrors(false);
compiler.generate();
}
use of org.eclipse.ceylon.compiler.js.JsCompiler in project ceylon by eclipse.
the class TestSiteVariance method testSiteVariance.
@Test
@SuppressWarnings("unchecked")
public void testSiteVariance() throws IOException {
// Typecheck
Options opts = options("src/test/resources/variance/phase1");
TypeChecker tc = typeChecker(opts);
// Compile
JsCompiler jsc = new JsCompiler(tc, opts);
jsc.generate();
Map<String, Object> model = JavaScriptResolver.readJsonModel(new File("modules/phase1/0.1/phase1-0.1-model.js"));
Assert.assertNotNull("Model not found", model);
model = (Map<String, Object>) model.get("phase1");
Assert.assertNotNull("Default package not found", model);
model = (Map<String, Object>) model.get("m2");
Assert.assertNotNull("Function m2 not found", model);
Map<String, Object> type = (Map<String, Object>) model.get(MetamodelGenerator.KEY_TYPE);
List<Map<String, Object>> targs = (List<Map<String, Object>>) type.get(MetamodelGenerator.KEY_TYPE_PARAMS);
type = targs.get(0);
List<List<Map<String, Object>>> paramLists = (List<List<Map<String, Object>>>) model.get(MetamodelGenerator.KEY_PARAMS);
Map<String, Object> parm = paramLists.get(0).get(0);
parm = (Map<String, Object>) parm.get(MetamodelGenerator.KEY_TYPE);
targs = (List<Map<String, Object>>) parm.get(MetamodelGenerator.KEY_TYPE_PARAMS);
parm = targs.get(0);
Assert.assertEquals(SiteVariance.OUT.ordinal(), type.get(MetamodelGenerator.KEY_US_VARIANCE));
Assert.assertEquals(SiteVariance.IN.ordinal(), parm.get(MetamodelGenerator.KEY_US_VARIANCE));
// Typecheck phase2
opts = options("src/test/resources/variance/phase2");
tc = typeChecker(opts);
Function m2 = (Function) tc.getPhasedUnits().getPhasedUnits().get(0).getPackage().getModule().getPackage("phase1").getDirectMember("m2", null, false);
Assert.assertNotNull("phase1::m2 missing", m2);
Assert.assertFalse("Missing variance overrides in return type", m2.getType().getVarianceOverrides().isEmpty());
Assert.assertFalse("Missing variance overrides in parameter", m2.getFirstParameterList().getParameters().get(0).getType().getVarianceOverrides().isEmpty());
jsc = new JsCompiler(tc, opts);
jsc.generate();
Assert.assertTrue("Should compile without errors", jsc.getErrors().isEmpty());
}
Aggregations