Skip to content
Browse files

Fixes #12 - Fixed override logic

    Overwrittem methods were not being picked up if there was only one.
    Under the hood it was doing a falsey check against a method
    at index 0 which caused the overwritten method to show twice.
  • Loading branch information...
1 parent af3ca7c commit e67f65e5f94bdfeaa5087a13a2833b224d8b3bbc @davglass committed
Showing with 81 additions and 3 deletions.
  1. +4 −3 lib/builder.js
  2. +25 −0 tests/builder.js
  3. +48 −0 tests/input/inherit/examplemodule.js
  4. +4 −0 tests/parser.js
View
7 lib/builder.js
@@ -816,7 +816,7 @@ YUI.add('doc-builder', function(Y) {
});
},
hasProperty: function(a, b) {
- var other;
+ var other = false;
var h = Y.some(a, function(i, k) {
if ((i.itemtype === b.itemtype) && (i.name === b.name)) {
other = k;
@@ -840,7 +840,7 @@ YUI.add('doc-builder', function(Y) {
if (hasItems[v.class]) {
if (!v.static) {
var override = self.hasProperty(classItems, v);
- if (!override) {
+ if (override === false) {
//This method was extended from the parent class but not over written
//console.error('Merging extends from', v.class, 'onto', info.name);
var q = Y.merge({}, v);
@@ -1119,11 +1119,12 @@ YUI.add('doc-builder', function(Y) {
self.files++;
stack.html = html;
stack.view = view;
+ stack.opts = opts;
}));
});
stack.done(function() {
- cb(stack.html, stack.view);
+ cb(stack.html, stack.view, stack.opts);
});
},
/**
View
25 tests/builder.js
@@ -10,6 +10,18 @@ process.chdir(__dirname);
var suite = new YUITest.TestSuite({
name: 'Builder Test Suite',
+ findByName: function(name, cl) {
+ var items = this.data.classitems,
+ ret;
+
+ items.forEach(function(i) {
+ if (i.name === name && i.class === cl) {
+ ret = i;
+ }
+ });
+
+ return ret;
+ },
setUp: function() {
var test = this;
var options = {
@@ -112,5 +124,18 @@ suite.add(new YUITest.TestCase({
}
}));
+suite.add(new YUITest.TestCase({
+ name: 'Builder Augmentation Tests',
+ 'test: inherited methods': function() {
+ var item = suite.data.classes['mywidget.SubWidget'];
+ Assert.isObject(item, 'Failed to parse class');
+ suite.builder.renderClass(function(html, view, opts) {
+ var method = opts.meta.methods[0];
+ Assert.isObject(method, 'Failed to find inherited method');
+ Assert.isObject(method.overwritten_from, 'Failed to find overwritten data');
+ }, item);
+ }
+}));
+
YUITest.TestRunner.add(suite);
View
48 tests/input/inherit/examplemodule.js
@@ -0,0 +1,48 @@
+/**
+ * @module ExampleModule
+ */
+
+YUI.add('examplemodule', function (Y) {
+ Y.namespace('mywidget');
+
+ /**
+ * Superclass description.
+ *
+ * @constructor
+ * @class SuperWidget
+ * @namespace mywidget
+ */
+ Y.mywidget.superwidget = Y.Base.create("mysuperwidget", Y.Widget, [], {
+
+ /**
+ * Supermethod description.
+ *
+ * @method myMethod
+ */
+ myMethod: function () {}
+
+ }, {
+
+ });
+
+ /**
+ * Subclass description.
+ *
+ * @constructor
+ * @class SubWidget
+ * @extends mywidget.SuperWidget
+ * @namespace mywidget
+ */
+ Y.mywidget.superwidget = Y.Base.create("mysuperwidget", Y.mywidget.superwidget, [], {
+
+ /**
+ * Submethod description.
+ *
+ * @method myMethod
+ */
+ myMethod: function () {}
+
+ }, {
+
+ });
+});
View
4 tests/parser.js
@@ -308,6 +308,10 @@ suite.add(new YUITest.TestCase({
var mod_good = cls['Foo.Bar'];
Assert.isUndefined(mod_bad, 'Found class Foo.Bar.Foo.Bar');
Assert.isObject(mod_good, 'Failed to parse Foo.Bar namespace');
+ },
+ 'test: inherited methods': function() {
+ var item = this.findByName('myMethod', 'mywidget.SubWidget');
+ Assert.isObject(item, 'Failed to parse second method');
}
}));

0 comments on commit e67f65e

Please sign in to comment.
Something went wrong with that request. Please try again.