MCPcopy
hub / github.com/vercel-labs/just-bash / parseSpecFile

Function parseSpecFile

packages/just-bash/src/spec-tests/parser.ts:48–233  ·  view source on GitHub ↗
(
  content: string,
  filePath: string,
)

Source from the content-addressed store, hash-verified

46 * Parse a spec test file content
47 */
48export function parseSpecFile(
49 content: string,
50 filePath: string,
51): ParsedSpecFile {
52 const lines = content.split("\n");
53 const header: FileHeader = {};
54 const testCases: TestCase[] = [];
55
56 let currentTest: TestCase | null = null;
57 let scriptLines: string[] = [];
58 let hasInlineCode = false; // True if ## code: directive was used
59 let inMultiLineBlock = false;
60 let multiLineType:
61 | "stdout"
62 | "stderr"
63 | "stdout-json"
64 | "stderr-json"
65 | null = null;
66 let multiLineContent: string[] = [];
67 let multiLineShells: string[] | undefined;
68 let multiLineVariant: "OK" | "N-I" | "BUG" | undefined;
69
70 for (let i = 0; i < lines.length; i++) {
71 const line = lines[i];
72 const lineNumber = i + 1;
73
74 // Inside a multi-line block
75 if (inMultiLineBlock) {
76 // Handle both "## END" and "## END:" (with trailing colon)
77 if (line === "## END" || line === "## END:") {
78 // End of multi-line block
79 if (currentTest && multiLineType) {
80 currentTest.assertions.push({
81 type: multiLineType,
82 value: multiLineContent.join("\n"),
83 shells: multiLineShells,
84 variant: multiLineVariant,
85 });
86 }
87 inMultiLineBlock = false;
88 multiLineType = null;
89 multiLineContent = [];
90 multiLineShells = undefined;
91 multiLineVariant = undefined;
92 continue;
93 }
94 // Check if another assertion is starting (ends current block without ## END)
95 if (line.startsWith("## ") && isAssertionLine(line.slice(3))) {
96 // End current block first
97 if (currentTest && multiLineType) {
98 currentTest.assertions.push({
99 type: multiLineType,
100 value: multiLineContent.join("\n"),
101 shells: multiLineShells,
102 variant: multiLineVariant,
103 });
104 }
105 inMultiLineBlock = false;

Callers 1

spec.test.tsFile · 0.85

Calls 5

isAssertionLineFunction · 0.85
parseHeaderLineFunction · 0.85
parseSingleLineAssertionFunction · 0.85
splitMethod · 0.65
matchMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…