コード例 #1
0
  private void test(Compiler compiler, FunctionInformationMap expected) {
    Node root = compiler.parseInputs();
    Node externsRoot = root.getFirstChild();
    Node mainRoot = externsRoot.getNext();

    FunctionNames functionNames = new FunctionNames(compiler);
    functionNames.process(externsRoot, mainRoot);

    RecordFunctionInformation processor = new RecordFunctionInformation(compiler, functionNames);
    processor.process(externsRoot, mainRoot);
    FunctionInformationMap result = processor.getMap();
    assertTrue(
        "\nExpected: " + expected.toString() + "\nResult: " + result.toString() + "\n",
        result.equals(expected));
  }
コード例 #2
0
  public void testFunction() {
    String g = "function g(){}";
    String fAndG = "function f(){" + g + "}";
    String js = "var h=" + fAndG + ";h()";

    FunctionInformationMap.Builder expected = FunctionInformationMap.newBuilder();
    expected.addEntry(
        FunctionInformationMap.Entry.newBuilder()
            .setId(0)
            .setSourceName("testcode")
            .setLineNumber(1)
            .setModuleName("")
            .setSize(g.length())
            .setName("f::g")
            .setCompiledSource(g)
            .build());
    expected.addEntry(
        FunctionInformationMap.Entry.newBuilder()
            .setId(1)
            .setSourceName("testcode")
            .setLineNumber(1)
            .setModuleName("")
            .setSize(fAndG.length())
            .setName("f")
            .setCompiledSource(fAndG)
            .build());
    expected.addModule(
        FunctionInformationMap.Module.newBuilder().setName("").setCompiledSource(js + ";").build());

    test(js, expected.build());
  }
コード例 #3
0
  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());
  }