generated from JetBrains/intellij-platform-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #193 from marhali/next
Next
- Loading branch information
Showing
28 changed files
with
361 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/main/java/de/marhali/easyi18n/util/WildcardRegexMatcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package de.marhali.easyi18n.util; | ||
|
||
import org.apache.commons.io.FilenameUtils; | ||
|
||
/** | ||
* Utilities for wildcard / regex matching. | ||
* @author marhali | ||
*/ | ||
public class WildcardRegexMatcher { | ||
public static boolean matchWildcardRegex(String string, String pattern) { | ||
boolean wildcardMatch = FilenameUtils.wildcardMatchOnSystem(string, pattern); | ||
|
||
if(wildcardMatch) { | ||
return true; | ||
} | ||
|
||
try { | ||
return string.matches(pattern); | ||
} catch (Exception e) { | ||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/test/java/de/marhali/easyi18n/WildcardRegexMatcherTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package de.marhali.easyi18n; | ||
|
||
import de.marhali.easyi18n.util.WildcardRegexMatcher; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
/** | ||
* Unit tests for {@link WildcardRegexMatcher}. | ||
* @author marhali | ||
*/ | ||
public class WildcardRegexMatcherTest extends WildcardRegexMatcher { | ||
@Test | ||
public void testWildcard() { | ||
Assert.assertTrue(matchWildcardRegex("en.json", "*.json")); | ||
Assert.assertTrue(matchWildcardRegex("de.json", "*.json")); | ||
Assert.assertFalse(matchWildcardRegex("index.html", "*.json")); | ||
|
||
Assert.assertTrue(matchWildcardRegex("en.json", "*.*")); | ||
Assert.assertFalse(matchWildcardRegex("file", "*.*")); | ||
|
||
Assert.assertTrue(matchWildcardRegex("en.txt", "*.???")); | ||
Assert.assertFalse(matchWildcardRegex("en.json", "*.???")); | ||
} | ||
|
||
@Test | ||
public void testRegex() { | ||
Assert.assertTrue(matchWildcardRegex("en.json", "^(en|de)\\.json")); | ||
Assert.assertFalse(matchWildcardRegex("gb.json", "^(en|de)\\.json")); | ||
|
||
Assert.assertTrue(matchWildcardRegex("en.jpg", "^.*\\.(jpg|JPG|gif|GIF)$")); | ||
Assert.assertFalse(matchWildcardRegex("en.json", "^.*\\.(jpg|JPG|gif|GIF)$")); | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
src/test/java/de/marhali/easyi18n/e2e/EndToEndTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package de.marhali.easyi18n.e2e; | ||
|
||
import com.intellij.testFramework.fixtures.BasePlatformTestCase; | ||
|
||
import de.marhali.easyi18n.InstanceManager; | ||
import de.marhali.easyi18n.settings.ProjectSettings; | ||
import de.marhali.easyi18n.settings.ProjectSettingsService; | ||
import de.marhali.easyi18n.settings.ProjectSettingsState; | ||
|
||
import org.apache.commons.io.FileUtils; | ||
import org.apache.commons.io.filefilter.IOFileFilter; | ||
import org.apache.commons.io.filefilter.TrueFileFilter; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.charset.Charset; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.Arrays; | ||
import java.util.Objects; | ||
|
||
/** | ||
* End-to-end test case. | ||
* @author marhali | ||
*/ | ||
public abstract class EndToEndTestCase extends BasePlatformTestCase { | ||
|
||
private static final Charset CHARSET = StandardCharsets.UTF_8; | ||
|
||
private final ProjectSettings settings; | ||
private Path tempPath; | ||
|
||
public EndToEndTestCase(ProjectSettings settings) { | ||
this.settings = settings; | ||
} | ||
|
||
@Override | ||
protected void setUp() throws Exception { | ||
super.setUp(); | ||
ProjectSettingsService.get(getProject()).setState(new ProjectSettingsState(settings)); | ||
tempPath = Files.createTempDirectory("tests-easyi18n-"); | ||
} | ||
|
||
@Override | ||
protected void tearDown() throws Exception { | ||
FileUtils.deleteDirectory(tempPath.toFile()); | ||
super.tearDown(); | ||
} | ||
|
||
public void testParseAndSerialize() throws IOException { | ||
// Read translation files based on the provided settings | ||
InstanceManager.get(getProject()).store().loadFromPersistenceLayer(success -> {}); | ||
|
||
// Save the cached translation data to a temporary output directory | ||
ProjectSettingsState out = new ProjectSettingsState(settings); | ||
out.setLocalesDirectory(tempPath.toString()); | ||
ProjectSettingsService.get(getProject()).setState(out); | ||
|
||
InstanceManager.get(getProject()).store().saveToPersistenceLayer(success -> {}); | ||
|
||
// Compare file structure and contents | ||
IOFileFilter fileFilter = TrueFileFilter.INSTANCE; | ||
|
||
File originalDirectory = new File(Objects.requireNonNull(settings.getLocalesDirectory())); | ||
File[] originalFiles = FileUtils.listFiles(originalDirectory, fileFilter, fileFilter).toArray(new File[0]); | ||
|
||
File outputDirectory = tempPath.toFile(); | ||
File[] outputFiles = FileUtils.listFiles(outputDirectory, fileFilter, fileFilter).toArray(new File[0]); | ||
|
||
Arrays.sort(originalFiles); | ||
Arrays.sort(outputFiles); | ||
|
||
assertEquals(originalFiles.length, outputFiles.length); | ||
|
||
for(int i = 0; i < originalFiles.length; i++) { | ||
File originalFile = originalFiles[i]; | ||
File outputFile = outputFiles[i]; | ||
|
||
// Replace originalFile with os-dependent line-separators | ||
assertEquals(FileUtils.readFileToString(originalFile, CHARSET).replace("\n", System.lineSeparator()), | ||
FileUtils.readFileToString(outputFile, CHARSET)); | ||
} | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
src/test/java/de/marhali/easyi18n/e2e/TestSettingsState.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package de.marhali.easyi18n.e2e; | ||
|
||
import de.marhali.easyi18n.io.folder.FolderStrategyType; | ||
import de.marhali.easyi18n.io.parser.ParserStrategyType; | ||
import de.marhali.easyi18n.settings.presets.DefaultPreset; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
/** | ||
* Settings base for end-to-end tests. | ||
* @author marhali | ||
*/ | ||
public class TestSettingsState extends DefaultPreset { | ||
|
||
private final String localesDirectory; | ||
private final FolderStrategyType folderStrategy; | ||
private final ParserStrategyType parserStrategy; | ||
|
||
public TestSettingsState(String localesDirectory, FolderStrategyType folderStrategy, ParserStrategyType parserStrategy) { | ||
this.localesDirectory = localesDirectory; | ||
this.folderStrategy = folderStrategy; | ||
this.parserStrategy = parserStrategy; | ||
} | ||
|
||
|
||
@Override | ||
public @Nullable String getLocalesDirectory() { | ||
return localesDirectory; | ||
} | ||
|
||
@Override | ||
public @NotNull FolderStrategyType getFolderStrategy() { | ||
return folderStrategy; | ||
} | ||
|
||
@Override | ||
public @NotNull ParserStrategyType getParserStrategy() { | ||
return parserStrategy; | ||
} | ||
|
||
@Override | ||
public @NotNull String getFilePattern() { | ||
return "*.*"; | ||
} | ||
|
||
@Override | ||
public boolean isSorting() { | ||
return false; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/test/java/de/marhali/easyi18n/e2e/single/SingleJson5Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package de.marhali.easyi18n.e2e.single; | ||
|
||
import de.marhali.easyi18n.e2e.EndToEndTestCase; | ||
import de.marhali.easyi18n.e2e.TestSettingsState; | ||
import de.marhali.easyi18n.io.folder.FolderStrategyType; | ||
import de.marhali.easyi18n.io.parser.ParserStrategyType; | ||
|
||
/** | ||
* @author marhali | ||
* End-to-end tests for single directory json5 files. | ||
*/ | ||
public class SingleJson5Test extends EndToEndTestCase { | ||
public SingleJson5Test() { | ||
super(new TestSettingsState( | ||
"src/test/resources/single/json5", | ||
FolderStrategyType.SINGLE, | ||
ParserStrategyType.JSON5) | ||
); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/test/java/de/marhali/easyi18n/e2e/single/SingleJsonTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package de.marhali.easyi18n.e2e.single; | ||
|
||
import de.marhali.easyi18n.e2e.EndToEndTestCase; | ||
import de.marhali.easyi18n.e2e.TestSettingsState; | ||
import de.marhali.easyi18n.io.folder.FolderStrategyType; | ||
import de.marhali.easyi18n.io.parser.ParserStrategyType; | ||
|
||
/** | ||
* End-to-end tests for single directory json files. | ||
* @author marhali | ||
*/ | ||
public class SingleJsonTest extends EndToEndTestCase { | ||
public SingleJsonTest() { | ||
super(new TestSettingsState( | ||
"src/test/resources/single/json", | ||
FolderStrategyType.SINGLE, | ||
ParserStrategyType.JSON) | ||
); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/test/java/de/marhali/easyi18n/e2e/single/SinglePropertiesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package de.marhali.easyi18n.e2e.single; | ||
|
||
import de.marhali.easyi18n.e2e.EndToEndTestCase; | ||
import de.marhali.easyi18n.e2e.TestSettingsState; | ||
import de.marhali.easyi18n.io.folder.FolderStrategyType; | ||
import de.marhali.easyi18n.io.parser.ParserStrategyType; | ||
|
||
/** | ||
* End-to-end tests for single directory .properties files. | ||
* @author marhali | ||
*/ | ||
public class SinglePropertiesTest extends EndToEndTestCase { | ||
public SinglePropertiesTest() { | ||
super(new TestSettingsState( | ||
"src/test/resources/single/properties", | ||
FolderStrategyType.SINGLE, | ||
ParserStrategyType.PROPERTIES) | ||
); | ||
} | ||
} |
Oops, something went wrong.