From c70a0e35433494454d864f361b676ed504d7f8c4 Mon Sep 17 00:00:00 2001 From: ThetaDev Date: Fri, 14 Jul 2023 23:56:15 +0200 Subject: [PATCH] Add a test for textual durations parsing using TimeAgoParser's patterns --- .../localization/TimeAgoParserTest.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 extractor/src/test/java/org/schabi/newpipe/extractor/localization/TimeAgoParserTest.java diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/localization/TimeAgoParserTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/localization/TimeAgoParserTest.java new file mode 100644 index 000000000..4d12b3da9 --- /dev/null +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/localization/TimeAgoParserTest.java @@ -0,0 +1,31 @@ +package org.schabi.newpipe.extractor.localization; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.schabi.newpipe.extractor.exceptions.ParsingException; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +class TimeAgoParserTest { + private static TimeAgoParser timeAgoParser; + + @BeforeAll + static void setUp() { + timeAgoParser = TimeAgoPatternsManager.getTimeAgoParserFor(Localization.DEFAULT); + } + + @Test + void testGetDuration() throws ParsingException { + assertEquals(1, timeAgoParser.parseDuration("one second")); + assertEquals(1, timeAgoParser.parseDuration("second")); + assertEquals(49, timeAgoParser.parseDuration("49 seconds")); + assertEquals(61, timeAgoParser.parseDuration("1 minute, 1 second")); + } + + @Test + void testGetDurationError() { + assertThrows(ParsingException.class, () -> timeAgoParser.parseDuration("abcd")); + assertThrows(ParsingException.class, () -> timeAgoParser.parseDuration("12 abcd")); + } +} \ No newline at end of file