/*
 * Copyright 2014 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 com.google.javascript.jscomp.CompilerOptions.LanguageMode;

/**
 * Test cases for ES6 transpilation. Despite the name, this isn't just testing {@link
 * Es6ToEs3Converter}, but also some other ES6 transpilation passes. See #getProcessor.
 */
public final class Es7RewriteExponentialOperatorTest extends CompilerTestCase {

  public Es7RewriteExponentialOperatorTest() {
    super(MINIMAL_EXTERNS);
  }

  @Override
  protected void setUp() throws Exception {
    super.setUp();
    setAcceptedLanguage(LanguageMode.ECMASCRIPT_2016);
    setLanguageOut(LanguageMode.ECMASCRIPT5);
    enableRunTypeCheckAfterProcessing();
  }

  @Override
  protected CompilerPass getProcessor(Compiler compiler) {
    return new Es7RewriteExponentialOperator(compiler);
  }

  @Override
  protected int getNumRepetitions() {
    return 1;
  }

  public void testExponentiationOperator() {
    test("2 ** 2;", "Math.pow(2,2)");
  }

  public void testExponentiationAssignmentOperator() {
    test("x **= 2;", "x=Math.pow(x,2)");
  }

  public void testIssue2821() {
    test("2 ** 3 > 0", "Math.pow(2, 3) > 0");
  }
}

@@ -715,19 +715,16 @@
 de;%0A%0A/**
-%0A *
  Test ca
@@ -731,20 +731,16 @@
 ses for 
-ES6 
 transpil
@@ -748,147 +748,60 @@
 tion
-. Despite the name, this isn't just testing %7B@link%0A * Es6ToEs3Converter%7D, but also some other ES6 transpilation passes. See #getProcessor.%0A
+ pass that replaces the exponential operator (%60**%60).
  */%0A
@@ -885,88 +885,8 @@
  %7B%0A%0A
-  public Es7RewriteExponentialOperatorTest() %7B%0A    super(MINIMAL_EXTERNS);%0A  %7D%0A%0A
   @O
@@ -956,16 +956,17 @@
 etUp();%0A
+%0A
     setA
@@ -1058,16 +1058,17 @@
 RIPT5);%0A
+%0A
     enab
@@ -1073,35 +1073,49 @@
 able
-RunTypeCheckAfterProcessing
+TypeInfoValidation();%0A    enableTypeCheck
 ();%0A
@@ -1378,19 +1378,33 @@
 est(
+srcs(
 %222 ** 2
-;%22, 
+%22), expected(
 %22Mat
@@ -1411,20 +1411,22 @@
 h.pow(2,
+ 
 2)%22)
+)
 ;%0A  %7D%0A%0A 
@@ -1488,16 +1488,21 @@
    test(
+srcs(
 %22x **= 2
@@ -1507,13 +1507,25 @@
  2;%22
+)
 , 
-%22x=
+expected(%22x = 
 Math
@@ -1531,20 +1531,22 @@
 h.pow(x,
+ 
 2)%22)
+)
 ;%0A  %7D%0A%0A 
@@ -1550,62 +1550,207 @@
 %0A%0A  
-public void test
+/** @see %3Ca href=%22https://github.com/google/closure-compiler/issues/2821%22%3E
 Issue
+ 
 2821
-() %7B%0A    test(%222 ** 3 %3E 0%22, %22
+%3C/a%3E */%0A  public void testExponentialOperatorInIfCondition() %7B%0A    test(srcs(%22if (2 ** 3 %3E 0) %7B %7D%22), expected(%22if (
 Math
@@ -1763,17 +1763,23 @@
 , 3) %3E 0
-%22
+) %7B %7D%22)
 );%0A  %7D%0A%7D

Update `Es7RewriteExponentialOperatorTest` to cover type-checking and use newer test definition syntax.