Skip to content

Commit

Permalink
Not use a block text of an arg theme as a default value
Browse files Browse the repository at this point in the history
  • Loading branch information
sttk committed Mar 31, 2018
1 parent f820a7a commit ebd4b65
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ Also, this mark can escape `{` and `}`.
##### Theme for argument

A logging function created by this function can take multiple arguments.
A themed text to be converted to an argument has same format with a normal themed text but its theme name is a number starting from 1, which indicates the index of the argument, like `{2}` or `{2: alternative text }`.
A themed text to be converted to an argument has same format with a normal themed text but its theme name is a number starting from 1, which indicates the index of the argument, like `{2}` or `{2: Explanatory text }`.

A block content in a theme block for argument is outputted alternatively when there is no argument corresponding to a number of a theme name.

* `{ 1 }` → replaced with the second argument (the first argument except the themed text) of logging function, or an empty string if the second argument is not given.
* `{ 3 : yyyy }` → replaced with the fourth argument (the third argument except the themed text) of logging function, or `'yyyy'` if the fourth argument is not given.
* `{ 3 : yyyy }` → replaced with the fourth argument (the third argument except the themed text) of logging function, or an empty string if the fourth argument is not given. (`'yyyy'` is not used.)

#### Parameters:

Expand Down
2 changes: 1 addition & 1 deletion lib/arg-theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function isArgTheme(themeName) {
function convertArgTheme(args, themeName, nodeText) {
var argIndex = toInteger(themeName);
if (!argIndex || argIndex >= args.length || argIndex <= 0) {
return nodeText || '';
return '';
}

return args[argIndex];
Expand Down
2 changes: 1 addition & 1 deletion test/lib/apply-theme.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ describe('lib/apply-theme', function() {
'This text has arg-theme: A1, true and 222');

expect(apply(parsed, themeSet)).to.equal(
'This text has arg-theme: , and Two');
'This text has arg-theme: , and ');
});

it('Should support theme defined by nested properties', function() {
Expand Down
10 changes: 5 additions & 5 deletions test/lib/arg-theme.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ describe('lib/arg-theme', function() {

it('Should convert an arg identifier to an argument value', function() {
var args = ['Arg0', 'Arg1', 'Arg2', 'Arg3'];
expect(argTheme.convert(args, '-1', 'X1-')).to.equal('X1-');
expect(argTheme.convert(args, '0', 'X0')).to.equal('X0');
expect(argTheme.convert(args, '-1', 'X1-')).to.equal('');
expect(argTheme.convert(args, '0', 'X0')).to.equal('');
expect(argTheme.convert(args, '1', 'X1')).to.equal('Arg1');
expect(argTheme.convert(args, '2', 'X2')).to.equal('Arg2');
expect(argTheme.convert(args, '3', 'X3')).to.equal('Arg3');
expect(argTheme.convert(args, '4', 'X4')).to.equal('X4');
expect(argTheme.convert(args, '4', 'X4')).to.equal('');

expect(argTheme.convert(args, '', 'X')).to.equal('X');
expect(argTheme.convert(args, 'a', 'X')).to.equal('X');
expect(argTheme.convert(args, '', 'X')).to.equal('');
expect(argTheme.convert(args, 'a', 'X')).to.equal('');
});

});
6 changes: 3 additions & 3 deletions test/theming-log.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,11 @@ describe('theming-log', function() {
expect(logBuf).to.equal('This text has arg-theme: Arg2 and Arg1\n');
});

it('Should replace arg-themes to block text when corresponding arg are' +
'\n\tnot exist', function() {
it('Should replace arg-themes to an empty string when corresponding' +
'\n\targ are not exist', function() {
var log = themingLog(themes, origLogger);
log('This text has arg-theme: {5} and {3: Three}', 'Arg1', 'Arg2');
expect(logBuf).to.equal('This text has arg-theme: and Three\n');
expect(logBuf).to.equal('This text has arg-theme: and \n');
});

it('Should replace arg-theme in nested theme', function() {
Expand Down

0 comments on commit ebd4b65

Please sign in to comment.