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

Side by Side Diff: packages/package_config/test/parse_write_test.dart

Issue 1400473008: Roll Observatory packages and add a roll script (Closed) Base URL: git@github.com:dart-lang/observatory_pub_packages.git@master
Patch Set: Created 5 years, 2 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
« no previous file with comments | « packages/package_config/test/parse_test.dart ('k') | packages/package_config/tool/travis.sh » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 library package_config.parse_write_test;
6
7 import "package:package_config/packages_file.dart";
8 import "package:test/test.dart";
9
10 main() {
11 testBase(baseDirString) {
12 var baseDir = Uri.parse(baseDirString);
13 group("${baseDir.scheme} base", () {
14 Uri packagesFile = baseDir.resolve(".packages");
15
16 roundTripTest(String name, Map<String, Uri> map) {
17 group(name, () {
18 test("write with no baseUri", () {
19 var content = writeToString(map).codeUnits;
20 var resultMap = parse(content, packagesFile);
21 expect(resultMap, map);
22 });
23
24 test("write with base directory", () {
25 var content = writeToString(map, baseUri: baseDir).codeUnits;
26 var resultMap = parse(content, packagesFile);
27 expect(resultMap, map);
28 });
29
30 test("write with base .packages file", () {
31 var content = writeToString(map, baseUri: packagesFile).codeUnits;
32 var resultMap = parse(content, packagesFile);
33 expect(resultMap, map);
34 });
35 });
36 }
37 var lowerDir = baseDir.resolve("path3/path4/");
38 var higherDir = baseDir.resolve("../");
39 var parallelDir = baseDir.resolve("../path3/");
40 var rootDir = baseDir.resolve("/");
41 var fileDir = Uri.parse("file:///path1/part2/");
42 var httpDir = Uri.parse("http://example.com/path1/path2/");
43 var otherDir = Uri.parse("other:/path1/path2/");
44
45 roundTripTest("empty", {});
46 roundTripTest("lower directory", {"foo": lowerDir});
47 roundTripTest("higher directory", {"foo": higherDir});
48 roundTripTest("parallel directory", {"foo": parallelDir});
49 roundTripTest("same directory", {"foo": baseDir});
50 roundTripTest("root directory", {"foo": rootDir});
51 roundTripTest("file directory", {"foo": fileDir});
52 roundTripTest("http directory", {"foo": httpDir});
53 roundTripTest("other scheme directory", {"foo": otherDir});
54 roundTripTest("multiple same-type directories",
55 {"foo": lowerDir, "bar": higherDir, "baz": parallelDir});
56 roundTripTest("multiple scheme directories",
57 {"foo": fileDir, "bar": httpDir, "baz": otherDir});
58 roundTripTest("multiple scheme directories and mutliple same type",
59 {"foo": fileDir, "bar": httpDir, "baz": otherDir,
60 "qux": lowerDir, "hip": higherDir, "dep": parallelDir});
61 });
62 }
63
64 testBase("file:///base1/base2/");
65 testBase("http://example.com/base1/base2/");
66 testBase("other:/base1/base2/");
67
68 // Check that writing adds the comment.
69 test("write preserves comment", () {
70 var comment = "comment line 1\ncomment line 2\ncomment line 3";
71 var result = writeToString({}, comment: comment);
72 // Comment with "# " before each line and "\n" after last.
73 var expectedComment =
74 "# comment line 1\n# comment line 2\n# comment line 3\n";
75 expect(result, startsWith(expectedComment));
76 });
77 }
78
79 String writeToString(Map map, {Uri baseUri, String comment}) {
80 var buffer = new StringBuffer();
81 write(buffer, map, baseUri: baseUri, comment: comment);
82 return buffer.toString();
83 }
OLDNEW
« no previous file with comments | « packages/package_config/test/parse_test.dart ('k') | packages/package_config/tool/travis.sh » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698