Skip to content

Commit

Permalink
Format and analyze excerpts with 3.7 (#6401)
Browse files Browse the repository at this point in the history
  • Loading branch information
parlough authored Feb 12, 2025
1 parent e32e97b commit 568924c
Show file tree
Hide file tree
Showing 220 changed files with 1,919 additions and 1,384 deletions.
2 changes: 1 addition & 1 deletion examples/analysis/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: dart.dev example code.

resolution: workspace
environment:
sdk: ^3.6.1
sdk: ^3.7.0

dependencies:
examples_util: {path: ../util}
2 changes: 1 addition & 1 deletion examples/analysis_alt/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ description: dart.dev example code.

resolution: workspace
environment:
sdk: ^3.6.1
sdk: ^3.7.0
1 change: 1 addition & 0 deletions examples/async_await/bin/futures_intro.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ void main() {
fetchUserOrder();
print('Fetching user order...');
}

// #enddocregion no-error, error
7 changes: 2 additions & 5 deletions examples/async_await/bin/get_order.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@ Future<String> createOrderMessage() async {
}

Future<String> fetchUserOrder() =>
// Imagine that this function is more complex and slow.
Future.delayed(
const Duration(seconds: 2),
() => 'Large Latte',
);
// Imagine that this function is more complex and slow.
Future.delayed(const Duration(seconds: 2), () => 'Large Latte');

// #docregion main-sig
Future<void> main() async {
Expand Down
8 changes: 3 additions & 5 deletions examples/async_await/bin/get_order_sync_bad.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@ String createOrderMessage() {
}

Future<String> fetchUserOrder() =>
// Imagine that this function is more complex and slow.
Future.delayed(
const Duration(seconds: 2),
() => 'Large Latte',
);
// Imagine that this function is more complex and slow.
Future.delayed(const Duration(seconds: 2), () => 'Large Latte');

// #docregion main-sig
void main() {
// #enddocregion main-sig
print('Fetching user order...');
print(createOrderMessage());
}

// #enddocregion no-warning
7 changes: 4 additions & 3 deletions examples/async_await/bin/try_catch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ Future<void> printOrderMessage() async {
Future<String> fetchUserOrder() {
// Imagine that this function is more complex.
var str = Future.delayed(
const Duration(seconds: 4),
// ignore: only_throw_errors
() => throw 'Cannot locate user order');
const Duration(seconds: 4),
// ignore: only_throw_errors
() => throw 'Cannot locate user order',
);
return str;
}

Expand Down
1 change: 1 addition & 0 deletions examples/async_await/lib/practice_errors/solution.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ Future<String> changeUsername() async {
return err.toString();
}
}

// #enddocregion
24 changes: 16 additions & 8 deletions examples/async_await/lib/practice_errors/test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,28 @@ Future<String> fetchNewUsername() {
void main() async {
try {
messages
..add(makeReadable(
..add(
makeReadable(
testLabel: '',
testResult: await asyncDidCatchException(changeUsername),
readableErrors: {
typoMessage: typoMessage,
noCatch:
'Did you remember to call fetchNewUsername within a try/catch block?',
}))
..add(makeReadable(
},
),
)
..add(
makeReadable(
testLabel: '',
testResult: await asyncErrorEquals(changeUsername),
readableErrors: {
typoMessage: typoMessage,
noCatch:
'Did you remember to call fetchNewUsername within a try/catch block?',
}))
},
),
)
..removeWhere((m) => m.contains(passed))
..toList();

Expand Down Expand Up @@ -73,10 +79,11 @@ void passIfNoMessages(List<String> messages, Map<String, String> readable) {
if (messages.isEmpty) {
_result(true);
} else {
final userMessages = messages
.where((message) => readable.containsKey(message))
.map((message) => readable[message]!)
.toList();
final userMessages =
messages
.where((message) => readable.containsKey(message))
.map((message) => readable[message]!)
.toList();
print(messages);

_result(false, userMessages);
Expand Down Expand Up @@ -109,4 +116,5 @@ Future<String> asyncDidCatchException(Function fn) async {
return passed;
}
}

// #enddocregion
1 change: 1 addition & 0 deletions examples/async_await/lib/practice_using/solution.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ Future<String> reportLogins() async {
var logins = await fetchLoginAmount();
return 'Total number of logins: $logins';
}

// #enddocregion
33 changes: 20 additions & 13 deletions examples/async_await/lib/practice_using/test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ Future<int> fetchLoginAmount() => Future.delayed(oneSecond, () => logins);
void main() async {
try {
messages
..add(makeReadable(
..add(
makeReadable(
testLabel: 'Part 1',
testResult: await asyncEquals(
expected: 'User role: administrator',
actual: await reportUserRole(),
typoKeyword: role),
expected: 'User role: administrator',
actual: await reportUserRole(),
typoKeyword: role,
),
readableErrors: {
typoMessage: typoMessage,
'null': '$didNotImplement reportUserRole?',
Expand All @@ -39,13 +41,17 @@ void main() async {
'$testFailedMessage reportUserRole. Did you return a user role?',
'User role: tester':
'$testFailedMessage reportUserRole. Did you invoke fetchRole to fetch the user\'s role?',
}))
..add(makeReadable(
},
),
)
..add(
makeReadable(
testLabel: 'Part 2',
testResult: await asyncEquals(
expected: 'Total number of logins: 42',
actual: await reportLogins(),
typoKeyword: logins.toString()),
expected: 'Total number of logins: 42',
actual: await reportLogins(),
typoKeyword: logins.toString(),
),
readableErrors: {
typoMessage: typoMessage,
'null': '$didNotImplement reportLogins?',
Expand All @@ -59,7 +65,9 @@ void main() async {
'$testFailedMessage reportLogins. Did you return the number of logins?',
'Total number of logins: 57':
'$testFailedMessage reportLogins. Did you invoke fetchLoginAmount to fetch the number of user logins?',
}))
},
),
)
..removeWhere((m) => m.contains(passed))
..toList();

Expand All @@ -69,9 +77,7 @@ void main() async {
_result(false, messages);
}
} on UnimplementedError {
_result(false, [
'$didNotImplement reportUserRole?',
]);
_result(false, ['$didNotImplement reportUserRole?']);
} catch (e) {
_result(false, ['Tried to run solution, but received an exception: $e']);
}
Expand Down Expand Up @@ -114,4 +120,5 @@ Future<String> asyncEquals({
return e.toString();
}
}

// #enddocregion
1 change: 1 addition & 0 deletions examples/async_await/lib/putting_together/solution.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ Future<String> sayGoodbye() async {
return 'Failed to logout user: $e';
}
}

// #enddocregion
59 changes: 38 additions & 21 deletions examples/async_await/lib/putting_together/test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,32 @@ Future<String> logoutUser() => Future.delayed(oneSecond, failOnce);
void main() async {
try {
messages
..add(makeReadable(
..add(
makeReadable(
testLabel: 'Part 1',
testResult: await asyncEquals(
expected: 'Hello Jerry',
actual: addHello('Jerry'),
typoKeyword: 'Jerry'),
expected: 'Hello Jerry',
actual: addHello('Jerry'),
typoKeyword: 'Jerry',
),
readableErrors: {
typoMessage: typoMessage,
'null': '$didNotImplement addHello?',
'Hello Instance of \'Future<String>\'':
'Looks like you forgot to use the \'await\' keyword!',
'Hello Instance of \'_Future<String>\'':
'Looks like you forgot to use the \'await\' keyword!',
}))
..add(makeReadable(
},
),
)
..add(
makeReadable(
testLabel: 'Part 2',
testResult: await asyncEquals(
expected: 'Hello Jean',
actual: await greetUser(),
typoKeyword: 'Jean'),
expected: 'Hello Jean',
actual: await greetUser(),
typoKeyword: 'Jean',
),
readableErrors: {
typoMessage: typoMessage,
'null': '$didNotImplement greetUser?',
Expand All @@ -62,8 +68,11 @@ void main() async {
'Did you place the \'\$\' character correctly?',
'{Closure \'addHello\'(await fetchUsername())}':
'Did you place the \'\$\' character correctly?',
}))
..add(makeReadable(
},
),
)
..add(
makeReadable(
testLabel: 'Part 3',
testResult: await asyncDidCatchException(sayGoodbye),
readableErrors: {
Expand All @@ -76,13 +85,17 @@ void main() async {
'Did you remember to use the \'await\' keyword in the sayGoodbye function?',
'Instance of \'_Future<String>\' Thanks, see you next time':
'Did you remember to use the \'await\' keyword in the sayGoodbye function?',
}))
..add(makeReadable(
},
),
)
..add(
makeReadable(
testLabel: 'Part 3',
testResult: await asyncEquals(
expected: 'Success! Thanks, see you next time',
actual: await sayGoodbye(),
typoKeyword: 'Success'),
expected: 'Success! Thanks, see you next time',
actual: await sayGoodbye(),
typoKeyword: 'Success',
),
readableErrors: {
typoMessage:
'$typoMessage. Did you add the text \'Thanks, see you next time\'?',
Expand All @@ -95,7 +108,9 @@ void main() async {
'Did you remember to use the \'await\' keyword in the sayGoodbye function?',
'Instance of \'_Exception\'':
'CAUGHT Did you remember to return a string?',
}))
},
),
)
..removeWhere((m) => m.contains(passed))
..toList();

Expand Down Expand Up @@ -133,10 +148,11 @@ void passIfNoMessages(List<String> messages, Map<String, String> readable) {
if (messages.isEmpty) {
_result(true);
} else {
final userMessages = messages
.where((message) => readable.containsKey(message))
.map((message) => readable[message]!)
.toList();
final userMessages =
messages
.where((message) => readable.containsKey(message))
.map((message) => readable[message]!)
.toList();
print(messages);

_result(false, userMessages);
Expand Down Expand Up @@ -179,4 +195,5 @@ Future<String> asyncDidCatchException(Function fn) async {
return noCatch;
}
}

// #enddocregion
2 changes: 1 addition & 1 deletion examples/async_await/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: dart.dev example code.

resolution: workspace
environment:
sdk: ^3.6.1
sdk: ^3.7.0

dependencies:
examples_util: {path: ../util}
Expand Down
11 changes: 6 additions & 5 deletions examples/async_await/test/async_await_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ void main() {
Large Latte
''';
expect(
() => Future.wait([
Future.delayed(const Duration(seconds: 4)),
Future.sync(futures_intro.main),
]),
m.printsLines(output));
() => Future.wait([
Future.delayed(const Duration(seconds: 4)),
Future.sync(futures_intro.main),
]),
m.printsLines(output),
);
});

test('get_order_sync_bad', () {
Expand Down
2 changes: 1 addition & 1 deletion examples/build_runner_usage/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: dart.dev build_runner example code.

resolution: workspace
environment:
sdk: ^3.6.1
sdk: ^3.7.0

dev_dependencies:
args: ^2.5.0
Expand Down
1 change: 1 addition & 0 deletions examples/cli/bin/dcat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,6 @@ Future<void> _handleError(String path) async {
}
// #enddocregion await-entity
}

// #enddocregion handle-error
// #enddocregion dcat-app
2 changes: 1 addition & 1 deletion examples/cli/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Examples for CLI tutorials on dart.dev

resolution: workspace
environment:
sdk: ^3.6.1
sdk: ^3.7.0

dependencies:
args: ^2.5.0
Expand Down
1 change: 1 addition & 0 deletions examples/concurrency/lib/async_number_of_keys.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ Future<String> _readFileAsync() async {
final contents = await file.readAsString();
return contents.trim();
}

// #enddocregion non-blocking
1 change: 1 addition & 0 deletions examples/concurrency/lib/basic_ports_example/complete.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,6 @@ class Worker {
await _isolateReady.future;
_sendPort.send(message);
}

// #enddocregion parse-json
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class Worker {
}
}

// rest of class..
// #enddocregion
// rest of class..
// #enddocregion

Future<void> spawn() async {
final receivePort = ReceivePort();
Expand Down
Loading

0 comments on commit 568924c

Please sign in to comment.