Skip to content

Commit 283269a

Browse files
committed
feat(attacher): attacher
Signed-off-by: Lexus Drumgold <[email protected]>
1 parent 81ba062 commit 283269a

File tree

9 files changed

+363
-175
lines changed

9 files changed

+363
-175
lines changed

src/__snapshots__/parser.functional.snap renamed to src/__snapshots__/attacher.functional.snap

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Vitest Snapshot v1
22

3-
exports[`functional:parser > should create ast for abstract class declaration 1`] = `
3+
exports[`functional:attacher > should create ast for abstract class declaration 1`] = `
44
root[6]
55
├─0 comment[2] (1:1-4:4, 0-61)
66
│ │ data: {"symbol":null,"value":"/**\\n * @file Fixtures - Person\\n * @module fixtures/Person\\n */"}
@@ -52,7 +52,7 @@ exports[`functional:parser > should create ast for abstract class declaration 1`
5252
data: {"tag":"@return","text":"{string} String representation of \`this\`","value":"@return {string} String representation of \`this\`"}
5353
`;
5454

55-
exports[`functional:parser > should create ast for async function declaration 1`] = `
55+
exports[`functional:attacher > should create ast for async function declaration 1`] = `
5656
root[7]
5757
├─0 comment[3] (1:1-5:4, 0-126)
5858
│ │ data: {"symbol":null,"value":"/**\\n * @file Fixtures - dblLinear\\n * @module fixtures/dblLinear\\n * @see https://codewars.com/kata/5672682212c8ecf83e000050\\n */"}
@@ -106,7 +106,7 @@ exports[`functional:parser > should create ast for async function declaration 1`
106106
data: {"tag":"@const","text":"{number} z - \`z\`","value":"@const {number} z - \`z\`"}
107107
`;
108108

109-
exports[`functional:parser > should create ast for async function* declaration 1`] = `
109+
exports[`functional:attacher > should create ast for async function* declaration 1`] = `
110110
root[4]
111111
├─0 comment[2] (1:1-4:4, 0-67)
112112
│ │ data: {"symbol":null,"value":"/**\\n * @file Fixtures - fibonacci\\n * @module fixtures/fibonacci\\n */"}
@@ -144,7 +144,7 @@ exports[`functional:parser > should create ast for async function* declaration 1
144144
data: {"tag":"@var","text":"{IteratorResult<number, number>} curr - Current sequence value","value":"@var {IteratorResult<number, number>} curr - Current sequence value"}
145145
`;
146146

147-
exports[`functional:parser > should create ast for class declaration 1`] = `
147+
exports[`functional:attacher > should create ast for class declaration 1`] = `
148148
root[9]
149149
├─0 comment[3] (1:1-5:4, 0-142)
150150
│ │ data: {"symbol":null,"value":"/**\\n * @file Fixtures - FibonacciSequence\\n * @module fixtures/FibonacciSequence\\n * @see https://codewars.com/kata/55695bc4f75bbaea5100016b\\n */"}
@@ -216,7 +216,7 @@ exports[`functional:parser > should create ast for class declaration 1`] = `
216216
data: {"tag":"@const","text":"{number} value - Temporary sequence value","value":"@const {number} value - Temporary sequence value"}
217217
`;
218218

219-
exports[`functional:parser > should create ast for const enum declaration 1`] = `
219+
exports[`functional:attacher > should create ast for const enum declaration 1`] = `
220220
root[2]
221221
├─0 comment[2] (1:1-4:4, 0-65)
222222
│ │ data: {"symbol":null,"value":"/**\\n * @file Fixtures - LogLevel\\n * @module fixtures/LogLevel\\n */"}
@@ -232,7 +232,7 @@ exports[`functional:parser > should create ast for const enum declaration 1`] =
232232
data: {"tag":"@enum","text":"{number}","value":"@enum {number}"}
233233
`;
234234

235-
exports[`functional:parser > should create ast for default function declaration 1`] = `
235+
exports[`functional:attacher > should create ast for default function declaration 1`] = `
236236
root[4]
237237
├─0 comment[3] (1:1-5:4, 0-136)
238238
│ │ data: {"symbol":null,"value":"/**\\n * @file Fixtures - sumOfIntervals\\n * @module fixtures/sumOfIntervals\\n * @see https://codewars.com/kata/52b7ed099cdc285c300001cd\\n */"}
@@ -268,7 +268,7 @@ exports[`functional:parser > should create ast for default function declaration
268268
data: {"tag":"@const","text":"{[number, number] | undefined} prev - Previous interval","value":"@const {[number, number] | undefined} prev - Previous interval"}
269269
`;
270270

271-
exports[`functional:parser > should create ast for default variable declaration 1`] = `
271+
exports[`functional:attacher > should create ast for default variable declaration 1`] = `
272272
root[5]
273273
├─0 comment[3] (1:1-5:4, 0-136)
274274
│ │ data: {"symbol":null,"value":"/**\\n * @file Fixtures - miniStringFuck\\n * @module fixtures/miniStringFuck\\n * @see https://codewars.com/kata/586dd26a69b6fd46dd0000c0\\n */"}
@@ -300,7 +300,7 @@ exports[`functional:parser > should create ast for default variable declaration
300300
data: {"tag":"@var","text":"{string} output - Program output","value":"@var {string} output - Program output"}
301301
`;
302302

303-
exports[`functional:parser > should create ast for enum declaration 1`] = `
303+
exports[`functional:attacher > should create ast for enum declaration 1`] = `
304304
root[6]
305305
├─0 comment[2] (1:1-4:4, 0-53)
306306
│ │ data: {"symbol":null,"value":"/**\\n * @file Fixtures - Op\\n * @module fixtures/Op\\n */"}
@@ -332,7 +332,7 @@ exports[`functional:parser > should create ast for enum declaration 1`] = `
332332
data: {"value":"Subtraction operator."}
333333
`;
334334

335-
exports[`functional:parser > should create ast for function declaration 1`] = `
335+
exports[`functional:attacher > should create ast for function declaration 1`] = `
336336
root[8]
337337
├─0 comment[3] (1:1-5:4, 0-126)
338338
│ │ data: {"symbol":null,"value":"/**\\n * @file Fixtures - calculate\\n * @module fixtures/calculate\\n * @see https://codewars.com/kata/581bc0629ad9ff9873000316\\n */"}
@@ -394,7 +394,7 @@ exports[`functional:parser > should create ast for function declaration 1`] = `
394394
data: {"tag":"@var","text":"{number} result - Result of calculating two-term expression","value":"@var {number} result - Result of calculating two-term expression"}
395395
`;
396396

397-
exports[`functional:parser > should create ast for function* declaration 1`] = `
397+
exports[`functional:attacher > should create ast for function* declaration 1`] = `
398398
root[2]
399399
├─0 comment[2] (1:1-4:4, 0-65)
400400
│ │ data: {"symbol":null,"value":"/**\\n * @file Fixtures - alphabet\\n * @module fixtures/alphabet\\n */"}
@@ -416,7 +416,7 @@ exports[`functional:parser > should create ast for function* declaration 1`] = `
416416
data: {"tag":"@return","text":"{Generator<string, void, void>} Alphabet generator","value":"@return {Generator<string, void, void>} Alphabet generator"}
417417
`;
418418

419-
exports[`functional:parser > should create ast for interface declaration 1`] = `
419+
exports[`functional:attacher > should create ast for interface declaration 1`] = `
420420
root[4]
421421
├─0 comment[2] (1:1-4:4, 0-77)
422422
│ │ data: {"symbol":null,"value":"/**\\n * @file Fixtures - CoordinatePair\\n * @module fixtures/CoordinatePair\\n */"}
@@ -438,7 +438,7 @@ exports[`functional:parser > should create ast for interface declaration 1`] = `
438438
data: {"value":"y-coordinate."}
439439
`;
440440

441-
exports[`functional:parser > should create ast for namespace declaration 1`] = `
441+
exports[`functional:attacher > should create ast for namespace declaration 1`] = `
442442
root[4]
443443
├─0 comment[2] (1:1-4:4, 0-71)
444444
│ │ data: {"symbol":null,"value":"/**\\n * @file Fixtures - StringUtils\\n * @module fixtures/StringUtils\\n */"}
@@ -470,7 +470,7 @@ exports[`functional:parser > should create ast for namespace declaration 1`] = `
470470
data: {"tag":"@template","text":"D - String delimiter","value":"@template D - String delimiter"}
471471
`;
472472

473-
exports[`functional:parser > should create ast for type declaration 1`] = `
473+
exports[`functional:attacher > should create ast for type declaration 1`] = `
474474
root[2]
475475
├─0 comment[2] (1:1-4:4, 0-69)
476476
│ │ data: {"symbol":null,"value":"/**\\n * @file Fixtures - Coordinate\\n * @module fixtures/Coordinate\\n */"}
@@ -484,7 +484,7 @@ exports[`functional:parser > should create ast for type declaration 1`] = `
484484
data: {"value":"One member in a pair of numbers that represent a single point on a\\ntwo-dimensional grid."}
485485
`;
486486

487-
exports[`functional:parser > should create ast for variable declaration 1`] = `
487+
exports[`functional:attacher > should create ast for variable declaration 1`] = `
488488
root[3]
489489
├─0 comment[2] (1:1-4:4, 0-57)
490490
│ │ data: {"symbol":null,"value":"/**\\n * @file Fixtures - psum\\n * @module fixtures/psum\\n */"}
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
/**
2+
* @file Functional Tests - attacher
3+
* @module docast/tests/attacher/functional
4+
*/
5+
6+
import type { Options, ParserOptions } from '#src/interfaces'
7+
import type { Root } from '#src/nodes'
8+
import fs from 'node:fs'
9+
import path from 'node:path'
10+
import { unified, type Processor } from 'unified'
11+
import { inspect } from 'unist-util-inspect'
12+
import type { TestContext } from 'vitest'
13+
import testSubject from '../attacher'
14+
15+
describe('functional:attacher', () => {
16+
let processor: Processor
17+
18+
beforeEach((ctx: TestContext): void => {
19+
processor = unified()
20+
21+
ctx.expect.addSnapshotSerializer({
22+
print: (val: unknown): string => inspect(val),
23+
test: (): boolean => true
24+
})
25+
})
26+
27+
it('should create ast for abstract class declaration', () => {
28+
// Arrange
29+
const filepath: string = path.resolve('__fixtures__/person.ts')
30+
const file: string = fs.readFileSync(filepath, 'utf8')
31+
const options: ParserOptions = { ...path.parse(filepath), path: filepath }
32+
processor.use<[Options?], string, Root>(testSubject, options)
33+
34+
// Act + Expect
35+
expect(processor.parse(file)).toMatchSnapshot()
36+
})
37+
38+
it('should create ast for async function declaration', () => {
39+
// Arrange
40+
const filepath: string = path.resolve('__fixtures__/dbl-linear.ts')
41+
const file: string = fs.readFileSync(filepath, 'utf8')
42+
const options: ParserOptions = { ...path.parse(filepath), path: filepath }
43+
processor.use<[Options?], string, Root>(testSubject, options)
44+
45+
// Act + Expect
46+
expect(processor.parse(file)).toMatchSnapshot()
47+
})
48+
49+
it('should create ast for async function* declaration', () => {
50+
// Arrange
51+
const filepath: string = path.resolve('__fixtures__/fibonacci.ts')
52+
const file: string = fs.readFileSync(filepath, 'utf8')
53+
const options: ParserOptions = { ...path.parse(filepath), path: filepath }
54+
processor.use<[Options?], string, Root>(testSubject, options)
55+
56+
// Act + Expect
57+
expect(processor.parse(file)).toMatchSnapshot()
58+
})
59+
60+
it('should create ast for class declaration', () => {
61+
// Arrange
62+
const filepath: string = path.resolve('__fixtures__/fibonacci-sequence.ts')
63+
const file: string = fs.readFileSync(filepath, 'utf8')
64+
const options: ParserOptions = { ...path.parse(filepath), path: filepath }
65+
processor.use<[Options?], string, Root>(testSubject, options)
66+
67+
// Act + Expect
68+
expect(processor.parse(file)).toMatchSnapshot()
69+
})
70+
71+
it('should create ast for const enum declaration', () => {
72+
// Arrange
73+
const filepath: string = path.resolve('__fixtures__/log-level.ts')
74+
const file: string = fs.readFileSync(filepath, 'utf8')
75+
const options: ParserOptions = { ...path.parse(filepath), path: filepath }
76+
processor.use<[Options?], string, Root>(testSubject, options)
77+
78+
// Act + Expect
79+
expect(processor.parse(file)).toMatchSnapshot()
80+
})
81+
82+
it('should create ast for default function declaration', () => {
83+
// Arrange
84+
const filepath: string = path.resolve('__fixtures__/sum-of-intervals.ts')
85+
const file: string = fs.readFileSync(filepath, 'utf8')
86+
const options: ParserOptions = { ...path.parse(filepath), path: filepath }
87+
processor.use<[Options?], string, Root>(testSubject, options)
88+
89+
// Act + Expect
90+
expect(processor.parse(file)).toMatchSnapshot()
91+
})
92+
93+
it('should create ast for default variable declaration', () => {
94+
// Arrange
95+
const filepath: string = path.resolve('__fixtures__/mini-string-fuck.ts')
96+
const file: string = fs.readFileSync(filepath, 'utf8')
97+
const options: ParserOptions = { ...path.parse(filepath), path: filepath }
98+
processor.use<[Options?], string, Root>(testSubject, options)
99+
100+
// Act + Expect
101+
expect(processor.parse(file)).toMatchSnapshot()
102+
})
103+
104+
it('should create ast for enum declaration', () => {
105+
// Arrange
106+
const filepath: string = path.resolve('__fixtures__/op.ts')
107+
const file: string = fs.readFileSync(filepath, 'utf8')
108+
const options: ParserOptions = { ...path.parse(filepath), path: filepath }
109+
processor.use<[Options?], string, Root>(testSubject, options)
110+
111+
// Act + Expect
112+
expect(processor.parse(file)).toMatchSnapshot()
113+
})
114+
115+
it('should create ast for function declaration', () => {
116+
// Arrange
117+
const filepath: string = path.resolve('__fixtures__/calculate.ts')
118+
const file: string = fs.readFileSync(filepath, 'utf8')
119+
const options: ParserOptions = { ...path.parse(filepath), path: filepath }
120+
processor.use<[Options?], string, Root>(testSubject, options)
121+
122+
// Act + Expect
123+
expect(processor.parse(file)).toMatchSnapshot()
124+
})
125+
126+
it('should create ast for function* declaration', () => {
127+
// Arrange
128+
const filepath: string = path.resolve('__fixtures__/alphabet.ts')
129+
const file: string = fs.readFileSync(filepath, 'utf8')
130+
const options: ParserOptions = { ...path.parse(filepath), path: filepath }
131+
processor.use<[Options?], string, Root>(testSubject, options)
132+
133+
// Act + Expect
134+
expect(processor.parse(file)).toMatchSnapshot()
135+
})
136+
137+
it('should create ast for interface declaration', () => {
138+
// Arrange
139+
const filepath: string = path.resolve('__fixtures__/coordinate-pair.ts')
140+
const file: string = fs.readFileSync(filepath, 'utf8')
141+
const options: ParserOptions = { ...path.parse(filepath), path: filepath }
142+
processor.use<[Options?], string, Root>(testSubject, options)
143+
144+
// Act + Expect
145+
expect(processor.parse(file)).toMatchSnapshot()
146+
})
147+
148+
it('should create ast for namespace declaration', () => {
149+
// Arrange
150+
const filepath: string = path.resolve('__fixtures__/string-utils.ts')
151+
const file: string = fs.readFileSync(filepath, 'utf8')
152+
const options: ParserOptions = { ...path.parse(filepath), path: filepath }
153+
processor.use<[Options?], string, Root>(testSubject, options)
154+
155+
// Act + Expect
156+
expect(processor.parse(file)).toMatchSnapshot()
157+
})
158+
159+
it('should create ast for type declaration', () => {
160+
// Arrange
161+
const filepath: string = path.resolve('__fixtures__/coordinate.ts')
162+
const file: string = fs.readFileSync(filepath, 'utf8')
163+
const options: ParserOptions = { ...path.parse(filepath), path: filepath }
164+
processor.use<[Options?], string, Root>(testSubject, options)
165+
166+
// Act + Expect
167+
expect(processor.parse(file)).toMatchSnapshot()
168+
})
169+
170+
it('should create ast for variable declaration', () => {
171+
// Arrange
172+
const filepath: string = path.resolve('__fixtures__/psum.ts')
173+
const file: string = fs.readFileSync(filepath, 'utf8')
174+
const options: ParserOptions = { ...path.parse(filepath), path: filepath }
175+
processor.use<[Options?], string, Root>(testSubject, options)
176+
177+
// Act + Expect
178+
expect(processor.parse(file)).toMatchSnapshot()
179+
})
180+
})

0 commit comments

Comments
 (0)