Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
bitjson committed Apr 19, 2015
1 parent ee83392 commit 25c92ad
Showing 1 changed file with 43 additions and 11 deletions.
54 changes: 43 additions & 11 deletions test/spec.localize.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ describe('s18n()', function() {
'3c82f755': 'Thís ís á tést.'
};
assert.throws(
function(){
function() {
s18n(html, {
locales: [{'accents': accentedLocale}]
locales: [{
'accents': accentedLocale
}]
});
},
function(err){
if ((err instanceof Error) && /`nativeLocale`/.test(err) ) {
function(err) {
if ((err instanceof Error) && /`nativeLocale`/.test(err)) {
return true;
}
}, 'unexpected error message');
Expand All @@ -37,13 +39,13 @@ describe('s18n()', function() {
'3c82f755': 'This is a test.'
};
assert.throws(
function(){
function() {
s18n(html, {
nativeLocale: nativeLocale
});
},
function(err){
if ((err instanceof Error) && /`locales`/.test(err) ) {
function(err) {
if ((err instanceof Error) && /`locales`/.test(err)) {
return true;
}
}, 'unexpected error message');
Expand All @@ -59,9 +61,13 @@ describe('s18n()', function() {
};
var localizedHtml = s18n(html, {
nativeLocale: nativeLocale,
locales: [{'accents': accentedLocale}]
locales: [{
'accents': accentedLocale
}]
});
assert.deepEqual(localizedHtml, {
accents: '<p>Thís ís á tést.</p>'
});
assert.deepEqual(localizedHtml, { accents: '<p>Thís ís á tést.</p>' });
});

it('should localize strings only in localizable places (`>*<`, `"*"`, `\'\'`)', function() {
Expand All @@ -74,9 +80,35 @@ describe('s18n()', function() {
};
var localizedHtml = s18n(html, {
nativeLocale: nativeLocale,
locales: [{'accents': accentedLocale}]
locales: [{
'accents': accentedLocale
}]
});
assert.deepEqual(localizedHtml, {
accents: '<test test="tést" testattr=\'tést\'>tést</test>'
});
});

it('should localize some html with multiple locales', function() {
var html = '<p>This is a test.</p>';
var localizedHtml = s18n(html, {
nativeLocale: {
'3c82f755': 'This is a test.'
},
locales: [{
'accents': {
'3c82f755': 'Thís ís á tést.'
}
}, {
'denglish': {
'3c82f755': 'Zis ist a tesht.'
}
}]
});
assert.deepEqual(localizedHtml, {
accents: '<p>Thís ís á tést.</p>',
denglish: '<p>Zis ist a tesht.</p>'
});
assert.deepEqual(localizedHtml, { accents: '<test test="tést" testattr=\'tést\'>tést</test>' });
});

});

0 comments on commit 25c92ad

Please sign in to comment.