Skip to content
This repository was archived by the owner on Apr 30, 2021. It is now read-only.

Commit 0ee3334

Browse files
committed
pkgspec parsing.
1 parent 4d8c35d commit 0ee3334

File tree

6 files changed

+61
-1
lines changed

6 files changed

+61
-1
lines changed

lib/src/utils.dart

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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 analyzer_cli.src.utils;
6+
7+
import 'dart:io';
8+
9+
/// Parses a package map cfg file into a String map.
10+
Map<String, String> readPackageMap(File file) {
11+
var map = <String, String>{};
12+
file.readAsLinesSync().forEach((String line) {
13+
if (!line.startsWith('#')) {
14+
var entry = line.split('=');
15+
map[entry[0]] = entry[1];
16+
}
17+
});
18+
return map;
19+
}

test/all.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import 'package:unittest/unittest.dart';
77
import 'error_test.dart' as error;
88
import 'options_test.dart' as options;
99
import 'reporter_test.dart' as reporter;
10+
import 'utils_test.dart' as utils;
1011

1112
main() {
1213
// Tidy up output.
@@ -16,4 +17,5 @@ main() {
1617
error.main();
1718
options.main();
1819
reporter.main();
20+
utils.main();
1921
}

test/data/test.cfg

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# This file has been generate by the Dart tool pub on Apr 14 09:14:14 2015.
2+
# It contains a map from Dart package names to Dart package locations.
3+
# Dart tools, including Dart VM and and Dart analyzer, rely on the content.
4+
# AUTO GENERATED - DO NOT EDIT
5+
unittest=/home/somebody/.pub/cache/unittest-0.9.9/lib/
6+
async=/home/somebody/.pub/cache/async-1.1.0/lib/
7+
quiver=/home/somebody/.pub/cache/quiver-1.2.1/lib/

test/error_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ library analyzer_cli.test.error;
66

77
import 'package:unittest/unittest.dart';
88

9-
import 'utils.dart';
9+
import 'test_utils.dart';
1010

1111
void main() {
1212
groupSep = ' | ';
File renamed without changes.

test/utils_test.dart

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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 analyzer_cli.test.utils;
6+
7+
import 'dart:io';
8+
9+
import 'package:analyzer_cli/src/utils.dart';
10+
import 'package:unittest/unittest.dart';
11+
12+
main() {
13+
groupSep = ' | ';
14+
15+
defineTests();
16+
}
17+
18+
defineTests() {
19+
group('utils', () {
20+
group('packagemap.cfg', () {
21+
test('parsing', () {
22+
var map = readPackageMap(new File('test/data/test.cfg'));
23+
expect(map, containsPair(
24+
'unittest', '/home/somebody/.pub/cache/unittest-0.9.9/lib/'));
25+
expect(map, containsPair(
26+
'async', '/home/somebody/.pub/cache/async-1.1.0/lib/'));
27+
expect(map, containsPair(
28+
'quiver', '/home/somebody/.pub/cache/quiver-1.2.1/lib/'));
29+
});
30+
});
31+
});
32+
}

0 commit comments

Comments
 (0)