Пример #1
0
    it('maps a DocumentEntity to a Document', function() {
      const documents = [
        b.document({
          id: 'Klass'
        }),
        b.documentEntity({
          id: 'Method',
        })
      ]
      const tree = subject({
        id: 'foo',
        documents,
        treeOperations: [
          {
            type: 'CHANGE_NODE_PARENT',
            data: {
              parentUid: uidOf('Klass', documents),
              uid: uidOf('Method', documents),
            },
          }
        ]
      })

      assert.equal(tree.documents.length, 1)
      assert.equal(tree.documents[0].id, 'Klass')
      assert.equal(tree.documents[0].entities.length, 1)
      assert.equal(tree.documents[0].entities[0].id, 'Method')
    });
Пример #2
0
  it('wires documents nested inside namespaces to their namespace nodes', function() {
    const documents = [
      b.document({
        id: 'MyNamespace',
        properties: {}
      }),

      b.document({
        id: 'truck',
        title: 'truck',
        properties: {
          namespace: 'MyNamespace',
          isModule: true
        }
      }),
    ];

    const treeOperations = subject(defaultContext, documents)

    assert.equal(treeOperations.length, 2);
    assert.include(treeOperations[1].data, {
      uid: uidOf('truck', documents),
      parentUid: uidOf('MyNamespace', documents),
    });
  });
Пример #3
0
    it('sample 3: example with code only', function() {
      var tag = parse(function() {;
        // /**
        //  * @example
        //  *     module.exports = {
        //  *       name: 'author.user',
        //  *       path: ':userId',
        //  *       parent: 'author.users'
        //  *     };
        //  *
        //  *     // visitable at "/author/users/1" or "/author/users/:userId"
        //  */
      });


      assert.equal(tag.typeInfo.name, null);
      assert.deepEqual(tag.typeInfo.description, [
        "",
        "    module.exports = {",
        "      name: 'author.user',",
        "      path: ':userId',",
        "      parent: 'author.users'",
        "    };",
        "",
        "    // visitable at \"/author/users/1\" or \"/author/users/:userId\"",
        "",
      ].join('\n'));
    });
Пример #4
0
  it('wires entities to their parents', function() {
    const documents = [
      b.document({
        id: 'truck',
        title: 'truck',
        properties: {
          id: 'truck',
          isModule: true
        }
      }),

      b.documentEntity({
        id: '#beep',
        properties: {
          receiver: 'truck'
        }
      })
    ];

    const treeOperations = subject(defaultContext, documents)

    assert.equal(treeOperations.length, 2);
    assert.include(treeOperations[1].data, {
      uid: uidOf('#beep', documents),
      parentUid: uidOf('truck', documents),
    });
  });
Пример #5
0
    it('parses a free-text description', function() {
      var docstring = multiline(function() {
        // hello
      });

      var comment = subject.parseComment(docstring);

      assert.ok(comment);
      assert.equal(comment.description, 'hello');
    });
Пример #6
0
    it('parses a tag', function() {
      var docstring = multiline(function() {
        // @module
      });

      var comment = subject.parseComment(docstring);

      assert.ok(comment);
      assert.equal(comment.tags.length, 1);
    });
Пример #7
0
  it('parses inline "description"', function() {
    var tag = parse(function() {;
      // /**
      //  * @param {String} name this is a description
      //  */
    });

    assert.equal(tag.typeInfo.name, 'name');
    assert.equal(tag.typeInfo.description, 'this is a description');
  });
Пример #8
0
    it('parses inline description without a name', function() {
      var tag = parse(function() {;
        // /**
        //  * @return {true} If the record is valid.
        //  */
      }, { namedReturnTags: false });

      assert.equal(tag.typeInfo.name, undefined);
      assert.equal(tag.typeInfo.description, 'If the record is valid.');
    });
Пример #9
0
    it('parses the name', function() {
      var tag = parse(function() {;
        // /**
        //  * @return {String} foo
        //  */
      });

      assert.equal(tag.typeInfo.name, 'foo');
      assert.equal(tag.typeInfo.description, undefined);
    });
Пример #10
0
    it('parses the name', function() {
      var tag = parse(function() {;
        // /**
        //  * @property {String} foo
        //  */
      });

      assert.equal(tag.typeInfo.name, 'foo');
      assert.include(tag.typeInfo.type, { name: 'String' });
    });
Пример #11
0
    it('parses an optional property', function() {
      var tag = parse(function() {;
        // /**
        //  * @property {String} [foo]
        //  */
      });

      assert.equal(tag.typeInfo.isOptional, true);
      assert.equal(tag.typeInfo.name, 'foo');
    });
Пример #12
0
    it('parses the tag type', function() {
      var docstring = multiline(function() {
        // @module
      });

      var tag = subject.parseTag(docstring.trim());

      assert.ok(tag);
      assert.equal(tag.type, 'module')
    });
Пример #13
0
    it('"{string[]}" => "Array.<string>"', function() {
      var docstring = multiline(function() {
        // {string[]}
      }).trim();

      var types = subject.parseTagTypes(docstring);

      assert.ok(types);
      assert.equal(types.length, 1);
      assert.equal(types[0], 'Array.<string>');
    });
Пример #14
0
  it('understands a variable-bound function', function() {
    var nodeInfo = parseNode(function() {;
      // function me.something()
      // end
    });

    assert.equal(nodeInfo.id, 'something')
    assert.equal(nodeInfo.ctx.type, 'function')
    assert.equal(nodeInfo.receiver, 'me')
    assert.equal(nodeInfo.indexer, '.')
  });
Пример #15
0
  it('understands a function assigned to a table property', function() {
    var nodeInfo = parseNode(function() {;
      // me.something = function()
      // end
    });

    assert.equal(nodeInfo.id, 'something')
    assert.equal(nodeInfo.ctx.type, 'function')
    assert.equal(nodeInfo.receiver, 'me')
    assert.equal(nodeInfo.indexer, '.')
  });
Пример #16
0
    it('parses description without a name', function() {
      var tag = parse(function() {;
        // /**
        //  * @return {String}
        //  *         Something.
        //  */
      });

      assert.equal(tag.typeInfo.name, undefined);
      assert.equal(tag.typeInfo.description, 'Something.');
    });
Пример #17
0
    it('parses name and description', function() {
      var tag = parse(function() {;
        // /**
        //  * @return {String} foo
        //  *         Something.
        //  */
      });

      assert.equal(tag.typeInfo.name, 'foo');
      assert.equal(tag.typeInfo.description, 'Something.');
    });
Пример #18
0
    it('works with "{string}"', function() {
      var docstring = multiline(function() {
        // {string}
      }).trim();

      var types = subject.parseTagTypes(docstring);

      assert.ok(types);
      assert.equal(types.length, 1);
      assert.equal(types[0], 'string');
    });
Пример #19
0
  it('understands an assignment of a literal table property', function() {
    var nodeInfo = parseNode(function() {;
      // local t = {}
      //
      // t.foo = 'bar'
    });

    assert.equal(nodeInfo.length, 2);
    assert.equal(nodeInfo[0].id, 't')
    assert.equal(nodeInfo[0].ctx.type, 'table')

    assert.equal(nodeInfo[1].id, 'foo')
    assert.equal(nodeInfo[1].ctx.type, 'literal')
  });
Пример #20
0
  it('understands an inline table property', function() {
    var nodeInfo = parseNode(function() {;
      // local t = {
      //   foo = 'bar'
      // }
    });

    assert.equal(nodeInfo.length, 2);
    assert.equal(nodeInfo[0].id, 't')
    assert.equal(nodeInfo[0].ctx.type, 'table')

    assert.equal(nodeInfo[1].id, 'foo')
    assert.equal(nodeInfo[1].ctx.type, 'literal')
  });
Пример #21
0
        it('parses a default value of "' + sample.defaultValue + '" => "' + sample.defaultValue + '"', function() {
          var docstring = '/** @property {Mixed} ' + sample.string + ' */'

          if (sample.error) {
            assert.throws(function() {
              parse(docstring);
            }, sample.error);
          }
          else {
            var tag = parse(docstring);

            assert.equal(tag.typeInfo.name, 'foo');
            assert.equal(tag.typeInfo.defaultValue, sample.defaultValue);
          }
        });
Пример #22
0
  it('understands an inline table function', function() {
    var nodeInfo = parseNode(function() {;
      // local t = {
      //   foo = function()
      //   end
      // }
    });

    assert.equal(nodeInfo.length, 2);
    assert.equal(nodeInfo[0].id, 't')
    assert.equal(nodeInfo[0].ctx.type, 'table')

    assert.equal(nodeInfo[1].id, 'foo')
    assert.equal(nodeInfo[1].ctx.type, 'function')
  });
Пример #23
0
            process: function(tag) {
              assert.doesNotThrow(function() {
                tag.setCustomAttribute('width', 240);
              });

              done();
            }
Пример #24
0
  it('ignores multiple local variable declarations', function() {
    var nodeInfo = parseNode(function() {;
      // local foo, _ = 'bar'
    });

    assert.equal(nodeInfo.id, undefined)
  });
Пример #25
0
  it('understands a global variable declaration', function() {
    var nodeInfo = parseNode(function() {;
      // foo = 'bar'
    });

    assert.equal(nodeInfo.id, 'foo')
  });
Пример #26
0
    it('should leave undescribed properties of an object untouched', function() {
      const nextValue = subject({
        name: 'foo',
      }, {}, useNext)

      assert.deepEqual(nextValue, { name: 'foo' });
    })
Пример #27
0
    it('does not cause double-escaping of text', function() {
      var text = subject({ text: 'hello [<world />](http://foobar)' });

      assert.deepEqual(text.trim(),
        '<p>hello <a href="http://foobar">&lt;world /&gt;</a></p>'
      );
    });
Пример #28
0
    it('whines if the node could not be found', function() {
      sinon.spy(NullLinter, 'logError');

      const documents = [
        b.document({
          id: 'Klass',
        })
      ];

      subject({
        id: 'foo',
        documents,
        linter: NullLinter,
        treeOperations: [
          {
            type: 'CHANGE_NODE_PARENT',
            data: {
              uid: uidOf('Child', documents),
              parentUid: uidOf('Klass', documents),
            },
          }
        ]
      })

      assert.calledWith(NullLinter.logError, sinon.match({
        message: sinon.match(/Node with UID ".+" specified as a child for node ".+" could not be found./)
      }))
    });
Пример #29
0
            process: function(tag) {
              assert.throws(function() {
                tag.setCustomAttribute('foo', 'bar');
              }, /Unrecognized custom attribute/);

              done();
            }
Пример #30
0
    it('reports the line of the comment in file', function() {
      sinon.spy(NullLinter, 'logRuleEntry')

      parse(function() {;
        // /**
        //  * @property {(Object) -> Object} foo
        //  */
      }, {}, {
        commentNode: {
          loc: {
            start: {
              line: 3
            }
          }
        }
      });

      // assert.ok(tag.invalid)
      assert.calledWith(NullLinter.logRuleEntry, sinon.match({
        rule: TypeExpressions,
        params: sinon.match({
          typeString: '(Object) -> Object'
        })
      }))
    })