From 11ae06e988de929c529e171a9cc05b29bc619e9f Mon Sep 17 00:00:00 2001 From: Robert Nystrom Date: Fri, 14 Feb 2020 22:54:07 +0000 Subject: [PATCH] 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 Commit-Queue: Mayank Patke Auto-Submit: Bob Nystrom Reviewed-by: Mayank Patke --- .../dart2js/sourcemaps/lax_json_test.dart | 94 +++++++++---------- .../dart2js/sourcemaps/load_save_test.dart | 59 ++++++------ 2 files changed, 72 insertions(+), 81 deletions(-) diff --git a/tests/compiler/dart2js/sourcemaps/lax_json_test.dart b/tests/compiler/dart2js/sourcemaps/lax_json_test.dart index 1d172f9a472..ac532c7579d 100644 --- a/tests/compiler/dart2js/sourcemaps/lax_json_test.dart +++ b/tests/compiler/dart2js/sourcemaps/lax_json_test.dart @@ -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}); } diff --git a/tests/compiler/dart2js/sourcemaps/load_save_test.dart b/tests/compiler/dart2js/sourcemaps/load_save_test.dart index 4cc87219006..3666fb11d29 100644 --- a/tests/compiler/dart2js/sourcemaps/load_save_test.dart +++ b/tests/compiler/dart2js/sourcemaps/load_save_test.dart @@ -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()); }