mirror of
https://github.com/dart-lang/sdk
synced 2024-09-05 00:13:50 +00:00
Migrate dart2js unit tests of the ancient unittest package.
These were easy enough to simplify all the way down to just using expect, so I did that. Change-Id: Ibeefbd8b22319258de1c2e92b026ac31bf9d5eae Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/136021 Commit-Queue: Bob Nystrom <rnystrom@google.com> Commit-Queue: Mayank Patke <fishythefish@google.com> Auto-Submit: Bob Nystrom <rnystrom@google.com> Reviewed-by: Mayank Patke <fishythefish@google.com>
This commit is contained in:
parent
d39cdf03f8
commit
11ae06e988
|
@ -2,63 +2,53 @@
|
|||
// 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.
|
||||
|
||||
import 'package:unittest/unittest.dart';
|
||||
import 'package:expect/expect.dart';
|
||||
import 'helpers/lax_json.dart';
|
||||
|
||||
void main() {
|
||||
test('primitives', () {
|
||||
expect(decode('true'), equals(true));
|
||||
expect(decode(' true'), equals(true));
|
||||
expect(decode('true '), equals(true));
|
||||
expect(decode('true// '), equals(true));
|
||||
expect(decode('// \ntrue'), equals(true));
|
||||
expect(decode('\ttrue\r'), equals(true));
|
||||
expect(decode('\t\ntrue\r\n'), equals(true));
|
||||
expect(decode('true/* */'), equals(true));
|
||||
expect(decode('/* */true'), equals(true));
|
||||
expect(decode('/* false */true '), equals(true));
|
||||
// Primitives.
|
||||
Expect.isTrue(decode('true'));
|
||||
Expect.isTrue(decode(' true'));
|
||||
Expect.isTrue(decode('true '));
|
||||
Expect.isTrue(decode('true// '));
|
||||
Expect.isTrue(decode('// \ntrue'));
|
||||
Expect.isTrue(decode('\ttrue\r'));
|
||||
Expect.isTrue(decode('\t\ntrue\r\n'));
|
||||
Expect.isTrue(decode('true/* */'));
|
||||
Expect.isTrue(decode('/* */true'));
|
||||
Expect.isTrue(decode('/* false */true '));
|
||||
|
||||
expect(decode('false'), equals(false));
|
||||
expect(decode('null'), equals(null));
|
||||
});
|
||||
Expect.isFalse(decode('false'));
|
||||
Expect.isNull(decode('null'));
|
||||
|
||||
test('string', () {
|
||||
expect(decode('"foo"'), equals("foo"));
|
||||
expect(decode('"foo bar baz"'), equals("foo bar baz"));
|
||||
expect(decode(r'"\""'), equals(r'"'));
|
||||
expect(decode(r'"\\"'), equals(r'\'));
|
||||
expect(decode(r'"\/"'), equals('/'));
|
||||
expect(decode(r'"\b"'), equals('\b'));
|
||||
expect(decode(r'"\f"'), equals('\f'));
|
||||
expect(decode(r'"\r"'), equals('\r'));
|
||||
expect(decode(r'"\n"'), equals('\n'));
|
||||
expect(decode(r'"\t"'), equals('\t'));
|
||||
expect(decode(r'"\t\"\\\/\f\nfoo\r\t"'), equals('\t\"\\/\f\nfoo\r\t'));
|
||||
});
|
||||
// Strings.
|
||||
Expect.equals(decode('"foo"'), "foo");
|
||||
Expect.equals(decode('"foo bar baz"'), "foo bar baz");
|
||||
Expect.equals(decode(r'"\""'), r'"');
|
||||
Expect.equals(decode(r'"\\"'), r'\');
|
||||
Expect.equals(decode(r'"\/"'), '/');
|
||||
Expect.equals(decode(r'"\b"'), '\b');
|
||||
Expect.equals(decode(r'"\f"'), '\f');
|
||||
Expect.equals(decode(r'"\r"'), '\r');
|
||||
Expect.equals(decode(r'"\n"'), '\n');
|
||||
Expect.equals(decode(r'"\t"'), '\t');
|
||||
Expect.equals(decode(r'"\t\"\\\/\f\nfoo\r\t"'), '\t\"\\/\f\nfoo\r\t');
|
||||
|
||||
test('list', () {
|
||||
expect(decode('[]'), equals([]));
|
||||
expect(decode('[\n]'), equals([]));
|
||||
expect(decode('["foo"]'), equals(['foo']));
|
||||
expect(decode('["foo",]'), equals(['foo']));
|
||||
expect(decode('["foo", "bar", true, \nnull\n,false,]'),
|
||||
equals(['foo', 'bar', true, null, false]));
|
||||
});
|
||||
// Lists.
|
||||
Expect.listEquals(decode('[]'), []);
|
||||
Expect.listEquals(decode('[\n]'), []);
|
||||
Expect.listEquals(decode('["foo"]'), ['foo']);
|
||||
Expect.listEquals(decode('["foo",]'), ['foo']);
|
||||
Expect.listEquals(decode('["foo", "bar", true, \nnull\n,false,]'),
|
||||
['foo', 'bar', true, null, false]);
|
||||
|
||||
test('map', () {
|
||||
expect(decode('{}'), equals({}));
|
||||
expect(decode('{\n}'), equals({}));
|
||||
expect(decode('{"foo":"bar"}'), equals({'foo': 'bar'}));
|
||||
expect(decode('{"foo":"bar",}'), equals({'foo': 'bar'}));
|
||||
expect(
|
||||
decode('{"foo":true, "bar": false, "baz": true, '
|
||||
'"boz": \nnull\n,"qux": false,}'),
|
||||
equals({
|
||||
'foo': true,
|
||||
'bar': false,
|
||||
'baz': true,
|
||||
'boz': null,
|
||||
'qux': false
|
||||
}));
|
||||
});
|
||||
// Maps.
|
||||
Expect.mapEquals(decode('{}'), {});
|
||||
Expect.mapEquals(decode('{\n}'), {});
|
||||
Expect.mapEquals(decode('{"foo":"bar"}'), {'foo': 'bar'});
|
||||
Expect.mapEquals(decode('{"foo":"bar",}'), {'foo': 'bar'});
|
||||
Expect.mapEquals(
|
||||
decode('{"foo":true, "bar": false, "baz": true, '
|
||||
'"boz": \nnull\n,"qux": false,}'),
|
||||
{'foo': true, 'bar': false, 'baz': true, 'boz': null, 'qux': false});
|
||||
}
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'dart:convert';
|
||||
import 'package:expect/expect.dart';
|
||||
import 'package:source_maps/source_maps.dart';
|
||||
import 'package:unittest/unittest.dart';
|
||||
import 'tools/load.dart';
|
||||
import 'tools/save.dart';
|
||||
|
||||
|
@ -45,32 +45,33 @@ const String HUMAN_READABLE_SOURCE_MAP = '''
|
|||
}''';
|
||||
|
||||
void main() {
|
||||
test('read/write', () {
|
||||
SingleMapping sourceMap =
|
||||
new SingleMapping.fromJson(json.decode(SOURCEMAP));
|
||||
String humanReadable = convertToHumanReadableSourceMap(sourceMap);
|
||||
SingleMapping sourceMap2 = convertFromHumanReadableSourceMap(humanReadable);
|
||||
String humanReadable2 = convertToHumanReadableSourceMap(sourceMap2);
|
||||
SingleMapping sourceMap3 =
|
||||
convertFromHumanReadableSourceMap(humanReadable2);
|
||||
String humanReadable3 = convertToHumanReadableSourceMap(sourceMap3);
|
||||
|
||||
// Target line entries without sourceUrl are removed.
|
||||
//expect(sourceMap.toJson(), equals(sourceMap2.toJson()));
|
||||
expect(sourceMap2.toJson(), equals(sourceMap3.toJson()));
|
||||
expect(json.decode(humanReadable), equals(json.decode(humanReadable2)));
|
||||
expect(json.decode(humanReadable2), equals(json.decode(humanReadable3)));
|
||||
});
|
||||
|
||||
test('write/read', () {
|
||||
SingleMapping sourceMap =
|
||||
convertFromHumanReadableSourceMap(HUMAN_READABLE_SOURCE_MAP);
|
||||
print(sourceMap);
|
||||
String humanReadable = convertToHumanReadableSourceMap(sourceMap);
|
||||
print(humanReadable);
|
||||
SingleMapping sourceMap2 = convertFromHumanReadableSourceMap(humanReadable);
|
||||
expect(json.decode(HUMAN_READABLE_SOURCE_MAP),
|
||||
equals(json.decode(humanReadable)));
|
||||
expect(sourceMap.toJson(), equals(sourceMap2.toJson()));
|
||||
});
|
||||
testReadWrite();
|
||||
testWriteRead();
|
||||
}
|
||||
|
||||
void testReadWrite() {
|
||||
SingleMapping sourceMap = new SingleMapping.fromJson(json.decode(SOURCEMAP));
|
||||
String humanReadable = convertToHumanReadableSourceMap(sourceMap);
|
||||
SingleMapping sourceMap2 = convertFromHumanReadableSourceMap(humanReadable);
|
||||
String humanReadable2 = convertToHumanReadableSourceMap(sourceMap2);
|
||||
SingleMapping sourceMap3 = convertFromHumanReadableSourceMap(humanReadable2);
|
||||
String humanReadable3 = convertToHumanReadableSourceMap(sourceMap3);
|
||||
|
||||
// Target line entries without sourceUrl are removed.
|
||||
//Expect.deepEquals(sourceMap.toJson(), sourceMap2.toJson());
|
||||
Expect.deepEquals(sourceMap2.toJson(), sourceMap3.toJson());
|
||||
Expect.deepEquals(json.decode(humanReadable), json.decode(humanReadable2));
|
||||
Expect.deepEquals(json.decode(humanReadable2), json.decode(humanReadable3));
|
||||
}
|
||||
|
||||
void testWriteRead() {
|
||||
SingleMapping sourceMap =
|
||||
convertFromHumanReadableSourceMap(HUMAN_READABLE_SOURCE_MAP);
|
||||
print(sourceMap);
|
||||
String humanReadable = convertToHumanReadableSourceMap(sourceMap);
|
||||
print(humanReadable);
|
||||
SingleMapping sourceMap2 = convertFromHumanReadableSourceMap(humanReadable);
|
||||
Expect.deepEquals(
|
||||
json.decode(HUMAN_READABLE_SOURCE_MAP), json.decode(humanReadable));
|
||||
Expect.deepEquals(sourceMap.toJson(), sourceMap2.toJson());
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue