Skip to content

Commit

Permalink
improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bitjson committed Apr 4, 2015
1 parent d84784a commit 250be93
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 55 deletions.
1 change: 0 additions & 1 deletion lib/extract.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ module.exports = function(html, options) {
options.directives = options.directives || ['localize'];
options.algorithm = options.hashAlgorithm || 'md5';
options.hashLength = options.hashLength || 8;
options.nativeLocale = options.nativeLocale || 'en';

var locale = {};

Expand Down
64 changes: 64 additions & 0 deletions test/extract.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
'use strict';

var assert = require('assert');
var s18n = require('../');

describe('s18n.extract()', function() {

it('should have an "extract" method', function() {
assert.equal(typeof s18n, 'object');
assert.equal(typeof s18n.extract, 'function');
});

it('should extract locale strings from configured html attributes', function() {
var html = '<img src="example.gif" data-custom="custom attribute">';
var locale = s18n.extract(html, {
attributes: ['data-custom']
});
assert.deepEqual(JSON.parse(locale), {
'89f8af89':'custom attribute'
});
});

it('should extract locale strings from configured html elements', function() {
var html = '<h1>heading</h1><custom>Custom element</custom>';
var locale = s18n.extract(html, {
elements: ['custom']
});
assert.deepEqual(JSON.parse(locale), {
'74251aeb':'Custom element'
});
});

it('should extract locale strings from html elements with configured directives', function() {
var html = '<div localize>This is a test.</div><div custom>custom directive</div>';
var locale = s18n.extract(html, {
directives : ['localize', 'custom']
});
assert.deepEqual(JSON.parse(locale), {
'120ea8a2':'This is a test.',
'6bd3b8ac':'custom directive'
});
});

it('should allow other hash algorithms', function() {
var html = '<p>This is a test.</p>';
var locale = s18n.extract(html, {
hashAlgorithm : 'rmd160'
});
assert.deepEqual(JSON.parse(locale), {
'3c82f755':'This is a test.'
});
});

it('should allow for different hash lengths', function() {
var html = '<p>This is a test.</p>';
var locale = s18n.extract(html, {
hashLength : 13
});
assert.deepEqual(JSON.parse(locale), {
'120ea8a25e5d4':'This is a test.'
});
});

});
13 changes: 13 additions & 0 deletions test/localize.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';

var assert = require('assert');
var s18n = require('../');

describe('s18n.localize()', function() {

it('should have a "localize" method', function() {
assert.equal(typeof s18n, 'object');
assert.equal(typeof s18n.extract, 'function');
});

});
13 changes: 13 additions & 0 deletions test/map.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';

var assert = require('assert');
var s18n = require('../');

describe('s18n.map()', function() {

it('should have a "map" method', function() {
assert.equal(typeof s18n, 'object');
assert.equal(typeof s18n.extract, 'function');
});

});
54 changes: 0 additions & 54 deletions test/test.js

This file was deleted.

0 comments on commit 250be93

Please sign in to comment.