/*
 * Copyright 2011 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.javascript.jscomp;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

/** Unit tests for {@link ConvertChunksToESModules} */
@RunWith(JUnit4.class)
public final class ConvertChunksToESModulesTest extends CompilerTestCase {
  @Override
  protected CompilerPass getProcessor(Compiler compiler) {
    return new ConvertChunksToESModules(compiler);
  }

  @Override
  @Before
  public void setUp() throws Exception {
    super.setUp();
  }

  @Test
  public void testVarDeclarations_acrossModules() {
    test(
        createModules("var a = 1;", "a"),
        createModules("var a = 1; export {a}", "import {a} from './m0.js'; a"));
    test(
        createModules("var a = 1, b = 2, c = 3;", "a;c;"),
        createModules(
            "var a = 1, b = 2, c = 3; export {a, c};", "import {a, c} from './m0.js'; a; c;"));
    test(
        createModules("var a = 1, b = 2, c = 3;", "b;c;"),
        createModules(
            "var a = 1, b = 2, c = 3; export {b,c};", "import {b, c} from './m0.js'; b;c;"));
  }
}

@@ -646,16 +646,81 @@
 scomp;%0A%0A
+import com.google.javascript.jscomp.testing.JSChunkGraphBuilder;%0A
 import o
@@ -1275,63 +1275,175 @@
     
-createModules(%22var a = 1;%22, %22a%22),%0A        createModules
+JSChunkGraphBuilder.forStar()%0A          .addChunk(%22var a = 1;%22)%0A          .addChunk( %22a%22)%0A          .build(),%0A        JSChunkGraphBuilder.forStar()%0A          .addChunk
 (%22va
@@ -1462,18 +1462,38 @@
 ort %7Ba%7D%22
-, 
+)%0A          .addChunk(
 %22import 
@@ -1515,16 +1515,35 @@
 js'; a%22)
+%0A          .build()
 );%0A    t
@@ -1559,81 +1559,171 @@
     
-createModules(%22var a = 1, b = 2, c = 3;%22, %22a;c;%22),%0A        createModules(
+JSChunkGraphBuilder.forStar()%0A          .addChunk(%22var a = 1, b = 2, c = 3;%22)%0A          .addChunk(%22a;c;%22)%0A          .build(),%0A        JSChunkGraphBuilder.forStar()
 %0A   
@@ -1721,34 +1721,42 @@
 tar()%0A          
-  
+.addChunk(
 %22var a = 1, b = 
@@ -1776,26 +1776,46 @@
 ort %7Ba, c%7D;%22
-, 
+)%0A          .addChunk(
 %22import %7Ba, 
@@ -1836,24 +1836,43 @@
 js'; a; c;%22)
+%0A          .build()
 );%0A    test(
@@ -1884,81 +1884,171 @@
     
-createModules(%22var a = 1, b = 2, c = 3;%22, %22b;c;%22),%0A        createModules(
+JSChunkGraphBuilder.forStar()%0A          .addChunk(%22var a = 1, b = 2, c = 3;%22)%0A          .addChunk(%22b;c;%22)%0A          .build(),%0A        JSChunkGraphBuilder.forStar()
 %0A   
@@ -2054,18 +2054,26 @@
         
-  
+.addChunk(
 %22var a =
@@ -2104,18 +2104,38 @@
  %7Bb,c%7D;%22
-, 
+)%0A          .addChunk(
 %22import 
@@ -2163,16 +2163,35 @@
 ; b;c;%22)
+%0A          .build()
 );%0A  %7D%0A%7D

Update test