|
| 1 | +package dev.felnull.itts.core.dict; |
| 2 | + |
| 3 | +import org.junit.jupiter.api.Assertions; |
| 4 | +import org.junit.jupiter.params.ParameterizedTest; |
| 5 | +import org.junit.jupiter.params.provider.Arguments; |
| 6 | +import org.junit.jupiter.params.provider.MethodSource; |
| 7 | + |
| 8 | +import java.util.Arrays; |
| 9 | +import java.util.stream.Stream; |
| 10 | + |
| 11 | +public class URLReplacerTest { |
| 12 | + private static final String REPLACED_TEXT = "[URL_SYORYAKU]"; |
| 13 | + |
| 14 | + private static final TestEntry[] ENTRIES = new TestEntry[]{ |
| 15 | + new TestEntry("https://www.google.com/", "[URL_SYORYAKU]"), |
| 16 | + new TestEntry("AAA https://www.google.com/ AAA", "AAA [URL_SYORYAKU] AAA"), |
| 17 | + new TestEntry("AAAhttps://www.google.com/aaa", "AAA[URL_SYORYAKU]"), |
| 18 | + new TestEntry("AAAhttps://www.google.com/ AAA", "AAA[URL_SYORYAKU] AAA"), |
| 19 | + new TestEntry("課長壊れる https://www.google.com/ 課長壊れる", "課長壊れる [URL_SYORYAKU] 課長壊れる"), |
| 20 | + new TestEntry("課長壊れるhttps://www.google.com/課長壊れる", "課長壊れる[URL_SYORYAKU]"), |
| 21 | + new TestEntry("課長壊れるhttps://www.google.com/ 課長壊れる", "課長壊れる[URL_SYORYAKU] 課長壊れる"), |
| 22 | + new TestEntry("課長壊れるhttps://www.google.com/ 課長壊れる", "課長壊れる[URL_SYORYAKU] 課長壊れる"), |
| 23 | + new TestEntry("課長壊れる https://www.google.com/ 課長壊れる", "課長壊れる [URL_SYORYAKU] 課長壊れる"), |
| 24 | + new TestEntry(""" |
| 25 | + AAA |
| 26 | + https://www.google.com/ |
| 27 | + AAA |
| 28 | + """, """ |
| 29 | + AAA |
| 30 | + [URL_SYORYAKU] |
| 31 | + AAA |
| 32 | + """), |
| 33 | + new TestEntry(""" |
| 34 | + AAA |
| 35 | + AAA https://www.google.com/ AAA |
| 36 | + AAA |
| 37 | + """, """ |
| 38 | + AAA |
| 39 | + AAA [URL_SYORYAKU] AAA |
| 40 | + AAA |
| 41 | + """), |
| 42 | + new TestEntry(""" |
| 43 | + AAA |
| 44 | + AAAhttps://www.google.com/aaa |
| 45 | + AAA |
| 46 | + """, """ |
| 47 | + AAA |
| 48 | + AAA[URL_SYORYAKU] |
| 49 | + AAA |
| 50 | + """), |
| 51 | + new TestEntry(""" |
| 52 | + AAA |
| 53 | + AAAhttps://www.google.com AAA |
| 54 | + AAA |
| 55 | + """, """ |
| 56 | + AAA |
| 57 | + AAA[URL_SYORYAKU] AAA |
| 58 | + AAA |
| 59 | + """), |
| 60 | + new TestEntry(""" |
| 61 | + https://www.google.com |
| 62 | + AAAhttps://www.google.com AAAhttps://www.google.com |
| 63 | + AAA |
| 64 | + """, """ |
| 65 | + [URL_SYORYAKU] |
| 66 | + AAA[URL_SYORYAKU] AAA[URL_SYORYAKU] |
| 67 | + AAA |
| 68 | + """), |
| 69 | + new TestEntry("https://www.google.com/ https://www.google.com/", "[URL_SYORYAKU] [URL_SYORYAKU]"), |
| 70 | + new TestEntry("AAA http://ikisugi.ad.jp/katyou/broken/aiki/#:~:text=野獣先輩 AAA", "AAA [URL_SYORYAKU] AAA"), |
| 71 | + new TestEntry("AAAhttp://ikisugi.ad.jp/katyou/broken/aiki/#:~:text=野獣先輩aaa", "AAA[URL_SYORYAKU]"), |
| 72 | + new TestEntry("AAAhttp://ikisugi.ad.jp/katyou/broken/aiki/#:~:text=野獣先輩 AAA", "AAA[URL_SYORYAKU] AAA"), |
| 73 | + new TestEntry("AAA https://www.google.com/114514 AAA", "AAA [URL_SYORYAKU] AAA"), |
| 74 | + new TestEntry("ftp://ikisugi.tokyo/", "[URL_SYORYAKU]"), |
| 75 | + new TestEntry("AAA ftp://ikisugi.tokyo/ AAA", "AAA [URL_SYORYAKU] AAA"), |
| 76 | + new TestEntry("https://www.google.com", "[URL_SYORYAKU]"), |
| 77 | + new TestEntry("AAA https://www.google.com AAA", "AAA [URL_SYORYAKU] AAA"), |
| 78 | + new TestEntry("http://www.google.com/", "[URL_SYORYAKU]"), |
| 79 | + new TestEntry("AAA http://www.google.com/ AAA", "AAA [URL_SYORYAKU] AAA"), |
| 80 | + }; |
| 81 | + |
| 82 | + @ParameterizedTest |
| 83 | + @MethodSource("entries") |
| 84 | + void testReplace(String before, String after) { |
| 85 | + URLReplacer replacer = new URLReplacer(REPLACED_TEXT); |
| 86 | + String ret = replacer.replace(before); |
| 87 | + Assertions.assertEquals(after, ret); |
| 88 | + } |
| 89 | + |
| 90 | + private static Stream<Arguments> entries() { |
| 91 | + return Arrays.stream(ENTRIES).map(it -> Arguments.arguments(it.before, it.after)); |
| 92 | + } |
| 93 | + |
| 94 | + private record TestEntry(String before, String after) { |
| 95 | + } |
| 96 | +} |
0 commit comments