Use typescript again
This commit is contained in:
parent
31921f95bf
commit
e80b28c10d
6 changed files with 1076 additions and 260 deletions
61
test/test.ts
61
test/test.ts
|
@ -1,11 +1,10 @@
|
|||
import * as main from '../src/main'
|
||||
import {test} from 'ava'
|
||||
|
||||
const c = (comment: string, context: string | null) => ({comment, context})
|
||||
import test from 'ava'
|
||||
|
||||
test('tests', t => {
|
||||
t.plan(1)
|
||||
t.deepEqual(
|
||||
main.tests(`*
|
||||
main.extractScripts(`*
|
||||
|
||||
foo // => 1
|
||||
|
||||
|
@ -15,22 +14,20 @@ test('tests', t => {
|
|||
})
|
||||
|
||||
test('tests', t => {
|
||||
t.plan(1)
|
||||
t.deepEqual(
|
||||
main.tests(`*
|
||||
main.extractScripts(`*
|
||||
|
||||
a
|
||||
b /* => 1 +
|
||||
2 +
|
||||
3
|
||||
*/
|
||||
b // => 1 + 2 + 3
|
||||
c // => 1
|
||||
d
|
||||
|
||||
`),
|
||||
*/`),
|
||||
[
|
||||
[
|
||||
{tag: 'Statement', stmt: 'a;'},
|
||||
{tag: '==', lhs: 'b', rhs: '1+2+3'},
|
||||
{tag: '==', lhs: 'b', rhs: '1 + 2 + 3'},
|
||||
{tag: '==', lhs: 'c', rhs: '1'},
|
||||
{tag: 'Statement', stmt: 'd;'},
|
||||
],
|
||||
|
@ -38,23 +35,33 @@ test('tests', t => {
|
|||
)
|
||||
})
|
||||
|
||||
test.failing('modules and namespace', t => {
|
||||
|
||||
|
||||
const c = (comment: string, context: string | null) => ({comment, context})
|
||||
|
||||
test('modules and namespace', t => {
|
||||
t.plan(1)
|
||||
const cs = main.Comments(`
|
||||
/** m */
|
||||
namespace m {}
|
||||
|
||||
/** ns */
|
||||
namespace ns {}
|
||||
`)
|
||||
t.deepEqual(cs, [c('* m ', 'm'), c('* ns ', 'ns')])
|
||||
t.deepEqual(cs, [c('m ', 'm'), c('ns ', 'ns')])
|
||||
})
|
||||
|
||||
test('const', t => {
|
||||
t.plan(1)
|
||||
const cs = main.Comments(`
|
||||
/** u */
|
||||
const u = 1
|
||||
`)
|
||||
t.deepEqual(cs, [c('* u ', 'u')])
|
||||
t.deepEqual(cs, [c('u ', 'u')])
|
||||
})
|
||||
|
||||
test('const object', t => {
|
||||
t.plan(1)
|
||||
const cs = main.Comments(`
|
||||
/** k */
|
||||
const k = {
|
||||
|
@ -64,28 +71,31 @@ test('const object', t => {
|
|||
b(x: string) { return x+x }
|
||||
}
|
||||
`)
|
||||
t.deepEqual(cs, [c('* k ', 'k'), c('* a ', 'a'), c('* b ', 'b')])
|
||||
t.deepEqual(cs, [c('k ', 'k'), c('a ', 'a'), c('b ', 'b')])
|
||||
})
|
||||
|
||||
test('object deconstruction', t => {
|
||||
t.plan(1)
|
||||
const cs = main.Comments(`
|
||||
/** hello */
|
||||
const {u, v} = {u: 1, v: 2}
|
||||
`)
|
||||
t.deepEqual(cs, [c('* hello ', null)])
|
||||
t.deepEqual(cs, [c('hello ', null)])
|
||||
})
|
||||
|
||||
test('function', t => {
|
||||
t.plan(1)
|
||||
const cs = main.Comments(`
|
||||
/** v */
|
||||
function v(s: string): number {
|
||||
return s.length + 1
|
||||
}
|
||||
`)
|
||||
t.deepEqual(cs, [c('* v ', 'v')])
|
||||
t.deepEqual(cs, [c('v ', 'v')])
|
||||
})
|
||||
|
||||
test('class', t => {
|
||||
t.plan(1)
|
||||
const cs = main.Comments(`
|
||||
/** C */
|
||||
class C<A> {
|
||||
|
@ -99,14 +109,15 @@ test('class', t => {
|
|||
}
|
||||
`)
|
||||
t.deepEqual(cs, [
|
||||
c('* C ', 'C'),
|
||||
c('* constructor ', 'constructor'),
|
||||
c('* m ', 'm'),
|
||||
c('* p ', 'p'),
|
||||
c('C ', 'C'),
|
||||
c('constructor ', 'constructor'),
|
||||
c('m ', 'm'),
|
||||
c('p ', 'p'),
|
||||
])
|
||||
})
|
||||
|
||||
test('interface', t => {
|
||||
t.plan(1)
|
||||
const cs = main.Comments(`
|
||||
/** I */
|
||||
interface I<A> {
|
||||
|
@ -116,18 +127,20 @@ test('interface', t => {
|
|||
j(a: A): string
|
||||
}
|
||||
`)
|
||||
t.deepEqual(cs, [c('* I ', 'I'), c('* i ', 'i'), c('* j ', 'j')])
|
||||
t.deepEqual(cs, [c('I ', 'I'), c('i ', 'i'), c('j ', 'j')])
|
||||
})
|
||||
|
||||
test('type', t => {
|
||||
t.plan(1)
|
||||
const cs = main.Comments(`
|
||||
/** T */
|
||||
type T = number
|
||||
`)
|
||||
t.deepEqual(cs, [c('* T ', 'T')])
|
||||
t.deepEqual(cs, [c('T ', 'T')])
|
||||
})
|
||||
|
||||
test('anywhere', t => {
|
||||
t.plan(1)
|
||||
const cs = main.Comments(`
|
||||
const $ = () => {
|
||||
/** test1 */
|
||||
|
@ -142,5 +155,5 @@ test('anywhere', t => {
|
|||
return f(f(w))
|
||||
}
|
||||
`)
|
||||
t.deepEqual(cs, [c('* test1 ', 'w'), c('* test2 ', 'f'), c('* test3 ', null)])
|
||||
t.deepEqual(cs, [c('test1 ', 'w'), c('test2 ', 'f')])
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue