/*______________
| ______ | U I Z E J A V A S C R I P T F R A M E W O R K
| / / | ---------------------------------------------------
| / O / | MODULE : Uize.Test.Uize.Loc.FileFormats.ProjectStrings.Xliff Class
| / / / |
| / / / /| | ONLINE : http://uize.com
| /____/ /__/_| | COPYRIGHT : (c)2014-2016 UIZE
| /___ | LICENSE : Available under MIT License or GNU General Public License
|_______________| http://uize.com/license.html
*/
/* Module Meta Data
type: Test
importance: 1
codeCompleteness: 100
docCompleteness: 100
*/
/*?
Introduction
The =Uize.Test.Uize.Loc.FileFormats.ProjectStrings.Xliff= module defines a suite of unit tests for the =Uize.Loc.FileFormats.ProjectStrings.Xliff= module.
*DEVELOPERS:* `Chris van Rensburg`
*/
Uize.module ({
name:'Uize.Test.Uize.Loc.FileFormats.ProjectStrings.Xliff',
builder:function () {
'use strict';
return Uize.Test.resolve ({
title:'Test for Uize.Loc.FileFormats.ProjectStrings.Xliff Module',
test:[
Uize.Test.requiredModulesTest ('Uize.Loc.FileFormats.ProjectStrings.Xliff'),
Uize.Test.staticMethodsTest ([
['Uize.Loc.FileFormats.ProjectStrings.Xliff.to',[
['An object containing multiple resource strings for a file can be serialized to XLIFF format',
{
sourceLanguage:'en_US',
targetLanguage:'fr_FR',
strings:{
'foo/bar.properties':{
widget1:{
TITLE:'widget 1 title',
DESCRIPTION:'the first widget'
},
widget2:{
TITLE:'widget 2 title',
DESCRIPTION:'the second widget'
}
}
}
},
[
'',
'',
' ',
' ',
' ',
' widget 1 title',
' ',
' ',
' ',
' the first widget',
' ',
' ',
' ',
' widget 2 title',
' ',
' ',
' ',
' the second widget',
' ',
' ',
' ',
' ',
''
].join ('\n')
],
['An object containing resource strings for multiple files can be serialized to XLIFF format',
{
sourceLanguage:'en_US',
targetLanguage:'fr_FR',
strings:{
'foo/bar.properties':{
widget1:{
TITLE:'widget 1 title',
DESCRIPTION:'the first widget'
}
},
'baz/qux.properties':{
widget2:{
TITLE:'widget 2 title',
DESCRIPTION:'the second widget'
}
}
}
},
[
'',
'',
' ',
' ',
' ',
' widget 1 title',
' ',
' ',
' ',
' the first widget',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' widget 2 title',
' ',
' ',
' ',
' the second widget',
' ',
' ',
' ',
' ',
''
].join ('\n')
],
['When the resource strings contain substitution tokens and a value is specified for the tokenSplitter option, then the substitution tokens are wrapped in tags when serialized to XLIFF format',
[
{
sourceLanguage:'en_US',
targetLanguage:'fr_FR',
strings:{
'foo/bar.properties':{
STR1:'foo {param} bar',
STR2:'foo {param}',
STR3:'{param} bar',
STR4:'{param}',
STR5:'{param1}{param2}'
}
}
},
{tokenSplitter:/\{[\w\d]+\}/}
],
[
'',
'',
' ',
' ',
' ',
' foo {param} bar',
' ',
' ',
' ',
' foo {param}',
' ',
' ',
' ',
' {param} bar',
' ',
' ',
' ',
' {param}',
' ',
' ',
' ',
' {param1}{param2}',
' ',
' ',
' ',
' ',
''
].join ('\n')
],
['When the value true is specified for the seedTarget option, then the value of each tag\'s tag is seeded with the untranslated source value of the resource string',
[
{
sourceLanguage:'en_US',
targetLanguage:'fr_FR',
strings:{
'foo/bar.properties':{
widget1:{
TITLE:'widget 1 title',
DESCRIPTION:'the first widget'
},
widget2:{
TITLE:'widget 2 title',
DESCRIPTION:'the second widget'
}
}
}
},
{seedTarget:true}
],
[
'',
'',
' ',
' ',
' ',
' widget 1 title',
' widget 1 title',
' ',
' ',
' the first widget',
' the first widget',
' ',
' ',
' widget 2 title',
' widget 2 title',
' ',
' ',
' the second widget',
' the second widget',
' ',
' ',
' ',
''
].join ('\n')
],
['When an object value is specified for the seedTarget option, then the value of each tag\'s tag is seeded with a corresponding value from the seedTarget object, if present, or the untranslated source value of the resource string',
[
{
sourceLanguage:'en_US',
targetLanguage:'fr_FR',
strings:{
'foo/bar.properties':{
widget1:{
TITLE:'widget 1 title',
DESCRIPTION:'the first widget'
},
widget2:{
TITLE:'widget 2 title',
DESCRIPTION:'the second widget'
}
}
}
},
{
seedTarget:{
'foo/bar.properties':{
widget1:{
TITLE:'titre de widget de 1',
DESCRIPTION:'le premier widget'
}
}
}
}
],
[
'',
'',
' ',
' ',
' ',
' widget 1 title',
' titre de widget de 1',
' ',
' ',
' the first widget',
' le premier widget',
' ',
' ',
' widget 2 title',
' widget 2 title',
' ',
' ',
' the second widget',
' the second widget',
' ',
' ',
' ',
''
].join ('\n')
],
['When an object value is specified for the seedTarget option, the value for each tag\'s tag is encoded in the same way as the value for its tag',
[
{
sourceLanguage:'en_US',
targetLanguage:'fr_FR',
strings:{
'foo/bar.properties':{
widgetN:{
TITLE:'widget {widgetNo} title',
DESCRIPTION:'the first widget',
BODY:'
{body}
'
}
}
}
},
{
seedTarget:{
'foo/bar.properties':{
widgetN:{
TITLE:'titre de widget de {widgetNo}',
DESCRIPTION:'le premier widget',
BODY:'
{body}
'
}
}
},
tokenSplitter:/\{[\w\d]+\}/
}
],
[
'',
'',
' ',
' ',
' ',
' widget {widgetNo} title',
' titre de widget de {widgetNo}',
' ',
' ',
' <b>the first widget</b>',
' <b>le premier widget</b>',
' ',
' ',
' <div>{body}</div>',
' <div>{body}</div>',
' ',
' ',
' ',
''
].join ('\n')
],
['An object containing string arrays for a file can be serialized to XLIFF format',
{
sourceLanguage:'en_US',
targetLanguage:'fr_FR',
strings:{
'foo/bar.properties':{
widget1:{
OPTIONS:[
'Option 1',
'Option 2'
]
},
widget2:{
OPTIONS:[
'foo',
'bar'
]
}
}
}
},
[
'',
'',
' ',
' ',
' ',
' Option 1',
' ',
' ',
' ',
' Option 2',
' ',
' ',
' ',
' foo',
' ',
' ',
' ',
' bar',
' ',
' ',
' ',
' ',
''
].join ('\n')
],
['When resource strings contain line break characters, these characters are encoded as XML entities',
{
sourceLanguage:'en_US',
targetLanguage:'fr_FR',
strings:{
'foo/bar.properties':{
STR:'this string\nspans\rmultiple\r\nlines'
}
}
},
[
'',
'',
' ',
' ',
' ',
' this string
spans
multiple
lines',
' ',
' ',
' ',
' ',
''
].join ('\n')
]
]],
['Uize.Loc.FileFormats.ProjectStrings.Xliff.from',[
['An XLIFF format document containing multiple resource strings for a file can be parsed to produce a resource strings object',
[
'',
'',
' ',
' ',
' ',
' widget 1 title',
' titre de widget de 1',
' ',
' ',
' the first widget',
' le premier widget',
' ',
' ',
' widget 2 title',
' titre de widget de 2',
' ',
' ',
' the second widget',
' le deuxième widget',
' ',
' ',
' ',
''
].join ('\n'),
{
'foo/bar.properties':{
widget1:{
TITLE:'titre de widget de 1',
DESCRIPTION:'le premier widget'
},
widget2:{
TITLE:'titre de widget de 2',
DESCRIPTION:'le deuxième widget'
}
}
}
],
['An XLIFF format document containing resource strings for multiple files can be parsed to produce a resource strings object',
[
'',
'',
' ',
' ',
' ',
' widget 1 title',
' titre de widget de 1',
' ',
' ',
' the first widget',
' le premier widget',
' ',
' ',
' ',
' ',
' ',
' ',
' widget 2 title',
' titre de widget de 2',
' ',
' ',
' the second widget',
' le deuxième widget',
' ',
' ',
' ',
''
].join ('\n'),
{
'foo/bar.properties':{
widget1:{
TITLE:'titre de widget de 1',
DESCRIPTION:'le premier widget'
}
},
'baz/qux.properties':{
widget2:{
TITLE:'titre de widget de 2',
DESCRIPTION:'le deuxième widget'
}
}
}
],
['An XLIFF format document may contain trans-unit tags with substitution tokens wrapped in tags',
[
'',
'',
' ',
' ',
' ',
' foo {param} bar',
' foo {param} bar',
' ',
' ',
' foo {param}',
' foo {param}',
' ',
' ',
' {param} bar',
' {param} bar',
' ',
' ',
' {param}',
' {param}',
' ',
' ',
' {param1}{param2}',
' {param1}{param2}',
' ',
' ',
' ',
''
].join ('\n'),
{
'foo/bar.properties':{
STR1:'foo {param} bar',
STR2:'foo {param}',
STR3:'{param} bar',
STR4:'{param}',
STR5:'{param1}{param2}'
}
}
],
['An XLIFF format document may contain trans-unit tags with empty, self-closing source and target tags, and such tags are parsed to empty string values',
[
'',
'',
' ',
' ',
' ',
' ',
' ' +
' ',
' ',
' ',
''
].join ('\n'),
{
'foo/bar.properties':{
STR:''
}
}
],
['An XLIFF format document may contain trans-unit tags that contain values for elements of string arrays, and these are parsed to produce string arrays in the returned strings object',
[
'',
'',
' ',
' ',
' ',
' Option 1',
' Option 1',
' ',
' ',
' Option 2',
' Option 2',
' ',
' ',
' foo',
' le foo',
' ',
' ',
' bar',
' le bar',
' ',
' ',
' ',
''
].join ('\n'),
{
'foo/bar.properties':{
widget1:{
OPTIONS:[
'Option 1',
'Option 2'
]
},
widget2:{
OPTIONS:[
'le foo',
'le bar'
]
}
}
}
],
{
title:
'When an XLIFF document is serialized from a strings object using the Uize.Loc.FileFormats.ProjectStrings.Xliff.to method and the seedTarget option, and that document is then parsed to produce a strings object using the Uize.Loc.FileFormats.ProjectStrings.Xliff.from method, the returned strings object is identical to the original strings object',
test:function () {
var
_sourceStrings = {
'foo/bar.properties':{
widget1:{
TITLE:'widget 1 title',
DESCRIPTION:'the first widget'
},
widget2:{
TITLE:'widget 2 title',
DESCRIPTION:'the second widget'
}
}
},
_parsedStrings = Uize.Loc.FileFormats.ProjectStrings.Xliff.from (
Uize.Loc.FileFormats.ProjectStrings.Xliff.to (
{
sourceLanguage:'en_US',
targetLanguage:'fr_FR',
strings:_sourceStrings
},
{seedTarget:true}
)
)
;
return this.expect (_sourceStrings,_parsedStrings);
}
}
]]
])
]
});
}
});