Opt test/ and tool/ into null safety (dart-lang/markdown#392)
diff --git a/pkgs/markdown/test/markdown_test.dart b/pkgs/markdown/test/markdown_test.dart index 542a601..1abe941 100644 --- a/pkgs/markdown/test/markdown_test.dart +++ b/pkgs/markdown/test/markdown_test.dart
@@ -2,8 +2,6 @@ // 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. -// @dart=2.9 - import 'package:markdown/markdown.dart'; import 'package:test/test.dart'; @@ -52,7 +50,7 @@ }); group('Resolver', () { - Node nyanResolver(String text, [_]) => + Node? nyanResolver(String text, [_]) => text.isEmpty ? null : Text('~=[,,_${text}_,,]:3'); validateCore( 'simple link resolver', @@ -127,7 +125,7 @@ validateCore('dart custom links', 'links [are<foo>] awesome', '<p>links <a>are<foo></a> awesome</p>\n', - linkResolver: (String text, [String /*?*/ _]) => + linkResolver: (String text, [String? _]) => Element.text('a', text.replaceAll('<', '<'))); // TODO(amouravski): need more tests here for custom syntaxes, as some
diff --git a/pkgs/markdown/test/util.dart b/pkgs/markdown/test/util.dart index 8700160..362649b 100644 --- a/pkgs/markdown/test/util.dart +++ b/pkgs/markdown/test/util.dart
@@ -2,8 +2,6 @@ // 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. -// @dart=2.9 - import 'dart:isolate'; import 'package:io/ansi.dart' as ansi; @@ -12,8 +10,8 @@ import 'package:test/test.dart'; import '../tool/expected_output.dart'; -/// Run tests defined in "*.unit" files inside directory [name]. -Future<void> testDirectory(String name, {ExtensionSet extensionSet}) async { +/// Runs tests defined in "*.unit" files inside directory [name]. +Future<void> testDirectory(String name, {ExtensionSet? extensionSet}) async { await for (var dataCase in dataCasesUnder(testDirectory: name)) { var description = '${dataCase.directory}/${dataCase.file}.unit ${dataCase.description}'; @@ -28,12 +26,14 @@ Future<String> get markdownPackageRoot async => p.dirname(p.dirname((await Isolate.resolvePackageUri( - Uri.parse('package:markdown/markdown.dart'))) + Uri.parse('package:markdown/markdown.dart')))! .path)); -void testFile(String file, - {Iterable<BlockSyntax> blockSyntaxes, - Iterable<InlineSyntax> inlineSyntaxes}) async { +void testFile( + String file, { + Iterable<BlockSyntax> blockSyntaxes = const [], + Iterable<InlineSyntax> inlineSyntaxes = const [], +}) async { var directory = p.join(await markdownPackageRoot, 'test'); for (var dataCase in dataCasesInFile(path: p.join(directory, file))) { var description = @@ -47,11 +47,11 @@ String description, String markdown, String html, { - Iterable<BlockSyntax> blockSyntaxes, - Iterable<InlineSyntax> inlineSyntaxes, - Resolver linkResolver, - Resolver imageLinkResolver, - ExtensionSet extensionSet, + Iterable<BlockSyntax> blockSyntaxes = const [], + Iterable<InlineSyntax> inlineSyntaxes = const [], + ExtensionSet? extensionSet, + Resolver? linkResolver, + Resolver? imageLinkResolver, bool inlineOnly = false, }) { test(description, () { @@ -70,8 +70,8 @@ } String whitespaceColor(String input) => input - .replaceAll(' ', ansi.lightBlue.wrap('·')) - .replaceAll('\t', ansi.backgroundDarkGray.wrap('\t')); + .replaceAll(' ', ansi.lightBlue.wrap('·')!) + .replaceAll('\t', ansi.backgroundDarkGray.wrap('\t')!); void markdownPrintOnFailure(String markdown, String expected, String actual) { printOnFailure("""
diff --git a/pkgs/markdown/test/version_test.dart b/pkgs/markdown/test/version_test.dart index df2149a..b9c3878 100644 --- a/pkgs/markdown/test/version_test.dart +++ b/pkgs/markdown/test/version_test.dart
@@ -2,8 +2,6 @@ // 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. -// @dart=2.9 - import 'dart:io'; import 'package:path/path.dart' as p;
diff --git a/pkgs/markdown/tool/stats.dart b/pkgs/markdown/tool/stats.dart index b8b4e76..1006f94 100644 --- a/pkgs/markdown/tool/stats.dart +++ b/pkgs/markdown/tool/stats.dart
@@ -2,8 +2,6 @@ // 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. -// @dart=2.9 - import 'dart:async'; import 'dart:collection'; import 'dart:convert'; @@ -56,11 +54,11 @@ return; } - var specifiedSection = options['section'] as String; - var raw = options['raw'] as bool /*!*/; - var verbose = options['verbose'] as bool /*!*/; - var verboseLooseMatch = options['verbose-loose'] as bool /*!*/; - var updateFiles = options['update-files'] as bool /*!*/; + var specifiedSection = options['section'] as String?; + var raw = options['raw'] as bool; + var verbose = options['verbose'] as bool; + var verboseLooseMatch = options['verbose-loose'] as bool; + var updateFiles = options['update-files'] as bool; if (updateFiles && (raw || verbose || (specifiedSection != null))) { stderr.writeln('The `update-files` flag must be used by itself'); @@ -69,7 +67,7 @@ return; } - var testPrefix = options['flavor'] as String; + var testPrefix = options['flavor'] as String?; if (!updateFiles) { testPrefix = _configs.first.prefix; } @@ -99,7 +97,7 @@ bool raw, bool updateFiles, bool verbose, - String specifiedSection, + String? specifiedSection, bool verboseLooseMatch, ) async { final config = _configs.singleWhere((c) => c.prefix == testPrefix); @@ -126,7 +124,7 @@ expectedOutput: (_improveStrict && result.compareLevel == CompareLevel.loose) ? result.testCase.html - : result.result, + : result.result!, )); var nestedMap = scores.putIfAbsent( @@ -156,7 +154,7 @@ } } -Object _convert(Object obj) { +Object? _convert(Object? obj) { if (obj is CompareLevel) { switch (obj) { case CompareLevel.strict: @@ -172,7 +170,7 @@ } } if (obj is Map) { - var map = <String, Object>{}; + var map = <String, Object?>{}; obj.forEach((k, v) { var newKey = k.toString(); map[newKey] = v;
diff --git a/pkgs/markdown/tool/stats_lib.dart b/pkgs/markdown/tool/stats_lib.dart index a4a7e20..7439766 100644 --- a/pkgs/markdown/tool/stats_lib.dart +++ b/pkgs/markdown/tool/stats_lib.dart
@@ -2,8 +2,6 @@ // 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. -// @dart=2.9 - import 'dart:convert'; import 'dart:io'; import 'dart:mirrors'; @@ -20,7 +18,7 @@ String get toolDir => p.dirname((reflect(loadCommonMarkSections) as ClosureMirror) .function - .location + .location! .sourceUri .path); @@ -57,7 +55,7 @@ final String prefix; final String baseUrl; - final ExtensionSet extensionSet; + final ExtensionSet? extensionSet; Config._(this.prefix, this.baseUrl, this.extensionSet); } @@ -92,7 +90,7 @@ class CompareResult { final CompareLevel compareLevel; final CommonMarkTestCase testCase; - final String result; + final String? result; CompareResult(this.testCase, this.result, this.compareLevel); }