/*
 * Copyright 2009 The Closure Compiler Authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.google.debugging.sourcemap;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;

import junit.framework.TestCase;

import java.util.Map;

/**
 * Tests for {@link SourceMapConsumerV3}
 *
 */
public class SourceMapConsumerV3Test extends TestCase {

  public void testSources() throws Exception{
    String sourceMap =  "{\n" +
                        "\"version\":3,\n" +
                        "\"file\":\"testcode\",\n" +
                        "\"lineCount\":1,\n" +
                        "\"mappings\":\"AAAAA,QAASA,UAAS,EAAG;\",\n" +
                        "\"sources\":[\"testcode\"],\n" +
                        "\"names\":[\"__BASIC__\"]\n" +
                        "}\n";

    SourceMapConsumerV3 consumer = new SourceMapConsumerV3();
    consumer.parse(sourceMap);

    String[] sources = (String[]) consumer.getOriginalSources().toArray();

    assertEquals(1, sources.length);
    assertEquals(null, consumer.getSourceRoot());
    assertEquals("testcode", sources[0]);
  }

  public void testSourcesWithRoot() throws Exception{
    String sourceMap =  "{\n" +
                        "\"version\":3,\n" +
                        "\"file\":\"testcode\",\n" +
                        "\"lineCount\":1,\n" +
                        "\"sourceRoot\":\"http://server/path/\",\n" +
                        "\"mappings\":\"AAAAA,QAASA,UAAS,EAAG;\",\n" +
                        "\"sources\":[\"testcode\"],\n" +
                        "\"names\":[\"__BASIC__\"]\n" +
                        "}\n";

    SourceMapConsumerV3 consumer = new SourceMapConsumerV3();
    consumer.parse(sourceMap);

    String[] sources = (String[]) consumer.getOriginalSources().toArray();

    assertEquals(1, sources.length);
    assertEquals("http://server/path/", consumer.getSourceRoot());
    //By default sourceRoot is not prepended
    assertEquals("testcode", sources[0]);
  }

  public void testExtensions() throws Exception{
    String sourceMap =  "{\n" +
                        "\"version\":3,\n" +
                        "\"file\":\"testcode\",\n" +
                        "\"lineCount\":1,\n" +
                        "\"mappings\":\"AAAAA,QAASA,UAAS,EAAG;\",\n" +
                        "\"sources\":[\"testcode\"],\n" +
                        "\"names\":[\"__BASIC__\"],\n" +
                        "\"x_org_int\":2,\n" +
                        "\"x_org_array\":[]\n" +
                        "}\n";

    SourceMapConsumerV3 consumer = new SourceMapConsumerV3();
    consumer.parse(sourceMap);

    Map<String, Object> exts = consumer.getExtensions();

    assertEquals(2, exts.size());
    assertFalse(exts.containsKey("org_int"));
    assertEquals(2, ((JsonElement) exts.get("x_org_int")).getAsInt());
    assertEquals(0, ((JsonArray) exts.get("x_org_array")).size());
  }

}

@@ -1621,32 +1621,746 @@
 urces%5B0%5D);%0A  %7D%0A%0A
+  public void testMap() throws Exception%7B%0A    String sourceMap = %22%22%0A        + %22%7B%22%0A        + %22  %5C%22version%5C%22: 3,%22%0A        + %22  %5C%22file%5C%22: %5C%22testcode.js%5C%22,%22%0A        + %22  %5C%22sections%5C%22: %5B%22%0A        + %22    %7B%22%0A        + %22      %5C%22map%5C%22: %7B%22%0A        + %22         %5C%22version%5C%22: 3,%22%0A        + %22         %5C%22mappings%5C%22: %5C%22AAAAA,QAASA,UAAS,EAAG;%5C%22,%22%0A        + %22         %5C%22sources%5C%22: %5B%5C%22testcode.js%5C%22%5D,%22%0A        + %22         %5C%22names%5C%22: %5B%5C%22foo%5C%22%5D%22%0A        + %22      %7D,%22%0A        + %22      %5C%22offset%5C%22: %7B%22%0A        + %22        %5C%22line%5C%22: 1,%22%0A        + %22        %5C%22column%5C%22: 1%22%0A        + %22      %7D%22%0A        + %22    %7D%22%0A        + %22  %5D%22%0A        + %22%7D%22;%0A%0A    SourceMapConsumerV3 consumer = new SourceMapConsumerV3();%0A    consumer.parse(sourceMap);%0A%0A  %7D%0A%0A
   public void te

Add a test that would have caught the Gson breakage ------------- Created by MOE: http://code.google.com/p/moe-java MOE_MIGRATED_REVID=77605647