Skip to content

Commit

Permalink
fix for previos commit (always exiting instead of beautifying); openb…
Browse files Browse the repository at this point in the history
…race tests; v0.2.1
  • Loading branch information
cy6erskunk committed Aug 19, 2013
1 parent 59e8e47 commit 461165a
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 27 deletions.
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,19 @@ Options:
```

__Note__
__Notes__
It seems to me that `optimist` introduces strange behaviour in some cases, e.g.
it's mpossible to pass empty `indent` option in the following form: `-i ''`,
but following solutions work just fine: `-i0`, `--indent ''`, `--indent=''`, `--indent=0`.

It's mpossible to pass empty `indent` option in the following form: `-i ''`
Following solutions work just fine: `-i0`, `--indent ''`, `--indent=''`, `--indent=0`
Also the behaviour of boolean `-a` option is quite strange sometimes, check `test/autosemicolon.js` for
details.


## Versions
**0.2.1**
* some minor fixes

**0.2.0**
* file is now passed in -f (--file) option

Expand Down
12 changes: 7 additions & 5 deletions lib/cssbeautify-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ var fs = require('fs'),
})
.boolean('autosemicolon')
.describe('a', 'insert a semicolon after the last ruleset')
.boolean('a')
.alias('f', 'file')
.describe('f', 'file to beautify')
.alias('h', 'help')
Expand All @@ -57,13 +58,8 @@ function CssbeautifyCli() {
return new CssbeautifyCli();
}

this.argv = undefined;
this.options = null;
this.filename = null;
this.exit = {
fn: function (){},
code: 0
};
}

CssbeautifyCli.prototype.parse = function () {
Expand Down Expand Up @@ -107,6 +103,12 @@ CssbeautifyCli.prototype.process = function () {
console.log('Error: invalid openbrace value, use either "end-of-line" or "separate-line"');
}, 1);
}

if (typeof this.argv.a !== 'boolean') {
this.setExit(function () {
console.log('Error: invalid autosemicolon value, use boolean');
}, 1);
}
this.options = this.exit && this.exit.code !== 0 ? null : {
indent: this.argv.indent,
openbrace: this.argv.openbrace,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "cssbeautify-cli",
"description": "CLI for cssbeautify",
"version": "0.2.0",
"version": "0.2.1",
"author": {
"name": "Igor Shevchenko",
"email": "cyberskunk@yandex.ru"
Expand Down
74 changes: 74 additions & 0 deletions test/autosemicolon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
var CssbeautifyCli = require('../lib/cssbeautify-cli'),
cssbeautifyCli,
filename = 'test.css';

exports.autosemicolon_true = function (test) {
([
['node', 'lol', '-f', filename, '-a', 'true'],
['node', 'lol', '-f', filename, '-a', '1'],
['node', 'lol', '-f', filename, '--autosemicolon', 'true'],
['node', 'lol', '-f', filename, '--autosemicolon', '1'],
['node', 'lol', '-f', filename, '-a'],
['node', 'lol', '-f', filename, '--autosemicolon'],
// it's strange parsing of 'boolean' by optimist, isn't it?
['node', 'lol', '-f', filename, '-a', '0'],
['node', 'lol', '-f', filename, '-a', 'xxx'],
['node', 'lol', '-f', filename, '--autosemicolon', '0'],
['node', 'lol', '-f', filename, '--autosemicolon', 'xxx'],

]).forEach(function (argv) {
process.argv = argv;

cssbeautifyCli = CssbeautifyCli()
.parse()
.process();

test.strictEqual(cssbeautifyCli.options.autosemicolon, true);
test.strictEqual(typeof cssbeautifyCli.exit, 'undefined');
});


test.done();
};

exports.autosemicolon_false = function (test) {
([
['node', 'lol', '-f', filename, '-a', 'false'],
['node', 'lol', '-f', filename, '--autosemicolon', 'false'],
['node', 'lol', '-f', filename, '--no-a'],
['node', 'lol', '-f', filename, '--no-autosemicolon']
]).forEach(function (argv) {
process.argv = argv;

cssbeautifyCli = CssbeautifyCli()
.parse()
.process();

test.strictEqual(cssbeautifyCli.options.autosemicolon, false);
test.strictEqual(typeof cssbeautifyCli.exit, 'undefined');
});


test.done();
};

exports.autosemicolon_wrong = function (test) {
process.argv = ['node', 'lol', '-f', filename, '-a', 'xxx'];

([
['node', 'lol', '-f', filename, '--autosemicolon=true'],
['node', 'lol', '-f', filename, '--autosemicolon=false']
]).forEach(function (argv) {
process.argv = argv;

cssbeautifyCli = CssbeautifyCli()
.parse()
.process();

test.strictEqual(cssbeautifyCli.options, null);
test.strictEqual(cssbeautifyCli.exit.code, 1);
});

test.done();
};

4 changes: 2 additions & 2 deletions test/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ exports.singleParam_f = function (test) {
test.strictEqual(options[option], defaults[option], 'bad option ' + option);
});
test.strictEqual(cssbeautifyCli.filename, filename, 'bad filename');
test.strictEqual(cssbeautifyCli.exit.code, 0, 'bad exit object');
test.strictEqual(typeof cssbeautifyCli.exit, 'undefined', 'bad exit object');

test.done();
};
Expand All @@ -29,7 +29,7 @@ exports.singleParam_file = function (test) {
test.strictEqual(options[option], defaults[option], 'bad option ' + option);
});
test.strictEqual(cssbeautifyCli.filename, filename, 'bad filename');
test.strictEqual(cssbeautifyCli.exit.code, 0, 'bad exit object');
test.strictEqual(typeof cssbeautifyCli.exit, 'undefined', 'bad exit object');

test.done();
};
14 changes: 7 additions & 7 deletions test/indent.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ exports.i_spaces = function (test) {
cssbeautifyCli = CssbeautifyCli().parse().process();

test.strictEqual(cssbeautifyCli.options.indent, indent);
test.strictEqual(cssbeautifyCli.exit.code, 0);
test.strictEqual(typeof cssbeautifyCli.exit, 'undefined');
});

test.done();
Expand All @@ -38,7 +38,7 @@ exports.indent_spaces = function (test) {
cssbeautifyCli = CssbeautifyCli().parse().process();

test.strictEqual(cssbeautifyCli.options.indent, indent);
test.strictEqual(cssbeautifyCli.exit.code, 0);
test.strictEqual(typeof cssbeautifyCli.exit, 'undefined');
});

test.done();
Expand All @@ -50,7 +50,7 @@ exports['indent=_spaces'] = function (test) {

cssbeautifyCli = CssbeautifyCli().parse().process();

test.strictEqual(cssbeautifyCli.exit.code, 0);
test.strictEqual(typeof cssbeautifyCli.exit, 'undefined');
test.strictEqual(cssbeautifyCli.options.indent, indent);
});

Expand All @@ -64,7 +64,7 @@ exports.i_numbers = function (test) {
cssbeautifyCli = CssbeautifyCli().parse().process();

test.strictEqual(cssbeautifyCli.options.indent, indent.expected);
test.strictEqual(cssbeautifyCli.exit.code, 0);
test.strictEqual(typeof cssbeautifyCli.exit, 'undefined');
});

test.done();
Expand All @@ -77,7 +77,7 @@ exports.i_numbers2 = function (test) {
cssbeautifyCli = CssbeautifyCli().parse().process();

test.strictEqual(cssbeautifyCli.options.indent, indent.expected);
test.strictEqual(cssbeautifyCli.exit.code, 0);
test.strictEqual(typeof cssbeautifyCli.exit, 'undefined');
});

test.done();
Expand All @@ -90,7 +90,7 @@ exports.indent_numbers = function (test) {
cssbeautifyCli = CssbeautifyCli().parse().process();

test.strictEqual(cssbeautifyCli.options.indent, indent.expected);
test.strictEqual(cssbeautifyCli.exit.code, 0);
test.strictEqual(typeof cssbeautifyCli.exit, 'undefined');
});

test.done();
Expand All @@ -105,7 +105,7 @@ exports['indent=_numbers'] = function (test) {
.process();

test.strictEqual(cssbeautifyCli.options.indent, indent.expected);
test.strictEqual(cssbeautifyCli.exit.code, 0);
test.strictEqual(typeof cssbeautifyCli.exit, 'undefined');
});

test.done();
Expand Down
51 changes: 42 additions & 9 deletions test/openbrace.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,53 @@
var CssbeautifyCli = require('../lib/cssbeautify-cli'),
defaults = {
indent: ' ', // 4 spaces
openbrace: 'end-of-line',
autosemicolon: false
},
cssbeautifyCli,
filename = 'test.css';

exports.openbrace = function (test) {
exports.o = function (test) {
var openbrace = ['end-of-line', 'separate-line'];

openbrace.forEach(function (openbrace) {
process.argv = ['node', 'lol', '-f', filename, '-o', openbrace];

options = CssbeautifyCli().parse().process().options;
cssbeautifyCli = CssbeautifyCli()
.parse()
.process();

test.strictEqual(cssbeautifyCli.options.openbrace, openbrace);
test.strictEqual(typeof cssbeautifyCli.exit, 'undefined');
});

test.done();
};

exports.openbrace = function (test) {
var openbrace = ['end-of-line', 'separate-line'];

openbrace.forEach(function (openbrace) {
process.argv = ['node', 'lol', '-f', filename, '--openbrace', openbrace];

cssbeautifyCli = CssbeautifyCli()
.parse()
.process();

test.strictEqual(cssbeautifyCli.options.openbrace, openbrace);
test.strictEqual(typeof cssbeautifyCli.exit, 'undefined');
});

test.done();
};

exports.openbrace = function (test) {
var openbrace = ['end-of-line', 'separate-line'];

openbrace.forEach(function (openbrace) {
process.argv = ['node', 'lol', '-f', filename, '--openbrace=' + openbrace];

cssbeautifyCli = CssbeautifyCli()
.parse()
.process();

test.strictEqual(options.openbrace, openbrace);
test.strictEqual(cssbeautifyCli.options.openbrace, openbrace);
test.strictEqual(typeof cssbeautifyCli.exit, 'undefined');
});

test.done();
Expand All @@ -25,7 +58,7 @@ exports.openbrace_wrong = function (test) {

process.argv = ['node', 'lol', '-f', filename, '-o', openbrace];

var cssbeautifyCli = CssbeautifyCli()
cssbeautifyCli = CssbeautifyCli()
.parse()
.process();

Expand Down

0 comments on commit 461165a

Please sign in to comment.