-
-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
121 additions
and
8 deletions.
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
backend/data/src/main/kotlin/io/tolgee/formats/csv/in/CsvDelimiterDetector.kt
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
58 changes: 58 additions & 0 deletions
58
backend/data/src/test/kotlin/io/tolgee/unit/formats/csv/in/CsvImportFormatDetectorTest.kt
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,58 @@ | ||
package io.tolgee.unit.formats.csv.`in` | ||
|
||
import io.tolgee.formats.csv.`in`.CSVImportFormatDetector | ||
import io.tolgee.formats.csv.`in`.CsvFileParser | ||
import io.tolgee.formats.importCommon.ImportFormat | ||
import io.tolgee.testing.assert | ||
import io.tolgee.util.FileProcessorContextMockUtil | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
import java.io.File | ||
|
||
class CsvImportFormatDetectorTest { | ||
lateinit var mockUtil: FileProcessorContextMockUtil | ||
|
||
@BeforeEach | ||
fun setup() { | ||
mockUtil = FileProcessorContextMockUtil() | ||
} | ||
|
||
@Test | ||
fun `detected i18next`() { | ||
"src/test/resources/import/csv/example.csv".assertDetected(ImportFormat.CSV_ICU) | ||
} | ||
|
||
@Test | ||
fun `detected icu`() { | ||
"src/test/resources/import/csv/icu.csv".assertDetected(ImportFormat.CSV_ICU) | ||
} | ||
|
||
@Test | ||
fun `detected java`() { | ||
"src/test/resources/import/csv/java.csv".assertDetected(ImportFormat.CSV_JAVA) | ||
} | ||
|
||
@Test | ||
fun `detected php`() { | ||
"src/test/resources/import/csv/php.csv".assertDetected(ImportFormat.CSV_PHP) | ||
} | ||
|
||
@Test | ||
fun `fallbacks to icu`() { | ||
"src/test/resources/import/csv/unknown.csv".assertDetected(ImportFormat.CSV_ICU) | ||
} | ||
|
||
private fun parseFile(path: String): Any? { | ||
val parser = | ||
CsvFileParser( | ||
inputStream = File(path).inputStream(), | ||
delimiter = ',', | ||
languageFallback = "unknown", | ||
) | ||
return parser.rows | ||
} | ||
|
||
private fun String.assertDetected(format: ImportFormat) { | ||
CSVImportFormatDetector().detectFormat(parseFile(this)).assert.isEqualTo(format) | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,12 @@ | ||
"key","en","cs" | ||
"key","value","hodnota" | ||
"key","value",hodnota | ||
"keyDeep.inner","value","hodnota" | ||
"keyInterpolate","replace this {value}","nahradit toto {value}" | ||
"keyInterpolate","replace this {value}",nahradit toto {value} | ||
"keyInterpolateWithFormatting","replace this {value, number}","nahradit toto {value, number}" | ||
"keyPluralSimple"," {value, plural, one {the singular} other {the plural {value}}}"," {value, plural, one {jednotné číslo} other {množné číslo {value}}}" | ||
"escapedCharacters","this is a \"quote\"","toto je \"citace\"" | ||
"escapedCharacters2","this is a | ||
new line","toto je | ||
nový řádek" | ||
"escapedCharacters3","this is a \\ backslash","toto je zpětné \\ lomítko" | ||
"escapedCharacters4","this is a , comma","toto je , čárka" |
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,2 @@ | ||
key,en | ||
key,{param} |
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,3 @@ | ||
key,en | ||
"key","%D this is java %d" | ||
"key2","%D this is 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,2 @@ | ||
key,en | ||
key,"%'s with ' flag" |
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,2 @@ | ||
key,en | ||
key,This suits php and java |