fix git support for v1.5.3 (or higher) by setting "--work-tree"
[translate_toolkit.git] / storage / test_php.py
blob444928047f28b4470848b1ab6c5259c0ea6c388f
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
4 from translate.storage import php
5 from translate.storage import test_monolingual
6 from translate.misc import wStringIO
8 def test_php_escaping():
9 """Test the helper escaping funtions"""
10 # Encoding
11 assert php.phpencode("'") == "\\'"
12 assert php.phpencode('"', quotechar='"') == '\\"'
13 assert php.phpencode("\n") == "\\n"
14 # Decoding
15 assert php.phpdecode("\\'") == "'"
16 assert php.phpdecode('\\"') == '"'
17 assert php.phpdecode("\\n") == "\n"
19 class TestPhpUnit(test_monolingual.TestMonolingualUnit):
20 UnitClass = php.phpunit
22 def test_difficult_escapes(self):
23 pass
25 class TestPhpFile(test_monolingual.TestMonolingualStore):
26 StoreClass = php.phpfile
28 def phpparse(self, phpsource):
29 """helper that parses php source without requiring files"""
30 dummyfile = wStringIO.StringIO(phpsource)
31 phpfile = php.phpfile(dummyfile)
32 return phpfile
34 def phpregen(self, phpsource):
35 """helper that converts php source to phpfile object and back"""
36 return str(self.phpparse(phpsource))
38 def test_simpledefinition(self):
39 """checks that a simple php definition is parsed correctly"""
40 phpsource = """$lang['mediaselect'] = 'Bestand selectie';"""
41 phpfile = self.phpparse(phpsource)
42 assert len(phpfile.units) == 1
43 phpunit = phpfile.units[0]
44 assert phpunit.name == "$lang['mediaselect']"
45 assert phpunit.source == "Bestand selectie"
47 def test_simpledefinition_source(self):
48 """checks that a simple php definition can be regenerated as source"""
49 phpsource = """$lang['mediaselect']='Bestand selectie';"""
50 phpregen = self.phpregen(phpsource)
51 assert phpsource + '\n' == phpregen
53 def test_spaces_in_name(self):
54 """check that spaces in the array name doesn't throw us off"""
55 phpsource = """$lang[ 'mediaselect' ] = 'Bestand selectie';"""
56 phpfile = self.phpparse(phpsource)
57 assert len(phpfile.units) == 1
58 phpunit = phpfile.units[0]
59 assert phpunit.name == "$lang['mediaselect']"
60 assert phpunit.source == "Bestand selectie"