Skip to content

Commit

Permalink
allow for additional whitespace in localisation
Browse files Browse the repository at this point in the history
  • Loading branch information
hans-d committed Oct 21, 2013
1 parent 3b0e664 commit b1bf0f0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules/
npm-debug.log
*.swp
*.swo
*.iml
6 changes: 3 additions & 3 deletions lib/localisation/English.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@ var English = function(dictionary, library) {

library.given = function(signatures, fn, ctx) {
return $(signatures).each(function(signature) {
var signature = prefix_signature('(?:[Gg]iven|[Ww]ith|[Aa]nd|[Bb]ut|[Ee]xcept) ', signature);
var signature = prefix_signature('(?:[Gg]iven|[Ww]ith|[Aa]nd|[Bb]ut|[Ee]xcept)\\s+', signature);
return library.define(signature, fn, ctx);
});
};

library.when = function(signatures, fn, ctx) {
return $(signatures).each(function(signature) {
var signature = prefix_signature('(?:[Ww]hen|[Ii]f|[Aa]nd|[Bb]ut) ', signature);
var signature = prefix_signature('(?:[Ww]hen|[Ii]f|[Aa]nd|[Bb]ut)\\s+', signature);
return library.define(signature, fn, ctx);
});
};

library.then = function(signatures, fn, ctx) {
return $(signatures).each(function(signature) {
var signature = prefix_signature('(?:[Tt]hen|[Ee]xpect|[Aa]nd|[Bb]ut) ', signature);
var signature = prefix_signature('(?:[Tt]hen|[Ee]xpect|[Aa]nd|[Bb]ut)\\s+', signature);
return library.define(signature, fn, ctx);
});
};
Expand Down
6 changes: 3 additions & 3 deletions lib/localisation/Pirate.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@ var Pirate = function(dictionary, library) {

library.given = function(signatures, fn, ctx) {
return $(signatures).each(function(signature) {
var signature = prefix_signature('(?:[Gg]iveth|[Ww]ith|[Aa]nd|[Bb]ut) ', signature);
var signature = prefix_signature('(?:[Gg]iveth|[Ww]ith|[Aa]nd|[Bb]ut)\\s+', signature);
return library.define(signature, fn, ctx);
});
};

library.when = function(signatures, fn, ctx) {
return $(signatures).each(function(signature) {
var signature = localisation.prefix_signature('(?:[Ww]hilst|[Aa]nd|[Bb]ut) ', signature);
var signature = localisation.prefix_signature('(?:[Ww]hilst|[Aa]nd|[Bb]ut)\\s+', signature);
return library.define(signature, fn, ctx);
});
};

library.then = function(signatures, fn, ctx) {
return $(signatures).each(function(signature) {
var signature = prefix_signature('(?:[Tt]hence|[Dd]emand|[Aa]nd|[Bb]ut) ', signature);
var signature = prefix_signature('(?:[Tt]hence|[Dd]emand|[Aa]nd|[Bb]ut)\\s+', signature);
return library.define(signature, fn, ctx);
});
};
Expand Down
17 changes: 10 additions & 7 deletions test/LibraryTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,18 @@ describe('Library', function() {

var givens = [
'Given a wall with 100 bottles',
'Given a wall with 100 bottles',
'given a wall with 100 bottles',
'And a wall with 100 bottles',
'and a wall with 100 bottles'
'and a wall with 100 bottles',
'with a wall with 100 bottles'
];

var whens = [
'When 1 bottle accidentally falls',
'when 1 bottle accidentally falls',
'and 1 bottle accidentally falls',
'And 1 bottle accidentally falls'
'And 1 bottle accidentally falls',
'but 1 bottle accidentally falls'
];

var thens = [
Expand All @@ -93,12 +95,13 @@ describe('Library', function() {
'And there are 99 bottles left',
'and there are 99 bottles left',
'Expect there are 99 bottles left',
'expect there are 99 bottles left'
'expect there are 99 bottles left',
'but there are 99 bottles left'
];

assert_localisation(library, givens, '/(?:[Gg]iven|[Ww]ith|[Aa]nd|[Bb]ut|[Ee]xcept) a wall with (\\d+) bottles/');
assert_localisation(library, whens, '/(?:[Ww]hen|[Ii]f|[Aa]nd|[Bb]ut) (\\d+) bottle(?:s)? accidentally falls/');
assert_localisation(library, thens, '/(?:[Tt]hen|[Ee]xpect|[Aa]nd|[Bb]ut) there are (\\d+) bottles left/');
assert_localisation(library, givens, '/(?:[Gg]iven|[Ww]ith|[Aa]nd|[Bb]ut|[Ee]xcept)\\s+a wall with (\\d+) bottles/');
assert_localisation(library, whens, '/(?:[Ww]hen|[Ii]f|[Aa]nd|[Bb]ut)\\s+(\\d+) bottle(?:s)? accidentally falls/');
assert_localisation(library, thens, '/(?:[Tt]hen|[Ee]xpect|[Aa]nd|[Bb]ut)\\s+there are (\\d+) bottles left/');
});

it('should supports localised aliased macros', function() {
Expand Down

0 comments on commit b1bf0f0

Please sign in to comment.