Skip to content

Commit

Permalink
Add basic unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanrideshark committed Jan 4, 2017
1 parent eee722a commit 957faac
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ logs
results

npm-debug.log

node_modules/**/*
82 changes: 82 additions & 0 deletions js/rison.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
var rison = require('./rison');
var chai = require('chai');
var expect = chai.expect;



describe('Rison', function() {

it('Should do what the README says it does', function() {

var encoded = rison.encode({any: "json", yes:true});

expect(encoded).to.equal(`(any:json,yes:!t)`);

var decoded = `(any:json,yes:!t)`;

var decodedValue = rison.decode(decoded);

expect(decodedValue).to.deep.equal({any:'json', yes:true});
});

it('Should handle deeply nested objects', function() {
var deeplyNested = {
A: {
B: {
C: {
D: 'E',
F: 'G'
}
},
H: {
I: {
J:'K',
L:'M'
}
}
}
};

var encoded = rison.encode(deeplyNested);

expect(encoded).to.equal(`(A:(B:(C:(D:E,F:G)),H:(I:(J:K,L:M))))`);

var serializedDeeplyNested = `(A:(B:(C:(D:E,F:G)),H:(I:(J:K,L:M))))`;

var deserializedDeeplyNested = rison.decode(serializedDeeplyNested);

expect(deserializedDeeplyNested).to.deep.equal(deeplyNested);
})
})

describe('O-Rison', function() {

it('Should do what the README says it does', function() {

var encoded = rison.encode_object({supportsObjects: true, ints: 435});

expect(encoded).to.equal(`ints:435,supportsObjects:!t`);

var decoded = `ints:435,supportsObjects:!t`;

var decodedValue = rison.decode_object(decoded);

expect(decodedValue).to.deep.equal({supportsObjects: true, ints: 435});
});
})

describe('A-Rison', function() {

it('Should do what the README says it does', function() {

var encoded = rison.encode_array(['A', 'B', {supportsObjects: true}]);

expect(encoded).to.equal(`A,B,(supportsObjects:!t)`);

var decoded = `A,B,(supportsObjects:!t)`;

var decodedValue = rison.decode_array(decoded);

expect(decodedValue).to.deep.equal(['A', 'B', {supportsObjects:true}]);
});
})
24 changes: 15 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@

{
"name": "rison",
"version": "0.1.2",
"author": "Metaweb Technologies <[email protected]>",
"description": "URI friendly encoding for JSON structures",
"license": "MIT",
"name": "rison",
"version": "0.1.2",
"scripts": {
"test": "mocha js/rison.spec.js"
},
"author": "Metaweb Technologies <[email protected]>",
"description": "URI friendly encoding for JSON structures",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/Nanonid/rison.git"
"type": "git",
"url": "https://github.com/Nanonid/rison.git"
},
"main": "js/rison.js"
"main": "js/rison.js",
"devDependencies": {
"chai": "^3.5.0",
"mocha": "^3.2.0"
}
}

0 comments on commit 957faac

Please sign in to comment.