assertEquals("/**@param {...number} foo */", JSDocInfoPrinter.print(info));
}
public void testTypes() {
builder.recordReturnType(
new JSTypeExpression(JsDocInfoParser.parseTypeString("number|string"), ""));
JSDocInfo info = builder.build(null);
assertEquals("/**@return {number|string} */", JSDocInfoPrinter.print(info));
builder.recordParameter("foo",
new JSTypeExpression(new Node(Token.ELLIPSIS, IR.string("number")), ""));
info = builder.build(null);
assertEquals("/**@param {...number} foo */", JSDocInfoPrinter.print(info));
builder.recordThrowType(new JSTypeExpression(new Node(Token.STAR), ""));
info = builder.build(null);
assertEquals("/**@throws {*} */", JSDocInfoPrinter.print(info));
builder.recordTypedef(new JSTypeExpression(new Node(Token.QMARK), ""));
info = builder.build(null);
assertEquals("/**@typedef {?} */", JSDocInfoPrinter.print(info));
builder.recordType(new JSTypeExpression(new Node(Token.VOID), ""));
info = builder.build(null);
assertEquals("/**@type {void} */", JSDocInfoPrinter.print(info));
// Object types
builder.recordEnumParameterType(new JSTypeExpression(
JsDocInfoParser.parseTypeString("{foo:number,bar:string}"), ""));
info = builder.build(null);
assertEquals(
"/**@enum {{foo:number,bar:string}} */", JSDocInfoPrinter.print(info));
// Array types
builder.recordType(new JSTypeExpression(
JsDocInfoParser.parseTypeString("!Array.<number|string>"), ""));
info = builder.build(null);
assertEquals(
"/**@type {!Array.<number|string>} */", JSDocInfoPrinter.print(info));
builder.recordType(new JSTypeExpression(
JsDocInfoParser.parseTypeString("Array"), ""));
builder.recordInlineType();
info = builder.build(null);
assertEquals("/** Array */", JSDocInfoPrinter.print(info));
// Function types
builder.recordType(new JSTypeExpression(
JsDocInfoParser.parseTypeString("function()"), ""));
info = builder.build(null);
assertEquals("/**@type {function()} */", JSDocInfoPrinter.print(info));
builder.recordType(new JSTypeExpression(
JsDocInfoParser.parseTypeString("function(foo,bar)"), ""));
info = builder.build(null);
assertEquals("/**@type {function(foo,bar)} */", JSDocInfoPrinter.print(info));
builder.recordType(new JSTypeExpression(
JsDocInfoParser.parseTypeString("function(foo):number"), ""));
info = builder.build(null);
assertEquals("/**@type {function(foo):number} */", JSDocInfoPrinter.print(info));
builder.recordType(new JSTypeExpression(
JsDocInfoParser.parseTypeString("function(new:goog,number)"), ""));
info = builder.build(null);
assertEquals("/**@type {function(new:goog,number)} */",
JSDocInfoPrinter.print(info));
builder.recordType(new JSTypeExpression(
JsDocInfoParser.parseTypeString("function(this:number,...)"), ""));
info = builder.build(null);
assertEquals("/**@type {function(this:number,...)} */",
JSDocInfoPrinter.print(info));
builder.recordType(new JSTypeExpression(
JsDocInfoParser.parseTypeString("function(...[number])"), ""));
info = builder.build(null);
assertEquals("/**@type {function(...[number])} */",
JSDocInfoPrinter.print(info));
builder.recordType(new JSTypeExpression(
JsDocInfoParser.parseTypeString("function():void"), ""));
info = builder.build(null);
assertEquals("/**@type {function():void} */", JSDocInfoPrinter.print(info));
}