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

Function parseAwkTestFile

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

Source from the content-addressed store, hash-verified

61 * Parse a T.* shell test file
62 */
63export function parseAwkTestFile(
64 content: string,
65 filePath: string,
66): ParsedAwkTestFile {
67 const fileName = filePath.split("/").pop() || filePath;
68 const lines = content.split("\n");
69 const testCases: AwkTestCase[] = [];
70 const unparsedTests: string[] = [];
71
72 // Track state for multi-line parsing
73 let i = 0;
74
75 while (i < lines.length) {
76 const line = lines[i];
77
78 // Look for piped input: echo '...' | $awk '...' >foo (multi-line version)
79 // The pipe might be on a different line than the echo start
80 if (line.includes("| $awk")) {
81 const result = tryParseMultiLinePipedAwkTest(lines, i);
82 if (result) {
83 testCases.push(result.testCase);
84 i = result.nextLine;
85 continue;
86 }
87 }
88
89 // Look for $awk commands that write to foo1 or foo2
90 if (line.includes("$awk") && line.includes(">foo")) {
91 const result = tryParseBuiltinStyleTestImpl(
92 lines,
93 i,
94 tryParseMultiLineAwkTestImpl,
95 );
96 if (result) {
97 testCases.push(result.testCase);
98 i = result.nextLine;
99 continue;
100 }
101 }
102
103 // Look for multi-line $awk programs starting on a line
104 // Check if this is a $TEMP-style test by looking ahead for >$TEMP or >foo
105 if (line.match(/^\$awk\s+'/) && !line.includes(">foo")) {
106 // Look ahead to see if this test uses $TEMP or foo patterns
107 let usesTempPattern = false;
108 for (let j = i; j < Math.min(i + 30, lines.length); j++) {
109 if (lines[j].match(/>\s*\$TEMP/)) {
110 usesTempPattern = true;
111 break;
112 }
113 if (lines[j].match(/>\s*foo[12]/)) {
114 break;
115 }
116 }
117
118 if (usesTempPattern) {
119 // Use $TEMP-style parser
120 const result = tryParseTempVarStyleTest(lines, i);

Callers 1

awk-spec.test.tsFile · 0.85

Calls 6

tryParseTempVarStyleTestFunction · 0.85
tryParseReversedTestFunction · 0.85
tryParseHeredocTestsFunction · 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…