Skip to content

Commit 8f8803f

Browse files
committed
Add test cases
1 parent 321d082 commit 8f8803f

File tree

10 files changed

+119
-4
lines changed

10 files changed

+119
-4
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Translation services have been around for a long time.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Any web page can be viewed in multiple languages.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Translation services have been around for a long time.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Any web page can be viewed in multiple languages.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Polska wersja o tłumaczeniach AI
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Polska wersja o tłumaczeniu stron
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Translation services have been around for a long time.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Any web page can be viewed in multiple languages.

src/main/java/io/simplelocalize/cli/io/FileListReader.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ private List<FileToUpload> findMatchingFiles(Path parentDirectory, String patter
3838
if (matcher.matches())
3939
{
4040
String translationKey = getGroupOrNull("translationKey", matcher);
41-
String lang = getGroupOrNull("lang", matcher);
42-
String ns = getGroupOrNull("ns", matcher);
41+
String languageKey = getGroupOrNull("lang", matcher);
42+
String namespace = getGroupOrNull("ns", matcher);
4343
return FileToUpload.builder()
44-
.withLanguage(lang)
45-
.withNamespace(ns)
44+
.withLanguage(languageKey)
45+
.withNamespace(namespace)
4646
.withTranslationKey(translationKey)
4747
.withPath(file)
4848
.build();

src/test/java/io/simplelocalize/cli/util/FileListReaderTest.java

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,113 @@ class FileListReaderTest
1515

1616
private final FileListReader sut = new FileListReader();
1717

18+
@Test
19+
void shouldFindMarkdownBlogPostsWithNamespaceAndLanguageKey() throws IOException
20+
{
21+
//given
22+
String path = "./junit/blog-posts-with-lang-name-and-namespace/{lang}/{translationKey}_{ns}.md";
23+
24+
//when
25+
List<FileToUpload> result = sut.findFilesToUpload(path);
26+
27+
//then
28+
Assertions.assertThat(result)
29+
.containsExactlyInAnyOrder(
30+
FileToUpload.builder()
31+
.withPath(Paths.get("./junit/blog-posts-with-lang-name-and-namespace/en/ai-translations_common.md"))
32+
.withLanguage("en")
33+
.withNamespace("common")
34+
.withTranslationKey("ai-translations")
35+
.build(),
36+
FileToUpload.builder()
37+
.withPath(Paths.get("./junit/blog-posts-with-lang-name-and-namespace/en/how-to-translate-website_common.md"))
38+
.withLanguage("en")
39+
.withNamespace("common")
40+
.withTranslationKey("how-to-translate-website")
41+
.build(),
42+
FileToUpload.builder()
43+
.withPath(Paths.get("./junit/blog-posts-with-lang-name-and-namespace/pl/ai-translations_common.md"))
44+
.withLanguage("pl")
45+
.withNamespace("common")
46+
.withTranslationKey("ai-translations")
47+
.build(),
48+
FileToUpload.builder()
49+
.withPath(Paths.get("./junit/blog-posts-with-lang-name-and-namespace/pl/how-to-translate-website_common.md"))
50+
.withLanguage("pl")
51+
.withNamespace("common")
52+
.withTranslationKey("how-to-translate-website")
53+
.build()
54+
);
55+
}
56+
57+
@Test
58+
void shouldFindMarkdownBlogPostsWithoutExtension() throws IOException
59+
{
60+
//given
61+
String path = "./junit/blog-posts/{translationKey}.md";
62+
63+
//when
64+
List<FileToUpload> result = sut.findFilesToUpload(path);
65+
66+
//then
67+
Assertions.assertThat(result)
68+
.containsExactlyInAnyOrder(
69+
FileToUpload.builder()
70+
.withPath(Paths.get("./junit/blog-posts/ai-translations.md"))
71+
.withTranslationKey("ai-translations")
72+
.build(),
73+
FileToUpload.builder()
74+
.withPath(Paths.get("./junit/blog-posts/how-to-translate-website.md"))
75+
.withTranslationKey("how-to-translate-website")
76+
.build()
77+
);
78+
}
79+
80+
@Test
81+
void shouldFindMarkdownBlogPostsWithExtension() throws IOException
82+
{
83+
//given
84+
String path = "./junit/blog-posts/{translationKey}";
85+
86+
//when
87+
List<FileToUpload> result = sut.findFilesToUpload(path);
88+
89+
//then
90+
Assertions.assertThat(result)
91+
.containsExactlyInAnyOrder(
92+
FileToUpload.builder()
93+
.withPath(Paths.get("./junit/blog-posts/ai-translations.md"))
94+
.withTranslationKey("ai-translations.md")
95+
.build(),
96+
FileToUpload.builder()
97+
.withPath(Paths.get("./junit/blog-posts/how-to-translate-website.md"))
98+
.withTranslationKey("how-to-translate-website.md")
99+
.build()
100+
);
101+
}
102+
103+
@Test
104+
void shouldFindMarkdownBlogPostsWhenKeyAsDirName() throws IOException
105+
{
106+
//given
107+
String path = "./junit/blog-posts-keys-as-dir-name/{translationKey}/index.md";
108+
109+
//when
110+
List<FileToUpload> result = sut.findFilesToUpload(path);
111+
112+
//then
113+
Assertions.assertThat(result)
114+
.containsExactlyInAnyOrder(
115+
FileToUpload.builder()
116+
.withPath(Paths.get("./junit/blog-posts-keys-as-dir-name/ai-translations/index.md"))
117+
.withTranslationKey("ai-translations")
118+
.build(),
119+
FileToUpload.builder()
120+
.withPath(Paths.get("./junit/blog-posts-keys-as-dir-name/how-to-translate-website/index.md"))
121+
.withTranslationKey("how-to-translate-website")
122+
.build()
123+
);
124+
}
18125

19126
@Test
20127
void shouldFindJsonFilesWithInLocaleDirectoryWhenNamespaceFirst() throws IOException

0 commit comments

Comments
 (0)