Skip to content

Commit c70a0e3

Browse files
Theta-DevStypox
authored andcommitted
Add a test for textual durations parsing using TimeAgoParser's patterns
1 parent 7366eab commit c70a0e3

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package org.schabi.newpipe.extractor.localization;
2+
3+
import org.junit.jupiter.api.BeforeAll;
4+
import org.junit.jupiter.api.Test;
5+
import org.schabi.newpipe.extractor.exceptions.ParsingException;
6+
7+
import static org.junit.jupiter.api.Assertions.assertEquals;
8+
import static org.junit.jupiter.api.Assertions.assertThrows;
9+
10+
class TimeAgoParserTest {
11+
private static TimeAgoParser timeAgoParser;
12+
13+
@BeforeAll
14+
static void setUp() {
15+
timeAgoParser = TimeAgoPatternsManager.getTimeAgoParserFor(Localization.DEFAULT);
16+
}
17+
18+
@Test
19+
void testGetDuration() throws ParsingException {
20+
assertEquals(1, timeAgoParser.parseDuration("one second"));
21+
assertEquals(1, timeAgoParser.parseDuration("second"));
22+
assertEquals(49, timeAgoParser.parseDuration("49 seconds"));
23+
assertEquals(61, timeAgoParser.parseDuration("1 minute, 1 second"));
24+
}
25+
26+
@Test
27+
void testGetDurationError() {
28+
assertThrows(ParsingException.class, () -> timeAgoParser.parseDuration("abcd"));
29+
assertThrows(ParsingException.class, () -> timeAgoParser.parseDuration("12 abcd"));
30+
}
31+
}

0 commit comments

Comments
 (0)