Browse Source

Fix isDict when type is missing in dictionary.

Brendan Dahl 12 years ago
parent
commit
a79f005527
  1. 9
      src/util.js
  2. 13
      test/unit/util_spec.js

9
src/util.js

@ -441,7 +441,14 @@ function isCmd(v, cmd) { @@ -441,7 +441,14 @@ function isCmd(v, cmd) {
}
function isDict(v, type) {
return v instanceof Dict && (!type || v.get('Type').name == type);
if (!(v instanceof Dict)) {
return false;
}
if (!type) {
return true;
}
var dictType = v.get('Type');
return isName(dictType) && dictType.name == type;
}
function isArray(v) {

13
test/unit/util_spec.js

@ -63,5 +63,18 @@ describe('util', function() { @@ -63,5 +63,18 @@ describe('util', function() {
});
});
describe('isDict', function() {
it('handles empty dictionaries with type check', function() {
var dict = new Dict();
expect(isDict(dict, 'Page')).toEqual(false);
});
it('handles dictionaries with type check', function() {
var dict = new Dict();
dict.set('Type', new Name('Page'));
expect(isDict(dict, 'Page')).toEqual(true);
});
});
});

Loading…
Cancel
Save