924cf941e9
Closes #51029 Change-Id: I7ee15c5e9cde19a323b4a2778c673017cac3795f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/279714 Commit-Queue: Johnni Winther <johnniwinther@google.com> Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
39 lines
814 B
Dart
39 lines
814 B
Dart
// Copyright (c) 2023, 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.
|
|
|
|
class Square {
|
|
final void Function(String s)? logFunction;
|
|
final double length;
|
|
|
|
const Square(this.length, [this.logFunction = null]);
|
|
|
|
void _log(String toLog) {
|
|
void Function(String s)? _l = logFunction;
|
|
if (_l != null) {
|
|
_l(toLog);
|
|
}
|
|
}
|
|
|
|
double get area {
|
|
_log("Square.area");
|
|
return length * length;
|
|
}
|
|
}
|
|
|
|
String log = "";
|
|
|
|
void logger(String s) {
|
|
log += s;
|
|
}
|
|
|
|
main() {
|
|
var Square(area: _) = Square(2, logger);
|
|
expect("Square.area", log);
|
|
}
|
|
|
|
expect(expected, actual) {
|
|
if (expected != actual) {
|
|
throw 'Expected $expected, actual $actual';
|
|
}
|
|
} |