From 0c3e348c825ca7049a43b93fb7ab2ddbc3f244df Mon Sep 17 00:00:00 2001 From: Nikhil Rajput Date: Fri, 13 Sep 2024 17:12:00 +0530 Subject: [PATCH] Updated to v2.0.0 --- lib/get_time_ago.dart | 1 + test/get_time_ago_test.dart | 2 +- test/messages/language/ar_msg_test.dart | 170 ++++++++++++++++++++++++ test/messages/language/de_msg_test.dart | 131 ++++++++++++++++++ test/messages/language/en_msg_test.dart | 131 ++++++++++++++++++ test/messages/language/es_msg_test.dart | 131 ++++++++++++++++++ test/messages/language/fa_msg_test.dart | 131 ++++++++++++++++++ test/messages/language/fr_msg_test.dart | 131 ++++++++++++++++++ test/messages/language/hi_msg_test.dart | 131 ++++++++++++++++++ test/messages/language/id_msg_test.dart | 131 ++++++++++++++++++ test/messages/language/ja_msg_test.dart | 131 ++++++++++++++++++ test/messages/language/ro_msg_test.dart | 146 +++++++++++++++----- 12 files changed, 1333 insertions(+), 34 deletions(-) create mode 100644 test/messages/language/ar_msg_test.dart create mode 100644 test/messages/language/de_msg_test.dart create mode 100644 test/messages/language/en_msg_test.dart create mode 100644 test/messages/language/es_msg_test.dart create mode 100644 test/messages/language/fa_msg_test.dart create mode 100644 test/messages/language/fr_msg_test.dart create mode 100644 test/messages/language/hi_msg_test.dart create mode 100644 test/messages/language/id_msg_test.dart create mode 100644 test/messages/language/ja_msg_test.dart diff --git a/lib/get_time_ago.dart b/lib/get_time_ago.dart index e97c4c5..6664858 100644 --- a/lib/get_time_ago.dart +++ b/lib/get_time_ago.dart @@ -19,6 +19,7 @@ export 'package:get_time_ago/src/messages/languages/ja_msg.dart'; export 'package:get_time_ago/src/messages/languages/ko_msg.dart'; export 'package:get_time_ago/src/messages/languages/oc_msg.dart'; export 'package:get_time_ago/src/messages/languages/pt_br_msg.dart'; +export 'package:get_time_ago/src/messages/languages/ro_msg.dart'; export 'package:get_time_ago/src/messages/languages/tr_msg.dart'; export 'package:get_time_ago/src/messages/languages/ur_msg.dart'; export 'package:get_time_ago/src/messages/languages/vi_msg.dart'; diff --git a/test/get_time_ago_test.dart b/test/get_time_ago_test.dart index ae37d1e..bb5010f 100644 --- a/test/get_time_ago_test.dart +++ b/test/get_time_ago_test.dart @@ -10,7 +10,7 @@ void main() { return DateTime.now().subtract(duration); } - group('GetTimeAgo parse function', () { + group('GetTimeAgo Test Cases', () { test('Test seconds ago (less than 15 seconds)', () { final dateTime = _getRelativeDateTime(const Duration(seconds: 10)); final result = GetTimeAgo.parse(dateTime); diff --git a/test/messages/language/ar_msg_test.dart b/test/messages/language/ar_msg_test.dart new file mode 100644 index 0000000..f259023 --- /dev/null +++ b/test/messages/language/ar_msg_test.dart @@ -0,0 +1,170 @@ +import 'package:get_time_ago/get_time_ago.dart'; +import 'package:test/test.dart'; + +void main() { + final messages = ArabicMessages(); + + group('ArabicMessages Test', () { + test('prefixAgo should return "قبل"', () { + expect(messages.prefixAgo(), 'قبل'); + }); + + test('suffixAgo should return empty string', () { + expect(messages.suffixAgo(), ''); + }); + + test('justNow should return "الآن"', () { + expect(messages.justNow(10), 'الآن'); + }); + + test('secsAgo should return correct seconds ago format', () { + expect(messages.secsAgo(5), '۵ ثوان'); + }); + + test('minAgo should return "دقيقة واحدة"', () { + expect(messages.minAgo(1), 'دقيقة واحدة'); + }); + + test('minsAgo should return correct plural form for 2 minutes', () { + expect(messages.minsAgo(2), 'دقيقتين'); + }); + + test('minsAgo should return correct plural form for more than 2 minutes', + () { + expect(messages.minsAgo(5), '۵ دقائق'); + }); + + test('hourAgo should return "ساعة واحدة"', () { + expect(messages.hourAgo(60), 'ساعة واحدة'); + }); + + test('hoursAgo should return correct plural form for 2 hours', () { + expect(messages.hoursAgo(2), 'ساعتين'); + }); + + test('hoursAgo should return correct plural form for more than 2 hours', + () { + expect(messages.hoursAgo(5), '۵ ساعات'); + }); + + test('dayAgo should return "يوم واحد"', () { + expect(messages.dayAgo(24), 'يوم واحد'); + }); + + test('daysAgo should return correct plural form for 2 days', () { + expect(messages.daysAgo(2), 'يومين'); + }); + + test('daysAgo should return correct plural form for more than 2 days', () { + expect(messages.daysAgo(5), '۵ أيام'); + }); + + test('wordSeparator should return a space', () { + expect(messages.wordSeparator(), ' '); + }); + }); + + // Helper function to get the DateTime relative to now + DateTime _getRelativeDateTime(Duration duration) { + return DateTime.now().subtract(duration); + } + + group('GetTimeAgo Test with Arabic Locale', () { + test('should return الآن for time less than 15 seconds', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(seconds: 0)), + locale: 'ar', + ); + expect(result, 'الآن'); + }); + + test('should return correct format for 30 seconds ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(seconds: 30)), + locale: 'ar', + ); + expect(result, 'قبل ۳۰ ثوان'); + }); + + test('should return دقيقة واحدة for 1 minute ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(minutes: 1)), + locale: 'ar', + ); + expect(result, 'قبل دقيقة واحدة'); + }); + + test('should return دقيقتين for 2 minutes ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(minutes: 2)), + locale: 'ar', + ); + print(result.toString() == 'قبل دقيقتين'); + expect(result, 'قبل دقيقتين'); + }); + + test('should return correct format for 5 minutes ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(minutes: 5)), + locale: 'ar', + ); + expect(result, 'قبل ۵ دقائق'); + }); + + test('should return ساعة واحدة for 1 hour ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(hours: 1)), + locale: 'ar', + ); + expect(result, 'قبل ساعة واحدة'); + }); + + test('should return ساعتين for 2 hours ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(hours: 2)), + locale: 'ar', + ); + expect(result, 'قبل ساعتين'); + }); + + test('should return correct format for 5 hours ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(hours: 5)), + locale: 'ar', + ); + expect(result, 'قبل ۵ ساعات'); + }); + + test('should return يوم واحد for 1 day ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(days: 1)), + locale: 'ar', + ); + expect(result, 'قبل يوم واحد'); + }); + + test('should return يومين for 2 days ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(days: 2)), + locale: 'ar', + ); + expect(result, 'قبل يومين'); + }); + + test('should return correct format for 5 days ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(days: 5)), + locale: 'ar', + ); + expect(result, 'قبل ۵ أيام'); + }); + + test('should return formatted date for dates beyond 7 days', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(days: 10)), + locale: 'ar', + ); + expect(result, isNot('قبل ۱۰ أيام')); + }); + }); +} diff --git a/test/messages/language/de_msg_test.dart b/test/messages/language/de_msg_test.dart new file mode 100644 index 0000000..27974f6 --- /dev/null +++ b/test/messages/language/de_msg_test.dart @@ -0,0 +1,131 @@ +import 'package:get_time_ago/get_time_ago.dart'; +import 'package:test/test.dart'; + +void main() { + final messages = GermanMessages(); + + group('GermanMessages Test', () { + test('prefixAgo should return "vor"', () { + expect(messages.prefixAgo(), 'vor'); + }); + + test('suffixAgo should return an empty string', () { + expect(messages.suffixAgo(), ''); + }); + + test('justNow should return "vorhin"', () { + expect(messages.justNow(10), 'vorhin'); + }); + + test('secsAgo should return correct seconds ago format', () { + expect(messages.secsAgo(25), '25 Sekunden'); + }); + + test('minAgo should return "einer Minute"', () { + expect(messages.minAgo(1), 'einer Minute'); + }); + + test('minsAgo should return correct minutes ago format', () { + expect(messages.minsAgo(5), '5 Minuten'); + }); + + test('hourAgo should return "einer Stunde"', () { + expect(messages.hourAgo(60), 'einer Stunde'); + }); + + test('hoursAgo should return correct hours ago format', () { + expect(messages.hoursAgo(5), '5 Stunden'); + }); + + test('dayAgo should return "einem Tag"', () { + expect(messages.dayAgo(24), 'einem Tag'); + }); + + test('daysAgo should return correct days ago format', () { + expect(messages.daysAgo(5), '5 Tagen'); + }); + + test('wordSeparator should return a space', () { + expect(messages.wordSeparator(), ' '); + }); + }); + + // Helper function to get the DateTime relative to now + DateTime _getRelativeDateTime(Duration duration) { + return DateTime.now().subtract(duration); + } + + group('GetTimeAgo Test with German Locale', () { + test('should return vorhin for time less than 15 seconds', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(seconds: 0)), + locale: 'de', + ); + expect(result, 'vorhin'); + }); + + test('should return correct format for seconds ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(seconds: 20)), + locale: 'de', + ); + expect(result, 'vor 20 Sekunden'); + }); + + test('should return einer Minute for 1 minute ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(minutes: 1)), + locale: 'de', + ); + expect(result, 'vor einer Minute'); + }); + + test('should return correct format for 5 minutes ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(minutes: 5)), + locale: 'de', + ); + expect(result, 'vor 5 Minuten'); + }); + + test('should return einer Stunde for 1 hour ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(hours: 1)), + locale: 'de', + ); + expect(result, 'vor einer Stunde'); + }); + + test('should return correct format for 5 hours ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(hours: 5)), + locale: 'de', + ); + expect(result, 'vor 5 Stunden'); + }); + + test('should return einem Tag for 1 day ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(days: 1)), + locale: 'de', + ); + expect(result, 'vor einem Tag'); + }); + + test('should return correct format for 5 days ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(days: 5)), + locale: 'de', + ); + expect(result, 'vor 5 Tagen'); + }); + + test('should return formatted date for dates beyond 7 days', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(days: 10)), + locale: 'de', + ); + expect(result, isNot('vor 10 Tagen')); + }); + }); +} diff --git a/test/messages/language/en_msg_test.dart b/test/messages/language/en_msg_test.dart new file mode 100644 index 0000000..6348d7b --- /dev/null +++ b/test/messages/language/en_msg_test.dart @@ -0,0 +1,131 @@ +import 'package:get_time_ago/get_time_ago.dart'; +import 'package:test/test.dart'; + +void main() { + final messages = EnglishMessages(); + + group('EnglishMessages Test', () { + test('prefixAgo should return an empty string', () { + expect(messages.prefixAgo(), ''); + }); + + test('suffixAgo should return "ago"', () { + expect(messages.suffixAgo(), 'ago'); + }); + + test('justNow should return "just now"', () { + expect(messages.justNow(10), 'just now'); + }); + + test('secsAgo should return correct seconds ago format', () { + expect(messages.secsAgo(25), '25 seconds'); + }); + + test('minAgo should return "a minute"', () { + expect(messages.minAgo(1), 'a minute'); + }); + + test('minsAgo should return correct minutes ago format', () { + expect(messages.minsAgo(5), '5 minutes'); + }); + + test('hourAgo should return "an hour"', () { + expect(messages.hourAgo(60), 'an hour'); + }); + + test('hoursAgo should return correct hours ago format', () { + expect(messages.hoursAgo(5), '5 hours'); + }); + + test('dayAgo should return "a day"', () { + expect(messages.dayAgo(24), 'a day'); + }); + + test('daysAgo should return correct days ago format', () { + expect(messages.daysAgo(5), '5 days'); + }); + + test('wordSeparator should return a space', () { + expect(messages.wordSeparator(), ' '); + }); + }); + + // Helper function to get the DateTime relative to now + DateTime _getRelativeDateTime(Duration duration) { + return DateTime.now().subtract(duration); + } + + group('GetTimeAgo Test with German Locale', () { + test('should return "just now" for time less than 15 seconds', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(seconds: 0)), + locale: 'en', + ); + expect(result, 'just now'); + }); + + test('should return correct format for seconds ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(seconds: 20)), + locale: 'en', + ); + expect(result, '20 seconds ago'); + }); + + test('should return "a minute ago" for 1 minute ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(minutes: 1)), + locale: 'en', + ); + expect(result, 'a minute ago'); + }); + + test('should return correct format for 5 minutes ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(minutes: 5)), + locale: 'en', + ); + expect(result, '5 minutes ago'); + }); + + test('should return "an hour ago" for 1 hour ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(hours: 1)), + locale: 'en', + ); + expect(result, 'an hour ago'); + }); + + test('should return correct format for 5 hours ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(hours: 5)), + locale: 'en', + ); + expect(result, '5 hours ago'); + }); + + test('should return "a day ago" for 1 day ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(days: 1)), + locale: 'en', + ); + expect(result, 'a day ago'); + }); + + test('should return correct format for 5 days ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(days: 5)), + locale: 'en', + ); + expect(result, '5 days ago'); + }); + + test('should return formatted date for dates beyond 7 days', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(days: 10)), + locale: 'en', + ); + expect(result, isNot('10 days ago')); + }); + }); +} diff --git a/test/messages/language/es_msg_test.dart b/test/messages/language/es_msg_test.dart new file mode 100644 index 0000000..9a9e90e --- /dev/null +++ b/test/messages/language/es_msg_test.dart @@ -0,0 +1,131 @@ +import 'package:get_time_ago/get_time_ago.dart'; +import 'package:test/test.dart'; + +void main() { + final messages = EspanaMessages(); + + group('EspanaMessages Test', () { + test('prefixAgo should return "hace"', () { + expect(messages.prefixAgo(), 'hace'); + }); + + test('suffixAgo should return an empty string', () { + expect(messages.suffixAgo(), ''); + }); + + test('justNow should return "hace poco"', () { + expect(messages.justNow(10), 'hace poco'); + }); + + test('secsAgo should return correct seconds ago format', () { + expect(messages.secsAgo(25), '25 segundos'); + }); + + test('minAgo should return "un minuto"', () { + expect(messages.minAgo(1), 'un minuto'); + }); + + test('minsAgo should return correct minutes ago format', () { + expect(messages.minsAgo(5), '5 minutos'); + }); + + test('hourAgo should return "una hora"', () { + expect(messages.hourAgo(60), 'una hora'); + }); + + test('hoursAgo should return correct hours ago format', () { + expect(messages.hoursAgo(5), '5 horas'); + }); + + test('dayAgo should return "un día"', () { + expect(messages.dayAgo(24), 'un día'); + }); + + test('daysAgo should return correct days ago format', () { + expect(messages.daysAgo(5), '5 días'); + }); + + test('wordSeparator should return a space', () { + expect(messages.wordSeparator(), ' '); + }); + }); + + // Helper function to get the DateTime relative to now + DateTime _getRelativeDateTime(Duration duration) { + return DateTime.now().subtract(duration); + } + + group('GetTimeAgo Test with Spanish Locale', () { + test('should return "hace poco" for time less than 15 seconds', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(seconds: 00)), + locale: 'es', + ); + expect(result, 'hace poco'); + }); + + test('should return correct format for seconds ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(seconds: 20)), + locale: 'es', + ); + expect(result, 'hace 20 segundos'); + }); + + test('should return "un minuto" for 1 minute ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(minutes: 1)), + locale: 'es', + ); + expect(result, 'hace un minuto'); + }); + + test('should return correct format for 5 minutes ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(minutes: 5)), + locale: 'es', + ); + expect(result, 'hace 5 minutos'); + }); + + test('should return "una hora" for 1 hour ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(hours: 1)), + locale: 'es', + ); + expect(result, 'hace una hora'); + }); + + test('should return correct format for 5 hours ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(hours: 5)), + locale: 'es', + ); + expect(result, 'hace 5 horas'); + }); + + test('should return "un día" for 1 day ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(days: 1)), + locale: 'es', + ); + expect(result, 'hace un día'); + }); + + test('should return correct format for 5 days ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(days: 5)), + locale: 'es', + ); + expect(result, 'hace 5 días'); + }); + + test('should return formatted date for dates beyond 7 days', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(days: 10)), + locale: 'es', + ); + expect(result, isNot('hace 10 días')); + }); + }); +} diff --git a/test/messages/language/fa_msg_test.dart b/test/messages/language/fa_msg_test.dart new file mode 100644 index 0000000..802b2b2 --- /dev/null +++ b/test/messages/language/fa_msg_test.dart @@ -0,0 +1,131 @@ +import 'package:get_time_ago/get_time_ago.dart'; +import 'package:test/test.dart'; + +void main() { + group('PersianMessages Test', () { + final persianMessages = PersianMessages(); + + test('prefixAgo should return correct prefix', () { + expect(persianMessages.prefixAgo(), '\u202B'); + }); + + test('suffixAgo should return correct suffix', () { + expect(persianMessages.suffixAgo(), 'پیش'); + }); + + test('justNow should return correct message', () { + expect(persianMessages.justNow(10), 'همین الان'); + }); + + test('secsAgo should return correct message', () { + expect(persianMessages.secsAgo(30), '۳۰ ثانیه'); + }); + + test('minAgo should return correct message', () { + expect(persianMessages.minAgo(1), 'یک دقیقه'); + }); + + test('minsAgo should return correct message', () { + expect(persianMessages.minsAgo(5), '۵ دقیقه'); + }); + + test('hourAgo should return correct message', () { + expect(persianMessages.hourAgo(60), 'یک ساعت'); + }); + + test('hoursAgo should return correct message', () { + expect(persianMessages.hoursAgo(3), '۳ ساعت'); + }); + + test('dayAgo should return correct message', () { + expect(persianMessages.dayAgo(24), 'یک روز'); + }); + + test('daysAgo should return correct message', () { + expect(persianMessages.daysAgo(4), '۴ روز'); + }); + + test('wordSeparator should return correct separator', () { + expect(persianMessages.wordSeparator(), ' '); + }); + }); + + // Helper function to get the DateTime relative to now + DateTime _getRelativeDateTime(Duration duration) { + return DateTime.now().subtract(duration); + } + + group('GetTimeAgo Test with Persian Locale', () { + test('should return همین الان for time less than 15 seconds', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(seconds: 0)), + locale: 'fa', + ); + expect(result, 'همین الان'); + }); + + test('should return ۳۰ ثانیه پیش for 30 seconds ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(seconds: 30)), + locale: 'fa', + ); + expect(result, '\u202B ۳۰ ثانیه پیش'); + }); + + test('should return یک دقیقه پیش for 1 minute ago', () { + final result = GetTimeAgo.parse( + DateTime.now().subtract(const Duration(minutes: 1)), + locale: 'fa', + ); + expect(result, '\u202B یک دقیقه پیش'); + }); + + test('should return ۱۰ دقیقه پیش for 10 minutes ago', () { + final result = GetTimeAgo.parse( + DateTime.now().subtract(const Duration(minutes: 10)), + locale: 'fa', + ); + expect(result, '\u202B ۱۰ دقیقه پیش'); + }); + + test('should return یک ساعت پیش for 1 hour ago', () { + final result = GetTimeAgo.parse( + DateTime.now().subtract(const Duration(hours: 1)), + locale: 'fa', + ); + expect(result, '\u202B یک ساعت پیش'); + }); + + test('should return ۵ ساعت پیش for 5 hours ago', () { + final result = GetTimeAgo.parse( + DateTime.now().subtract(const Duration(hours: 5)), + locale: 'fa', + ); + expect(result, '\u202B ۵ ساعت پیش'); + }); + + test('should return یک روز پیش for 1 day ago', () { + final result = GetTimeAgo.parse( + DateTime.now().subtract(const Duration(days: 1)), + locale: 'fa', + ); + expect(result, '\u202B یک روز پیش'); + }); + + test('should return ۳ روز پیش for 3 days ago', () { + final result = GetTimeAgo.parse( + DateTime.now().subtract(const Duration(days: 3)), + locale: 'fa', + ); + expect(result, '\u202B ۳ روز پیش'); + }); + + test('should return formatted date for dates beyond 7 days', () { + final result = GetTimeAgo.parse( + DateTime.now().subtract(const Duration(days: 10)), + locale: 'fa', + ); + expect(result, isNot('\u202B ۳ روز پیش')); + }); + }); +} diff --git a/test/messages/language/fr_msg_test.dart b/test/messages/language/fr_msg_test.dart new file mode 100644 index 0000000..de1ac0d --- /dev/null +++ b/test/messages/language/fr_msg_test.dart @@ -0,0 +1,131 @@ +import 'package:get_time_ago/get_time_ago.dart'; +import 'package:test/test.dart'; + +void main() { + final frenchMessages = FrenchMessages(); + + group('FrenchMessages Test', () { + test('prefixAgo should return "il y a"', () { + expect(frenchMessages.prefixAgo(), 'il y a'); + }); + + test('suffixAgo should return an empty string', () { + expect(frenchMessages.suffixAgo(), ''); + }); + + test('justNow should return "en ce moment"', () { + expect(frenchMessages.justNow(20), 'en ce moment'); + }); + + test('secsAgo should return correct seconds ago format', () { + expect(frenchMessages.secsAgo(25), '25 secondes'); + }); + + test('minAgo should return "une minute"', () { + expect(frenchMessages.minAgo(1), 'une minute'); + }); + + test('minsAgo should return correct minutes ago format', () { + expect(frenchMessages.minsAgo(5), '5 minutes'); + }); + + test('hourAgo should return "une heure"', () { + expect(frenchMessages.hourAgo(60), 'une heure'); + }); + + test('hoursAgo should return correct hours ago format', () { + expect(frenchMessages.hoursAgo(5), '5 heures'); + }); + + test('dayAgo should return "un jour"', () { + expect(frenchMessages.dayAgo(24), 'un jour'); + }); + + test('daysAgo should return correct days ago format', () { + expect(frenchMessages.daysAgo(5), '5 jours'); + }); + + test('wordSeparator should return a space', () { + expect(frenchMessages.wordSeparator(), ' '); + }); + }); + + // Helper function to get the DateTime relative to now + DateTime _getRelativeDateTime(Duration duration) { + return DateTime.now().subtract(duration); + } + + group('GetTimeAgo Test with French Locale', () { + test('should return "en ce moment" for time less than 15 seconds', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(seconds: 0)), + locale: 'fr', + ); + expect(result, 'en ce moment'); + }); + + test('should return correct format for seconds ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(seconds: 20)), + locale: 'fr', + ); + expect(result, 'il y a 20 secondes'); + }); + + test('should return "une minute" for 1 minute ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(minutes: 1)), + locale: 'fr', + ); + expect(result, 'il y a une minute'); + }); + + test('should return correct format for 5 minutes ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(minutes: 5)), + locale: 'fr', + ); + expect(result, 'il y a 5 minutes'); + }); + + test('should return "une heure" for 1 hour ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(hours: 1)), + locale: 'fr', + ); + expect(result, 'il y a une heure'); + }); + + test('should return correct format for 5 hours ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(hours: 5)), + locale: 'fr', + ); + expect(result, 'il y a 5 heures'); + }); + + test('should return "un jour" for 1 day ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(days: 1)), + locale: 'fr', + ); + expect(result, 'il y a un jour'); + }); + + test('should return correct format for 5 days ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(days: 5)), + locale: 'fr', + ); + expect(result, 'il y a 5 jours'); + }); + + test('should return formatted date for dates beyond 7 days', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(days: 10)), + locale: 'fr', + ); + expect(result, isNot('il y a 10 jours')); + }); + }); +} diff --git a/test/messages/language/hi_msg_test.dart b/test/messages/language/hi_msg_test.dart new file mode 100644 index 0000000..d6fcb49 --- /dev/null +++ b/test/messages/language/hi_msg_test.dart @@ -0,0 +1,131 @@ +import 'package:get_time_ago/get_time_ago.dart'; +import 'package:test/test.dart'; + +void main() { + final messages = HindiMessages(); + + group('HindiMessages Test', () { + test('prefixAgo should return an empty string', () { + expect(messages.prefixAgo(), ''); + }); + + test('suffixAgo should return "पहले"', () { + expect(messages.suffixAgo(), 'पहले'); + }); + + test('justNow should return "अभी"', () { + expect(messages.justNow(10), 'अभी'); + }); + + test('secsAgo should return correct seconds ago format', () { + expect(messages.secsAgo(25), '25 क्षण'); + }); + + test('minAgo should return "एक मिनट"', () { + expect(messages.minAgo(1), 'एक मिनट'); + }); + + test('minsAgo should return correct minutes ago format', () { + expect(messages.minsAgo(5), '5 मिनट'); + }); + + test('hourAgo should return "एक घंटा"', () { + expect(messages.hourAgo(60), 'एक घंटा'); + }); + + test('hoursAgo should return correct hours ago format', () { + expect(messages.hoursAgo(5), '5 घंटे'); + }); + + test('dayAgo should return "एक दिन"', () { + expect(messages.dayAgo(24), 'एक दिन'); + }); + + test('daysAgo should return correct days ago format', () { + expect(messages.daysAgo(5), '5 दिन'); + }); + + test('wordSeparator should return a space', () { + expect(messages.wordSeparator(), ' '); + }); + }); + + // Helper function to get the DateTime relative to now + DateTime _getRelativeDateTime(Duration duration) { + return DateTime.now().subtract(duration); + } + + group('GetTimeAgo Test with Hindi Locale', () { + test('should return "अभी" for time less than 15 seconds', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(seconds: 0)), + locale: 'hi', + ); + expect(result, 'अभी'); + }); + + test('should return correct format for seconds ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(seconds: 20)), + locale: 'hi', + ); + expect(result, '20 क्षण पहले'); + }); + + test('should return "एक मिनट पहले" for 1 minute ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(minutes: 1)), + locale: 'hi', + ); + expect(result, 'एक मिनट पहले'); + }); + + test('should return correct format for 5 minutes ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(minutes: 5)), + locale: 'hi', + ); + expect(result, '5 मिनट पहले'); + }); + + test('should return "एक घंटा पहले" for 1 hour ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(hours: 1)), + locale: 'hi', + ); + expect(result, 'एक घंटा पहले'); + }); + + test('should return correct format for 5 hours ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(hours: 5)), + locale: 'hi', + ); + expect(result, '5 घंटे पहले'); + }); + + test('should return "एक दिन पहले" for 1 day ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(days: 1)), + locale: 'hi', + ); + expect(result, 'एक दिन पहले'); + }); + + test('should return correct format for 5 days ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(days: 5)), + locale: 'hi', + ); + expect(result, '5 दिन पहले'); + }); + + test('should return formatted date for dates beyond 7 days', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(days: 10)), + locale: 'hi', + ); + expect(result, isNot('10 दिन पहले')); + }); + }); +} diff --git a/test/messages/language/id_msg_test.dart b/test/messages/language/id_msg_test.dart new file mode 100644 index 0000000..7520079 --- /dev/null +++ b/test/messages/language/id_msg_test.dart @@ -0,0 +1,131 @@ +import 'package:get_time_ago/get_time_ago.dart'; +import 'package:test/test.dart'; + +void main() { + final indonesianMessages = IndonesianMessages(); + + group('FrenchMessages Test', () { + test('prefixAgo should return an empty string', () { + expect(indonesianMessages.prefixAgo(), ''); + }); + + test('suffixAgo should return "lalu"', () { + expect(indonesianMessages.suffixAgo(), 'lalu'); + }); + + test('justNow should return "baru saja"', () { + expect(indonesianMessages.justNow(20), 'baru saja'); + }); + + test('secsAgo should return correct seconds ago format', () { + expect(indonesianMessages.secsAgo(25), '25 detik'); + }); + + test('minAgo should return "semenit"', () { + expect(indonesianMessages.minAgo(1), 'semenit'); + }); + + test('minsAgo should return correct minutes ago format', () { + expect(indonesianMessages.minsAgo(5), '5 menit'); + }); + + test('hourAgo should return "sejam"', () { + expect(indonesianMessages.hourAgo(60), 'sejam'); + }); + + test('hoursAgo should return correct hours ago format', () { + expect(indonesianMessages.hoursAgo(5), '5 jam'); + }); + + test('dayAgo should return "sehari"', () { + expect(indonesianMessages.dayAgo(24), 'sehari'); + }); + + test('daysAgo should return correct days ago format', () { + expect(indonesianMessages.daysAgo(5), '5 hari'); + }); + + test('wordSeparator should return a space', () { + expect(indonesianMessages.wordSeparator(), ' '); + }); + }); + + // Helper function to get the DateTime relative to now + DateTime _getRelativeDateTime(Duration duration) { + return DateTime.now().subtract(duration); + } + + group('GetTimeAgo Test with Indonesian Locale', () { + test('should return "baru saja" for time less than 15 seconds', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(seconds: 5)), + locale: 'id', + ); + expect(result, 'baru saja'); + }); + + test('should return "25 detik lalu" for 25 seconds ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(seconds: 25)), + locale: 'id', + ); + expect(result, '25 detik lalu'); + }); + + test('should return "semenit lalu" for 1 minute ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(minutes: 1)), + locale: 'id', + ); + expect(result, 'semenit lalu'); + }); + + test('should return "2 menit lalu" for 2 minutes ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(minutes: 2)), + locale: 'id', + ); + expect(result, '2 menit lalu'); + }); + + test('should return "sejam lalu" for 1 hour ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(hours: 1)), + locale: 'id', + ); + expect(result, 'sejam lalu'); + }); + + test('should return "2 jam lalu" for 2 hours ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(hours: 2)), + locale: 'id', + ); + expect(result, '2 jam lalu'); + }); + + test('should return "sehari lalu" for 1 day ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(hours: 24)), + locale: 'id', + ); + expect(result, 'sehari lalu'); + }); + + test('should return "3 hari lalu" for 3 days ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(days: 3)), + locale: 'id', + ); + expect(result, '3 hari lalu'); + }); + + test('should return formatted date for dates beyond 7 days', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(days: 10)), + locale: 'id', + ); + expect(result, isNot('10 hari lalu')); + }); + }); +} diff --git a/test/messages/language/ja_msg_test.dart b/test/messages/language/ja_msg_test.dart new file mode 100644 index 0000000..5fdd372 --- /dev/null +++ b/test/messages/language/ja_msg_test.dart @@ -0,0 +1,131 @@ +import 'package:get_time_ago/get_time_ago.dart'; +import 'package:test/test.dart'; + +void main() { + final japaneseMessages = JapaneseMessages(); + + group('FrenchMessages Test', () { + test('prefixAgo should return an empty string', () { + expect(japaneseMessages.prefixAgo(), ''); + }); + + test('suffixAgo should return "前"', () { + expect(japaneseMessages.suffixAgo(), '前'); + }); + + test('justNow should return "唯今"', () { + expect(japaneseMessages.justNow(20), '唯今'); + }); + + test('secsAgo should return correct seconds ago format', () { + expect(japaneseMessages.secsAgo(25), '25秒'); + }); + + test('minAgo should return "1分"', () { + expect(japaneseMessages.minAgo(1), '1分'); + }); + + test('minsAgo should return correct minutes ago format', () { + expect(japaneseMessages.minsAgo(5), '5分'); + }); + + test('hourAgo should return "1時間"', () { + expect(japaneseMessages.hourAgo(60), '1時間'); + }); + + test('hoursAgo should return correct hours ago format', () { + expect(japaneseMessages.hoursAgo(5), '5時間'); + }); + + test('dayAgo should return "1日"', () { + expect(japaneseMessages.dayAgo(24), '1日'); + }); + + test('daysAgo should return correct days ago format', () { + expect(japaneseMessages.daysAgo(5), '5日'); + }); + + test('wordSeparator should return a space', () { + expect(japaneseMessages.wordSeparator(), ''); + }); + }); + + // Helper function to get the DateTime relative to now + DateTime _getRelativeDateTime(Duration duration) { + return DateTime.now().subtract(duration); + } + + group('GetTimeAgo tests with JapaneseMessages', () { + test('should return "唯今" for time less than 15 seconds', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(seconds: 5)), + locale: 'ja', + ); + expect(result, '唯今'); + }); + + test('should return "20秒前" for 20 seconds ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(seconds: 20)), + locale: 'ja', + ); + expect(result, '20秒前'); + }); + + test('should return "1分前" for 1 minute ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(minutes: 1)), + locale: 'ja', + ); + expect(result, '1分前'); + }); + + test('should return "2分前" for 2 minutes ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(minutes: 2)), + locale: 'ja', + ); + expect(result, '2分前'); + }); + + test('should return "1時間前" for 1 hour ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(hours: 1)), + locale: 'ja', + ); + expect(result, '1時間前'); + }); + + test('should return "2時間前" for 2 hours ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(hours: 2)), + locale: 'ja', + ); + expect(result, '2時間前'); + }); + + test('should return "1日前" for 1 day ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(hours: 24)), + locale: 'ja', + ); + expect(result, '1日前'); + }); + + test('should return "3日前" for 3 days ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(days: 3)), + locale: 'ja', + ); + expect(result, '3日前'); + }); + + test('should return formatted date for dates beyond 7 days', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(days: 10)), + locale: 'ja', + ); + expect(result, isNot('10日前')); + }); + }); +} diff --git a/test/messages/language/ro_msg_test.dart b/test/messages/language/ro_msg_test.dart index 5f2d494..c43bbc8 100644 --- a/test/messages/language/ro_msg_test.dart +++ b/test/messages/language/ro_msg_test.dart @@ -1,50 +1,130 @@ -import 'package:get_time_ago/src/messages/languages/ro_msg.dart'; +import 'package:get_time_ago/get_time_ago.dart'; import 'package:test/test.dart'; void main() { - final messages = RomanianMessages(); + final romanianMessages = RomanianMessages(); - test('prefixAgo returns "acum"', () { - expect(messages.prefixAgo(), 'acum'); - }); + group('RomanianMessages Test', () { + test('prefixAgo should return "acum"', () { + expect(romanianMessages.prefixAgo(), 'acum'); + }); - test('suffixAgo returns empty string', () { - expect(messages.suffixAgo(), ''); - }); + test('suffixAgo should return an empty string', () { + expect(romanianMessages.suffixAgo(), ''); + }); - test('justNow returns correct strings', () { - expect(messages.justNow(7), 'tocmai acum'); - }); + test('justNow should return "tocmai acum"', () { + expect(romanianMessages.justNow(20), 'tocmai acum'); + }); - test('secsAgo returns correct strings', () { - expect(messages.secsAgo(5), '5 secunde'); - }); + test('secsAgo should return correct seconds ago format', () { + expect(romanianMessages.secsAgo(25), '25 secunde'); + }); - test('minAgo returns "un minut"', () { - expect(messages.minAgo(1), 'un minut'); - }); + test('minAgo should return "un minut"', () { + expect(romanianMessages.minAgo(1), 'un minut'); + }); - test('minsAgo returns correct strings', () { - expect(messages.minsAgo(2), '2 minute'); - }); + test('minsAgo should return correct minutes ago format', () { + expect(romanianMessages.minsAgo(5), '5 minute'); + }); - test('hourAgo returns "o oră"', () { - expect(messages.hourAgo(1), 'o oră'); - }); + test('hourAgo should return "o oră"', () { + expect(romanianMessages.hourAgo(60), 'o oră'); + }); - test('hoursAgo returns correct strings', () { - expect(messages.hoursAgo(3), '3 ore'); - }); + test('hoursAgo should return correct hours ago format', () { + expect(romanianMessages.hoursAgo(5), '5 ore'); + }); - test('dayAgo returns "o zi"', () { - expect(messages.dayAgo(1), 'o zi'); - }); + test('dayAgo should return "o zi"', () { + expect(romanianMessages.dayAgo(24), 'o zi'); + }); + + test('daysAgo should return correct days ago format', () { + expect(romanianMessages.daysAgo(5), '5 zile'); + }); - test('daysAgo returns correct strings', () { - expect(messages.daysAgo(4), '4 zile'); + test('wordSeparator should return a space', () { + expect(romanianMessages.wordSeparator(), ' '); + }); }); - test('wordSeparator returns space', () { - expect(messages.wordSeparator(), ' '); + // Helper function to get the DateTime relative to now + DateTime _getRelativeDateTime(Duration duration) { + return DateTime.now().subtract(duration); + } + + group('GetTimeAgo Test with Romanian Locale', () { + test('should return "tocmai acum" for just now (0 seconds ago)', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(seconds: 0)), + locale: 'ro', + ); + expect(result, 'tocmai acum'); + }); + + test('should return correct format for 25 seconds ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(seconds: 25)), + locale: 'ro', + ); + expect(result, 'acum 25 secunde'); + }); + + test('should return "un minut" for 1 minute ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(minutes: 1)), + locale: 'ro', + ); + expect(result, 'acum un minut'); + }); + + test('should return correct format for 5 minutes ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(minutes: 5)), + locale: 'ro'); + expect(result, 'acum 5 minute'); + }); + + test('should return "o oră" for 1 hour ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(hours: 1)), + locale: 'ro', + ); + expect(result, 'acum o oră'); + }); + + test('should return correct format for 5 hours ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(hours: 5)), + locale: 'ro', + ); + expect(result, 'acum 5 ore'); + }); + + test('should return "o zi" for 1 day ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(days: 1)), + locale: 'ro', + ); + expect(result, 'acum o zi'); + }); + + test('should return correct format for 5 days ago', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(days: 5)), + locale: 'ro', + ); + expect(result, 'acum 5 zile'); + }); + + test('should return formatted date for dates beyond 7 days', () { + final result = GetTimeAgo.parse( + _getRelativeDateTime(const Duration(days: 10)), + locale: 'ro', + ); + expect(result, isNot('acum 10 zile')); + }); }); }