def test_literal(): [mod] = parse(""" odoo.define('a.ns', function (r) { /** whop whop */ return { 'a': 1, /** wheee */ 'b': 2, }; }); """) assert mod.exports.doc == 'whop whop' [(_1, a), (_2, b)] = mod.exports.properties assert params(a) == ('a', 'Number', '') assert params(b) == ('b', 'Number', 'wheee')
def test_literal(): [mod] = parse(""" flectra.define('a.ns', function (r) { /** whop whop */ return { 'a': 1, /** wheee */ 'b': 2, }; }); """) assert mod.exports.doc == 'whop whop' [(_1, a), (_2, b)] = mod.exports.properties assert params(a) == ('a', 'Number', '') assert params(b) == ('b', 'Number', 'wheee')
def test_methods(): [mod] = parse(""" odoo.define('a.A', function(require) { var Class = require('Class'); return Class.extend({ /** * @param {Widget} parent */ init: function (parent) {}, /** * @returns {Widget} */ itself: function () { return this; }, /** * @param {MouseEvent} e */ _onValidate: function (e) {}, }); }); """) cls = mod.exports assert len(cls.properties) == 3 assert cls.constructor # assume methods are in source order [_, init] = cls.properties[0] assert init == cls.constructor assert init.name == 'init' assert not init.is_private assert init.is_constructor [param] = init.params assert params(param) == ('parent', 'Widget', '') [_, itself] = cls.properties[1] assert itself.name == 'itself' assert not itself.is_private assert not itself.is_constructor assert not itself.params assert params(itself.return_val) == ('', 'Widget', '') [_, _on] = cls.properties[2] assert _on.name == '_onValidate' assert _on.is_private assert not _on.is_constructor [param] = _on.params assert params(param) == ('e', 'MouseEvent', '')
def test_methods(): [mod] = parse(""" actpy.define('a.A', function(require) { var Class = require('Class'); return Class.extend({ /** * @param {Widget} parent */ init: function (parent) {}, /** * @returns {Widget} */ itself: function () { return this; }, /** * @param {MouseEvent} e */ _onValidate: function (e) {}, }); }); """) cls = mod.exports assert len(cls.properties) == 3 assert cls.constructor # assume methods are in source order [_, init] = cls.properties[0] assert init == cls.constructor assert init.name == 'init' assert not init.is_private assert init.is_constructor [param] = init.params assert params(param) == ('parent', 'Widget', '') [_, itself] = cls.properties[1] assert itself.name == 'itself' assert not itself.is_private assert not itself.is_constructor assert not itself.params assert params(itself.return_val) == ('', 'Widget', '') [_, _on] = cls.properties[2] assert _on.name == '_onValidate' assert _on.is_private assert not _on.is_constructor [param] = _on.params assert params(param) == ('e', 'MouseEvent', '')
def test_mixin_implicit(): [mod] = parse(""" actpy.define('a.A', function(require) { var Class = require('Class'); var Mixin = require('Mixin'); /** * This is my class-kai */ return Class.extend(Mixin, { foo: function() {} }); }); """) cls = mod.exports [mixin] = cls.mixins assert type(mixin) == jsdoc.MixinDoc assert params(mixin.properties[0][1]) == ('a', 'Function', '') assert params(mixin.get_property('a')) == ('a', 'Function', '') assert params(cls.get_property('foo')) == ('foo', 'Function', '')
def test_mixin_implicit(): [mod] = parse(""" odoo.define('a.A', function(require) { var Class = require('Class'); var Mixin = require('Mixin'); /** * This is my class-kai */ return Class.extend(Mixin, { foo: function() {} }); }); """) cls = mod.exports [mixin] = cls.mixins assert type(mixin) == jsdoc.MixinDoc assert params(mixin.properties[0][1]) == ('a', 'Function', '') assert params(mixin.get_property('a')) == ('a', 'Function', '') assert params(cls.get_property('foo')) == ('foo', 'Function', '')
def test_mixin(): [mod] = parse(""" flectra.define('a.mixin', function (r) { /** * @mixin */ return { /** * @returns {Number} a number */ do_thing: function other() { return 42; } } }); """) assert isinstance(mod.exports, jsdoc.MixinDoc) [(n, p)] = mod.exports.properties assert n == 'do_thing' assert params(p) == ('other', 'Function', '') assert params(p.return_val) == ('', 'Number', 'a number')
def test_mixin(): [mod] = parse(""" odoo.define('a.mixin', function (r) { /** * @mixin */ return { /** * @returns {Number} a number */ do_thing: function other() { return 42; } } }); """) assert isinstance(mod.exports, jsdoc.MixinDoc) [(n, p)] = mod.exports.properties assert n == 'do_thing' assert params(p) == ('other', 'Function', '') assert params(p.return_val) == ('', 'Number', 'a number')
def test_header(): [mod] = parse(""" flectra.define('a.ns', function (r) { /** * @property {Boolean} a a thing */ return { a: true } }); """) assert isinstance(mod.exports, jsdoc.NSDoc) [(_, p)] = mod.exports.properties assert params(p) == ('a', 'Boolean', 'a thing')
def test_header(): [mod] = parse(""" odoo.define('a.ns', function (r) { /** * @property {Boolean} a a thing */ return { a: true } }); """) assert isinstance(mod.exports, jsdoc.NSDoc) [(_, p)] = mod.exports.properties assert params(p) == ('a', 'Boolean', 'a thing')
def test_fill_ns(): [mod] = parse(""" odoo.define('a.ns', function (r) { var Class = r('Class'); var ns = {}; /** ok */ ns.a = 1; /** @type {String} */ ns['b'] = 2; /** Ike */ ns.c = Class.extend({}); ns.d = function () {} return ns; }); """) ns = mod.exports assert type(ns) == jsdoc.NSDoc [(_a, a), (_b, b), (_c, c), (_d, d)] = ns.properties assert params(a) == ('a', 'Number', 'ok') assert params(b) == ('b', 'String', '') assert type(c) == jsdoc.ClassDoc assert type(d) == jsdoc.FunctionDoc
def test_fill_ns(): [mod] = parse(""" flectra.define('a.ns', function (r) { var Class = r('Class'); var ns = {}; /** ok */ ns.a = 1; /** @type {String} */ ns['b'] = 2; /** Ike */ ns.c = Class.extend({}); ns.d = function () {} return ns; }); """) ns = mod.exports assert type(ns) == jsdoc.NSDoc [(_a, a), (_b, b), (_c, c), (_d, d)] = ns.properties assert params(a) == ('a', 'Number', 'ok') assert params(b) == ('b', 'String', '') assert type(c) == jsdoc.ClassDoc assert type(d) == jsdoc.FunctionDoc
def test_func(): [mod] = parse(""" odoo.define('module', function (d) { /** * @param {Foo} bar this is a bar * @param {Baz} qux this is a qux */ return function (bar, qux) { return 42; } }); """) exports = mod.exports assert type(exports) == jsdoc.FunctionDoc assert exports['sourcemodule'] is mod assert exports.name == '' assert exports.is_constructor == False assert exports.is_private == False assert params(exports.params[0]) == ('bar', 'Foo', 'this is a bar') assert params(exports.params[1]) == ('qux', 'Baz', 'this is a qux') assert params(exports.return_val) == ('', '', '')
def test_func(): [mod] = parse(""" flectra.define('module', function (d) { /** * @param {Foo} bar this is a bar * @param {Baz} qux this is a qux */ return function (bar, qux) { return 42; } }); """) exports = mod.exports assert type(exports) == jsdoc.FunctionDoc assert exports['sourcemodule'] is mod assert exports.name == '' assert exports.is_constructor == False assert exports.is_private == False assert params(exports.params[0]) == ('bar', 'Foo', 'this is a bar') assert params(exports.params[1]) == ('qux', 'Baz', 'this is a qux') assert params(exports.return_val) == ('', '', '')
def test_members(): [mod] = parse(""" actpy.define('A', function (r) { var Class = r('Class'); return Class.extend({ init: function () { /** * This is bob * @var {Foo} */ this.foo = 3; this.bar = 42; /** * @member {Baz} */ this.baz = null; } }); }); """) cls = mod.exports assert params(cls.members[0]) == ('foo', 'Foo', 'This is bob') assert params(cls.members[1]) == ('bar', '', '') assert params(cls.members[2]) == ('baz', 'Baz', '')
def test_extend(): [a, _] = parse(""" odoo.define('A', function (require) { var Class = require('Class'); return Class.extend({}); }); odoo.define('B', function (require) { var A = require('A'); A.include({ /** A property */ a: 3, /** A method */ b: function () {} }); }); """) cls = a.exports assert type(cls) == jsdoc.ClassDoc a = cls.get_property('a') assert type(a) == jsdoc.PropertyDoc assert params(a) == ('a', 'Number', 'A property') b = cls.get_property('b') assert type(b) == jsdoc.FunctionDoc assert params(b) == ('b', 'Function', 'A method')
def test_members(): [mod] = parse(""" odoo.define('A', function (r) { var Class = r('Class'); return Class.extend({ init: function () { /** * This is bob * @var {Foo} */ this.foo = 3; this.bar = 42; /** * @member {Baz} */ this.baz = null; } }); }); """) cls = mod.exports assert params(cls.members[0]) == ('foo', 'Foo', 'This is bob') assert params(cls.members[1]) == ('bar', '', '') assert params(cls.members[2]) == ('baz', 'Baz', '')
def test_extend(): [a, _] = parse(""" actpy.define('A', function (require) { var Class = require('Class'); return Class.extend({}); }); actpy.define('B', function (require) { var A = require('A'); A.include({ /** A property */ a: 3, /** A method */ b: function () {} }); }); """) cls = a.exports assert type(cls) == jsdoc.ClassDoc a = cls.get_property('a') assert type(a) == jsdoc.PropertyDoc assert params(a) == ('a', 'Number', 'A property') b = cls.get_property('b') assert type(b) == jsdoc.FunctionDoc assert params(b) == ('b', 'Function', 'A method')
def test_non_function_properties(): [A] = parse(""" actpy.define('A', function (r) { var Class = r('Class'); return Class.extend({ template: 'thing', a_prop: [1, 2, 3], 'other': {a: 7} }); }); """) t = A.exports.get_property('template') assert type(t) == jsdoc.PropertyDoc assert params(t) == ('template', 'String', '') assert not t.is_private
def test_non_function_properties(): [A] = parse(""" odoo.define('A', function (r) { var Class = r('Class'); return Class.extend({ template: 'thing', a_prop: [1, 2, 3], 'other': {a: 7} }); }); """) t = A.exports.get_property('template') assert type(t) == jsdoc.PropertyDoc assert params(t) == ('template', 'String', '') assert not t.is_private
def test_inline(): [mod] = parse(""" odoo.define('a.ns', function (r) { return { /** * a thing * @type {Boolean} */ a: true } }); """) assert isinstance(mod.exports, jsdoc.NSDoc) [(n, p)] = mod.exports.properties assert n == 'a' assert params(p) == ('a', 'Boolean', 'a thing')
def test_header_conflict(): """ should the header or the inline comment take precedence? """ [mod] = parse(""" flectra.define('a.ns', function (r) { /** * @property {Boolean} a a thing */ return { /** @type {String} */ a: true } }); """) assert isinstance(mod.exports, jsdoc.NSDoc) [(_, p)] = mod.exports.properties assert params(p) == ('a', 'Boolean', 'a thing')
def test_inline(): [mod] = parse(""" flectra.define('a.ns', function (r) { return { /** * a thing * @type {Boolean} */ a: true } }); """) assert isinstance(mod.exports, jsdoc.NSDoc) [(n, p)] = mod.exports.properties assert n == 'a' assert params(p) == ('a', 'Boolean', 'a thing')
def test_hoist(): [mod] = parse(""" flectra.define('module', function() { return foo; /** * @param a_thing */ function foo(a_thing) { return 42; } }); """) actual = mod.exports assert type(actual) == jsdoc.FunctionDoc [param] = actual.params assert params(param) == ('a_thing', '', '')
def test_header_conflict(): """ should the header or the inline comment take precedence? """ [mod] = parse(""" odoo.define('a.ns', function (r) { /** * @property {Boolean} a a thing */ return { /** @type {String} */ a: true } }); """) assert isinstance(mod.exports, jsdoc.NSDoc) [(_, p)] = mod.exports.properties assert params(p) == ('a', 'Boolean', 'a thing')
def test_hoist(): [mod] = parse(""" odoo.define('module', function() { return foo; /** * @param a_thing */ function foo(a_thing) { return 42; } }); """) actual = mod.exports assert type(actual) == jsdoc.FunctionDoc [param] = actual.params assert params(param) == ('a_thing', '', '')