import * as main from '../src/main' import test from 'ava' test('tests', t => { t.plan(1) t.deepEqual( main.extractScripts(`* foo // => 1 `), [[{tag: '==', lhs: `foo`, rhs: `1`}]] ) }) test('tests', t => { t.plan(1) t.deepEqual( main.extractScripts(`* a b // => 1 + 2 + 3 c // => 1 d */`), [ [ {tag: 'Statement', stmt: 'a;'}, {tag: '==', lhs: 'b', rhs: '1 + 2 + 3'}, {tag: '==', lhs: 'c', rhs: '1'}, {tag: 'Statement', stmt: 'd;'}, ], ] ) }) 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')]) }) test('const', t => { t.plan(1) const cs = main.Comments(` /** u */ const u = 1 `) t.deepEqual(cs, [c('u ', 'u')]) }) test('const object', t => { t.plan(1) const cs = main.Comments(` /** k */ const k = { /** a */ a: 1, /** b */ b(x: string) { return x+x } } `) 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)]) }) 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')]) }) test('class', t => { t.plan(1) const cs = main.Comments(` /** C */ class C { /** constructor */ constructor() {} /** m */ m(s: Array): Array { } /** p */ p: Array } `) t.deepEqual(cs, [ 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 { /** i */ i: A, /** j */ j(a: A): string } `) 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')]) }) test('anywhere', t => { t.plan(1) const cs = main.Comments(` const $ = () => { /** test1 */ const w = 1 /** test2 */ function f(x) { return x * x } /** test3 */ return f(f(w)) } `) t.deepEqual(cs, [c('test1 ', 'w'), c('test2 ', 'f')]) })