-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from tmoiron/master
Adds a parameter (useArray) to allow converting object without using arrays.
- Loading branch information
Showing
3 changed files
with
108 additions
and
12 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
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
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,72 @@ | ||
'use strict'; | ||
|
||
require('should'); | ||
var Dot = require('../index'); | ||
|
||
describe('useArray:', function () { | ||
|
||
var dotObject, arrayObject, object; | ||
var arrayObjectExpected, objectExpected, dotObjectExpected; | ||
|
||
beforeEach(function () { | ||
|
||
dotObject = { | ||
'a.0': 'value' | ||
}; | ||
dotObjectExpected = { | ||
'a.0': 'value' | ||
}; | ||
arrayObject = { | ||
a: ['value'] | ||
}; | ||
arrayObjectExpected = { | ||
a: ['value'] | ||
}; | ||
object = { | ||
a: { | ||
'0': 'value' | ||
} | ||
}; | ||
objectExpected = { | ||
a: { | ||
'0': 'value' | ||
} | ||
}; | ||
|
||
}); | ||
|
||
|
||
it('default is using array ', function () { | ||
var dotLocal = require('../index'); | ||
arrayObjectExpected.should.eql(dotLocal.object(dotObject)); | ||
}); | ||
it('Should convert dot using arrays ', function () { | ||
Dot.useArray = true; | ||
arrayObjectExpected.should.eql(Dot.object(dotObject)); | ||
}); | ||
it('Should convert dot not using arrays ', function () { | ||
Dot.useArray = false; | ||
objectExpected.should.eql(Dot.object(dotObject)); | ||
}); | ||
it('Should convert object using arrays ', function () { | ||
Dot.useArray = true; | ||
arrayObjectExpected.should.eql(Dot.object(dotObject)); | ||
}); | ||
it('Should convert dot using arrays and convert back equals source', function () { | ||
Dot.useArray = true; | ||
dotObjectExpected.should.eql(Dot.dot(Dot.object(dotObject))); | ||
}); | ||
it('Should convert object using arrays and convert back equals source', function () { | ||
Dot.useArray = true; | ||
arrayObjectExpected.should.eql(Dot.object(Dot.dot(object))); | ||
}); | ||
it('Should convert dot not using arrays and convert back equals source', function () { | ||
Dot.useArray = false; | ||
dotObjectExpected.should.eql(Dot.dot(Dot.object(dotObject))); | ||
}); | ||
it('Should convert object not using arrays and convert back equals source', function () { | ||
Dot.useArray = false; | ||
objectExpected.should.eql(Dot.object(Dot.dot(arrayObject))); | ||
}); | ||
|
||
}); |