treewide: dart format + analyze + some other fixes

This commit is contained in:
2025-08-04 21:11:37 +02:00
parent 9f9757d710
commit c83821fa38
10 changed files with 863 additions and 844 deletions

View File

@@ -6,16 +6,17 @@ import 'package:kanimaji/svg/path.dart';
void main() {
group("Examples from the SVG spec", () {
test(
"[Path 1]: MLLz",
() => expect(
parsePath("M 100 100 L 300 100 L 200 300 z"),
Path.fromSegments(const [
Move(to: Point(100, 100)),
Line(start: Point(100, 100), end: Point(300, 100)),
Line(start: Point(300, 100), end: Point(200, 300)),
Close(start: Point(200, 300), end: Point(100, 100)),
]),
));
"[Path 1]: MLLz",
() => expect(
parsePath("M 100 100 L 300 100 L 200 300 z"),
Path.fromSegments(const [
Move(to: Point(100, 100)),
Line(start: Point(100, 100), end: Point(300, 100)),
Line(start: Point(300, 100), end: Point(200, 300)),
Close(start: Point(200, 300), end: Point(100, 100)),
]),
),
);
//
test(
@@ -160,10 +161,11 @@ void main() {
Path.fromSegments(const [
Move(to: Point(600, 800)),
CubicBezier(
start: Point(600, 800),
control1: Point(625, 700),
control2: Point(725, 700),
end: Point(750, 800)),
start: Point(600, 800),
control1: Point(625, 700),
control2: Point(725, 700),
end: Point(750, 800),
),
CubicBezier(
start: Point(750, 800),
control1: Point(775, 900),
@@ -347,9 +349,10 @@ void main() {
Path.fromSegments(const [
Move(to: Point(100, 200)),
QuadraticBezier(
start: Point(100, 200),
control: Point(100, 200),
end: Point(250, 200)),
start: Point(100, 200),
control: Point(100, 200),
end: Point(250, 200),
),
]),
),
);
@@ -361,9 +364,10 @@ void main() {
Path.fromSegments(const [
Move(to: Point(100, 200)),
QuadraticBezier(
start: Point(100, 200),
control: Point(100, 200),
end: Point(250, 200)),
start: Point(100, 200),
control: Point(100, 200),
end: Point(250, 200),
),
]),
),
);
@@ -382,12 +386,12 @@ void main() {
() =>
// It can be e or E, the plus is optional, and a minimum of +/-3.4e38 must be supported.
expect(
parsePath("M-3.4e38 3.4E+38L-3.4E-38,3.4e-38"),
Path.fromSegments(const [
Move(to: Point(-3.4e38, 3.4e38)),
Line(start: Point(-3.4e38, 3.4e38), end: Point(-3.4e-38, 3.4e-38))
]),
),
parsePath("M-3.4e38 3.4E+38L-3.4E-38,3.4e-38"),
Path.fromSegments(const [
Move(to: Point(-3.4e38, 3.4e38)),
Line(start: Point(-3.4e38, 3.4e38), end: Point(-3.4e-38, 3.4e-38)),
]),
),
);
test(
@@ -405,15 +409,17 @@ void main() {
);
test('svg.path library, issue 45', () {
final path = parsePath("m 1672.2372,-54.8161 "
"a 14.5445,14.5445 0 0 0 -11.3152,23.6652 "
"l 27.2573,27.2572 27.2572,-27.2572 "
"a 14.5445,14.5445 0 0 0 -11.3012,-23.634 "
"a 14.5445,14.5445 0 0 0 -11.414,5.4625 "
"l -4.542,4.5420 "
"l -4.5437,-4.5420 "
"a 14.5445,14.5445 0 0 0 -11.3984,-5.4937 "
"z");
final path = parsePath(
"m 1672.2372,-54.8161 "
"a 14.5445,14.5445 0 0 0 -11.3152,23.6652 "
"l 27.2573,27.2572 27.2572,-27.2572 "
"a 14.5445,14.5445 0 0 0 -11.3012,-23.634 "
"a 14.5445,14.5445 0 0 0 -11.414,5.4625 "
"l -4.542,4.5420 "
"l -4.5437,-4.5420 "
"a 14.5445,14.5445 0 0 0 -11.3984,-5.4937 "
"z",
);
expect(path.d(), contains("A 14.5445,14.5445 0 0,0 1672.2372,-54.8161 Z"));
});
}

File diff suppressed because it is too large Load Diff

View File

@@ -3,7 +3,8 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:kanimaji/common/point.dart';
import 'package:kanimaji/svg/parser.dart' show Command, Token, commandifyPath, parsePath, tokenizePath;
import 'package:kanimaji/svg/parser.dart'
show Command, Token, commandifyPath, parsePath, tokenizePath;
class TokenizerTest {
final String pathdef;
@@ -30,7 +31,7 @@ final List<TokenizerTest> tokenizerTests = [
Token(command: "M", args: [Point(100, 100)]),
Token(command: "L", args: [Point(300, 100)]),
Token(command: "L", args: [Point(200, 300)]),
Token(command: "z", args: [])
Token(command: "z", args: []),
],
),
const TokenizerTest(
@@ -42,17 +43,22 @@ final List<TokenizerTest> tokenizerTests = [
Command(command: "M", args: "5 1"),
Command(command: "v", args: "7.344"),
Command(
command: "A", args: "3.574 3.574 0 003.5 8 3.515 3.515 0 000 11.5"),
command: "A",
args: "3.574 3.574 0 003.5 8 3.515 3.515 0 000 11.5",
),
Command(command: "C", args: "0 13.421 1.579 15 3.5 15"),
Command(command: "A", args: "3.517 3.517 0 007 11.531"),
Command(command: "v", args: "-7.53"),
Command(command: "h", args: "6"),
Command(command: "v", args: "4.343"),
Command(
command: "A", args: "3.574 3.574 0 0011.5 8 3.515 3.515 0 008 11.5"),
command: "A",
args: "3.574 3.574 0 0011.5 8 3.515 3.515 0 008 11.5",
),
Command(
command: "c",
args: "0 1.921 1.579 3.5 3.5 3.5 1.9 0 3.465 -1.546 3.5 -3.437"),
command: "c",
args: "0 1.921 1.579 3.5 3.5 3.5 1.9 0 3.465 -1.546 3.5 -3.437",
),
Command(command: "V", args: "1"),
Command(command: "z", args: ""),
],
@@ -61,26 +67,36 @@ final List<TokenizerTest> tokenizerTests = [
Token(command: "v", args: [7.344]),
Token(command: "A", args: [3.574, 3.574, 0, false, false, Point(3.5, 8)]),
Token(
command: "A", args: [3.515, 3.515, 0, false, false, Point(0, 11.5)]),
command: "A",
args: [3.515, 3.515, 0, false, false, Point(0, 11.5)],
),
Token(
command: "C",
args: [Point(0, 13.421), Point(1.579, 15), Point(3.5, 15)]),
command: "C",
args: [Point(0, 13.421), Point(1.579, 15), Point(3.5, 15)],
),
Token(
command: "A",
args: [3.517, 3.517, 0, false, false, Point(7, 11.531)]),
command: "A",
args: [3.517, 3.517, 0, false, false, Point(7, 11.531)],
),
Token(command: "v", args: [-7.53]),
Token(command: "h", args: [6]),
Token(command: "v", args: [4.343]),
Token(
command: "A", args: [3.574, 3.574, 0, false, false, Point(11.5, 8)]),
command: "A",
args: [3.574, 3.574, 0, false, false, Point(11.5, 8)],
),
Token(
command: "A", args: [3.515, 3.515, 0, false, false, Point(8, 11.5)]),
command: "A",
args: [3.515, 3.515, 0, false, false, Point(8, 11.5)],
),
Token(
command: "c",
args: [Point(0, 1.921), Point(1.579, 3.5), Point(3.5, 3.5)]),
command: "c",
args: [Point(0, 1.921), Point(1.579, 3.5), Point(3.5, 3.5)],
),
Token(
command: "c",
args: [Point(1.9, 0), Point(3.465, -1.546), Point(3.5, -3.437)]),
command: "c",
args: [Point(1.9, 0), Point(3.465, -1.546), Point(3.5, -3.437)],
),
Token(command: "V", args: [1]),
Token(command: "z", args: []),
],
@@ -120,4 +136,4 @@ void main() {
parsePath(tokenizerTest.pathdef);
}
});
}
}