forked from Nanonid/rison
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eee722a
commit 957faac
Showing
3 changed files
with
99 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,3 +18,5 @@ logs | |
results | ||
|
||
npm-debug.log | ||
|
||
node_modules/**/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}]); | ||
}); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |