Skip to content

Commit f5cdf9f

Browse files
authored
Return text, expected, and config from fileTests
1 parent 34253b1 commit f5cdf9f

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/test.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,20 +146,33 @@ function toLineContext(file: string, index: number) {
146146

147147
export function fileTests(file: string, fileName: string, mayIgnore = defaultIgnore) {
148148
let caseExpr = /\s*#\s*(.*)(?:\r\n|\r|\n)([^]*?)==+>([^]*?)(?:$|(?:\r\n|\r|\n)+(?=#))/gy
149-
let tests: {name: string, run(parser: Parser): void}[] = []
149+
let tests: {
150+
name: string,
151+
text: string,
152+
expected: string,
153+
configStr: string,
154+
config: object,
155+
strict: boolean,
156+
run(parser: Parser): void
157+
}[] = []
150158
let lastIndex = 0;
151159
for (;;) {
152160
let m = caseExpr.exec(file)
153161
if (!m) throw new Error(`Unexpected file format in ${fileName} around\n\n${toLineContext(file, lastIndex)}`)
154162

163+
let text = m[2].trim(), expected = m[3].trim()
155164
let [, name, configStr] = /(.*?)(\{.*?\})?$/.exec(m[1])!
156165
let config = configStr ? JSON.parse(configStr) : null
166+
let strict = !/|\.\.\./.test(expected)
157167

158-
let text = m[2].trim(), expected = m[3]
159168
tests.push({
160169
name,
170+
text,
171+
expected,
172+
configStr,
173+
config,
174+
strict,
161175
run(parser: Parser) {
162-
let strict = !/|\.\.\./.test(expected)
163176
if ((parser as any).configure && (strict || config))
164177
parser = (parser as any).configure({strict, ...config})
165178
testTree(parser.parse(text), expected, mayIgnore)

0 commit comments

Comments
 (0)