/*
 * Copyright 2016 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 static com.google.common.truth.Truth.assertThat;

import junit.framework.TestCase;

/**
 * Tests {@link GwtProperties}.
 */
public final class GwtPropertiesTest extends TestCase {

  public void testLoadEmpty() {
    GwtProperties p = GwtProperties.load("");
    assertThat(p.propertyNames()).isEmpty();
  }

  public void testLoadWithComments() {
    String src = "\n"
        + "# not.set=value\n"
        + "is.set=value\n";
    GwtProperties p = GwtProperties.load(src);

    assertEquals(null, p.getProperty("not.set"));
    assertEquals("value", p.getProperty("is.set"));
  }

  public void testNoEquals() {
    GwtProperties p = GwtProperties.load("foo bar");
    assertEquals("bar", p.getProperty("foo"));
  }

  public void testExtraCR() {
    GwtProperties p = GwtProperties.load("value is \\\r\nradical");
    assertEquals("is radical", p.getProperty("value"));
  }

  public void testLongValue() {
    String src = "\n"
        + "property : 1,\\\n"
        + "   2,\\\n"
        + "   3\n";
    GwtProperties p = GwtProperties.load(src);

    assertEquals("1,2,3", p.getProperty("property"));
  }

}

@@ -1009,32 +1009,40 @@
     String src =
+%0A       
  %22%5Cn%22%0A        + 
@@ -1039,16 +1039,20 @@
         
+   
+ 
 + %22# not
@@ -1073,16 +1073,20 @@
         
+    
 + %22is.se
@@ -1095,16 +1095,145 @@
 value%5Cn%22
+%0A            + %22a = aaa%5Cn%22%0A            + %22b  = bbb%5Cn%22%0A            + %22c =ccc%5Cn%22%0A            + %22d= ddd%5Cn%22%0A            + %22e=  eee%5Cn%22
 ;%0A    Gw
@@ -1372,24 +1372,583 @@
 %22is.set%22));%0A
+    assertEquals(%22aaa%22, p.getProperty(%22a%22));%0A    assertEquals(%22bbb%22, p.getProperty(%22b%22));%0A    assertEquals(%22ccc%22, p.getProperty(%22c%22));%0A    assertEquals(%22ddd%22, p.getProperty(%22d%22));%0A    assertEquals(%22eee%22, p.getProperty(%22e%22));%0A  %7D%0A%0A  // https://en.wikipedia.org/wiki/.properties%0A  public void testSpaceEscapeNotSupported() %7B%0A    String src = %22key%5C%5C with%5C%5C spaces = value%5Cn%22;%0A    GwtProperties p = GwtProperties.load(src);%0A    // Asserts that we do not correctly handle escaped spaces.%0A    assertThat(p.getProperty(%22key%5C%5C with%5C%5C spaces%22)).isNotEqualTo(%22value%22);%0A
   %7D%0A%0A  publi

Add more test cases to GwtPropertiesTest.