-
-
Notifications
You must be signed in to change notification settings - Fork 45
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
1 parent
8014d7b
commit d7065a4
Showing
8 changed files
with
144 additions
and
78 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Bad @x escape = Bad @x escape |
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,4 @@ | ||
# textdomain: err_missing_eq | ||
|
||
Hello, World! = Bonjour, Monde! | ||
Invalid line |
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,8 @@ | ||
# textdomain: foobar | ||
|
||
Hello, World! = Bonjour, Monde! | ||
Hello @1!=@1, salut! | ||
Cats @= cool = Chats @= cool | ||
A @n newline = Une @ | ||
nouvelle ligne | ||
Maybe @@@n@@@=@@= Peut être @@@n@@@=@@ |
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 @@ | ||
Hello, World! = Bonjour, Monde! |
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,13 +1,61 @@ | ||
import os | ||
|
||
import pytest | ||
|
||
from app.tasks.minetestcheck.translation import parse_tr | ||
|
||
|
||
def test_parses_tr(): | ||
dirname = os.path.dirname(__file__) | ||
filepath = os.path.join(dirname, "test_file.fr.tr") | ||
filepath = os.path.join(dirname, "foobar.fr.tr") | ||
out = parse_tr(filepath) | ||
|
||
assert out.language == "fr" | ||
assert out.textdomain == "foobar" | ||
assert len(out.entries) == 5 | ||
assert out.entries["Hello, World!"] == "Bonjour, Monde!" | ||
assert out.entries["Hello @1!"] == "@1, salut!" | ||
assert out.entries["Cats = cool"] == "Chats = cool" | ||
assert out.entries["A \n newline"] == "Une \nnouvelle ligne" | ||
assert out.entries["Maybe @\n@=@"] == "Peut être @\n@=@" | ||
|
||
|
||
def test_parses_tr_infers_textdomain(): | ||
dirname = os.path.dirname(__file__) | ||
filepath = os.path.join(dirname, "no_textdomain_comment.fr.tr") | ||
out = parse_tr(filepath) | ||
|
||
assert out.language == "fr" | ||
assert out.textdomain == "no_textdomain_comment" | ||
assert len(out.entries) == 1 | ||
assert out.entries["Hello, World!"] == "Bonjour, Monde!" | ||
|
||
|
||
def test_parses_tr_error_on_textdomain_mismatch(): | ||
dirname = os.path.dirname(__file__) | ||
filepath = os.path.join(dirname, "textdomain_mismatch.fr.tr") | ||
|
||
with pytest.raises(SyntaxError) as e: | ||
parse_tr(filepath) | ||
|
||
assert str(e.value) == "Line 1: The filename's textdomain (textdomain_mismatch) should match the comment (foobar)" | ||
|
||
|
||
def test_parses_tr_error_on_missing_eq(): | ||
dirname = os.path.dirname(__file__) | ||
filepath = os.path.join(dirname, "err_missing_eq.fr.tr") | ||
|
||
with pytest.raises(SyntaxError) as e: | ||
parse_tr(filepath) | ||
|
||
assert str(e.value) == "Line 4: Missing = in line" | ||
|
||
|
||
def test_parses_tr_error_on_bad_escape(): | ||
dirname = os.path.dirname(__file__) | ||
filepath = os.path.join(dirname, "bad_escape.fr.tr") | ||
|
||
with pytest.raises(SyntaxError) as e: | ||
parse_tr(filepath) | ||
|
||
assert str(e.value) == "Line 1: Unknown escape character: x" |
File renamed without changes.