Commit 1fdbf6d6 authored by Wiktor Walasek's avatar Wiktor Walasek

Add test for over 10 lines and complex return types

parent 80d3f8df
......@@ -9,3 +9,4 @@ TODO
Add prettier
Release first version
Mention plugin in https://github.com/prettier/prettier/issues/5659
Investigate sorting of over 10 tags - failing test in ./tests/main.js:209
......@@ -206,6 +206,43 @@ test('Should keep defined inner types', () => {
expect(Result5).toEqual(Expected5)
})
test.skip('Sould keep params ordering when more than 10 tags are present', () => {
// this is broken. seems to originate in sort. As a short investigation I've
// printed tags before and after sort and those are results:
// before = [{"title":"param","name":"test1","type":{"type":"NameExpression","name":"Number"}},{"title":"param","name":"test2","type":{"type":"NameExpression","name":"Number"}},{"title":"param","name":"test3","type":{"type":"UnionType","elements":[{"type":"NameExpression","name":"Number"},{"type":"NameExpression","name":"String"}],"name":"Number|String"}},{"title":"param","name":"test4","type":{"type":"NullableType","expression":{"type":"UndefinedLiteral"},"prefix":true,"name":"?undefined"}},{"title":"param","name":"test5","type":{"type":"NonNullableType","expression":{"type":"UndefinedLiteral"},"prefix":true,"name":"!undefined"}},{"title":"param","name":"test6","type":{"type":"AllLiteral","name":"*"}},{"title":"param","name":"test7","type":{"type":"NullableType","expression":{"type":"NameExpression","name":"Number"},"prefix":true,"name":"?Number"}},{"title":"param","name":"test8","type":{"type":"RestType","expression":{"type":"NameExpression","name":"Number"},"name":"...Number"}},{"title":"param","name":"test9","type":{"type":"NonNullableType","expression":{"type":"NameExpression","name":"Number"},"prefix":true,"name":"!Number"}},{"title":"return","type":{"type":"TypeApplication","expression":{"type":"NameExpression","name":"Promise"},"applications":[{"type":"TypeApplication","expression":{"type":"NameExpression","name":"Object"},"applications":[{"type":"NameExpression","name":"string"},{"type":"UnionType","elements":[{"type":"NameExpression","name":"number"},{"type":"UndefinedLiteral"}]}]}],"name":"Promise.<Object.<string, number|undefined>>"}},{"title":"description"}]
// after = [{"title":"description"},{"title":"param","name":"test1","type":{"type":"NameExpression","name":"Number"}},{"title":"param","name":"test3","type":{"type":"UnionType","elements":[{"type":"NameExpression","name":"Number"},{"type":"NameExpression","name":"String"}],"name":"Number|String"}},{"title":"param","name":"test4","type":{"type":"NullableType","expression":{"type":"UndefinedLiteral"},"prefix":true,"name":"?undefined"}},{"title":"param","name":"test5","type":{"type":"NonNullableType","expression":{"type":"UndefinedLiteral"},"prefix":true,"name":"!undefined"}},{"title":"param","name":"test2","type":{"type":"NameExpression","name":"Number"}},{"title":"param","name":"test7","type":{"type":"NullableType","expression":{"type":"NameExpression","name":"Number"},"prefix":true,"name":"?Number"}},{"title":"param","name":"test8","type":{"type":"RestType","expression":{"type":"NameExpression","name":"Number"},"name":"...Number"}},{"title":"param","name":"test9","type":{"type":"NonNullableType","expression":{"type":"NameExpression","name":"Number"},"prefix":true,"name":"!Number"}},{"title":"param","name":"test6","type":{"type":"AllLiteral","name":"*"}},{"title":"return","type":{"type":"TypeApplication","expression":{"type":"NameExpression","name":"Promise"},"applications":[{"type":"TypeApplication","expression":{"type":"NameExpression","name":"Object"},"applications":[{"type":"NameExpression","name":"string"},{"type":"UnionType","elements":[{"type":"NameExpression","name":"number"},{"type":"UndefinedLiteral"}]}]}],"name":"Promise.<Object.<string, number|undefined>>"}}]
const Result1 = subject(`/**
* description
* @param {Number} test1 Test param
* @param {Number} test2 Test param
* @param {Number|String} test3 Test param
* @param {?undefined} test4 Test param
* @param {!undefined} test5 Test param
* @param {*} test6 Test param
* @param {?Number} test7 Test param
* @param {...Number} test8 Test param
* @param {!Number} test9 Test param
* @return {Promise<Object<string, number|undefined>>} test return
*/`)
const Expected1 = `/**
* @description Description
*
* @param {Number} test1 Test param
* @param {Number} test2 Test param
* @param {Number|String} test3 Test param
* @param {?undefined} test4 Test param
* @param {!undefined} test5 Test param
* @param {*} test6 Test param
* @param {?Number} test7 Test param
* @param {...Number} test8 Test param
* @param {!Number} test9 Test param
* @return {Promise.<Object.<string, number|undefined>>} Test return
*/
`
expect(Result1).toEqual(Expected1)
})
test('Sould keep complex inner types', () => {
const Result1 = subject(`/**
* @param {(String|Number)[]} test test param
......@@ -233,7 +270,16 @@ test('Sould keep complex inner types', () => {
*/
`
const Result2 = subject(`/**
* @return {Promise<Object<string, number|undefined>>} test return
*/`)
const Expected2 = `/**
* @return {Promise.<Object.<string, number|undefined>>} Test return
*/
`
expect(Result1).toEqual(Expected1)
expect(Result2).toEqual(Expected2)
})
test('Should add parentheses to union type if option set to true', () => {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment