Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: test improvements #385

Merged
merged 5 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions packages/mix/lib/src/attributes/border/border_radius_dto.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ sealed class BorderRadiusGeometryDto<T extends BorderRadiusGeometry>
extends Dto<T> with Diagnosticable {
const BorderRadiusGeometryDto();

Radius _getRadiusValue(MixData mix, Radius? radius) {
if (radius == null) return Radius.zero;

return radius is RadiusRef ? mix.tokens.radiiRef(radius) : radius;
}

Radius? get topLeft;
Radius? get topRight;
Radius? get bottomLeft;
Expand All @@ -38,6 +32,13 @@ sealed class BorderRadiusGeometryDto<T extends BorderRadiusGeometry>
Radius? get topEnd;
Radius? get bottomStart;
Radius? get bottomEnd;
@visibleForTesting
Radius getRadiusValue(MixData mix, Radius? radius) {
if (radius == null) return Radius.zero;

return radius is RadiusRef ? mix.tokens.radiiRef(radius) : radius;
}

@override
BorderRadiusGeometryDto<T> merge(covariant BorderRadiusGeometryDto<T>? other);

Expand Down Expand Up @@ -81,10 +82,10 @@ final class BorderRadiusDto extends BorderRadiusGeometryDto<BorderRadius>
@override
BorderRadius resolve(MixData mix) {
return BorderRadius.only(
topLeft: _getRadiusValue(mix, topLeft),
topRight: _getRadiusValue(mix, topRight),
bottomLeft: _getRadiusValue(mix, bottomLeft),
bottomRight: _getRadiusValue(mix, bottomRight),
topLeft: getRadiusValue(mix, topLeft),
topRight: getRadiusValue(mix, topRight),
bottomLeft: getRadiusValue(mix, bottomLeft),
bottomRight: getRadiusValue(mix, bottomRight),
);
}

Expand Down Expand Up @@ -124,10 +125,10 @@ final class BorderRadiusDirectionalDto
@override
BorderRadiusDirectional resolve(MixData mix) {
return BorderRadiusDirectional.only(
topStart: _getRadiusValue(mix, topStart),
topEnd: _getRadiusValue(mix, topEnd),
bottomStart: _getRadiusValue(mix, bottomStart),
bottomEnd: _getRadiusValue(mix, bottomEnd),
topStart: getRadiusValue(mix, topStart),
topEnd: getRadiusValue(mix, topEnd),
bottomStart: getRadiusValue(mix, bottomStart),
bottomEnd: getRadiusValue(mix, bottomEnd),
);
}

Expand Down
18 changes: 18 additions & 0 deletions packages/mix/lib/src/core/helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,20 @@ class MixHelpers {

static const lerpTextStyle = _lerpTextStyle;

static const lerpInt = _lerpInt;

static const lerpSnap = _lerpSnap;

const MixHelpers._();
}

P? _lerpSnap<P>(P? from, P? to, double t) {
if (from == null) return to;
if (to == null) return from;

return t < 0.5 ? from : to;
}

w.TextStyle? _lerpTextStyle(w.TextStyle? a, w.TextStyle? b, double t) {
return w.TextStyle.lerp(a, b, t)?.copyWith(
shadows: w.Shadow.lerpList(a?.shadows, b?.shadows, t),
Expand All @@ -37,6 +48,13 @@ w.TextStyle? _lerpTextStyle(w.TextStyle? a, w.TextStyle? b, double t) {
);
}

int _lerpInt(int? a, int? b, double t) {
a ??= 0;
b ??= 0;

return (a + (b - a) * t).round();
}

List<T>? _mergeDtoList<T>(List<T>? a, List<T>? b) {
if (b == null) return a;
if (a == null) return b;
Expand Down
16 changes: 0 additions & 16 deletions packages/mix/lib/src/internal/iterable_ext.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,3 @@ extension ListExt<T> on List<T> {
});
}
}

List<T>? merge<T>(List<T>? a, List<T>? b) {
if (b == null) return a;
if (a == null) return b;

return List.generate(max(a.length, b.length), (index) {
if (index < a.length) {
final currentValue = a[index];
final otherValue = index < b.length ? b[index] : null;

return otherValue ?? currentValue;
}

return b[index];
});
}
91 changes: 0 additions & 91 deletions packages/mix/lib/src/internal/lerp_helpers.dart

This file was deleted.

28 changes: 14 additions & 14 deletions packages/mix/lib/src/modifiers/clip_widget_modifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import 'package:flutter/widgets.dart';

import '../core/attribute.dart';
import '../core/factory/mix_data.dart';
import '../core/helpers.dart';
import '../core/modifier.dart';
import '../core/utility.dart';
import '../internal/diagnostic_properties_builder_ext.dart';
import '../internal/lerp_helpers.dart';

final class ClipOvalModifierSpec
extends WidgetModifierSpec<ClipOvalModifierSpec> {
Expand All @@ -20,8 +20,8 @@ final class ClipOvalModifierSpec
@override
ClipOvalModifierSpec lerp(ClipOvalModifierSpec? other, double t) {
return ClipOvalModifierSpec(
clipper: lerpSnap(clipper, other?.clipper, t),
clipBehavior: lerpSnap(clipBehavior, other?.clipBehavior, t),
clipper: MixHelpers.lerpSnap(clipper, other?.clipper, t),
clipBehavior: MixHelpers.lerpSnap(clipBehavior, other?.clipBehavior, t),
);
}

Expand Down Expand Up @@ -90,9 +90,9 @@ final class ClipRectModifierSpec
@override
ClipRectModifierSpec lerp(ClipRectModifierSpec? other, double t) {
return ClipRectModifierSpec(
clipper: lerpSnap(clipper, other?.clipper, t),
clipBehavior:
lerpSnap(clipBehavior, other?.clipBehavior, t) ?? clipBehavior,
clipper: MixHelpers.lerpSnap(clipper, other?.clipper, t),
clipBehavior: MixHelpers.lerpSnap(clipBehavior, other?.clipBehavior, t) ??
clipBehavior,
);
}

Expand Down Expand Up @@ -164,9 +164,9 @@ final class ClipRRectModifierSpec
return ClipRRectModifierSpec(
borderRadius:
BorderRadiusGeometry.lerp(borderRadius, other?.borderRadius, t),
clipper: lerpSnap(clipper, other?.clipper, t),
clipBehavior:
lerpSnap(clipBehavior, other?.clipBehavior, t) ?? clipBehavior,
clipper: MixHelpers.lerpSnap(clipper, other?.clipper, t),
clipBehavior: MixHelpers.lerpSnap(clipBehavior, other?.clipBehavior, t) ??
clipBehavior,
);
}

Expand Down Expand Up @@ -242,9 +242,9 @@ final class ClipPathModifierSpec
@override
ClipPathModifierSpec lerp(ClipPathModifierSpec? other, double t) {
return ClipPathModifierSpec(
clipper: lerpSnap(clipper, other?.clipper, t),
clipBehavior:
lerpSnap(clipBehavior, other?.clipBehavior, t) ?? clipBehavior,
clipper: MixHelpers.lerpSnap(clipper, other?.clipper, t),
clipBehavior: MixHelpers.lerpSnap(clipBehavior, other?.clipBehavior, t) ??
clipBehavior,
);
}

Expand Down Expand Up @@ -312,8 +312,8 @@ final class ClipTriangleModifierSpec
@override
ClipTriangleModifierSpec lerp(ClipTriangleModifierSpec? other, double t) {
return ClipTriangleModifierSpec(
clipBehavior:
lerpSnap(clipBehavior, other?.clipBehavior, t) ?? clipBehavior,
clipBehavior: MixHelpers.lerpSnap(clipBehavior, other?.clipBehavior, t) ??
clipBehavior,
);
}

Expand Down
6 changes: 3 additions & 3 deletions packages/mix/lib/src/modifiers/flexible_widget_modifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import 'package:flutter/widgets.dart';
import '../attributes/enum/enum_util.dart';
import '../core/attribute.dart';
import '../core/factory/mix_data.dart';
import '../core/helpers.dart';
import '../core/modifier.dart';
import '../core/utility.dart';
import '../internal/diagnostic_properties_builder_ext.dart';
import '../internal/lerp_helpers.dart';

final class FlexibleModifierSpec
extends WidgetModifierSpec<FlexibleModifierSpec> {
Expand All @@ -20,8 +20,8 @@ final class FlexibleModifierSpec
@override
FlexibleModifierSpec lerp(FlexibleModifierSpec? other, double t) {
return FlexibleModifierSpec(
flex: lerpInt(flex, other?.flex, t),
fit: lerpSnap(fit, other?.fit, t),
flex: MixHelpers.lerpInt(flex, other?.flex, t),
fit: MixHelpers.lerpSnap(fit, other?.fit, t),
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import 'package:flutter/widgets.dart';

import '../core/attribute.dart';
import '../core/factory/mix_data.dart';
import '../core/helpers.dart';
import '../core/modifier.dart';
import '../core/utility.dart';
import '../internal/diagnostic_properties_builder_ext.dart';
import '../internal/lerp_helpers.dart';

final class RotatedBoxModifierSpec
extends WidgetModifierSpec<RotatedBoxModifierSpec> {
Expand All @@ -19,7 +19,7 @@ final class RotatedBoxModifierSpec
RotatedBoxModifierSpec lerp(RotatedBoxModifierSpec? other, double t) {
// Use lerpInt for interpolating between integers
return RotatedBoxModifierSpec(
lerpInt(quarterTurns, other?.quarterTurns, t),
MixHelpers.lerpInt(quarterTurns, other?.quarterTurns, t),
);
}

Expand Down
4 changes: 2 additions & 2 deletions packages/mix/lib/src/modifiers/transform_widget_modifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import 'package:flutter/widgets.dart';

import '../core/attribute.dart';
import '../core/factory/mix_data.dart';
import '../core/helpers.dart';
import '../core/modifier.dart';
import '../core/utility.dart';
import '../internal/diagnostic_properties_builder_ext.dart';
import '../internal/lerp_helpers.dart';

final class TransformModifierSpec
extends WidgetModifierSpec<TransformModifierSpec> {
Expand All @@ -20,7 +20,7 @@ final class TransformModifierSpec
@override
TransformModifierSpec lerp(TransformModifierSpec? other, double t) {
return TransformModifierSpec(
transform: lerpMatrix4(transform, other?.transform, t),
transform: MixHelpers.lerpMatrix4(transform, other?.transform, t),
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import 'package:flutter/widgets.dart';

import '../core/attribute.dart';
import '../core/factory/mix_data.dart';
import '../core/helpers.dart';
import '../core/modifier.dart';
import '../core/utility.dart';
import '../internal/diagnostic_properties_builder_ext.dart';
import '../internal/lerp_helpers.dart';

final class VisibilityModifierSpec
extends WidgetModifierSpec<VisibilityModifierSpec> {
Expand All @@ -18,7 +18,7 @@ final class VisibilityModifierSpec
@override
VisibilityModifierSpec lerp(VisibilityModifierSpec? other, double t) {
return VisibilityModifierSpec(
lerpSnap(visible, other?.visible, t) ?? visible,
MixHelpers.lerpSnap(visible, other?.visible, t) ?? visible,
);
}

Expand Down
Loading
Loading