Skip to content

Commit 30416f4

Browse files
More ExtractorLoggerTest tests
1 parent c17a580 commit 30416f4

1 file changed

Lines changed: 89 additions & 3 deletions

File tree

extractor/src/test/java/org/schabi/newpipe/extractor/utils/ExtractorLoggerTest.java

Lines changed: 89 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import org.junit.jupiter.api.BeforeEach;
44
import org.junit.jupiter.api.Test;
5+
import org.junit.jupiter.params.ParameterizedTest;
6+
import org.junit.jupiter.params.provider.CsvSource;
57

68
import static org.junit.jupiter.api.Assertions.*;
79

@@ -48,16 +50,100 @@ void noArgsReturnsTemplateUnchanged() {
4850
assertEquals("No placeholders {} here", logger.lastDebug);
4951
}
5052

53+
@ParameterizedTest
54+
@CsvSource(value = {
55+
"Value {Unclosed,Value {Unclosed",
56+
"{({test_one)}}},}",
57+
"{{test},{test}",
58+
"{{test_three}}},{test_three}}",
59+
})
60+
void unmatchedBraceLeavesRemainder(final String message, final String expected) {
61+
ExtractorLogger.d("T", message, "");
62+
assertEquals(expected, logger.lastDebug);
63+
}
64+
65+
@ParameterizedTest
66+
@CsvSource({
67+
"{{,{",
68+
"}},}",
69+
"{{}},{}",
70+
"}}{{,}{",
71+
"hello},hello}",
72+
"hello{,hello{",
73+
})
74+
void doubleBraceEscaping(final String message, final String expected) {
75+
ExtractorLogger.d("T", message, "unconsumed");
76+
assertEquals(expected, logger.lastDebug);
77+
}
78+
79+
@Test
80+
void escapedBracesDoNotConsumeArg() {
81+
ExtractorLogger.d("T", "{{Name}}", "Alice");
82+
assertEquals("{Name}", logger.lastDebug);
83+
}
84+
85+
@Test
86+
void escapedBraceThenPlaceholder() {
87+
ExtractorLogger.d("T", "{{literal}} {Value}", "Alice");
88+
assertEquals("{literal} Alice", logger.lastDebug);
89+
}
90+
91+
@ParameterizedTest
92+
@CsvSource({
93+
"Value {Unclosed,Value {Unclosed",
94+
"{({test_one)}}},}",
95+
})
96+
void unclosedOrStrayBracesLeaveRemainderUnchanged(final String message, final String expected) {
97+
ExtractorLogger.d("T", message, "");
98+
assertEquals(expected, logger.lastDebug);
99+
}
100+
101+
@ParameterizedTest
102+
@CsvSource({
103+
"{{test},{test}",
104+
"{{test_three}}},{test_three}}",
105+
})
106+
void doubleBraceEscapesLiteralBraces(final String message, final String expected) {
107+
ExtractorLogger.d("T", message, "");
108+
assertEquals(expected, logger.lastDebug);
109+
}
110+
111+
@Test
112+
void tripleOpenBraceIsEscapedLiteralThenPlaceholder() {
113+
ExtractorLogger.d("T", "{{{Name}}}", "Alice");
114+
assertEquals("{Alice}", logger.lastDebug);
115+
}
116+
117+
@Test
118+
void mixedEscapedAndPlaceholders() {
119+
ExtractorLogger.d("T", "{A} {{B}} {C}", "1", "2");
120+
assertEquals("1 {B} 2", logger.lastDebug);
121+
}
122+
123+
@Test
124+
void nullArgFormatsAsNullString() {
125+
ExtractorLogger.d("T", "value is {V}", (Object) null);
126+
assertEquals("value is null", logger.lastDebug);
127+
}
128+
129+
@Test
130+
void emptyTemplateWithArgsReturnsEmpty() {
131+
ExtractorLogger.d("T", "", "X");
132+
assertEquals("", logger.lastDebug);
133+
}
134+
51135
@Test
52136
void nullTemplatePrintsNull() {
53137
ExtractorLogger.d("T", (String) null, "X");
54138
assertNull(logger.lastDebug);
55139
}
56140

57141
@Test
58-
void unmatchedBraceLeavesRemainder() {
59-
ExtractorLogger.d("T", "Value {Unclosed", "X");
60-
assertEquals("Value {Unclosed", logger.lastDebug);
142+
void escapedBracesWithThrowable() {
143+
RuntimeException ex = new RuntimeException("boom");
144+
ExtractorLogger.d("T", ex, "{{literal}} {Value}", "Alice");
145+
assertEquals("{literal} Alice", logger.lastDebug);
146+
assertSame(ex, logger.lastDebugThrowable);
61147
}
62148

63149
@Test

0 commit comments

Comments
 (0)