Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Side by Side Diff: dart/editor/tools/plugins/com.google.dart.engine_test/src/com/google/dart/engine/source/ExplicitPackageUriResolverTest.java

Issue 126303002: Version 1.1.0-dev.5.3 (Closed) Base URL: http://dart.googlecode.com/svn/trunk/
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012, the Dart project authors. 2 * Copyright (c) 2012, the Dart project authors.
3 * 3 *
4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u se this file except 4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u se this file except
5 * in compliance with the License. You may obtain a copy of the License at 5 * in compliance with the License. You may obtain a copy of the License at
6 * 6 *
7 * http://www.eclipse.org/legal/epl-v10.html 7 * http://www.eclipse.org/legal/epl-v10.html
8 * 8 *
9 * Unless required by applicable law or agreed to in writing, software distribut ed under the License 9 * Unless required by applicable law or agreed to in writing, software distribut ed under the License
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K IND, either express 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K IND, either express
11 * or implied. See the License for the specific language governing permissions a nd limitations under 11 * or implied. See the License for the specific language governing permissions a nd limitations under
12 * the License. 12 * the License.
13 */ 13 */
14 package com.google.dart.engine.source; 14 package com.google.dart.engine.source;
15 15
16 import com.google.dart.engine.utilities.io.FileUtilities2; 16 import com.google.dart.engine.utilities.io.FileUtilities2;
17 17
18 import static com.google.dart.engine.utilities.io.FileUtilities2.createFile; 18 import static com.google.dart.engine.utilities.io.FileUtilities2.createFile;
19 19
20 import junit.framework.TestCase; 20 import junit.framework.TestCase;
21 21
22 import org.json.JSONException; 22 import org.json.JSONException;
23 23
24 import java.io.File; 24 import java.io.File;
25 import java.net.URI; 25 import java.net.URI;
26 import java.net.URISyntaxException; 26 import java.net.URISyntaxException;
27 import java.util.HashMap; 27 import java.util.HashMap;
28 import java.util.List; 28 import java.util.List;
29 import java.util.Map; 29 import java.util.Map;
30 30
31 public class ExplicitPackageUriResolverTest extends TestCase { 31 public class ExplicitPackageUriResolverTest extends TestCase {
32 32
33 static class MockExplicitPackageUriResolver extends ExplicitPackageUriResolver { 33 public static class MockExplicitPackageUriResolver extends ExplicitPackageUriR esolver {
34
35 String jsonText = "{\"foo\":\"bar\"}";
36
34 public MockExplicitPackageUriResolver(File rootDir) { 37 public MockExplicitPackageUriResolver(File rootDir) {
35 super(null, rootDir); 38 super(null, rootDir);
36 } 39 }
37 40
41 public MockExplicitPackageUriResolver(File rootDir, String jsonPackageList) {
42 super(null, rootDir);
43 if (!jsonPackageList.isEmpty()) {
44 jsonText = jsonPackageList;
45 packageMap = calculatePackageMap();
46 }
47 }
48
38 @Override 49 @Override
39 protected Map<String, List<File>> calculatePackageMap() { 50 protected Map<String, List<File>> calculatePackageMap() {
40 final String jsonText = "{\"foo\":\"bar\"}";
41
42 try { 51 try {
43 return parsePackageMap(jsonText); 52 return parsePackageMap(jsonText);
44 } catch (JSONException e) { 53 } catch (JSONException e) {
45 return new HashMap<String, List<File>>(); 54 return new HashMap<String, List<File>>();
46 } 55 }
47 } 56 }
48 } 57 }
49 58
50 public void test_creation() { 59 public void test_creation() {
51 File directory = createFile("/does/not/exist/foo_project"); 60 File directory = createFile("/does/not/exist/foo_project");
(...skipping 23 matching lines...) Expand all
75 } 84 }
76 85
77 public void test_resolve_nonPackage() throws Exception { 86 public void test_resolve_nonPackage() throws Exception {
78 ContentCache contentCache = new ContentCache(); 87 ContentCache contentCache = new ContentCache();
79 File directory = createFile("/does/not/exist/foo_project"); 88 File directory = createFile("/does/not/exist/foo_project");
80 UriResolver resolver = new MockExplicitPackageUriResolver(directory); 89 UriResolver resolver = new MockExplicitPackageUriResolver(directory);
81 Source result = resolver.resolveAbsolute(contentCache, new URI("dart:core")) ; 90 Source result = resolver.resolveAbsolute(contentCache, new URI("dart:core")) ;
82 assertNull(result); 91 assertNull(result);
83 } 92 }
84 93
94 public void test_resolve_resolvePathToPackage() throws Exception {
95 File directory = createFile("/src/foo/bar/baz/lib");
96 String packages = "{\"packages\":{\"unittest\": [\"/dart/unittest/lib\"],"
97 + "\"foo.bar.baz\": [\"/src/foo/bar/baz/lib\",\"/gen/foo/bar/baz\"]}}";
98 ExplicitPackageUriResolver resolver = new MockExplicitPackageUriResolver(dir ectory, packages);
99 String resolvedPath = resolver.resolvePathToPackage(File.separator + "baz" + File.separator
100 + "lib");
101 assertNotNull(resolvedPath);
102 assertEquals("foo.bar.baz", resolvedPath);
103 resolvedPath = resolver.resolvePathToPackage(File.separator + "dart" + File. separator
104 + "mypackage");
105 assertNull(resolvedPath);
106 }
107
85 @Override 108 @Override
86 protected void tearDown() throws Exception { 109 protected void tearDown() throws Exception {
87 FileUtilities2.deleteTempDir(); 110 FileUtilities2.deleteTempDir();
88 } 111 }
89 } 112 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698