@Override
 protected void setUp() throws Exception {
   super.setUp();
   super.enableTypeCheck(CheckLevel.OFF);
   super.enableClosurePass();
   configuration = DEFAULT_CONFORMANCE;
 }
  private Compiler compile(String[] original) {
    CommandLineRunner runner = createCommandLineRunner(original);
    assertTrue(new String(errReader.toByteArray()), runner.shouldRunCompiler());
    Supplier<List<SourceFile>> inputsSupplier = null;
    Supplier<List<JSModule>> modulesSupplier = null;

    if (useModules == ModulePattern.NONE) {
      List<SourceFile> inputs = Lists.newArrayList();
      for (int i = 0; i < original.length; i++) {
        inputs.add(SourceFile.fromCode(getFilename(i), original[i]));
      }
      inputsSupplier = Suppliers.ofInstance(inputs);
    } else if (useModules == ModulePattern.STAR) {
      modulesSupplier =
          Suppliers.<List<JSModule>>ofInstance(
              Lists.<JSModule>newArrayList(CompilerTestCase.createModuleStar(original)));
    } else if (useModules == ModulePattern.CHAIN) {
      modulesSupplier =
          Suppliers.<List<JSModule>>ofInstance(
              Lists.<JSModule>newArrayList(CompilerTestCase.createModuleChain(original)));
    } else {
      throw new IllegalArgumentException("Unknown module type: " + useModules);
    }

    runner.enableTestMode(
        Suppliers.<List<SourceFile>>ofInstance(externs),
        inputsSupplier,
        modulesSupplier,
        new Function<Integer, Boolean>() {
          @Override
          public Boolean apply(Integer code) {
            return exitCodes.add(code);
          }
        });
    runner.run();
    lastCompiler = runner.getCompiler();
    lastCommandLineRunner = runner;
    return lastCompiler;
  }
  public void testModule() {
    String g = "function g(){}";
    String fAndG = "function f(){" + g + "}";
    String m0_js = "var h=" + fAndG + ";h()";
    String sum = "function(a,b){return a+b}";
    String m1_js = "var x=" + sum + "(1,2)";

    FunctionInformationMap.Builder expected = FunctionInformationMap.newBuilder();
    expected.addEntry(
        FunctionInformationMap.Entry.newBuilder()
            .setId(0)
            .setSourceName("i0")
            .setLineNumber(1)
            .setModuleName("m0")
            .setSize(g.length())
            .setName("f::g")
            .setCompiledSource(g)
            .build());
    expected.addEntry(
        FunctionInformationMap.Entry.newBuilder()
            .setId(1)
            .setSourceName("i0")
            .setLineNumber(1)
            .setModuleName("m0")
            .setSize(fAndG.length())
            .setName("f")
            .setCompiledSource(fAndG)
            .build());
    expected.addEntry(
        FunctionInformationMap.Entry.newBuilder()
            .setId(2)
            .setSourceName("i1")
            .setLineNumber(1)
            .setModuleName("m1")
            .setSize(sum.length())
            .setName("<anonymous>")
            .setCompiledSource(sum)
            .build());
    expected.addModule(
        FunctionInformationMap.Module.newBuilder()
            .setName("m0")
            .setCompiledSource(m0_js + ";")
            .build());
    expected.addModule(
        FunctionInformationMap.Module.newBuilder()
            .setName("m1")
            .setCompiledSource(m1_js + ";")
            .build());

    test(CompilerTestCase.createModules(m0_js, m1_js), expected.build());
  }
  @Override
  protected void setUp() throws Exception {
    super.setUp();
    previouslyUsedMap = new VariableMap(ImmutableMap.<String, String>of());
    prefix = DEFAULT_PREFIX;
    withClosurePass = false;
    withNormalize = false;
    localRenamingOnly = false;
    preserveFunctionExpressionNames = false;
    generatePseudoNames = false;
    shouldShadow = false;
    preferStableNames = false;
    nameGenerator = null;
    compareJsDoc = false;

    // TODO(johnlenz): Enable Normalize during these tests.
  }
 @Override
 public void tearDown() throws Exception {
   super.tearDown();
   disableTypeCheck();
 }
示例#6
0
 @Override
 protected void setUp() throws Exception {
   super.setUp();
   generatePseudoNames = false;
   previousMappings = null;
 }
 @Override
 public void setUp() throws Exception {
   super.setUp();
   late = false;
 }
 @Override
 public void setUp() {
   super.enableLineNumberCheck(true);
 }