Skip to content

Commit

Permalink
fix(build): update out-dated packages, including eslint and correspon…
Browse files Browse the repository at this point in the history
…ding es5 style issues
  • Loading branch information
Jiansen committed Jul 5, 2016
1 parent 1516c99 commit ae4f1f9
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 124 deletions.
26 changes: 26 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module.exports = {
"env": {
"browser": true,
"commonjs": true,
"mocha": true,
},
"extends": "eslint:recommended",
"rules": {
"indent": [
"error",
2
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"single"
],
"semi": [
"error",
"always"
]
}
};
11 changes: 5 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
"description": "Patten matching via extractor objects in JavaScript",
"main": "./lib/match-js.min.js",
"scripts": {
"build": "webpack --mode=build",
"build": "webpack --progress --colors --mode=dev",
"commit": "git-cz",
"dev": "webpack --progress --colors --watch --mode=dev",
"dev:single": "webpack --progress --colors --mode=dev",
"test:single": "npm run dev:single && npm run test:single:es5 && npm run test:single:es6 && npm run test:single:coffee",
"test:single": "npm run build && npm run test:single:es5 && npm run test:single:es6 && npm run test:single:coffee",
"test:es5": "eslint ./test/*.spec.es5.js && mocha --colors --watch ./test/*.spec.es5.js",
"test:es6": "mocha --compilers js:babel-core/register --colors --watch ./test/*.spec.es6.js",
"_test:coffee": "coffee --compile --output ./coffee-test/ ./test/*.spec.coffee && mocha --colors --watch ./coffee-test/*.spec.js",
Expand All @@ -22,20 +21,20 @@
"babel": "^6.3.13",
"babel-core": "^6.1.18",
"babel-loader": "^6.1.0",
"babel-plugin-add-module-exports": "^0.1.4",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-preset-es2015": "^6.9.0",
"chai": "^3.4.1",
"coffee-script": "^1.10.0",
"commitizen": "^2.8.2",
"cz-conventional-changelog": "^1.1.6",
"eslint": "^2.13.1",
"eslint": "^3.0.1",
"mocha": "^2.5.3",
"mocha-webpack": "^0.4.0",
"semantic-release": "^4.3.5",
"semantic-release-cli": "^1.4.1",
"webpack": "^1.13.1",
"webpack-node-externals": "^1.2.0",
"yargs": "^3.32.0"
"yargs": "^4.7.1"
},
"repository": {
"type": "git",
Expand Down
56 changes: 28 additions & 28 deletions test/adt_calculator.spec.es5.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,82 +4,82 @@ var match = require('../lib/match-js').match;
chai.expect();
var expect = chai.expect;

describe('Matching on Algebraic Data Type: An Calculator', function () {
function BinOpExp(x,y) {
describe('Matching on Algebraic Data Type: An Calculator', function() {
function BinOpExp(x, y) {
this.x = x;
this.y = y;
}

function Add(x,y) {
function Add(x, y) {
BinOpExp.call(this, x, y);
}
Add.prototype = Object.create(BinOpExp.prototype);
Add.prototype.unapply = function unapply(exp) {
if (exp instanceof Add){
if (exp instanceof Add) {
return [exp.x, exp.y];
}
return undefined;
}
};

function Min(x,y) {
function Min(x, y) {
BinOpExp.call(this, x, y);
}
Min.prototype = Object.create(BinOpExp.prototype);
Min.prototype.unapply = function unapply(exp) {
if (exp instanceof Min){
if (exp instanceof Min) {
return [exp.x, exp.y];
}
return undefined;
}
};

function Mul(x,y) {
function Mul(x, y) {
BinOpExp.call(this, x, y);
}
Mul.prototype = Object.create(BinOpExp.prototype);
Mul.prototype.unapply = function unapply(exp) {
if (exp instanceof Mul){
if (exp instanceof Mul) {
return [exp.x, exp.y];
}
return undefined;
}
};

function Div(x,y) {
function Div(x, y) {
BinOpExp.call(this, x, y);
}
Div.prototype = Object.create(BinOpExp.prototype);
Div.prototype.unapply = function unapply(exp) {
if (exp instanceof Div){
if (exp instanceof Div) {
return [exp.x, exp.y];
}
return undefined;
}
};

function Number() {}
Number.prototype.unapply = function unapply(e) {
if (typeof e === 'number'){
if (typeof e === 'number') {
return e;
}
return undefined;
}
};

var evaluate = function evaluate(exp) {
return match(exp)(
[Add, function(arr) { return evaluate(arr[0])+evaluate(arr[1]); }],
[Min, function(arr) { return evaluate(arr[0])-evaluate(arr[1]); }],
[Mul, function(arr) { return evaluate(arr[0])*evaluate(arr[1]); }],
[Div, function(arr) { return evaluate(arr[0])/evaluate(arr[1]); }],
[Number, function(x) { return x}]
)
[Add, function(arr) { return evaluate(arr[0]) + evaluate(arr[1]); }],
[Min, function(arr) { return evaluate(arr[0]) - evaluate(arr[1]); }],
[Mul, function(arr) { return evaluate(arr[0]) * evaluate(arr[1]); }],
[Div, function(arr) { return evaluate(arr[0]) / evaluate(arr[1]); }],
[Number, function(x) { return x; }]
);
};

it('evaluate(5) should eval to 5', function() {
expect(evaluate(5)).to.be.equal(5);
expect(evaluate(5)).to.be.equal(5);
});

it('/( *( +(3)(2) )(6) ) (2) should eval to 15', function () {
var exp = new Div(
new Mul( new Add(3, 2), 6),
2);
expect(evaluate(exp)).to.be.equal(15);
it('/( *( +(3)(2) )(6) ) (2) should eval to 15', function() {
var exp = new Div(
new Mul( new Add(3, 2), 6),
2);
expect(evaluate(exp)).to.be.equal(15);
});
});
40 changes: 20 additions & 20 deletions test/misc.spec.es5.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,48 +10,48 @@ var expect = chai.expect;

describe('Miscellaneous useages', function() {
it('execute statements should be allowed', function() {
var m = match(10)(
[1, "ONE"],
[10, function(){
return "TEN";
}, null]
)
expect(m).to.be.equal('TEN');
var m = match(10)(
[1, 'ONE'],
[10, function(){
return 'TEN';
}, null]
);
expect(m).to.be.equal('TEN');
});
it('pass additional parameters to matched patial function', function() {
var m = match(1)(
[1, function(x,y,z){
return "Match "+x+" "+y+" "+z;
return 'Match '+x+' '+y+' '+z;
}, 2,3]
)
);
expect(m).to.be.equal('Match 1 2 3');
});
it('default pattern (_) that matches everything', function() {
var i = 3;
var m = match(i)(
[1, "ONE"],
[2, "TOW"],
[_, function(){ return "_ matches "+i; }]
)
[1, 'ONE'],
[2, 'TOW'],
[_, function(){ return '_ matches '+i; }]
);
expect(m).to.be.equal('_ matches 3');
});
it('default pattern (otherwise) that matches everything', function() {
var i = 3;
var m = match(i)(
[1, "ONE"],
[2, "TOW"],
[otherwise, function(){ return "otherwise matches "+i; }]
)
[1, 'ONE'],
[2, 'TOW'],
[otherwise, function(){ return 'otherwise matches '+i; }]
);
expect(m).to.be.equal('otherwise matches 3');
});

it('id functions returns the same input value', function() {
var x = 10;
var m = match(x)(
[1, "ONE"],
[2, "TOW"],
[1, 'ONE'],
[2, 'TOW'],
[10, id]
)
);
expect(m).to.be.equal(x);
});

Expand Down
78 changes: 39 additions & 39 deletions test/primitive_type.spec.es5.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,53 +4,53 @@ var match = require('../lib/match-js').match;
chai.expect();
var expect = chai.expect;

describe('Matching on build-in primitive types', function () {
it('Integer value 10 should match value 10', function () {
var m = match(10)(
[1, "ONE"],
[10, "TEN"]
)
expect(m).to.be.equal('TEN');
describe('Matching on build-in primitive types', function() {
it('Integer value 10 should match value 10', function() {
var m = match(10)(
[1, 'ONE'],
[10, 'TEN']
);
expect(m).to.be.equal('TEN');
});
it('Integer veriable of value 2 should match the value 2', function () {
var two = 2;
var m = match(two)(
[1, "ONE"],
[2, "TWO"]
)
expect(m).to.be.equal('TWO');
it('Integer veriable of value 2 should match the value 2', function() {
var two = 2;
var m = match(two)(
[1, 'ONE'],
[2, 'TWO']
);
expect(m).to.be.equal('TWO');
});

it('Boolean value true should match value true', function () {
var m = match(true)(
[1, "ONE"],
[10, "TEN"],
[true, "TRUE"]
)
expect(m).to.be.equal('TRUE');
it('Boolean value true should match value true', function() {
var m = match(true)(
[1, 'ONE'],
[10, 'TEN'],
[true, 'TRUE']
);
expect(m).to.be.equal('TRUE');
});

it('String value \'Hello World\' should match value \'Hello World\'', function () {
var m = match('Hello World')(
[1, "ONE"],
[10, "TEN"],
['Hello World', "Hello World Matched"]
)
expect(m).to.be.equal('Hello World Matched');
it('String value \'Hello World\' should match value \'Hello World\'', function() {
var m = match('Hello World')(
[1, 'ONE'],
[10, 'TEN'],
['Hello World', 'Hello World Matched']
);
expect(m).to.be.equal('Hello World Matched');
});

it('Integer 1 should match int 1, not String \'1\'', function() {
var m = match(1)(
['1', "String ONE"],
[1, "Integer ONE"]
)
expect(m).to.be.equal('Integer ONE');
var m = match(1)(
['1', 'String ONE'],
[1, 'Integer ONE']
);
expect(m).to.be.equal('Integer ONE');
});
it('String \'1\' should match String \'1\', not int 1', function () {
var m = match(1)(
[1, "Integer ONE"],
['1', "String ONE"]
)
expect(m).to.be.equal('Integer ONE');
it('String \'1\' should match String \'1\', not int 1', function() {
var m = match(1)(
[1, 'Integer ONE'],
['1', 'String ONE']
);
expect(m).to.be.equal('Integer ONE');
});
});
Loading

0 comments on commit ae4f1f9

Please sign in to comment.