Ejemplo n.º 1
0
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')
Ejemplo n.º 2
0
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')
Ejemplo n.º 3
0
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', '')
Ejemplo n.º 4
0
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', '')
Ejemplo n.º 5
0
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', '')
Ejemplo n.º 6
0
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', '')
Ejemplo n.º 7
0
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')
Ejemplo n.º 8
0
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')
Ejemplo n.º 9
0
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')
Ejemplo n.º 10
0
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')
Ejemplo n.º 11
0
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
Ejemplo n.º 12
0
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
Ejemplo n.º 13
0
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) == ('', '', '')
Ejemplo n.º 14
0
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) == ('', '', '')
Ejemplo n.º 15
0
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', '')
Ejemplo n.º 16
0
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')
Ejemplo n.º 17
0
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', '')
Ejemplo n.º 18
0
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')
Ejemplo n.º 19
0
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
Ejemplo n.º 20
0
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
Ejemplo n.º 21
0
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')
Ejemplo n.º 22
0
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')
Ejemplo n.º 23
0
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')
Ejemplo n.º 24
0
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', '', '')
Ejemplo n.º 25
0
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')
Ejemplo n.º 26
0
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', '', '')