Skip to content
This repository has been archived by the owner on Jan 25, 2020. It is now read-only.

Commit

Permalink
Merge pull request #12 from bryanspears/master
Browse files Browse the repository at this point in the history
A hack of a fix for window systems. Fixes #11
  • Loading branch information
grawk committed Jan 29, 2015
2 parents 1014994 + 1b293da commit 4002551
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
2 changes: 1 addition & 1 deletion lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ exports.locate = function locate(name, root, start) {
file = path.join(start, name);
if (fs.existsSync(file)) {
return {
root : file.replace(name, ''),
root : file.replace(path.normalize(name), ''),
file: file,
ext: path.extname(name).substr(1),
name: name.replace(path.extname(name), '')
Expand Down
43 changes: 22 additions & 21 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use strict';

var fileResolver = require('../index'),
test = require('tape');
test = require('tape'),
path = require('path');

test('fileResolver', function (t) {
t.test('Creating a file resolver without options should throw assertion error', function (t) {
Expand All @@ -16,83 +17,83 @@ test('fileResolver', function (t) {
});

t.test('Creating a file resolver with options', function (t) {
var resolvr = fileResolver.create({root: __dirname + '/fixtures/root', fallback: 'en_US', ext: 'dust'});
var resolvr = fileResolver.create({root: __dirname + path.normalize('/fixtures/root'), fallback: 'en_US', ext: 'dust'});
t.deepEqual(resolvr.fallbackLocale, { country: 'US', language: 'en' });
t.equal(typeof resolvr._locate, 'function');
t.end();
});

t.test('Creating a file resolver with options', function (t) {
var resolvr = fileResolver.create({root: __dirname + '/fixtures/root', fallback: 'en_US', ext: '.dust'});
var resolvr = fileResolver.create({root: __dirname + path.normalize('/fixtures/root'), fallback: 'en_US', ext: '.dust'});
t.deepEqual(resolvr.fallbackLocale, { country: 'US', language: 'en' });
t.equal(typeof resolvr._locate, 'function');
t.end();
});


t.test('resolving for an extension with default locale', function (t) {
var resolvr = fileResolver.create({root: __dirname + '/fixtures/root', fallback: 'en_US', ext: 'dust'});
var resolvr = fileResolver.create({root: __dirname + path.normalize('/fixtures/root'), fallback: 'en_US', ext: 'dust'});
var info = resolvr.resolve('test');

t.equal(info.root, __dirname + '/fixtures/root/US/en/');
t.equal(info.file, __dirname + '/fixtures/root/US/en/test.dust');
t.equal(info.root, __dirname + path.normalize('/fixtures/root/US/en/'));
t.equal(info.file, __dirname + path.normalize('/fixtures/root/US/en/test.dust'));
t.equal(info.ext, 'dust');
t.equal(info.name, 'test');
t.end();
});

t.test('resolving for an extension with a specified locale', function (t) {
var resolvr = fileResolver.create({root: __dirname + '/fixtures/root', fallback: 'en_US', ext: 'dust'});
var resolvr = fileResolver.create({root: __dirname + path.normalize('/fixtures/root'), fallback: 'en_US', ext: 'dust'});
var info = resolvr.resolve('test', 'es_US');

t.equal(info.root, __dirname + '/fixtures/root/US/es/');
t.equal(info.file, __dirname + '/fixtures/root/US/es/test.dust');
t.equal(info.root, __dirname + path.normalize('/fixtures/root/US/es/'));
t.equal(info.file, __dirname + path.normalize('/fixtures/root/US/es/test.dust'));
t.equal(info.ext, 'dust');
t.equal(info.name, 'test');
t.end();
});

t.test('Resolve a bundle not in the primary langauge but is in the fallback', function (t) {
var resolvr = fileResolver.create({root: __dirname + '/fixtures/root', fallback: 'en_US', ext: 'dust'});
var resolvr = fileResolver.create({root: __dirname + path.normalize('/fixtures/root'), fallback: 'en_US', ext: 'dust'});
var info = resolvr.resolve('fallback', 'es_US');

t.equal(info.root, __dirname + '/fixtures/root/US/en/');
t.equal(info.file, __dirname + '/fixtures/root/US/en/fallback.dust');
t.equal(info.root, __dirname + path.normalize('/fixtures/root/US/en/'));
t.equal(info.file, __dirname + path.normalize('/fixtures/root/US/en/fallback.dust'));
t.equal(info.ext, 'dust');
t.equal(info.name, 'fallback');
t.end();
});

t.test('Creating a file resolver with options', function (t) {
var resolvr = fileResolver.create({root: __dirname + '/fixtures/root', ext: 'dust'});
var resolvr = fileResolver.create({root: __dirname + path.normalize('/fixtures/root'), ext: 'dust'});
t.deepEqual(resolvr.fallbackLocale, { country: '', language: '' });
t.equal(typeof resolvr._locate, 'function');
t.end();
});

t.test('resolving for an extension without locale', function (t) {
var resolvr = fileResolver.create({root: __dirname + '/fixtures/root', ext: 'dust'});
var resolvr = fileResolver.create({root: __dirname + path.normalize('/fixtures/root'), ext: 'dust'});
var info = resolvr.resolve('test');

t.equal(info.root, __dirname + '/fixtures/root/');
t.equal(info.file, __dirname + '/fixtures/root/test.dust');
t.equal(info.root, __dirname + path.normalize('/fixtures/root/'));
t.equal(info.file, __dirname + path.normalize('/fixtures/root/test.dust'));
t.equal(info.ext, 'dust');
t.equal(info.name, 'test');
t.end();
});

t.test('trying to resolve with a locale object', function (t) {
var resolvr = fileResolver.create({root: __dirname + '/fixtures/root', ext: 'dust'});
var resolvr = fileResolver.create({root: __dirname + path.normalize('/fixtures/root'), ext: 'dust'});
var info = resolvr.resolve('test', { country: 'US', language: 'es' });
t.equal(info.root, __dirname + '/fixtures/root/US/es/');
t.equal(info.file, __dirname + '/fixtures/root/US/es/test.dust');
t.equal(info.root, __dirname + path.normalize('/fixtures/root/US/es/'));
t.equal(info.file, __dirname + path.normalize('/fixtures/root/US/es/test.dust'));
t.equal(info.ext, 'dust');
t.equal(info.name, 'test');
t.end();
});

t.test('Creating a file resolver with invalid root', function (t) {
var resolvr = fileResolver.create({root: __dirname + '/fixtures', ext: 'dust'});
var resolvr = fileResolver.create({root: __dirname + path.normalize('/fixtures'), ext: 'dust'});
t.deepEqual(resolvr.fallbackLocale, { country: '', language: '' });
t.equal(typeof resolvr._locate, 'function');
var info = resolvr.resolve('test');
Expand All @@ -104,7 +105,7 @@ test('fileResolver', function (t) {
});

t.test('Creating a file resolver with invalid locale', function (t) {
var resolvr = fileResolver.create({root: __dirname + '/fixtures/root', ext: 'dust', fallback: 'es'});
var resolvr = fileResolver.create({root: __dirname + path.normalize('/fixtures/root'), ext: 'dust', fallback: 'es'});
t.deepEqual(resolvr.fallbackLocale, { country: '', language: 'es' });
t.equal(typeof resolvr._locate, 'function');
t.end();
Expand Down

0 comments on commit 4002551

Please sign in to comment.