Example #1
0
    it('ArrayType', function () {
        doctrine.type.stringify({
            type: doctrine.Syntax.ArrayType,
            elements: [{
                type: doctrine.Syntax.NameExpression,
                name: 'String'
            }]
        }).should.equal('[String]');

        doctrine.type.stringify({
            type: doctrine.Syntax.ArrayType,
            elements: [{
                type: doctrine.Syntax.NameExpression,
                name: 'String'
            }, {
                type: doctrine.Syntax.NameExpression,
                name: 'Number'
            }]
        }).should.equal('[String, Number]');

        doctrine.type.stringify({
            type: doctrine.Syntax.ArrayType,
            elements: []
        }).should.equal('[]');
    });
Example #2
0
    it('TypeApplication', function () {
        doctrine.type.stringify({
            type: doctrine.Syntax.TypeApplication,
            expression: {
                type: doctrine.Syntax.NameExpression,
                name: 'Array'
            },
            applications: [
                {
                    type: doctrine.Syntax.NameExpression,
                    name: 'String'
                }
            ]
        }).should.equal('Array.<String>');

        doctrine.type.stringify({
            type: doctrine.Syntax.TypeApplication,
            expression: {
                type: doctrine.Syntax.NameExpression,
                name: 'Array'
            },
            applications: [
                {
                    type: doctrine.Syntax.NameExpression,
                    name: 'String'
                },
                {
                    type: doctrine.Syntax.AllLiteral
                }
            ]
        }).should.equal('Array.<String, *>');
    });
Example #3
0
    it('UnionType', function () {
        doctrine.type.stringify({
            type: doctrine.Syntax.UnionType,
            elements: [{
                type: doctrine.Syntax.NameExpression,
                name: 'String'
            }]
        }).should.equal('(String)');

        doctrine.type.stringify({
            type: doctrine.Syntax.UnionType,
            elements: [{
                type: doctrine.Syntax.NameExpression,
                name: 'String'
            }, {
                type: doctrine.Syntax.NameExpression,
                name: 'Number'
            }]
        }, {compact: false }).should.equal('(String | Number)');

        doctrine.type.stringify({
            type: doctrine.Syntax.UnionType,
            elements: [{
                type: doctrine.Syntax.NameExpression,
                name: 'String'
            }, {
                type: doctrine.Syntax.NameExpression,
                name: 'Number'
            }]
        }, { topLevel: true, compact: true }).should.equal('String|Number');
    });
Example #4
0
 it('BooleanLiteralType', function () {
     doctrine.type.stringify({
         type: doctrine.Syntax.BooleanLiteralType,
         value: true
     }).should.equal('true');
     doctrine.type.stringify({
         type: doctrine.Syntax.BooleanLiteralType,
         value: false
     }).should.equal('false');
 });
Example #5
0
    it('NameExpression', function () {
        doctrine.type.stringify({
            type: doctrine.Syntax.NameExpression,
            name: 'this.is.valid'
        }).should.equal('this.is.valid');

        doctrine.type.stringify({
            type: doctrine.Syntax.NameExpression,
            name: 'String'
        }).should.equal('String');
    });
Example #6
0
    it('RecordType', function () {
        doctrine.type.stringify({
            type: doctrine.Syntax.RecordType,
            fields: [{
                type: doctrine.Syntax.FieldType,
                key: 'name',
                value: null
            }]
        }).should.equal('{name}');

        doctrine.type.stringify({
            type: doctrine.Syntax.RecordType,
            fields: [{
                type: doctrine.Syntax.FieldType,
                key: 'name',
                value: {
                    type: doctrine.Syntax.NameExpression,
                    name: 'String'
                }
            }]
        }).should.equal('{name: String}');

        doctrine.type.stringify({
            type: doctrine.Syntax.RecordType,
            fields: [{
                type: doctrine.Syntax.FieldType,
                key: 'string',
                value: {
                    type: doctrine.Syntax.NameExpression,
                    name: 'String'
                }
            }, {
                type: doctrine.Syntax.FieldType,
                key: 'number',
                value: {
                    type: doctrine.Syntax.NameExpression,
                    name: 'Number'
                }
            }]
        }).should.equal('{string: String, number: Number}');

        doctrine.type.stringify({
            type: doctrine.Syntax.RecordType,
            fields: []
        }).should.equal('{}');
    });
Example #7
0
 it('OptionalType', function () {
     doctrine.type.stringify({
         type: doctrine.Syntax.OptionalType,
         expression: {
             type: doctrine.Syntax.NameExpression,
             name: 'String'
         }
     }).should.equal('String=');
 });
Example #8
0
 it('RestType', function () {
     doctrine.type.stringify({
         type: doctrine.Syntax.RestType,
         expression: {
             type: doctrine.Syntax.NameExpression,
             name: 'String'
         }
     }).should.equal('...String');
 });
Example #9
0
    it('NullableType', function () {
        doctrine.type.stringify({
            type: doctrine.Syntax.NullableType,
            expression: {
                type: doctrine.Syntax.NameExpression,
                name: 'String'
            },
            prefix: true
        }).should.equal('?String');

        doctrine.type.stringify({
            type: doctrine.Syntax.NullableType,
            expression: {
                type: doctrine.Syntax.NameExpression,
                name: 'String'
            },
            prefix: false
        }).should.equal('String?');
    });
Example #10
0
 it('NullLiteral', function () {
     doctrine.type.stringify({
         type: doctrine.Syntax.NullLiteral
     }).should.equal('null');
 });
Example #11
0
    it('Functions', function () {
        var data01 = 'function (): void';
        doctrine.type.stringify(
            doctrine.type.parseType(data01)
        ).should.equal(data01);

        var data02 = 'function (): String';
        doctrine.type.stringify(
            doctrine.type.parseType(data02)
        ).should.equal(data02);

        var data03 = 'function (test: string): String';
        doctrine.type.stringify(
            doctrine.type.parseType(data03)
        ).should.equal(data03);

        var data04 = 'function (this: Date, test: String): String';
        doctrine.type.stringify(
            doctrine.type.parseType(data04)
        ).should.equal(data04);

        var data05 = 'function (this: Date, a: String, b: Number): String';
        doctrine.type.stringify(
            doctrine.type.parseType(data05)
        ).should.equal(data05);

        var data06 = 'function (this: Date, a: Array.<String, Number>, b: Number): String';
        doctrine.type.stringify(
            doctrine.type.parseType(data06)
        ).should.equal(data06);

        var data07 = 'function (new: Date, a: Array.<String, Number>, b: Number): HashMap.<String, Number>';
        doctrine.type.stringify(
            doctrine.type.parseType(data07)
        ).should.equal(data07);

        var data08 = 'function (new: Date, a: Array.<String, Number>, b: (Number | String | Date)): HashMap.<String, Number>';
        doctrine.type.stringify(
            doctrine.type.parseType(data08)
        ).should.equal(data08);

        var data09 = 'function (new: Date)';
        doctrine.type.stringify(
            doctrine.type.parseType(data09)
        ).should.equal(data09);

        var data10 = 'function (this: Date)';
        doctrine.type.stringify(
            doctrine.type.parseType(data10)
        ).should.equal(data10);

        var data11 = 'function (this: Date, ...list)';
        doctrine.type.stringify(
            doctrine.type.parseType(data11)
        ).should.equal(data11);

        var data11a = 'function (this: Date, test: String=)';
        doctrine.type.stringify(
            doctrine.type.parseType(data11a)
        ).should.equal(data11a);

        // raw ... are not supported
//        var data12 = 'function (this: Date, ...)';
//        doctrine.type.stringify(
//            doctrine.type.parseType(data12)
//        ).should.equal(data12);

        var data12a = 'function (this: Date, ?=)';
        doctrine.type.stringify(
            doctrine.type.parseType(data12a)
        ).should.equal(data12a);
    });
Example #12
0
 it (text, function() {
     var result = doctrine.parse("@param {" + text + "} name");
     //    console.log("Parse Tree: " + JSON.stringify(result, null, " "));
     var stringed = doctrine.type.stringify(result.tags[0].type, {compact:true});
     stringed.should.equal(text);
 });
Example #13
0
 it('NumericLiteralType', function () {
     doctrine.type.stringify({
         type: doctrine.Syntax.NumericLiteralType,
         value: -142.35
     }).should.equal('-142.35');
 });
Example #14
0
 it('StringLiteralType', function () {
     doctrine.type.stringify({
         type: doctrine.Syntax.StringLiteralType,
         value: 'Hello, World!'
     }).should.equal('"Hello, World!"');
 });
Example #15
0
 it('UndefinedLiteral', function () {
     doctrine.type.stringify({
         type: doctrine.Syntax.UndefinedLiteral
     }).should.equal('undefined');
 });