Search in sources :

Example 1 with ExtensionMergeAction

use of com.google.debugging.sourcemap.SourceMapGeneratorV3.ExtensionMergeAction in project closure-compiler by google.

the class SourceMapGeneratorV3Test method testSourceMapMergeExtensions.

public void testSourceMapMergeExtensions() throws Exception {
    SourceMapGeneratorV3 mapper = new SourceMapGeneratorV3();
    mapper.mergeMapSection(0, 0, "{\n" + "\"version\":3,\n" + "\"file\":\"testcode\",\n" + "\"lineCount\":1,\n" + "\"mappings\":\"AAAAA,QAASA,UAAS,EAAG;\",\n" + "\"sources\":[\"testcode\"],\n" + "\"names\":[\"__BASIC__\"],\n" + "\"x_company_foo\":2\n" + "}\n");
    assertThat(mapper.hasExtension("x_company_foo")).isFalse();
    mapper.addExtension("x_company_baz", 2);
    mapper.mergeMapSection(0, 0, "{\n" + "\"version\":3,\n" + "\"file\":\"testcode2\",\n" + "\"lineCount\":0,\n" + "\"mappings\":\"\",\n" + "\"sources\":[\"testcode2\"],\n" + "\"names\":[],\n" + "\"x_company_baz\":3,\n" + "\"x_company_bar\":false\n" + "}\n", new ExtensionMergeAction() {

        @Override
        public Object merge(String extensionKey, Object currentValue, Object newValue) {
            return (Integer) currentValue + ((JsonPrimitive) newValue).getAsInt();
        }
    });
    assertThat(mapper.getExtension("x_company_baz")).isEqualTo(5);
    assertThat(((JsonPrimitive) mapper.getExtension("x_company_bar")).getAsBoolean()).isFalse();
}
Also used : JsonPrimitive(com.google.gson.JsonPrimitive) ExtensionMergeAction(com.google.debugging.sourcemap.SourceMapGeneratorV3.ExtensionMergeAction) JsonObject(com.google.gson.JsonObject)

Aggregations

ExtensionMergeAction (com.google.debugging.sourcemap.SourceMapGeneratorV3.ExtensionMergeAction)1 JsonObject (com.google.gson.JsonObject)1 JsonPrimitive (com.google.gson.JsonPrimitive)1