Skip to content

Commit

Permalink
🔥 Remove some more test utils
Browse files Browse the repository at this point in the history
  • Loading branch information
misode committed May 11, 2024
1 parent 1137646 commit f2e8ef6
Showing 1 changed file with 0 additions and 48 deletions.
48 changes: 0 additions & 48 deletions packages/json/test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,57 +21,9 @@ import {
} from '@spyglassmc/core/test-out/utils.js'
import snapshot from 'snap-shot-it'
import { TextDocument } from 'vscode-languageserver-textdocument'
import type { JsonChecker } from '../lib/checker/JsonChecker.js'
import type { JsonExpectation, JsonNode } from '../lib/node/index.js'
import { entry as parser } from '../lib/parser/index.js'

export function testChecker(
checker: JsonChecker,
test: string,
{ project }: { project?: Partial<ProjectData> } = {},
): {
node: JsonNode | 'FAILURE'
parserErrors: readonly LanguageError[]
checkerErrors: readonly LanguageError[]
} {
const src = new Source(test)
const doc = TextDocument.create('file:///', 'json', 0, test)
const symbols = new SymbolUtil({}, NodeJsExternals.event.EventEmitter)
const parserCtx = ParserContext.create(
mockProjectData({ symbols, ...project }),
{ doc },
)
const checkerCtx = CheckerContext.create(
mockProjectData({ symbols, ...project }),
{ doc, src },
)
const result = parser(src, parserCtx)
if (result !== Failure) {
checker(result, { ...checkerCtx, context: '' })
}

return {
node: result === Failure ? 'FAILURE' : result,
parserErrors: parserCtx.err.dump(),
checkerErrors: checkerCtx.err.dump(),
}
}

export function testGrid(
suites: { content: string }[],
checkers: { name: string; checker: JsonChecker }[],
) {
for (const { name, checker } of checkers) {
describe(name, () => {
for (const { content } of suites) {
it(`Check "${showWhitespaceGlyph(content)}"`, () => {
snapshot(testChecker(checker, content))
})
}
})
}
}

export function testCompleter(
completer: Completer<any>,
text: string,
Expand Down

0 comments on commit f2e8ef6

Please sign in to comment.