-
Notifications
You must be signed in to change notification settings - Fork 122
/
Copy pathpackage_meta_test.dart
163 lines (133 loc) · 4.69 KB
/
package_meta_test.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
// Copyright (c) 2015, 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.
library dartdoc.package_utils_test;
import 'dart:io';
import 'package:dartdoc/src/package_meta.dart';
import 'package:path/path.dart' as path;
import 'package:pub_semver/pub_semver.dart';
import 'package:test/test.dart';
void main() {
group('NNBD', () {
void expectVersion(String version, bool expectation) {
var parsedVersion = Version.parse(version);
if (expectation == false) {
sdkNullableRanges.map((v) {
expect(v.allows(parsedVersion), isFalse);
});
} else {
expect(sdkNullableRanges.any((v) => v.allows(parsedVersion)), isTrue);
}
}
test('nnbd sdk ranges allow correct versions', () {
expectVersion(
'2.9.0-edge.b2d41ab0a219af9342fdf205e97bed68011fed51', true);
expectVersion('2.9.0-13.0.dev', true);
expectVersion('2.9.0-16.0.dev', true);
expectVersion('2.9.0-1.0.beta', true);
expectVersion('2.9.0', true);
expectVersion('2.10.0', true);
});
test('nnbd sdk ranges disallow other versions', () {
expectVersion('2.9.0-8.0.dev', false);
expectVersion('2.8.4', false);
expectVersion('2.0.0', false);
});
test('PackageMeta for a NNBD enabled package allows NNBD', () {
var p = pubPackageMetaProvider.fromDir(Directory(path.join(
Directory.current.path, 'testing', 'test_package_experiments')));
expect(p.allowsNNBD, isTrue);
});
test('PackageMeta for a non-NNBD enabled package disallows NNBD', () {
var p = pubPackageMetaProvider.fromDir(Directory(
path.join(Directory.current.path, 'testing', 'test_package')));
expect(p.allowsNNBD, isFalse);
});
});
group('PackageMeta for a directory without a pubspec', () {
PackageMeta p;
setUp(() {
var d = Directory.systemTemp.createTempSync('test_package_not_valid');
p = pubPackageMetaProvider.fromDir(d);
});
test('is not valid', () {
expect(p, isNull);
});
});
group('PackageMeta for the test package', () {
var p = pubPackageMetaProvider.fromDir(Directory(
path.join(Directory.current.path, 'testing', 'test_package')));
test('readme with corrupt UTF-8 loads without throwing', () {
expect(p.getReadmeContents().contents,
contains('Here is some messed up UTF-8.\nÃf'));
});
});
group('PackageMeta.fromDir for this package', () {
var p = pubPackageMetaProvider.fromDir(Directory.current);
test('has a name', () {
expect(p.name, 'dartdoc');
});
test('has a version', () {
expect(p.version, isNotNull);
});
test('has a description', () {
expect(
p.description,
equals(
'A non-interactive HTML documentation generator for Dart source code.'));
});
test('has a homepage', () {
expect(p.homepage, equals('https://github.com/dart-lang/dartdoc'));
});
test('is valid', () {
expect(p.isValid, isTrue);
expect(p.getInvalidReasons(), isEmpty);
});
test('has a readme', () {
expect(p.getReadmeContents(), isNotNull);
expect(
p.getReadmeContents().contents,
contains(
'Use `dartdoc` to generate HTML documentaton for your Dart package.'));
});
test('has a license', () {
expect(p.getLicenseContents(), isNotNull);
expect(p.getLicenseContents().contents,
contains('Copyright 2014, the Dart project authors.'));
});
test('has a changelog', () {
expect(p.getChangelogContents(), isNotNull);
expect(p.getChangelogContents().contents, contains('## 0.2.2'));
});
});
group('PackageMeta.fromSdk', () {
var p = pubPackageMetaProvider.fromDir(defaultSdkDir);
test('has a name', () {
expect(p.name, 'Dart');
});
test('is valid', () {
expect(p.isValid, isTrue);
expect(p.getInvalidReasons(), isEmpty);
expect(p.isSdk, isTrue);
});
test('has a version', () {
expect(p.version, isNotNull);
});
test('has a description', () {
expect(
p.description,
equals(
'The Dart SDK is a set of tools and libraries for the Dart programming language.'));
});
test('has a homepage', () {
expect(p.homepage, equals('https://github.com/dart-lang/sdk'));
});
test('has a readme', () {
expect(p.getReadmeContents(), isNotNull);
expect(p.getReadmeContents().contents, startsWith('Welcome'));
});
test('does not have a license', () {
expect(p.getLicenseContents(), isNull);
});
});
}