Files
sdk/pkg/front_end/test/incremental_expectations.dart
Paul Berry 95b1b8d756 [front_end] Migrate to new constructor decl syntax.
(Part of https://github.com/dart-lang/sdk/issues/63288)

This change migrates the front_end package to use the new
constructor declaration syntax, described in
https://github.com/dart-lang/language/blob/main/accepted/future-releases/primary-constructors/feature-specification.md#abbreviations-of-in-body-constructor-declarations.

This change was performed in an automated fashion, by (a) enabling the
lints `unnecessary_type_name_in_constructor` and
`unnecessary_const_in_enum_constructor`, (b) fixing the resulting lint
failures using `dart fix`, and then (c) reformatting the affected
files.

To ease code review, I've reverted unrelated formatting changes.

Change-Id: I6b48c0f1c762c3fa132fbd79382496ca6a6a6964
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/508368
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
SLSA-Policy-Verified: SLSA Policy Verification Service <devtools-gerritcodereview-exitgate@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2026-06-02 13:34:17 -07:00

82 lines
2.3 KiB
Dart

// Copyright (c) 2017, 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 "dart:convert" show JsonDecoder, JsonEncoder;
const JsonEncoder json = const JsonEncoder.withIndent(" ");
List<IncrementalExpectation> extractJsonExpectations(String source) {
return new List<IncrementalExpectation>.from(
source
.split("\n")
.where((l) => l.startsWith("<<<< ") || l.startsWith("==== "))
.map((l) => l.substring("<<<< ".length))
.map((l) => new IncrementalExpectation.fromJson(l)),
);
}
class IncrementalExpectation {
final List<String> messages;
final bool commitChangesShouldFail;
final bool hasCompileTimeError;
const new(
this.messages, {
this.commitChangesShouldFail = false,
this.hasCompileTimeError = false,
});
factory fromJson(String json) {
var data = const JsonDecoder().convert(json);
if (data is String) {
data = <String>[data];
}
if (data is List) {
return new IncrementalExpectation(data.cast<String>());
}
return new IncrementalExpectation(
extractMessages(data),
commitChangesShouldFail: extractCommitChangesShouldFail(data),
hasCompileTimeError: extractHasCompileTimeError(data),
);
}
dynamic toJson() {
if (!commitChangesShouldFail && !hasCompileTimeError) {
return messages.length == 1 ? messages.first : messages;
}
Map<String, dynamic> result = <String, dynamic>{"messages": messages};
if (commitChangesShouldFail) {
result['commitChangesShouldFail'] = 1;
}
if (hasCompileTimeError) {
result['hasCompileTimeError'] = 1;
}
return result;
}
@override
String toString() {
return """
IncrementalExpectation(
${json.convert(messages)},
commitChangesShouldFail: $commitChangesShouldFail,
hasCompileTimeError: $hasCompileTimeError)""";
}
static List<String> extractMessages(Map<String, dynamic> json) {
return new List<String>.from(json["messages"]);
}
static bool extractCommitChangesShouldFail(Map<String, dynamic> json) {
return json["commitChangesShouldFail"] == 1;
}
static bool extractHasCompileTimeError(Map<String, dynamic> json) {
return json["hasCompileTimeError"] == 1;
}
}