Skip to content

Commit ad0280f

Browse files
committed
Apply review feedback.
1 parent e2c5784 commit ad0280f

File tree

3 files changed

+31
-43
lines changed

3 files changed

+31
-43
lines changed

example/format.dart

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,12 @@ Future<void> _runTest(
116116
var actualText = actual.textWithSelectionMarkers;
117117
if (!testFile.isCompilationUnit) actualText += '\n';
118118

119-
String expectedText;
120-
switch (formatTest) {
121-
case UnversionedFormatTest():
122-
expectedText = formatTest.output.code.textWithSelectionMarkers;
123-
case VersionedFormatTest():
124-
// Pick the newest style for the expectation.
125-
expectedText =
126-
formatTest.outputs.entries.last.value.code.textWithSelectionMarkers;
127-
}
119+
var output = switch (formatTest) {
120+
UnversionedFormatTest(:var output) => output,
121+
// Used the newest style for the expectation.
122+
VersionedFormatTest(:var outputs) => outputs.values.last,
123+
};
124+
var expectedText = output.code.textWithSelectionMarkers;
128125

129126
print('$path ${formatTest.input.description}');
130127
_drawRuler('before', pageWidth);

lib/src/testing/test_file.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ final class VersionedFormatTest extends FormatTest {
358358
/// supported versions lower than the lowest key here, then the test is not
359359
/// run on those versions at all. These tests represent new syntax that isn't
360360
/// supported in later versions. For example, if the map has only a single
361-
/// entry whose key is 3.8, then the test is skipped on 3.8, run at 3.8, and
361+
/// entry whose key is 3.8, then the test is skipped on 3.7, run at 3.8, and
362362
/// should be valid at any higher version.
363363
///
364364
/// If there are multiple entries in the map, they represent versions where

test/utils.dart

Lines changed: 24 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -146,42 +146,33 @@ Future<void> testBenchmarks({required bool useTallStyle}) async {
146146
void _testFile(TestFile testFile) {
147147
group(testFile.path, () {
148148
for (var formatTest in testFile.tests) {
149+
Map<Version, TestEntry> testedVersions;
149150
if (testFile.isTall) {
150-
Map<Version, TestEntry> testedVersions;
151-
switch (formatTest) {
152-
case UnversionedFormatTest(:var output):
153-
// This output is unversioned, so test at the lowest and highest
154-
// supported versions. If it formats the same on those, we assume
155-
// it does for all of the intermediate versions too.
156-
testedVersions = {
157-
_testedTallVersions.first: output,
158-
_testedTallVersions.last: output,
159-
};
160-
case VersionedFormatTest(:var outputs):
161-
testedVersions = _versionedTestEntries(outputs);
162-
}
163-
164-
testedVersions.forEach((version, output) {
165-
_runTestAtVersion(testFile, formatTest, output, version);
166-
});
151+
testedVersions = switch (formatTest) {
152+
// This output is unversioned, so test at the lowest and highest
153+
// supported versions. If it formats the same on those, we assume
154+
// it does for all of the intermediate versions too.
155+
UnversionedFormatTest(:var output) => {
156+
_testedTallVersions.first: output,
157+
_testedTallVersions.last: output,
158+
},
159+
VersionedFormatTest(:var outputs) => _versionedTestEntries(outputs),
160+
};
167161
} else {
168-
switch (formatTest) {
169-
case UnversionedFormatTest(:var output):
170-
_runTestAtVersion(
171-
testFile,
172-
formatTest,
173-
output,
174-
DartFormatter.latestShortStyleLanguageVersion,
175-
);
176-
case VersionedFormatTest(:var outputs):
177-
// There is only one versioned short style test, for the legacy
178-
// switch syntax. If the test is versioned, only run it on those
179-
// versions and not anything later.
180-
outputs.forEach((version, output) {
181-
_runTestAtVersion(testFile, formatTest, output, version);
182-
});
183-
}
162+
testedVersions = switch (formatTest) {
163+
UnversionedFormatTest(:var output) => {
164+
DartFormatter.latestShortStyleLanguageVersion: output,
165+
},
166+
// There is only one versioned short style test, for the legacy
167+
// switch syntax. If the test is versioned, only run it on those
168+
// versions and not anything later.
169+
VersionedFormatTest(:var outputs) => outputs,
170+
};
184171
}
172+
173+
testedVersions.forEach((version, output) {
174+
_runTestAtVersion(testFile, formatTest, output, version);
175+
});
185176
}
186177
});
187178
}

0 commit comments

Comments
 (0)