Skip to content

Commit

Permalink
Linted all sources including tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ixti committed Dec 25, 2011
1 parent f1a22c0 commit 103f1b1
Show file tree
Hide file tree
Showing 15 changed files with 65 additions and 26 deletions.
4 changes: 2 additions & 2 deletions Makefile
Expand Up @@ -10,7 +10,7 @@ CURR_HEAD := $(firstword $(shell git show-ref --hash HEAD | cut --bytes=-6) mas
GITHUB_NAME := nodeca/js-yaml GITHUB_NAME := nodeca/js-yaml
SRC_URL_FMT := https://github.com/${GITHUB_NAME}/blob/${CURR_HEAD}/{file}\#L{line} SRC_URL_FMT := https://github.com/${GITHUB_NAME}/blob/${CURR_HEAD}/{file}\#L{line}


JS_FILES := $(shell find ./lib -type f -name '*.js' -print) JS_FILES := $(shell find ./bin ./lib ./test -type f -name '*.js' -print)


lint: lint:
@if test ! `which jslint` ; then \ @if test ! `which jslint` ; then \
Expand All @@ -23,7 +23,7 @@ lint:
# (nomen) -> tolerate underscores in identifiers (e.g. `var _val = 1`) # (nomen) -> tolerate underscores in identifiers (e.g. `var _val = 1`)
# (bitwise) -> tolerate bitwise operators (used in base64) # (bitwise) -> tolerate bitwise operators (used in base64)
# (white) -> tolerate messy whitespace # (white) -> tolerate messy whitespace
jslint --node --nomen --bitwise --white --indent=2 ${JS_FILES} jslint --node --nomen --bitwise --white --indent=2 ./index.js ${JS_FILES}


test: lint test: lint
@if test ! `which vows` ; then \ @if test ! `which vows` ; then \
Expand Down
3 changes: 2 additions & 1 deletion test/functional-test.js
@@ -1,3 +1,4 @@
'use strict';
require(__dirname + '/helper') require(__dirname + '/helper')
.suite('Functional', __dirname + '/functional', /^functional-.+?\.js$/) .suite('Functional', __dirname + '/functional', new RegExp("^functional-.+?\\.js$"))
.export(module); .export(module);
42 changes: 23 additions & 19 deletions test/functional/canonical.js
@@ -1,3 +1,5 @@
'use strict';

var fs = require('fs'), var fs = require('fs'),
assert = require('assert'), assert = require('assert'),
jsyaml = require(__dirname + '/../../lib/js-yaml'), jsyaml = require(__dirname + '/../../lib/js-yaml'),
Expand All @@ -6,6 +8,7 @@ var fs = require('fs'),
_errors = require(__dirname + '/../../lib/js-yaml/errors'), _errors = require(__dirname + '/../../lib/js-yaml/errors'),
_composer = require(__dirname + '/../../lib/js-yaml/composer'), _composer = require(__dirname + '/../../lib/js-yaml/composer'),
_constructor = require(__dirname + '/../../lib/js-yaml/construct'), _constructor = require(__dirname + '/../../lib/js-yaml/construct'),
_tokens = require(__dirname + '/../../lib/js-yaml/tokens'),
_resolver = require(__dirname + '/../../lib/js-yaml/resolver'); _resolver = require(__dirname + '/../../lib/js-yaml/resolver');




Expand Down Expand Up @@ -47,8 +50,8 @@ $$.inherits(CanonicalError, _errors.YAMLError);






function CanonicalScanner = (data) { function CanonicalScanner(data) {
this.data = data + '\0'; this.data = data + '\x00';
this.index = 0; this.index = 0;
this.tokens = []; this.tokens = [];
this.scanned = false; this.scanned = false;
Expand All @@ -66,7 +69,7 @@ CanonicalScanner.prototype.checkToken = function checkTokencheckToken() {
return true; return true;
} }


for (i = 0; i < arguments.length; i++) { for (i = 0; i < arguments.length; i += 1) {
if (this.tokens[0].isA(arguments[i])) { if (this.tokens[0].isA(arguments[i])) {
return true; return true;
} }
Expand Down Expand Up @@ -105,18 +108,20 @@ CanonicalScanner.prototype.getToken = function getToken(choice) {
}; };


CanonicalScanner.prototype.scan = function scan() { CanonicalScanner.prototype.scan = function scan() {
var ch;

this.tokens.push(new _tokens.StreamStartToken(null, null)); this.tokens.push(new _tokens.StreamStartToken(null, null));


while (true) { while (true) {
this.find_token(); this.find_token();
ch = this.data[this.index]; ch = this.data[this.index];


if (ch === '\0') { if (ch === '\x00') {
this.tokens.push(new _tokens.StreamEndToken(null, null)); this.tokens.push(new _tokens.StreamEndToken(null, null));
break; break;
} else if (ch === '%') { } else if (ch === '%') {
this.tokens.push(this.scanDirective()); this.tokens.push(this.scanDirective());
} else if (ch === '-' and this.data.silce(this.index, this.index+3) === '---') { } else if (ch === '-' && this.data.silce(this.index, this.index+3) === '---') {
this.index += 3; this.index += 3;
this.tokens.push(new _tokens.DocumentStartToken(null, null)); this.tokens.push(new _tokens.DocumentStartToken(null, null));
} else if (ch === '[') { } else if (ch === '[') {
Expand All @@ -140,7 +145,7 @@ CanonicalScanner.prototype.scan = function scan() {
} else if (ch === ',') { } else if (ch === ',') {
this.index += 1; this.index += 1;
this.tokens.push(new _tokens.FlowEntryToken(null, null)); this.tokens.push(new _tokens.FlowEntryToken(null, null));
} else if (ch === '*' or ch === '&') { } else if (ch === '*' || ch === '&') {
this.tokens.push(this.scanAlias()); this.tokens.push(this.scanAlias());
} else if (ch === '!') { } else if (ch === '!') {
this.tokens.push(this.scanTag()); this.tokens.push(this.scanTag());
Expand All @@ -156,9 +161,9 @@ CanonicalScanner.prototype.scan = function scan() {


CanonicalScanner.prototype.scanDirective = function scanDirective() { CanonicalScanner.prototype.scanDirective = function scanDirective() {
if (this.data.slice(this.index, this.index + DIRECTIVE.length) === this.DIRECTIVE if (this.data.slice(this.index, this.index + DIRECTIVE.length) === this.DIRECTIVE
&& 0 <= ' \n\0'.indexOf(this.data.slice(this.index + DIRECTIVE.length))) { && 0 <= ' \n\x00'.indexOf(this.data.slice(this.index + DIRECTIVE.length))) {
this.index += this.DIRECTIVE.length; this.index += this.DIRECTIVE.length;
return new _tokens.DirectiveToken('YAML', (1, 1), null, null); return new _tokens.DirectiveToken('YAML', [1, 1], null, null);
} }


throw new CanonicalError("invalid directive"); throw new CanonicalError("invalid directive");
Expand All @@ -173,7 +178,7 @@ CanonicalScanner.prototype.scanAlias = function scanAlias() {
this.index += 1; this.index += 1;
start = this.index; start = this.index;


while (-1 === ', \n\0'.indexOf(this.data[this.index])) { while (-1 === ', \n\x00'.indexOf(this.data[this.index])) {
this.index += 1; this.index += 1;
} }


Expand All @@ -187,7 +192,7 @@ CanonicalScanner.prototype.scanTag = function scanTag() {
this.index += 1; this.index += 1;
start = this.index; start = this.index;


while (-1 === ' \n\0'.indexOf(this.data[this.index])) { while (-1 === ' \n\x00'.indexOf(this.data[this.index])) {
this.index += 1; this.index += 1;
} }


Expand All @@ -197,7 +202,7 @@ CanonicalScanner.prototype.scanTag = function scanTag() {
value = '!'; value = '!';
} else if (value[0] === '!') { } else if (value[0] === '!') {
value = 'tag:yaml.org,2002:' + value.slice(1); value = 'tag:yaml.org,2002:' + value.slice(1);
} else if (value[0] == '<' && value[value.length-1] == '>') { } else if (value[0] === '<' && value[value.length-1] === '>') {
value = value.slice(1, value.length-2); value = value.slice(1, value.length-2);
} else { } else {
value = '!' + value; value = '!' + value;
Expand All @@ -207,12 +212,12 @@ CanonicalScanner.prototype.scanTag = function scanTag() {
}; };


CanonicalScanner.prototype.scanScalar = function scanScalar() { CanonicalScanner.prototype.scanScalar = function scanScalar() {
var chinks, start, ignoreSpaces, ch, code; var chunks, start, ignoreSpaces, ch, code, length;


this.index += 1; this.index += 1;
chunks = []; chunks = [];
start = this.index; start = this.index;
ignore_spaces = false; ignoreSpaces = false;


while (this.data[this.index] !== '"') { while (this.data[this.index] !== '"') {
if (this.data[this.index] === '\\') { if (this.data[this.index] === '\\') {
Expand All @@ -224,13 +229,13 @@ CanonicalScanner.prototype.scanScalar = function scanScalar() {


if (ch === '\n') { if (ch === '\n') {
ignoreSpaces = true; ignoreSpaces = true;
} else if (ch in QUOTE_CODES) { } else if (0 <= QUOTE_CODES.indexOf(ch)) {
length = QUOTE_CODES[ch]; length = QUOTE_CODES[ch];
code = parseInt(this.data.slice(this.index, this.index+length), 16); code = parseInt(this.data.slice(this.index, this.index+length), 16);
chunks.puush(String.fromCharCode(code)); chunks.puush(String.fromCharCode(code));
this.index += length; this.index += length;
} else { } else {
if (!(ch in QUOTE_REPLACES)) { if (-1 === QUOTE_REPLACES.indexOf(ch)) {
throw new CanonicalError("invalid escape code"); throw new CanonicalError("invalid escape code");
} }


Expand All @@ -243,7 +248,7 @@ CanonicalScanner.prototype.scanScalar = function scanScalar() {
chunks.push(' '); chunks.push(' ');
this.index += 1; this.index += 1;
start = this.index; start = this.index;
ignore_spaces = true; ignoreSpaces = true;
} else if (ignoreSpaces && this.data[this.index] === ' ') { } else if (ignoreSpaces && this.data[this.index] === ' ') {
this.index += 1; this.index += 1;
start = this.index; start = this.index;
Expand All @@ -269,11 +274,11 @@ CanonicalScanner.prototype.findToken = function findToken() {


if (this.data[this.index] === '#') { if (this.data[this.index] === '#') {
while (this.data[this.index] !== '\n') { while (this.data[this.index] !== '\n') {
self.index += 1; this.index += 1;
} }
} }


if (this.data[this.index] == '\n') { if (this.data[this.index] === '\n') {
this.index += 1; this.index += 1;
} else { } else {
found = true; found = true;
Expand All @@ -284,7 +289,6 @@ CanonicalScanner.prototype.findToken = function findToken() {


module.exports.CanonicalScanner = CanonicalScanner; module.exports.CanonicalScanner = CanonicalScanner;



//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// vim:ts=2:sw=2 // vim:ts=2:sw=2
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
3 changes: 3 additions & 0 deletions test/functional/functional-errors.js
@@ -1,3 +1,6 @@
'use strict';


var Assert = require('assert'); var Assert = require('assert');
var Fs = require('fs'); var Fs = require('fs');
var JsYaml = require('../../lib/js-yaml'); var JsYaml = require('../../lib/js-yaml');
Expand Down
3 changes: 3 additions & 0 deletions test/functional/functional-resolver.js
@@ -1,3 +1,6 @@
'use strict';


var Assert = require('assert'); var Assert = require('assert');
var Fs = require('fs'); var Fs = require('fs');
var JsYaml = require('../../lib/js-yaml'); var JsYaml = require('../../lib/js-yaml');
Expand Down
3 changes: 3 additions & 0 deletions test/functional/functional-structure.js
@@ -1,3 +1,6 @@
'use strict';


var Assert = require('assert'); var Assert = require('assert');
var Fs = require('fs'); var Fs = require('fs');
var JsYaml = require('../../lib/js-yaml'); var JsYaml = require('../../lib/js-yaml');
Expand Down
3 changes: 3 additions & 0 deletions test/functional/functional-tokens.js
@@ -1,3 +1,6 @@
'use strict';


var Assert = require('assert'); var Assert = require('assert');
var Fs = require('fs'); var Fs = require('fs');
var JsYaml = require('../../lib/js-yaml'); var JsYaml = require('../../lib/js-yaml');
Expand Down
9 changes: 6 additions & 3 deletions test/helper.js
@@ -1,3 +1,6 @@
'use strict';


var Vows = require('vows'); var Vows = require('vows');
var Assert = require('assert'); var Assert = require('assert');
var Path = require('path'); var Path = require('path');
Expand All @@ -9,17 +12,17 @@ var Helper = module.exports = {};




Helper.suite = function suite(name, dirname, regexp) { Helper.suite = function suite(name, dirname, regexp) {
var suite = Vows.describe(name); var obj = Vows.describe(name);


Fs.readdirSync(dirname).forEach(function (filename) { Fs.readdirSync(dirname).forEach(function (filename) {
var file = Path.join(dirname, filename); var file = Path.join(dirname, filename);


if (Fs.statSync(file).isFile() && regexp.test(filename)) { if (Fs.statSync(file).isFile() && regexp.test(filename)) {
suite.addBatch(require(file)); obj.addBatch(require(file));
} }
}); });


return suite; return obj;
}; };




Expand Down
3 changes: 2 additions & 1 deletion test/issues-test.js
@@ -1,3 +1,4 @@
'use strict';
require(__dirname + '/helper') require(__dirname + '/helper')
.suite('Issues', __dirname + '/issues', /^issue-\d+\.js$/) .suite('Issues', __dirname + '/issues', new RegExp("^issue-[1-9][0-9]*\\.js$"))
.export(module); .export(module);
3 changes: 3 additions & 0 deletions test/issues/issue-17.js
@@ -1,3 +1,6 @@
'use strict';


var Assert = require('assert'); var Assert = require('assert');
var JsYaml = require('../../lib/js-yaml'); var JsYaml = require('../../lib/js-yaml');
var source = __dirname + '/data/issue-17.yml'; var source = __dirname + '/data/issue-17.yml';
Expand Down
3 changes: 3 additions & 0 deletions test/issues/issue-19.js
@@ -1,3 +1,6 @@
'use strict';


var Assert = require('assert'); var Assert = require('assert');
var JsYaml = require('../../lib/js-yaml'); var JsYaml = require('../../lib/js-yaml');
var source = __dirname + '/data/issue-19.yml'; var source = __dirname + '/data/issue-19.yml';
Expand Down
3 changes: 3 additions & 0 deletions test/issues/issue-26.js
@@ -1,3 +1,6 @@
'use strict';


var Assert = require('assert'); var Assert = require('assert');
var JsYaml = require('../../lib/js-yaml'); var JsYaml = require('../../lib/js-yaml');
var source = __dirname + '/data/issue-26.yml'; var source = __dirname + '/data/issue-26.yml';
Expand Down
3 changes: 3 additions & 0 deletions test/issues/issue-33.js
@@ -1,3 +1,6 @@
'use strict';


var Assert = require('assert'); var Assert = require('assert');
var JsYaml = require('../../lib/js-yaml'); var JsYaml = require('../../lib/js-yaml');
var source = __dirname + '/data/issue-33.yml'; var source = __dirname + '/data/issue-33.yml';
Expand Down
3 changes: 3 additions & 0 deletions test/issues/issue-8.js
@@ -1,3 +1,6 @@
'use strict';


var Assert = require('assert'); var Assert = require('assert');
var JsYaml = require('../../lib/js-yaml'); var JsYaml = require('../../lib/js-yaml');
var source = __dirname + '/data/issue-8.yml'; var source = __dirname + '/data/issue-8.yml';
Expand Down
3 changes: 3 additions & 0 deletions test/issues/issue-9.js
@@ -1,3 +1,6 @@
'use strict';


var Assert = require('assert'); var Assert = require('assert');
var JsYaml = require('../../lib/js-yaml'); var JsYaml = require('../../lib/js-yaml');
var source = __dirname + '/data/issue-9.yml'; var source = __dirname + '/data/issue-9.yml';
Expand Down

0 comments on commit 103f1b1

Please sign in to comment.