Skip to content

Commit

Permalink
[rfw] Restore RFW to 100% coverage (flutter#4355)
Browse files Browse the repository at this point in the history
Fixes flutter#106205 by regenerating goldens.

This is a follow-up to flutter/packages#2493.

This won't work until flutter#129851 lands and rolls into this repo.

I ran a script that I use to remove trailing spaces in the wrong directory and it cleaned up a couple of other files. The changes seem harmless so I left them in.

As this is only adding tests, this does not require a new version.

Adding tests found two bugs; one, there was a dead code branch in the tokenizer (code is now removed), and two, it found a bug in the framework (see link to PR above).
  • Loading branch information
Hixie authored Jul 13, 2023
1 parent 2a508cb commit aa1eace
Show file tree
Hide file tree
Showing 9 changed files with 262 additions and 51 deletions.
5 changes: 5 additions & 0 deletions packages/rfw/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## NEXT

* Adds more testing to restore coverage to 100%.
* Removes some dead code.

## 1.0.11

* Adds more documentation in the README.md file!
Expand Down
37 changes: 3 additions & 34 deletions packages/rfw/lib/src/dart/text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -738,13 +738,12 @@ enum _TokenizerMode {
quoteEscapeUnicode2,
quoteEscapeUnicode3,
quoteEscapeUnicode4,
endQuote,
doubleQuoteEscape,
doubleQuoteEscapeUnicode1,
doubleQuoteEscapeUnicode2,
doubleQuoteEscapeUnicode3,
doubleQuoteEscapeUnicode4,
endDoubleQuote,
endQuote,
slash,
comment,
}
Expand Down Expand Up @@ -1821,36 +1820,6 @@ Iterable<_Token> _tokenize(String file) sync* {
}
break;

case _TokenizerMode.endQuote:
switch (current) {
case -1:
yield _EofToken(line, column);
return;
case 0x0A: // U+000A LINE FEED (LF)
case 0x20: // U+0020 SPACE character
mode = _TokenizerMode.main;
break;
case 0x28: // U+0028 LEFT PARENTHESIS character (()
case 0x29: // U+0029 RIGHT PARENTHESIS character ())
case 0x2C: // U+002C COMMA character (,)
case 0x3A: // U+003A COLON character (:)
case 0x3B: // U+003B SEMICOLON character (;)
case 0x3D: // U+003D EQUALS SIGN character (=)
case 0x5B: // U+005B LEFT SQUARE BRACKET character ([)
case 0x5D: // U+005D RIGHT SQUARE BRACKET character (])
case 0x7B: // U+007B LEFT CURLY BRACKET character ({)
case 0x7D: // U+007D RIGHT CURLY BRACKET character (})
yield _SymbolToken(current, line, column);
mode = _TokenizerMode.main;
break;
case 0x2E: // U+002E FULL STOP character (.)
mode = _TokenizerMode.dot1;
break;
default:
throw ParserException('Unexpected character ${_describeRune(current)} after end quote', line, column);
}
break;

case _TokenizerMode.doubleQuote:
switch (current) {
case -1:
Expand Down Expand Up @@ -2048,7 +2017,7 @@ Iterable<_Token> _tokenize(String file) sync* {
}
break;

case _TokenizerMode.endDoubleQuote:
case _TokenizerMode.endQuote:
switch (current) {
case -1:
yield _EofToken(line, column);
Expand All @@ -2074,7 +2043,7 @@ Iterable<_Token> _tokenize(String file) sync* {
mode = _TokenizerMode.dot1;
break;
default:
throw ParserException('Unexpected character ${_describeRune(current)} after end doublequote', line, column);
throw ParserException('Unexpected character ${_describeRune(current)} after end quote', line, column);
}
break;

Expand Down
57 changes: 47 additions & 10 deletions packages/rfw/test/argument_decoders_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@
// This file is hand-formatted.

import 'dart:io' show Platform;
import 'dart:ui' as ui;

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:rfw/formats.dart' show parseLibraryFile;
import 'package:rfw/rfw.dart';

final bool masterChannel =
!Platform.environment.containsKey('CHANNEL') ||
Platform.environment['CHANNEL'] == 'master';

// See Contributing section of README.md file.
final bool runGoldens = Platform.isLinux &&
(!Platform.environment.containsKey('CHANNEL') ||
Platform.environment['CHANNEL'] == 'master');
final bool runGoldens = Platform.isLinux && masterChannel;

void main() {
testWidgets('String example', (WidgetTester tester) async {
Expand Down Expand Up @@ -238,13 +241,17 @@ void main() {
..update(const LibraryName(<String>['core']), createCoreWidgets())
..update(const LibraryName(<String>['test']), parseLibraryFile('import core; widget root = SizedBox();'));
final DynamicContent data = DynamicContent();
final List<String> eventLog = <String>[];
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.rtl,
child: RemoteWidget(
runtime: runtime,
data: data,
widget: const FullyQualifiedWidgetName(LibraryName(<String>['test']), 'root'),
onEvent: (String eventName, DynamicMap eventArguments) {
eventLog.add('$eventName $eventArguments');
},
),
),
);
Expand All @@ -256,6 +263,20 @@ void main() {
insets: ArgumentDecoders.edgeInsets(source, <Object>['insets']) ?? EdgeInsets.zero,
);
};
ArgumentDecoders.gradientDecoders['custom'] = (DataSource source, List<Object> key) {
return const RadialGradient(
center: Alignment(0.7, -0.6),
radius: 0.2,
colors: <Color>[ Color(0xFFFFFF00), Color(0xFF0099FF) ],
stops: <double>[0.4, 1.0],
);
};
ArgumentDecoders.shapeBorderDecoders['custom'] = (DataSource source, List<Object> key) {
return StarBorder(
side: ArgumentDecoders.borderSide(source, <Object>[...key, 'side']) ?? const BorderSide(width: 2.0, color: Color(0xFFFFFFFF)),
points: source.v<double>(<Object>[...key, 'points']) ?? 5.0,
);
};

runtime.update(const LibraryName(<String>['test']), parseLibraryFile('''
import core;
Expand Down Expand Up @@ -297,6 +318,7 @@ void main() {
color: 0xFF8811FF,
blendMode: "xor",
},
onError: event 'image-error-event' { },
},
gradient: {
type: 'linear',
Expand Down Expand Up @@ -338,7 +360,7 @@ void main() {
{ type: 'continuous', borderRadius: [ { x: 60.0 }, { x: 80.0 }, { x: 0.0 }, { x: 20.0, y: 50.0 } ], side: { width: 10.0, color: 0xFFEEFF33 } },
{ type: 'rounded', borderRadius: [ { x: 20.0 } ], side: { width: 10.0, color: 0xFF00CCFF } },
{ type: 'stadium', side: { width: 10.0, color: 0xFF00FFFF } },
{ type: 'custom', side: { width: 100.0, color: 0xFFFF0000 } }, // should not render
{ type: 'custom', side: { width: 5.0, color: 0xFFFFFF00 }, points: 6 }, // star
],
gradient: {
type: 'radial',
Expand All @@ -349,10 +371,13 @@ void main() {
);
'''));
await tester.pump();
expect(eventLog, hasLength(1));
expect(eventLog.first, startsWith('image-error-event {exception: HTTP request failed, statusCode: 400, x-invalid:'));
eventLog.clear();
await expectLater(
find.byType(RemoteWidget),
matchesGoldenFile('goldens/argument_decoders_test.containers.png'),
skip: 'https://github.com/flutter/flutter/issues/106205'
skip: !runGoldens,
);
expect(find.byType(DecoratedBox), findsNWidgets(6));
expect(
Expand All @@ -368,6 +393,16 @@ void main() {
'opacity 1.0, FilterQuality.low)',
);

ArgumentDecoders.colorFilterDecoders['custom'] = (DataSource source, List<Object> key) {
return const ColorFilter.mode(Color(0x12345678), BlendMode.xor);
};
ArgumentDecoders.maskFilterDecoders['custom'] = (DataSource source, List<Object> key) {
return const MaskFilter.blur(BlurStyle.outer, 0.5);
};
ArgumentDecoders.shaderDecoders['custom'] = (DataSource source, List<Object> key) {
return ui.Gradient.linear(Offset.zero, const Offset(100.0, 100.0), const <Color>[Color(0xFFFFFF00), Color(0xFF00FFFF)]);
};

runtime.update(const LibraryName(<String>['test']), parseLibraryFile('''
import core;
widget root = Column(
Expand Down Expand Up @@ -428,7 +463,7 @@ void main() {
await expectLater(
find.byType(RemoteWidget),
matchesGoldenFile('goldens/argument_decoders_test.text.png'),
skip: 'https://github.com/flutter/flutter/issues/106205'
skip: !runGoldens,
);

runtime.update(const LibraryName(<String>['test']), parseLibraryFile('''
Expand All @@ -451,7 +486,7 @@ void main() {
await expectLater(
find.byType(RemoteWidget),
matchesGoldenFile('goldens/argument_decoders_test.gridview.fixed.png'),
skip: 'https://github.com/flutter/flutter/issues/106205'
skip: !runGoldens,
);

runtime.update(const LibraryName(<String>['test']), parseLibraryFile('''
Expand All @@ -474,7 +509,7 @@ void main() {
await expectLater(
find.byType(RemoteWidget),
matchesGoldenFile('goldens/argument_decoders_test.gridview.max.png'),
skip: 'https://github.com/flutter/flutter/issues/106205'
skip: !runGoldens,
);

int sawGridDelegateDecoder = 0;
Expand Down Expand Up @@ -504,7 +539,9 @@ void main() {
await expectLater(
find.byType(RemoteWidget),
matchesGoldenFile('goldens/argument_decoders_test.gridview.custom.png'),
skip: 'https://github.com/flutter/flutter/issues/106205'
skip: !runGoldens,
);
}, skip: !runGoldens);

expect(eventLog, isEmpty);
}, skip: !masterChannel); // https://github.com/flutter/flutter/pull/129851
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/rfw/test/goldens/argument_decoders_test.text.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion packages/rfw/test/material_widgets_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,15 @@ void main() {
await expectLater(
find.byType(RemoteWidget),
matchesGoldenFile('goldens/material_test.scaffold.png'),
skip: !runGoldens,
);
await tester.tapAt(const Offset(20.0, 20.0));
await tester.pump();
await tester.pump(const Duration(seconds: 1));
await expectLater(
find.byType(RemoteWidget),
matchesGoldenFile('goldens/material_test.drawer.png'),
skip: !runGoldens,
);
}, skip: !runGoldens);
});
}
Loading

0 comments on commit aa1eace

Please sign in to comment.