Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
converse.js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
converse.js
Commits
4753656b
Commit
4753656b
authored
Dec 13, 2012
by
Michal Čihař
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for format string checks
parent
1a5853fe
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
211 additions
and
0 deletions
+211
-0
weblate/trans/tests/test_checks.py
weblate/trans/tests/test_checks.py
+211
-0
No files found.
weblate/trans/tests/test_checks.py
View file @
4753656b
...
...
@@ -30,6 +30,7 @@ from weblate.trans.checks import (
EndStopCheck
,
EndColonCheck
,
EndQuestionCheck
,
EndExclamationCheck
,
EndEllipsisCheck
,
PythonFormatCheck
,
PHPFormatCheck
,
CFormatCheck
)
...
...
@@ -40,6 +41,12 @@ class Language(object):
def
__init__
(
self
,
code
):
self
.
code
=
code
class
Unit
(
object
):
'''
Mock unit object.
'''
def
__init__
(
self
,
checksum
):
self
.
checksum
=
checksum
class
SameCheckTest
(
TestCase
):
def
setUp
(
self
):
...
...
@@ -413,3 +420,207 @@ class EndEllipsisCheckTest(TestCase):
Language
(
'cs'
),
None
))
class
PythonFormatCheckTest
(
TestCase
):
def
setUp
(
self
):
self
.
check
=
PythonFormatCheck
()
def
test_no_format
(
self
):
self
.
assertFalse
(
self
.
check
.
check_single
(
'strins'
,
'string'
,
'python-format'
,
Language
(
'cs'
),
Unit
(
'python_no_format'
)
))
def
test_format
(
self
):
self
.
assertFalse
(
self
.
check
.
check_single
(
u'%s string'
,
u'%s string'
,
'python-format'
,
Language
(
'cs'
),
Unit
(
'python_format'
)
))
def
test_named_format
(
self
):
self
.
assertFalse
(
self
.
check
.
check_single
(
u'%(name)s string'
,
u'%(name)s string'
,
'python-format'
,
Language
(
'cs'
),
Unit
(
'python_named_format'
)
))
def
test_missing_format
(
self
):
self
.
assertTrue
(
self
.
check
.
check_single
(
u'%s string'
,
u'string'
,
'python-format'
,
Language
(
'cs'
),
Unit
(
'python_missing_format'
)
))
def
test_missing_named_format
(
self
):
self
.
assertTrue
(
self
.
check
.
check_single
(
u'%(name)s string'
,
u'string'
,
'python-format'
,
Language
(
'cs'
),
Unit
(
'python_missing_named_format'
)
))
def
test_wrong_format
(
self
):
self
.
assertTrue
(
self
.
check
.
check_single
(
u'%s string'
,
u'%c string'
,
'python-format'
,
Language
(
'cs'
),
Unit
(
'python_wrong_format'
)
))
def
test_wrong_named_format
(
self
):
self
.
assertTrue
(
self
.
check
.
check_single
(
u'%(name)s string'
,
u'%(jmeno)s string'
,
'python-format'
,
Language
(
'cs'
),
Unit
(
'python_wrong_named_format'
)
))
class
PHPFormatCheckTest
(
TestCase
):
def
setUp
(
self
):
self
.
check
=
PHPFormatCheck
()
def
test_no_format
(
self
):
self
.
assertFalse
(
self
.
check
.
check_single
(
'strins'
,
'string'
,
'php-format'
,
Language
(
'cs'
),
Unit
(
'php_no_format'
)
))
def
test_format
(
self
):
self
.
assertFalse
(
self
.
check
.
check_single
(
u'%s string'
,
u'%s string'
,
'php-format'
,
Language
(
'cs'
),
Unit
(
'php_format'
)
))
def
test_named_format
(
self
):
self
.
assertFalse
(
self
.
check
.
check_single
(
u'%1$s string'
,
u'%1$s string'
,
'php-format'
,
Language
(
'cs'
),
Unit
(
'php_named_format'
)
))
def
test_missing_format
(
self
):
self
.
assertTrue
(
self
.
check
.
check_single
(
u'%s string'
,
u'string'
,
'php-format'
,
Language
(
'cs'
),
Unit
(
'php_missing_format'
)
))
def
test_missing_named_format
(
self
):
self
.
assertTrue
(
self
.
check
.
check_single
(
u'%1$s string'
,
u'string'
,
'php-format'
,
Language
(
'cs'
),
Unit
(
'php_missing_named_format'
)
))
def
test_wrong_format
(
self
):
self
.
assertTrue
(
self
.
check
.
check_single
(
u'%s string'
,
u'%c string'
,
'php-format'
,
Language
(
'cs'
),
Unit
(
'php_wrong_format'
)
))
def
test_wrong_named_format
(
self
):
self
.
assertTrue
(
self
.
check
.
check_single
(
u'%1$s string'
,
u'%s string'
,
'php-format'
,
Language
(
'cs'
),
Unit
(
'php_wrong_named_format'
)
))
class
CFormatCheckTest
(
TestCase
):
def
setUp
(
self
):
self
.
check
=
CFormatCheck
()
def
test_no_format
(
self
):
self
.
assertFalse
(
self
.
check
.
check_single
(
'strins'
,
'string'
,
'c-format'
,
Language
(
'cs'
),
Unit
(
'c_no_format'
)
))
def
test_format
(
self
):
self
.
assertFalse
(
self
.
check
.
check_single
(
u'%s string'
,
u'%s string'
,
'c-format'
,
Language
(
'cs'
),
Unit
(
'c_format'
)
))
def
test_named_format
(
self
):
self
.
assertFalse
(
self
.
check
.
check_single
(
u'%10s string'
,
u'%10s string'
,
'c-format'
,
Language
(
'cs'
),
Unit
(
'c_named_format'
)
))
def
test_missing_format
(
self
):
self
.
assertTrue
(
self
.
check
.
check_single
(
u'%s string'
,
u'string'
,
'c-format'
,
Language
(
'cs'
),
Unit
(
'c_missing_format'
)
))
def
test_missing_named_format
(
self
):
self
.
assertTrue
(
self
.
check
.
check_single
(
u'%10s string'
,
u'string'
,
'c-format'
,
Language
(
'cs'
),
Unit
(
'c_missing_named_format'
)
))
def
test_wrong_format
(
self
):
self
.
assertTrue
(
self
.
check
.
check_single
(
u'%s string'
,
u'%c string'
,
'c-format'
,
Language
(
'cs'
),
Unit
(
'c_wrong_format'
)
))
def
test_wrong_named_format
(
self
):
self
.
assertTrue
(
self
.
check
.
check_single
(
u'%10s string'
,
u'%20s string'
,
'c-format'
,
Language
(
'cs'
),
Unit
(
'c_wrong_named_format'
)
))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment