Skip to content

Commit c00ad78

Browse files
committed
test: apply AI reviews
1 parent d5ce1b3 commit c00ad78

1 file changed

Lines changed: 27 additions & 29 deletions

File tree

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,41 @@
1+
/* eslint-disable vitest/expect-expect */
2+
13
import type { ParserOptions } from 'prettier'
24
import type { Node } from 'sh-syntax'
35

46
import { parsers } from 'prettier-plugin-sh'
57

6-
describe('Parser location functions', () => {
7-
const { locStart, locEnd } = parsers.sh
8+
const { locStart, locEnd } = parsers.sh
89

9-
it('should return correct offsets for simple shell scripts', async () => {
10-
const script = '#!/bin/sh\necho "Hello, world!"'
11-
const node = await parsers.sh.parse(script, {
12-
filepath: 'test.sh',
13-
} as ParserOptions<Node>)
10+
const testCase = async (script: string) => {
11+
const node = await parsers.sh.parse(script, {
12+
filepath: 'test.sh',
13+
} as ParserOptions<Node>)
1414

15-
// Root node should start at position 0
16-
expect(locStart(node)).toBe(0)
15+
expect(locStart(node)).toBe(0)
16+
expect(locEnd(node)).toBe(script.length)
17+
}
1718

18-
// Root node should end at the script length
19-
expect(locEnd(node)).toBe(script.length)
19+
describe('Parser location functions', () => {
20+
it('should handle simple commands', () => {
21+
const script = 'echo "simple"'
22+
return testCase(script)
2023
})
2124

22-
it('should handle scripts with various syntax constructs', async () => {
23-
const scripts = [
24-
// Simple command
25-
'echo "simple"',
26-
27-
// If statement
28-
'if [ "$1" = "test" ]; then\n echo "test"\nfi',
29-
30-
// Function definition
31-
'function say_hello() {\n echo "Hello"\n}',
32-
]
25+
it('should handle if statements', () => {
26+
const script = 'if [ "$1" = "test" ]; then\n echo "test"\nfi'
27+
return testCase(script)
28+
})
3329

34-
for (const script of scripts) {
35-
const node = await parsers.sh.parse(script, {
36-
filepath: 'test.sh',
37-
} as ParserOptions<Node>)
30+
it('should handle function definitions', async () => {
31+
const script = 'function say_hello() {\n echo "Hello"\n}'
32+
return testCase(script)
33+
})
3834

39-
expect(locStart(node)).toBe(0)
40-
expect(locEnd(node)).toBe(script.length)
41-
}
35+
it('should handle more complex constructs', async () => {
36+
// Add test for a more complex example, e.g. with loops and nesting
37+
const script =
38+
'for i in $(seq 1 3); do\n if [ "$i" -eq 2 ]; then\n echo "Found $i"\n fi\ndone'
39+
return testCase(script)
4240
})
4341
})

0 commit comments

Comments
 (0)