Cleaning up NNBD tests and migrations.

Change-Id: I0a63a6864c568491ad5e20b6eb490760e620a889
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/130200
Commit-Queue: Mark Zhou <markzipan@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
This commit is contained in:
Mark Zhou 2020-01-09 17:11:46 +00:00 committed by commit-bot@chromium.org
parent e57ac16a85
commit 96cea64fa6
13 changed files with 92 additions and 65 deletions

View file

@ -272,7 +272,7 @@ class _JsonMap extends MapBase<String, dynamic> {
List<String> _computeKeys() {
assert(!_isUpgraded);
List keys = _data;
List? keys = _data;
if (keys == null) {
keys = _data = _getPropertyNames(_original);
}

View file

@ -392,9 +392,9 @@ class JSArray<E> implements List<E>, JSIndexable<E> {
void fillRange(@nullCheck int start, @nullCheck int end, [E? fillValue]) {
checkMutable('fill range');
RangeError.checkValidRange(start, end, this.length);
E checkedFillValue = fillValue as E;
for (int i = start; i < end; i++) {
// Store is safe since [fillValue] type has been checked as parameter.
JS('', '#[#] = #', this, i, fillValue);
JS('', '#[#] = #', this, i, checkedFillValue);
}
}

View file

@ -512,10 +512,10 @@ abstract class _StreamController<T> implements _StreamControllerBase<T> {
// stream is listened to.
// While adding a stream, pending events are moved into the
// state object to allow the state object to use the _varData field.
_PendingEvents<T> get _pendingEvents {
_PendingEvents<T>? get _pendingEvents {
assert(_isInitialState);
if (!_isAddingStream) {
return _varData as _PendingEvents<T>;
return _varData;
}
var state = _varData as _StreamControllerAddStreamState<T>;
return state.varData;

View file

@ -125,7 +125,7 @@ class _BufferingStreamSubscription<T>
* This can only be done once. The pending events object is used for the
* rest of the subscription's life cycle.
*/
void _setPendingEvents(_PendingEvents<T> pendingEvents) {
void _setPendingEvents(_PendingEvents<T>? pendingEvents) {
assert(_pending == null);
if (pendingEvents == null) return;
_pending = pendingEvents;

View file

@ -2248,7 +2248,7 @@ class _Uri implements Uri {
var result = StringBuffer();
var separator = "";
void writeParameter(String key, String value) {
void writeParameter(String key, String? value) {
result.write(separator);
separator = "&";
result.write(Uri.encodeQueryComponent(key));

View file

@ -19,7 +19,7 @@ class TestIterableBase extends Iterable<int> {
final int count;
// call [callback] if generating callbackIndex.
final int callbackIndex;
final Function callback;
final Function? callback;
TestIterableBase(this.length, this.count, this.callbackIndex, this.callback);
Iterator<int> get iterator => new CallbackIterator(this);
}
@ -63,7 +63,7 @@ class CallbackIterator implements Iterator<int> {
void testConstructor() {
// Constructor can make both growable and fixed-length lists.
testGrowable(list) {
Expect.isTrue(list is List<int>);
Expect.isTrue(list is List<int?>);
Expect.isFalse(list is List<String>);
int length = list.length;
list.add(42);
@ -71,7 +71,7 @@ void testConstructor() {
}
testFixedLength(list) {
Expect.isTrue(list is List<int>);
Expect.isTrue(list is List<int?>);
int length = list.length;
Expect.throws(() {
list.add(42);

View file

@ -10,64 +10,82 @@ main() {
// testIterable takes an iterable and a list expected to be equal to
// the iterable's toList result, including the type parameter of the list.
testIterable(<dynamic>[], <dynamic>[]);
testIterable(<int>[], <int>[]);
testIterable(<String>[], <String>[]);
testIterable([1, 2, 3], [1, 2, 3]);
testIterable(<int>[1, 2, 3], <int>[1, 2, 3]);
testIterable(const [1, 2], [1, 2]);
testIterable(const <int>[1, 2], <int>[1, 2]);
testIterable(<dynamic?>[], <dynamic?>[]);
testIterable(<int>[], <int>[], 0);
testIterable(<int?>[], <int?>[]);
testIterable(<String>[], <String>[], "");
testIterable(<String?>[], <String?>[]);
testIterable([1, 2, 3], [1, 2, 3], 0);
testIterable(<int>[1, 2, 3], <int>[1, 2, 3], 0);
testIterable(<int?>[1, 2, 3], <int?>[1, 2, 3]);
testIterable(const [1, 2], [1, 2], 0);
testIterable(const <int>[1, 2], <int>[1, 2], 0);
testIterable(const <int?>[1, 2], <int?>[1, 2]);
testIterable(<dynamic, dynamic>{"x": 1, "y": 1}.keys, <dynamic>["x", "y"]);
testIterable(<String, int>{"x": 1, "y": 1}.keys, <String>["x", "y"]);
testIterable(<String, int>{"x": 1, "y": 1}.keys, <String>["x", "y"], "");
testIterable(<String?, int>{"x": 1, "y": 1}.keys, <String?>["x", "y"]);
testIterable(<dynamic, dynamic>{"x": 2, "y": 3}.values, <dynamic>[2, 3]);
testIterable(<String, int>{"x": 2, "y": 3}.values, <int>[2, 3]);
testIterable(new Iterable.generate(3), [0, 1, 2]);
testIterable(new Iterable<int>.generate(3), <int>[0, 1, 2]);
testIterable(<String, int>{"x": 2, "y": 3}.values, <int>[2, 3], 0);
testIterable(<String, int?>{"x": 2, "y": 3}.values, <int?>[2, 3]);
testIterable(new Iterable.generate(3), [0, 1, 2], 0);
testIterable(new Iterable<int>.generate(3), <int>[0, 1, 2], 0);
testIterable(new Iterable<int?>.generate(3), <int?>[0, 1, 2]);
testIterable(new Iterable<String>.generate(3, (x) => "$x"),
<String>["0", "1", "2"], "");
testIterable(
new Iterable<String>.generate(3, (x) => "$x"), <String>["0", "1", "2"]);
testIterable(new Set.from([1, 2, 3]), [1, 2, 3]);
testIterable(new Set<int>.from([1, 2, 3]), <int>[1, 2, 3]);
testIterable(new Queue.from([1, 2, 3]), [1, 2, 3]);
testIterable(new Queue<int>.from(<int>[1, 2, 3]), <int>[1, 2, 3]);
new Iterable<String?>.generate(3, (x) => "$x"), <String?>["0", "1", "2"]);
testIterable(new Set.from([1, 2, 3]), [1, 2, 3], 0);
testIterable(new Set<int>.from([1, 2, 3]), <int>[1, 2, 3], 0);
testIterable(new Set<int?>.from([1, 2, 3]), <int?>[1, 2, 3]);
testIterable(new Queue.from([1, 2, 3]), [1, 2, 3], 0);
testIterable(new Queue<int>.from(<int>[1, 2, 3]), <int>[1, 2, 3], 0);
testIterable(new Queue<int?>.from(<int?>[1, 2, 3]), <int?>[1, 2, 3]);
testIterable(new Uint8List.fromList(<int>[1, 2, 3]), // //# 01: ok
<int>[1, 2, 3]); // //# 01: continued
<int>[1, 2, 3], 0); // //# 01: continued
testIterable(new Float32List.fromList([1.0, 2.0, 3.0]), // //# 01: continued
<double>[1.0, 2.0, 3.0]); // //# 01: continued
<double>[1.0, 2.0, 3.0], 0.1); // //# 01: continued
testIterable("abc".codeUnits, <int>[97, 98, 99]); // //# 01: continued
testIterable("abc".runes, <int>[97, 98, 99]);
testIterable("abc".runes, <int>[97, 98, 99], 99);
}
testIterable(Iterable iterable, List expected, [int depth = 0]) {
testIterable(Iterable iterable, List expected, [element, int depth = 0]) {
print(" " * depth + "${iterable.runtimeType} vs ${expected.runtimeType}");
test(iterable, expected);
test(iterable, expected, growable: true);
test(iterable, expected, growable: false);
test(iterable, expected, element);
test(iterable, expected, element, growable: true);
test(iterable, expected, element, growable: false);
if (depth < 2) {
depth++;
testIterable(iterable.map((x) => x), new List.from(expected), depth);
testIterable(iterable.where((x) => true), expected, depth);
testIterable(iterable.expand((x) => [x]), new List.from(expected), depth);
testIterable(iterable.map((x) => x), new List.from(expected), depth);
testIterable(iterable.skipWhile((x) => false), expected, depth);
testIterable(iterable.takeWhile((x) => true), expected, depth);
testIterable(iterable.skip(0), expected, depth);
testIterable(iterable.take(expected.length * 2), expected, depth);
testIterable(iterable.toSet(), expected, depth);
testIterable(
iterable.map((x) => x), new List.from(expected), element, depth);
testIterable(iterable.where((x) => true), expected, element, depth);
testIterable(
iterable.expand((x) => [x]), new List.from(expected), element, depth);
testIterable(
iterable.map((x) => x), new List.from(expected), element, depth);
testIterable(iterable.skipWhile((x) => false), expected, element, depth);
testIterable(iterable.takeWhile((x) => true), expected, element, depth);
testIterable(iterable.skip(0), expected, element, depth);
testIterable(iterable.take(expected.length * 2), expected, element, depth);
testIterable(iterable.toSet(), expected, element, depth);
}
}
test(Iterable iterable, List expected, {bool growable: true}) {
test(Iterable iterable, List expected, element, {bool growable: true}) {
var list = iterable.toList(growable: growable);
Expect.listEquals(expected, list);
Expect.equals(expected is List<int>, list is List<int>, "int");
Expect.equals(expected is List<int?>, list is List<int?>, "int?");
Expect.equals(expected is List<double>, list is List<double>, "double");
Expect.equals(expected is List<String>, list is List<String>, "str");
Expect.equals(expected is List<String?>, list is List<String?>, "str?");
if (growable) {
int length = list.length;
list.add(null);
list.add(element);
Expect.equals(length + 1, list.length);
} else {
Expect.throws(() {
list.add(null);
list.add(element);
});
}
}

View file

@ -29,8 +29,7 @@ test(List expects, Iterable iterable, [String? name]) {
expect, iterable.elementAt(index), "$name: elementAt($index)");
Expect.isTrue(iterable.contains(expect), "$name:contains $index");
}
Expect.isFalse(it.moveNext(),
"$name: extra element at ${expects.length}: ${it.current}");
Expect.isFalse(it.moveNext(), "$name: extra element at ${expects.length}");
} on Error {
print("Failed during: $name");
rethrow;
@ -70,10 +69,15 @@ main() {
var c = new C();
var d = new D();
var n = null;
test([o, a, b, c, d, n], [o, a, b, c, d, n].whereType<Object>(), "Object");
test([o, a, b, c, d, n], [o, a, b, c, d, n].whereType<Object?>(), "Object?");
test([o, a, b, c, d], [o, a, b, c, d, n].whereType<Object>(), "Object");
test([a, b, c, d, n], [o, a, b, c, d, n].whereType<A?>(), "A?");
test([a, b, c, d], [o, a, b, c, d, n].whereType<A>(), "A");
test([b, d, n], [o, a, b, c, d, n].whereType<B?>(), "B?");
test([b, d], [o, a, b, c, d, n].whereType<B>(), "B");
test([c, d, n], [o, a, b, c, d, n].whereType<C?>(), "C?");
test([c, d], [o, a, b, c, d, n].whereType<C>(), "C");
test([d, n], [o, a, b, c, d, n].whereType<D?>(), "D?");
test([d], [o, a, b, c, d, n].whereType<D>(), "D");
test([n], [o, a, b, c, d, n].whereType<Null>(), "Null");

View file

@ -5,7 +5,7 @@
import "package:expect/expect.dart";
import "dart:collection";
test(List list, int start, int end, [fillValue]) {
test(List list, int start, int end, [fillValue = 42]) {
List copy = list.toList();
list.fillRange(start, end, fillValue);
Expect.equals(copy.length, list.length);

View file

@ -7,7 +7,7 @@ import "dart:collection";
import "dart:typed_data";
main() {
var intTest = new Test<int>();
var intTest = new Test<int>(0);
intTest.run("ConstList", createConstList);
intTest.run("FixedList", createFixedList);
intTest.run("GrowableList", createGrowableList);
@ -25,13 +25,17 @@ main() {
intTest.run("CodeUnits", createCodeUnits);
intTest.run("TypedList", createTypedList);
new Test<String>().test("strings", ["a", "b", "c"]);
new Test<String>("").test("strings", ["a", "b", "c"]);
new Test<num>().test("superclass", <int>[1, 2, 3]);
new Test<int>().test("subclass", <num>[1, 2, 3]);
new Test<num>(0).test("superclass", <int>[1, 2, 3]);
new Test<int>(0).test("subclass", <num>[1, 2, 3]);
}
class Test<E> {
final E element;
Test(this.element);
run(name, Iterable create(int size)) {
test(name, create(0));
test(name, create(1));
@ -53,7 +57,7 @@ class Test<E> {
var elements = iterable.toList();
int length = elements.length;
var list = new List<E?>.unmodifiable(iterable);
var list = new List<E>.unmodifiable(iterable);
Expect.isTrue(list is List<E>, "$name-type-$E");
Expect.isTrue(list is! List<Test>, "$name-!type-!$E");
@ -79,7 +83,7 @@ class Test<E> {
}
throws("[]=", () {
list[0] = null;
list[0] = element;
});
throws("length=", () {
list.length = length + 1;
@ -91,10 +95,10 @@ class Test<E> {
list.setAll(0, []);
});
throws("add", () {
list.add(null);
list.add(element);
});
throws("insert", () {
list.insert(0, null);
list.insert(0, element);
});
throws("insertAll", () {
list.insertAll(0, []);
@ -103,7 +107,7 @@ class Test<E> {
list.addAll([]);
});
throws("remove", () {
list.remove(null);
list.remove(element);
});
throws("removeWhere", () {
list.removeWhere((x) => true);
@ -136,7 +140,7 @@ class Test<E> {
list.replaceRange(0, 1, []);
});
throws("fillRange", () {
list.fillRange(0, 1, null);
list.fillRange(0, 1, element);
});
success(opName, op(List list), [bool throws = false]) {
@ -170,8 +174,8 @@ class Test<E> {
}
}
success("indexOf", (l) => l.indexOf(null));
success("lastIndexOf", (l) => l.lastIndexOf(null));
success("indexOf", (l) => l.indexOf(element));
success("lastIndexOf", (l) => l.lastIndexOf(element));
success("contains", (l) => l.contains(2));
success("elementAt", (l) => l.elementAt(1), list.length < 2);
success("reversed", (l) => l.reversed);

View file

@ -19,8 +19,8 @@ void main() {
test(new MapView(new HashMap()));
test(new MapBaseMap());
test(new MapMixinMap());
test(newJsonMap());
test(newJsonMapCustomReviver());
testNonNull(newJsonMap());
testNonNull(newJsonMapCustomReviver());
testNonNull(new SplayTreeMap());
testNonNull(new SplayTreeMap((a, b) => Comparable.compare(a!, b!)));
testNonNull(new MapView(new SplayTreeMap()));
@ -209,4 +209,4 @@ class TestKeyIterator<K> implements Iterator<K> {
K get current => _current;
}
Null unreachable([_, __]) => throw "unreachable";
Never unreachable([_, __]) => throw "unreachable";

View file

@ -9,7 +9,8 @@ import "package:expect/expect.dart";
main() {
var x;
Expect.isTrue(x is Object);
Expect.isTrue(x is Object?);
Expect.isTrue(x is! Object);
Expect.isTrue(x is dynamic);
Expect.isTrue(x is! String);
Expect.isTrue(x is! int);

View file

@ -86,7 +86,7 @@ void testListRead(list, index) {
void testListWrite(list, index) {
var exception = null;
try {
list[index] = null;
list[index] = 0;
} on RangeError catch (e) {
exception = e;
}