diff --git a/test/mustachio/aot_compiler_builder_test.dart b/test/mustachio/aot_compiler_builder_test.dart index 33968513ac..a14234adbe 100644 --- a/test/mustachio/aot_compiler_builder_test.dart +++ b/test/mustachio/aot_compiler_builder_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 - @Timeout.factor(4) import 'dart:convert'; import 'package:analyzer/dart/element/element.dart'; @@ -14,7 +12,7 @@ import 'package:test/test.dart'; import 'builder_test_base.dart'; void main() { - InMemoryAssetWriter writer; + late InMemoryAssetWriter writer; Future resolveGeneratedLibrary() async { var rendererAsset = AssetId('foo', 'lib/foo.aot_renderers_for_html.dart'); @@ -65,7 +63,7 @@ library foo; import 'package:mustachio/annotations.dart'; '''); var rendererAsset = AssetId('foo', 'lib/foo.aot_renderers_for_html.dart'); - var generatedContent = utf8.decode(writer.assets[rendererAsset]); + var generatedContent = utf8.decode(writer.assets[rendererAsset]!); expect( generatedContent, contains('String renderFoo(_i1.Foo context0)')); }); @@ -87,7 +85,7 @@ import 'package:mustachio/annotations.dart'; }, ); var rendererAsset = AssetId('foo', 'lib/foo.aot_renderers_for_html.dart'); - var generatedContent = utf8.decode(writer.assets[rendererAsset]); + var generatedContent = utf8.decode(writer.assets[rendererAsset]!); expect( generatedContent, contains( @@ -102,9 +100,9 @@ class Baz {} '''); var renderersLibrary = await resolveGeneratedLibrary(); - var fooRenderFunction = renderersLibrary.getTopLevelFunction('renderFoo'); + var fooRenderFunction = renderersLibrary.getTopLevelFunction('renderFoo')!; expect(fooRenderFunction.typeParameters, hasLength(1)); - var fBound = fooRenderFunction.typeParameters.single.bound; + var fBound = fooRenderFunction.typeParameters.single.bound!; expect(fBound.getDisplayString(withNullability: false), equals('num')); }); } diff --git a/test/mustachio/builder_test_base.dart b/test/mustachio/builder_test_base.dart index 5a0fce3d9e..008516555d 100644 --- a/test/mustachio/builder_test_base.dart +++ b/test/mustachio/builder_test_base.dart @@ -2,11 +2,10 @@ // 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:analyzer/dart/element/element.dart'; import 'package:build/build.dart'; import 'package:build_test/build_test.dart'; +import 'package:collection/collection.dart'; import '../../tool/mustachio/builder.dart'; @@ -57,7 +56,7 @@ Future testMustachioBuilder( InMemoryAssetWriter writer, String sourceLibraryContent, { String libraryFrontMatter = libraryFrontMatter, - Map additionalAssets, + Map additionalAssets = const {}, }) async { sourceLibraryContent = ''' $libraryFrontMatter @@ -74,15 +73,16 @@ $sourceLibraryContent 'foo|lib/templates/md/bar.md': 'EMPTY', 'foo|lib/templates/html/baz.html': 'EMPTY', 'foo|lib/templates/md/baz.md': 'EMPTY', - ...?additionalAssets, + ...additionalAssets, }, writer: writer, ); } extension LibraryExtensions on LibraryElement { - /// Returns the top-level function in [this] library, named [name]. - FunctionElement getTopLevelFunction(String name) => topLevelElements + /// Returns the top-level function in [this] library, named [name], or `null` + /// if no function is found. + FunctionElement? getTopLevelFunction(String name) => topLevelElements .whereType() - .firstWhere((element) => element.name == name, orElse: () => null); + .firstWhereOrNull((element) => element.name == name); } diff --git a/test/mustachio/parser_test.dart b/test/mustachio/parser_test.dart index b612db6b25..6fe0d53cc6 100644 --- a/test/mustachio/parser_test.dart +++ b/test/mustachio/parser_test.dart @@ -1,4 +1,6 @@ -// @dart=2.9 +// Copyright (c) 2021, 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. import 'package:dartdoc/src/mustachio/parser.dart'; import 'package:test/test.dart'; @@ -354,11 +356,11 @@ void main() { expect(ast, hasLength(2)); _expectText(ast[0], equals('Text ')); var section = ast[1] as Section; - _expectSection(section, equals(['key'])); + _expectSection(section, equals(['key']), spanStart: 5, spanEnd: 49); expect(section.children, hasLength(3)); _expectText(section.children[0], equals(' AA ')); var innerSection = section.children[1] as Section; - _expectSection(innerSection, equals(['key'])); + _expectSection(innerSection, equals(['key']), spanStart: 17, spanEnd: 37); expect(innerSection.children, hasLength(1)); _expectText(innerSection.children[0], equals(' BB ')); }); @@ -407,7 +409,7 @@ void main() { } void _expectText(MustachioNode node, Object matcher, - {int spanStart, int spanEnd}) { + {int? spanStart, int? spanEnd}) { expect(node, isA().having((e) => e.content, 'content', matcher)); if (spanStart != null) { expect( @@ -421,82 +423,94 @@ void _expectText(MustachioNode node, Object matcher, } } -void _expectVariable(MustachioNode node, Object matcher, - {bool escape = true, - int spanStart, - int spanEnd, - int keySpanStart, - int keySpanEnd}) { +void _expectVariable( + MustachioNode node, + Object matcher, { + bool escape = true, + required int spanStart, + required int spanEnd, + int? keySpanStart, + int? keySpanEnd, +}) { expect( node, isA() .having((e) => e.key, 'key', matcher) .having((e) => e.escape, 'escape', escape)); - if (spanStart != null) { - var actualSpanStart = (node as Variable).span.start.offset; - _expectSpanOffset('Variable', 'start', actualSpanStart, spanStart); - } - if (spanEnd != null) { - var actualSpanEnd = (node as Variable).span.end.offset; - _expectSpanOffset('Variable', 'end', actualSpanEnd, spanEnd); - } + node as Variable; + + var actualSpanStart = node.span.start.offset; + _expectSpanOffset('Variable', 'start', actualSpanStart, spanStart); + + var actualSpanEnd = node.span.end.offset; + _expectSpanOffset('Variable', 'end', actualSpanEnd, spanEnd); + if (keySpanStart != null) { - var actualKeySpanStart = (node as Variable).keySpan.start.offset; + var actualKeySpanStart = node.keySpan.start.offset; _expectSpanOffset( 'Variable key', 'start', actualKeySpanStart, keySpanStart); } if (keySpanEnd != null) { - var actualKeySpanEnd = (node as Variable).keySpan.end.offset; + var actualKeySpanEnd = node.keySpan.end.offset; _expectSpanOffset('Variable key', 'end', actualKeySpanEnd, keySpanEnd); } } -void _expectSection(MustachioNode node, Object matcher, - {bool invert = false, - int spanStart, - int spanEnd, - int keySpanStart, - int keySpanEnd}) { +void _expectSection( + MustachioNode node, + Object matcher, { + bool invert = false, + required int spanStart, + required int spanEnd, + int? keySpanStart, + int? keySpanEnd, +}) { expect( node, isA
() .having((e) => e.key, 'key', matcher) .having((e) => e.invert, 'invert', invert)); - if (spanStart != null) { - var actualSpanStart = (node as Section).span.start.offset; - _expectSpanOffset('Section', 'start', actualSpanStart, spanStart); - } - if (spanEnd != null) { - var actualSpanEnd = (node as Section).span.end.offset; - _expectSpanOffset('Section', 'end', actualSpanEnd, spanEnd); - } + node as Section; + + var actualSpanStart = node.span.start.offset; + _expectSpanOffset('Section', 'start', actualSpanStart, spanStart); + + var actualSpanEnd = node.span.end.offset; + _expectSpanOffset('Section', 'end', actualSpanEnd, spanEnd); + if (keySpanStart != null) { - var actualKeySpanStart = (node as Section).keySpan.start.offset; + var actualKeySpanStart = node.keySpan.start.offset; _expectSpanOffset('Section key', 'start', actualKeySpanStart, keySpanStart); } if (keySpanEnd != null) { - var actualKeySpanEnd = (node as Section).keySpan.end.offset; + var actualKeySpanEnd = node.keySpan.end.offset; _expectSpanOffset('Section key', 'end', actualKeySpanEnd, keySpanEnd); } } -void _expectPartial(MustachioNode node, Object matcher, - {int spanStart, int spanEnd, int keySpanStart, int keySpanEnd}) { +void _expectPartial( + MustachioNode node, + Object matcher, { + required int spanStart, + required int spanEnd, + int? keySpanStart, + int? keySpanEnd, +}) { expect(node, isA().having((e) => e.key, 'key', matcher)); - if (spanStart != null) { - var actualSpanStart = (node as Partial).span.start.offset; - _expectSpanOffset('Partial', 'start', actualSpanStart, spanStart); - } - if (spanEnd != null) { - var actualSpanEnd = (node as Partial).span.end.offset; - _expectSpanOffset('Partial', 'end', actualSpanEnd, spanEnd); - } + node as Partial; + + var actualSpanStart = node.span.start.offset; + _expectSpanOffset('Partial', 'start', actualSpanStart, spanStart); + + var actualSpanEnd = node.span.end.offset; + _expectSpanOffset('Partial', 'end', actualSpanEnd, spanEnd); + if (keySpanStart != null) { - var actualKeySpanStart = (node as Partial).keySpan.start.offset; + var actualKeySpanStart = node.keySpan.start.offset; _expectSpanOffset('Partial key', 'start', actualKeySpanStart, keySpanStart); } if (keySpanEnd != null) { - var actualKeySpanEnd = (node as Partial).keySpan.end.offset; + var actualKeySpanEnd = node.keySpan.end.offset; _expectSpanOffset('Partial key', 'end', actualKeySpanEnd, keySpanEnd); } } diff --git a/test/mustachio/render_tests_test.dart b/test/mustachio/render_tests_test.dart index 2b409addfa..395408ed7b 100644 --- a/test/mustachio/render_tests_test.dart +++ b/test/mustachio/render_tests_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 'dart:isolate' show Isolate; @@ -17,7 +15,7 @@ void main() { var testCasePattern = RegExp(r'test\(.*,'); var dartdocLibUri = await Isolate.resolvePackageUri( Uri.parse('package:dartdoc/dartdoc.dart')); - var dartdocPath = p.dirname(p.dirname(dartdocLibUri.path)); + var dartdocPath = p.dirname(p.dirname(dartdocLibUri!.path)); // Correct Windows issue path coming out of [Isolate.resolvePackageUri]. if (p.separator == p.windows.separator && dartdocPath.startsWith('/')) { dartdocPath = dartdocPath.substring(1).replaceAll('/', p.separator); @@ -35,7 +33,7 @@ void main() { .where((line) => !line.contains('Parser ')) // Ignore tests about the SimpleRenderer. .where((line) => !line.contains('SimpleRenderer')) - .map((line) => testCasePattern.firstMatch(line).group(0)) + .map((line) => testCasePattern.firstMatch(line)!.group(0)) .toSet(); var aotCompilerRenderTest = File(p.join( @@ -43,7 +41,7 @@ void main() { .readAsLinesSync(); var aotCompilerTestCases = aotCompilerRenderTest .where((line) => testCasePattern.hasMatch(line)) - .map((line) => testCasePattern.firstMatch(line).group(0)) + .map((line) => testCasePattern.firstMatch(line)!.group(0)) .toSet(); var difference = runtimeRendererTestCases.difference(aotCompilerTestCases); diff --git a/test/mustachio/runtime_renderer_builder_test.dart b/test/mustachio/runtime_renderer_builder_test.dart index d84cb543fb..cb87e9c8b6 100644 --- a/test/mustachio/runtime_renderer_builder_test.dart +++ b/test/mustachio/runtime_renderer_builder_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 - @Timeout.factor(2) import 'dart:convert'; import 'package:analyzer/dart/element/element.dart'; @@ -14,7 +12,7 @@ import 'package:test/test.dart'; import 'builder_test_base.dart'; void main() { - InMemoryAssetWriter writer; + late InMemoryAssetWriter writer; Future resolveGeneratedLibrary() async { var rendererAsset = AssetId('foo', 'lib/foo.runtime_renderers.dart'); @@ -29,8 +27,8 @@ void main() { }); group('builds a renderer class', () { - LibraryElement renderersLibrary; - String generatedContent; + late final LibraryElement renderersLibrary; + late final String generatedContent; // Builders are fairly expensive (about 4 seconds per `testBuilder` call), // so this [setUpAll] saves significant time over [setUp]. @@ -56,7 +54,7 @@ class Baz {} '''); renderersLibrary = await resolveGeneratedLibrary(); var rendererAsset = AssetId('foo', 'lib/foo.runtime_renderers.dart'); - generatedContent = utf8.decode(writer.assets[rendererAsset]); + generatedContent = utf8.decode(writer.assets[rendererAsset]!); }); test('for a class which implicitly extends Object', () { @@ -179,7 +177,7 @@ import 'package:mustachio/annotations.dart'; }); group('builds a renderer class for a generic type', () { - String generatedContent; + late final String generatedContent; // Builders are fairly expensive (about 4 seconds per `testBuilder` call), // so this [setUpAll] saves significant time over [setUp]. @@ -198,7 +196,7 @@ library foo; import 'package:mustachio/annotations.dart'; '''); var rendererAsset = AssetId('foo', 'lib/foo.runtime_renderers.dart'); - generatedContent = utf8.decode(writer.assets[rendererAsset]); + generatedContent = utf8.decode(writer.assets[rendererAsset]!); }); test('with a corresponding public API function', () async { @@ -241,19 +239,19 @@ class Baz {} '''); var renderersLibrary = await resolveGeneratedLibrary(); - var fooRenderFunction = renderersLibrary.getTopLevelFunction('renderFoo'); + var fooRenderFunction = renderersLibrary.getTopLevelFunction('renderFoo')!; expect(fooRenderFunction.typeParameters, hasLength(1)); - var fBound = fooRenderFunction.typeParameters.single.bound; + var fBound = fooRenderFunction.typeParameters.single.bound!; expect(fBound.getDisplayString(withNullability: false), equals('num')); - var fooRendererClass = renderersLibrary.getType('_Renderer_Foo'); + var fooRendererClass = renderersLibrary.getType('_Renderer_Foo')!; expect(fooRendererClass.typeParameters, hasLength(1)); - var cBound = fooRenderFunction.typeParameters.single.bound; + var cBound = fooRenderFunction.typeParameters.single.bound!; expect(cBound.getDisplayString(withNullability: false), equals('num')); }); group('does not generate a renderer', () { - LibraryElement renderersLibrary; + late final LibraryElement renderersLibrary; setUpAll(() async { writer = InMemoryAssetWriter();