Recently Written · git

scan-subread

PDF reader that follows an audiobook with the SubRead suite

git clone https://github.com/equwal/scan-subread

Log | Files | Refs


android/app/src/test/java/com/equwal/scansubread/SafeFileNameTest.java (1243 bytes)

1 package com.equwal.scansubread;
2 
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertNull;
5 
6 import org.junit.Test;
7 
8 /** The name of a result file comes from the web page, so it must stay in its folder. */
9 public class SafeFileNameTest {
10 
11     @Test
12     public void keepsLettersDigitsDotsLowLinesAndHyphens() {
13         assertEquals("Book_1.2-a.srt", SubReadPlugin.safeFileName("Book_1.2-a.srt"));
14     }
15 
16     @Test
17     public void changesEachOtherCharacterToALowLine() {
18         assertEquals("_____.pdf_1234.srt", SubReadPlugin.safeFileName("吾輩は猫だ.pdf|1234.srt"));
19         assertEquals("a_b_c_d", SubReadPlugin.safeFileName("a b/c\\d"));
20     }
21 
22     @Test
23     public void cannotPointToAnotherFolder() {
24         assertEquals(".._.._x", SubReadPlugin.safeFileName("../../x"));
25         assertNull(SubReadPlugin.safeFileName(".."));
26         assertNull(SubReadPlugin.safeFileName("."));
27         assertNull(SubReadPlugin.safeFileName(""));
28     }
29 
30     @Test
31     public void refusesANameThatIsTooLong() {
32         String longest = new String(new char[255]).replace('\0', 'a');
33         assertEquals(longest, SubReadPlugin.safeFileName(longest));
34         assertNull(SubReadPlugin.safeFileName(longest + "a"));
35     }
36 }