Debian Codegraph @

morfologik-stemming/src/test/java/morfologik/stemming/DictionaryMetadataTest.java

raw
1 package morfologik.stemming;
2
3 import java.io.ByteArrayInputStream;
4 import java.io.IOException;
5 import java.io.StringWriter;
6 import java.nio.charset.Charset;
7 import java.nio.charset.StandardCharsets;
8 import java.util.Arrays;
9
10 import org.assertj.core.api.Assertions;
11 import org.junit.Test;
12
13 import com.carrotsearch.randomizedtesting.RandomizedTest;
14
15 public class DictionaryMetadataTest extends RandomizedTest {
16 @Test
17 public void testEscapeSeparator() throws IOException {
18 DictionaryMetadata m = DictionaryMetadata.read(getClass().getResourceAsStream("escape-separator.info"));
19 Assertions.assertThat(m.getSeparator()).isEqualTo((byte) '\t');
20 }
21
22 @Test
23 public void testUnicodeSeparator() throws IOException {
24 DictionaryMetadata m = DictionaryMetadata.read(getClass().getResourceAsStream("unicode-separator.info"));
25 Assertions.assertThat(m.getSeparator()).isEqualTo((byte) '\t');
26 }
27
28 @Test
29 public void testWriteMetadata() throws IOException {
30 StringWriter sw = new StringWriter();
31
32 EncoderType encoder = randomFrom(EncoderType.values());
33 Charset encoding = randomFrom(Arrays.asList(
34 StandardCharsets.UTF_8,
35 StandardCharsets.ISO_8859_1,
36 StandardCharsets.US_ASCII));
37
38 DictionaryMetadata.builder()
39 .encoding(encoding)
40 .encoder(encoder)
41 .separator('|')
42 .build()
43 .write(sw);
44
45 DictionaryMetadata other =
46 DictionaryMetadata.read(new ByteArrayInputStream(sw.toString().getBytes(StandardCharsets.UTF_8)));
47
48 Assertions.assertThat(other.getSeparator()).isEqualTo((byte) '|');
49 Assertions.assertThat(other.getDecoder().charset()).isEqualTo(encoding);
50 Assertions.assertThat(other.getEncoder().charset()).isEqualTo(encoding);
51 Assertions.assertThat(other.getSequenceEncoderType()).isEqualTo(encoder);
52 }
53 }