Skip to content

Commit 0b87d05

Browse files
committed
Buat function removeTrailingSlash didalam helper.dart
Function tersebut berfungsi untuk menghapus karakter "/" diakhir dari sebuah String.
1 parent d15dc88 commit 0b87d05

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

lib/core/util/helper.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,8 @@ class Helper {
101101
return ConstantErrorMessage().failureUnknown;
102102
}
103103
}
104+
105+
String removeTrailingSlash(String input) {
106+
return input.replaceAll(RegExp(r'/+$'), '');
107+
}
104108
}

test/util/helper_test.dart

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,4 +170,25 @@ void main() {
170170
expect(unknownFailure, constantErrorMessage.failureUnknown);
171171
},
172172
);
173+
174+
test(
175+
'pastikan function removeTrailingSlash bisa menghapus karakter "/" diakhir dari sebuah string.',
176+
() async {
177+
// arrange
178+
const input = 'https://example.com/';
179+
const input2 = 'https://example.com';
180+
const input3 = 'https://example.com////';
181+
const output = 'https://example.com';
182+
183+
// act
184+
final actual1 = helper.removeTrailingSlash(input);
185+
final actual2 = helper.removeTrailingSlash(input2);
186+
final actual3 = helper.removeTrailingSlash(input3);
187+
188+
// assert
189+
expect(actual1, output);
190+
expect(actual2, output);
191+
expect(actual3, output);
192+
},
193+
);
173194
}

0 commit comments

Comments
 (0)