// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
package com.google.dart.compiler;

import com.google.dart.compiler.SystemLibrariesReader.DartLibrary;

import junit.framework.TestCase;

import java.io.File;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Map;
import java.util.Map.Entry;

/**
 * Test the {@link SystemLibrariesReader}
 */
public class SystemLibrariesReaderTest extends TestCase {

  
  public void testLibrariesFileExists(){
    File sdkLibPath = new File(PackageLibraryManager.DEFAULT_SDK_PATH, "lib");
    File librariesFile = new File(new File(sdkLibPath, SystemLibrariesReader.INTERNAL_DIR), SystemLibrariesReader.LIBRARIES_FILE);
    assertTrue(librariesFile.exists());
  }
  
  public void testLibrariesFileContent() throws URISyntaxException{
    File sdkLibPath = new File(PackageLibraryManager.DEFAULT_SDK_PATH, "lib");
    URI base = sdkLibPath.toURI();
    SystemLibrariesReader reader = new SystemLibrariesReader(sdkLibPath);
    Map<String, DartLibrary> librariesMap = reader.getLibrariesMap();
    assertTrue(!librariesMap.isEmpty());
    for (Entry<String, DartLibrary> entry : librariesMap.entrySet()) {
      String path = entry.getValue().getPath(); 
      File file = new File(base.resolve(new URI(null, null, path, null, null)).normalize());
      assertTrue(file.exists());
   }
   
    // check content
    //   "coreimpl": const LibraryInfo(
    //       "coreimpl/coreimpl_runtime.dart",
    //       implementation: true,
    //       dart2jsPath: "compiler/implementation/lib/coreimpl.dart",
    //       dart2jsPatchPath: "compiler/implementation/lib/coreimpl_patch.dart")
    DartLibrary library = librariesMap.get("dart:coreimpl");
    assertTrue(library != null);
    assertEquals("dart:coreimpl",library.getShortName());
    assertTrue(library.isImplementation());
    assertEquals("Shared", library.getCategory());
  }
  
}

@@ -587,309 +587,8 @@
  %7B%0A%0A
-  %0A  public void testLibrariesFileExists()%7B%0A    File sdkLibPath = new File(PackageLibraryManager.DEFAULT_SDK_PATH, %22lib%22);%0A    File librariesFile = new File(new File(sdkLibPath, SystemLibrariesReader.INTERNAL_DIR), SystemLibrariesReader.LIBRARIES_FILE);%0A    assertTrue(librariesFile.exists());%0A  %7D%0A  %0A
   pu
@@ -649,16 +649,17 @@
 xception
+ 
 %7B%0A    Fi
@@ -1069,17 +1069,16 @@
 tPath();
- 
 %0A      F
@@ -1173,43 +1173,180 @@
     
-assertTrue(file.exists()
+if (!file.exists()) %7B%0A        fail(%22Expected dart:%22 + entry.getKey() + %22 path in libraries.dart to exist in SDK%22%0A            + %22%5Cn  could not find %22 + file
 );%0A   
+  
+ 
 %7D%0A   
+ %7D%0A
 %0A   
@@ -1765,16 +1765,17 @@
 reimpl%22,
+ 
 library.
@@ -1890,13 +1890,316 @@
 ));%0A  %7D%0A
+%0A
   
+public void testLibrariesFileExists() %7B%0A    File sdkLibPath = new File(PackageLibraryManager.DEFAULT_SDK_PATH, %22lib%22);%0A    File librariesFile = new File(new File(sdkLibPath, SystemLibrariesReader.INTERNAL_DIR),%0A        SystemLibrariesReader.LIBRARIES_FILE);%0A    assertTrue(librariesFile.exists());%0A  %7D%0A
 %0A%7D%0A

improve libraries.dart test failure message Review URL: https://chromiumcodereview.appspot.com//10910052