Skip to content

Commit 870c08b

Browse files
srawlinsCommit Queue
authored andcommitted
analyzer_testing: Migrate dart:ui mocks to live in source strings
Change-Id: Idf51f83dfdf5c6173bbbdedabcd41d76c928cc8a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/465160 Commit-Queue: Samuel Rawlins <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent f977229 commit 870c08b

File tree

2 files changed

+213
-3
lines changed

2 files changed

+213
-3
lines changed

pkg/analyzer_testing/lib/mock_packages/mock_packages.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import 'package:analyzer_testing/src/mock_packages/fixnum/fixnum.dart'
1111
import 'package:analyzer_testing/src/mock_packages/meta/meta.dart' as mock_meta;
1212
import 'package:analyzer_testing/src/mock_packages/mock_library.dart';
1313
import 'package:analyzer_testing/src/mock_packages/test_reflective_loader/test_reflective_loader.dart'
14-
as test_reflective_loader;
14+
as mock_test_reflective_loader;
15+
import 'package:analyzer_testing/src/mock_packages/ui/ui.dart' as mock_ui;
1516
import 'package:analyzer_testing/src/mock_packages/vector_math/vector_math.dart'
1617
as mock_vector_math;
1718
import 'package:analyzer_testing/utilities/extensions/resource_provider.dart';
@@ -178,13 +179,13 @@ mixin MockPackagesMixin {
178179
Folder addTestReflectiveLoader() {
179180
var packageFolder = _addFiles2(
180181
'test_reflective_loader',
181-
test_reflective_loader.units,
182+
mock_test_reflective_loader.units,
182183
);
183184
return packageFolder.getChildAssumingFolder('lib');
184185
}
185186

186187
Folder addUI() {
187-
var packageFolder = _addFiles('ui');
188+
var packageFolder = _addFiles2('ui', mock_ui.units);
188189
return packageFolder.getChildAssumingFolder('lib');
189190
}
190191

Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:analyzer_testing/src/mock_packages/mock_library.dart';
6+
7+
/// The set of compilation units that make up the mock 'ui' package.
8+
final List<MockLibraryUnit> units = [_uiLibrary];
9+
10+
final _uiLibrary = MockLibraryUnit('lib/ui.dart', r'''
11+
library dart.ui;
12+
13+
class Radius {
14+
static const Radius zero = Radius.circular(0.0);
15+
16+
final double x;
17+
18+
final double y;
19+
20+
const Radius.circular(double radius) : this.elliptical(radius, radius);
21+
22+
const Radius.elliptical(this.x, this.y);
23+
}
24+
25+
enum BlendMode {
26+
clear,
27+
src,
28+
dst,
29+
srcOver,
30+
dstOver,
31+
srcIn,
32+
dstIn,
33+
srcOut,
34+
dstOut,
35+
srcATop,
36+
dstATop,
37+
xor,
38+
plus,
39+
modulate,
40+
screen,
41+
overlay,
42+
darken,
43+
lighten,
44+
colorDodge,
45+
colorBurn,
46+
hardLight,
47+
softLight,
48+
difference,
49+
exclusion,
50+
multiply,
51+
hue,
52+
saturation,
53+
color,
54+
luminosity,
55+
}
56+
57+
class Color {
58+
final double a;
59+
60+
final double r;
61+
62+
final double g;
63+
64+
final double b;
65+
66+
final ColorSpace colorSpace;
67+
68+
const Color(int value)
69+
: this._fromARGBC(
70+
value >> 24,
71+
value >> 16,
72+
value >> 8,
73+
value,
74+
ColorSpace.sRGB,
75+
);
76+
77+
const Color.from({
78+
required double alpha,
79+
required double red,
80+
required double green,
81+
required double blue,
82+
this.colorSpace = ColorSpace.sRGB,
83+
}) : a = alpha,
84+
r = red,
85+
g = green,
86+
b = blue;
87+
88+
const Color.fromARGB(int a, int r, int g, int b)
89+
: this._fromARGBC(a, r, g, b, ColorSpace.sRGB);
90+
91+
const Color.fromRGBO(int r, int g, int b, double opacity)
92+
: this._fromRGBOC(r, g, b, opacity, ColorSpace.sRGB);
93+
94+
const Color._fromARGBC(
95+
int alpha,
96+
int red,
97+
int green,
98+
int blue,
99+
ColorSpace colorSpace,
100+
) : this._fromRGBOC(red, green, blue, (alpha & 0xff) / 255, colorSpace);
101+
102+
const Color._fromRGBOC(int r, int g, int b, double opacity, this.colorSpace)
103+
: a = opacity,
104+
r = (r & 0xff) / 255,
105+
g = (g & 0xff) / 255,
106+
b = (b & 0xff) / 255;
107+
108+
@Deprecated('Use (*.a * 255.0).round() & 0xff')
109+
int get alpha => throw 0;
110+
111+
@Deprecated('Use (*.b * 255.0).round() & 0xff')
112+
int get blue => throw 0;
113+
114+
@Deprecated('Use (*.g * 255.0).round() & 0xff')
115+
int get green => throw 0;
116+
117+
@override
118+
int get hashCode => throw 0;
119+
120+
@Deprecated('Use .a.')
121+
double get opacity => throw 0;
122+
123+
@Deprecated('Use (*.r * 255.0).round() & 0xff')
124+
int get red => throw 0;
125+
126+
@Deprecated(
127+
'Use component accessors like .r or .g, or toARGB32 for an explicit conversion',
128+
)
129+
int get value => throw 0;
130+
131+
@override
132+
bool operator ==(Object other) => throw 0;
133+
134+
@override
135+
String toString() => throw 0;
136+
137+
Color withAlpha(int a) => throw 0;
138+
139+
Color withBlue(int b) => throw 0;
140+
141+
Color withGreen(int g) => throw 0;
142+
143+
@Deprecated('Use .withValues() to avoid precision loss.')
144+
Color withOpacity(double opacity) => throw 0;
145+
146+
Color withRed(int r) => throw 0;
147+
148+
Color withValues({
149+
double? alpha,
150+
double? red,
151+
double? green,
152+
double? blue,
153+
ColorSpace? colorSpace,
154+
}) => throw 0;
155+
156+
static int _floatToInt8(double x) => throw 0;
157+
}
158+
159+
enum FontStyle { normal, italic }
160+
161+
class FontWeight {
162+
static const FontWeight w100 = FontWeight._(0, 100);
163+
164+
static const FontWeight w200 = FontWeight._(1, 200);
165+
166+
static const FontWeight w300 = FontWeight._(2, 300);
167+
168+
static const FontWeight w400 = FontWeight._(3, 400);
169+
170+
static const FontWeight w500 = FontWeight._(4, 500);
171+
172+
static const FontWeight w600 = FontWeight._(5, 600);
173+
174+
static const FontWeight w700 = FontWeight._(6, 700);
175+
176+
static const FontWeight w800 = FontWeight._(7, 800);
177+
178+
static const FontWeight w900 = FontWeight._(8, 900);
179+
180+
static const FontWeight normal = w400;
181+
182+
static const FontWeight bold = w700;
183+
184+
static const List<FontWeight> values = <FontWeight>[
185+
w100,
186+
w200,
187+
w300,
188+
w400,
189+
w500,
190+
w600,
191+
w700,
192+
w800,
193+
w900,
194+
];
195+
196+
final int index;
197+
198+
const FontWeight._(this.index, int value);
199+
200+
@override
201+
String toString() => throw 0;
202+
}
203+
204+
enum TextAlign { left, right, center, justify, start, end }
205+
206+
enum TextBaseline { alphabetic, ideographic }
207+
208+
enum TextDirection { rtl, ltr }
209+
''');

0 commit comments

Comments
 (0)