-
-
Notifications
You must be signed in to change notification settings - Fork 221
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 #678 from tkefauver/patch-1
Improved fix for Google Lite translator
- Loading branch information
Showing
5 changed files
with
76 additions
and
44 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
namespace ResXManager.Tests.Model; | ||
|
||
using System; | ||
|
||
using Xunit; | ||
|
||
public class TranslatorTests | ||
{ | ||
[Fact] | ||
public void GoogleLiteParsesFragmentedResponseCorrectly() | ||
{ | ||
const string input = """ | ||
[[["Ei! ","Hey there! ",null,null,10],["Como tá indo? ","How's it going? ",null,null,10],["Isso é ótimo! ","That's great! ",null,null,10],["K, tchau","K, bye",null,null,3,null,null,[[]],[[["66379e56ded86dd057796dbeaebad517","en_pt_2023q1.md"]]]]],null,"en",null,null,null,null,[]] | ||
"""; | ||
|
||
var result = Translators.GoogleTranslatorLite.ParseResponse(input); | ||
|
||
Assert.Equal("Ei! Como tá indo? Isso é ótimo! K, tchau", result); | ||
} | ||
|
||
[Fact] | ||
public void GoogleLiteParsesInvalidResponseCorrectly() | ||
{ | ||
const string input = $$""" | ||
{"x":[["Ei! "]]} | ||
"""; | ||
|
||
var result = Translators.GoogleTranslatorLite.ParseResponse(input); | ||
|
||
Assert.Equal("", result); | ||
} | ||
|
||
[Fact] | ||
public void GoogleLiteThrowsOnBadJson() | ||
{ | ||
const string input = $$""" | ||
{"x":Ei!"]]} | ||
"""; | ||
|
||
Assert.ThrowsAny<Exception>(() => Translators.GoogleTranslatorLite.ParseResponse(input)); | ||
} | ||
} |
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