Permalink
Browse files

fix "Object" coersion, with a test

  • Loading branch information...
1 parent b6ed25e commit 711d1f9b9e15c2ea7fddb73888eb17f4c8b7fc3c @TooTallNate committed May 30, 2012
Showing with 8 additions and 1 deletion.
  1. +4 −1 lib/ref.js
  2. +4 −0 test/coerce.js
View
5 lib/ref.js
@@ -61,8 +61,11 @@ exports.derefType = function derefType (type) {
exports.coerceType = function coerceType (type) {
var rtn = type
if (typeof rtn === 'string') {
+ rtn = exports.types[type]
+ if (rtn) return rtn
+
// strip whitespace
- rtn = rtn.replace(/\s+/g, '').toLowerCase()
+ rtn = type.replace(/\s+/g, '').toLowerCase()
if (rtn === 'pointer') {
// legacy "pointer" being used :(
//console.warn('type of "pointer" should not be used...')
View
4 test/coerce.js
@@ -23,4 +23,8 @@ describe('coerce', function () {
assert.strictEqual('int', buf.type)
})
+ it('should coerce "Object" to `ref.types.Object`', function () {
+ assert.strictEqual(ref.types.Object, ref.coerceType('Object'))
+ })
+
})

0 comments on commit 711d1f9

Please sign in to comment.