From 4ee8a6b78c5fda8e221cf819706883ce26d41467 Mon Sep 17 00:00:00 2001 From: Ammel <77129284+Ammelll@users.noreply.github.com> Date: Tue, 12 Mar 2024 19:27:10 -0700 Subject: [PATCH 1/2] naming convention changes --- lib/pages/project/project_page.dart | 25 ++++++++++++++++++----- test/pages/project/project_page_test.dart | 8 ++++---- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/lib/pages/project/project_page.dart b/lib/pages/project/project_page.dart index 14705406..3228f0ec 100644 --- a/lib/pages/project/project_page.dart +++ b/lib/pages/project/project_page.dart @@ -889,9 +889,17 @@ class _ProjectPageState extends State { 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)){ + 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(() { @@ -1468,11 +1476,18 @@ class _ProjectPageState extends State { 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); diff --git a/test/pages/project/project_page_test.dart b/test/pages/project/project_page_test.dart index 5afddc54..041035e0 100644 --- a/test/pages/project/project_page_test.dart +++ b/test/pages/project/project_page_test.dart @@ -372,7 +372,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); @@ -381,7 +381,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); }); @@ -436,7 +436,7 @@ void main() { await widgetTester.pumpAndSettle(); expect( - find.widgetWithText(ProjectItemCard, 'Copy of auto1'), findsOneWidget); + find.widgetWithText(ProjectItemCard, 'auto1 (1)'), findsOneWidget); await widgetTester.tap(menuButton); await widgetTester.pumpAndSettle(); @@ -444,7 +444,7 @@ void main() { await widgetTester.tap(find.text('Duplicate')); await widgetTester.pumpAndSettle(); - expect(find.widgetWithText(ProjectItemCard, 'Copy of Copy of auto1'), + expect(find.widgetWithText(ProjectItemCard, 'auto1 (2)'), findsOneWidget); }); From 962e7a3b9c526c44f79207320c895ad8400b13bf Mon Sep 17 00:00:00 2001 From: Ammel <77129284+Ammelll@users.noreply.github.com> Date: Wed, 27 Nov 2024 17:22:28 -0800 Subject: [PATCH 2/2] Formatted changes --- lib/pages/project/project_page.dart | 24 +++++++++++------------ test/pages/project/project_page_test.dart | 6 ++---- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/lib/pages/project/project_page.dart b/lib/pages/project/project_page.dart index c5598da6..646b42ee 100644 --- a/lib/pages/project/project_page.dart +++ b/lib/pages/project/project_page.dart @@ -917,14 +917,14 @@ class _ProjectPageState extends State { } String pathName = _paths[i].name; RegExp exp = RegExp(r'\(\d+\)'); - String source = pathName.substring(pathName.length-3); + String source = pathName.substring(pathName.length - 3); while (pathNames.contains(pathName)) { - if(exp.hasMatch(source)){ + if (exp.hasMatch(source)) { 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)'; + int index = int.parse(match![0]!.substring(1, 2)) + 1; + pathName = '${pathName.substring(0, pathName.length - 3)}($index)'; + } else { + pathName = '$pathName (1)'; } } @@ -1525,14 +1525,14 @@ class _ProjectPageState extends State { } String autoName = _autos[i].name; RegExp exp = RegExp(r'\(\d+\)'); - String source = autoName.substring(autoName.length-3); + String source = autoName.substring(autoName.length - 3); while (autoNames.contains(autoName)) { - if(exp.hasMatch(source)){ + 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)'; + int index = int.parse(match![0]!.substring(1, 2)) + 1; + autoName = '${autoName.substring(0, autoName.length - 3)}($index)'; + } else { + autoName = '$autoName (1)'; } } setState(() { diff --git a/test/pages/project/project_page_test.dart b/test/pages/project/project_page_test.dart index 6280bcaf..04954b37 100644 --- a/test/pages/project/project_page_test.dart +++ b/test/pages/project/project_page_test.dart @@ -435,8 +435,7 @@ void main() { await widgetTester.tap(find.text('Duplicate')); await widgetTester.pumpAndSettle(); - expect( - find.widgetWithText(ProjectItemCard, 'auto1 (1)'), findsOneWidget); + expect(find.widgetWithText(ProjectItemCard, 'auto1 (1)'), findsOneWidget); await widgetTester.tap(menuButton); await widgetTester.pumpAndSettle(); @@ -444,8 +443,7 @@ void main() { await widgetTester.tap(find.text('Duplicate')); await widgetTester.pumpAndSettle(); - expect(find.widgetWithText(ProjectItemCard, 'auto1 (2)'), - findsOneWidget); + expect(find.widgetWithText(ProjectItemCard, 'auto1 (2)'), findsOneWidget); }); testWidgets('delete path', (widgetTester) async {