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

Altered Naming Convention for Duplicates #640

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
25 changes: 20 additions & 5 deletions lib/pages/project/project_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -908,9 +908,17 @@ class _ProjectPageState extends State<ProjectPage> {
for (PathPlannerPath path in _paths) {
pathNames.add(path.name);
}
String pathName = 'Copy of ${_paths[i].name}';
String pathName = _paths[i].name;
RegExp exp = RegExp(r'\(\d+\)');
String source = pathName.substring(pathName.length - 3);
while (pathNames.contains(pathName)) {
pathName = 'Copy of $pathName';
if (exp.hasMatch(source)) {
Copy link
Owner

@mjansen4857 mjansen4857 Dec 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming tests are failing because you're matching the regex against the substring with the (x) removed. I think this should be changed to match against the entire path name and then only do the substring if it has a match. Same thing for the autos.

EDIT: nvm I read this wrong, i thought the substring removed the (x) but it only contains that

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When fixing this, could you also add on to the duplication tests to duplicate them a third time. i.e. check for Example Path (3) just to be extra sure the increment works.

RegExpMatch? match = exp.firstMatch(source);
int index = int.parse(match![0]!.substring(1, 2)) + 1;
pathName = '${pathName.substring(0, pathName.length - 3)}($index)';
} else {
pathName = '$pathName (1)';
}
}

setState(() {
Expand Down Expand Up @@ -1414,11 +1422,18 @@ class _ProjectPageState extends State<ProjectPage> {
for (PathPlannerAuto auto in _autos) {
autoNames.add(auto.name);
}
String autoName = 'Copy of ${_autos[i].name}';
String autoName = _autos[i].name;
RegExp exp = RegExp(r'\(\d+\)');
String source = autoName.substring(autoName.length - 3);
while (autoNames.contains(autoName)) {
autoName = 'Copy of $autoName';
if (exp.hasMatch(source)) {
RegExpMatch? match = exp.firstMatch(source);
int index = int.parse(match![0]!.substring(1, 2)) + 1;
autoName = '${autoName.substring(0, autoName.length - 3)}($index)';
} else {
autoName = '$autoName (1)';
}
}

setState(() {
_autos.add(_autos[i].duplicate(autoName));
_sortAutos(_autoSortValue);
Expand Down
10 changes: 4 additions & 6 deletions test/pages/project/project_page_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ void main() {
await widgetTester.tap(find.text('Duplicate'));
await widgetTester.pumpAndSettle();

expect(find.widgetWithText(ProjectItemCard, 'Copy of Example Path'),
expect(find.widgetWithText(ProjectItemCard, 'Example Path (1)'),
findsOneWidget);

await widgetTester.tap(menuButton);
Expand All @@ -484,7 +484,7 @@ void main() {
await widgetTester.tap(find.text('Duplicate'));
await widgetTester.pumpAndSettle();

expect(find.widgetWithText(ProjectItemCard, 'Copy of Copy of Example Path'),
expect(find.widgetWithText(ProjectItemCard, 'Example Path (2)'),
findsOneWidget);
});

Expand Down Expand Up @@ -538,17 +538,15 @@ void main() {
await widgetTester.tap(find.text('Duplicate'));
await widgetTester.pumpAndSettle();

expect(
find.widgetWithText(ProjectItemCard, 'Copy of auto1'), findsOneWidget);
expect(find.widgetWithText(ProjectItemCard, 'auto1 (1)'), findsOneWidget);

await widgetTester.tap(menuButton);
await widgetTester.pumpAndSettle();

await widgetTester.tap(find.text('Duplicate'));
await widgetTester.pumpAndSettle();

expect(find.widgetWithText(ProjectItemCard, 'Copy of Copy of auto1'),
findsOneWidget);
expect(find.widgetWithText(ProjectItemCard, 'auto1 (2)'), findsOneWidget);
});

testWidgets('delete path', (widgetTester) async {
Expand Down
Loading