tstyche 7.2.5 → 8.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/dist/api.d.ts +16 -761
- package/dist/api.js +16 -6204
- package/dist/bin.js +2 -3
- package/dist/checker/BaseCheckerAdapter.d.ts +15 -0
- package/dist/checker/BaseCheckerAdapter.js +32 -0
- package/dist/checker/CompatCheckerAdapter.d.ts +70 -0
- package/dist/checker/CompatCheckerAdapter.js +221 -0
- package/dist/checker/NativeCheckerAdapter.d.ts +70 -0
- package/dist/checker/NativeCheckerAdapter.js +200 -0
- package/dist/checker/index.d.ts +3 -0
- package/dist/checker/index.js +2 -0
- package/dist/checker/types.d.ts +9 -0
- package/dist/checker/types.js +1 -0
- package/dist/cli/Cli.d.ts +5 -0
- package/dist/cli/Cli.js +144 -0
- package/dist/cli/CliDIagnosticText.d.ts +3 -0
- package/dist/cli/CliDIagnosticText.js +9 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.js +1 -0
- package/dist/collect/CollectDiagnosticText.d.ts +3 -0
- package/dist/collect/CollectDiagnosticText.js +5 -0
- package/dist/collect/CollectService.d.ts +9 -0
- package/dist/collect/CollectService.js +150 -0
- package/dist/collect/ExpectNode.d.ts +16 -0
- package/dist/collect/ExpectNode.js +30 -0
- package/dist/collect/IdentifierLookup.d.ts +18 -0
- package/dist/collect/IdentifierLookup.js +90 -0
- package/dist/collect/TestTree.d.ts +16 -0
- package/dist/collect/TestTree.js +15 -0
- package/dist/collect/TestTreeNode.d.ts +15 -0
- package/dist/collect/TestTreeNode.js +27 -0
- package/dist/collect/TestTreeNodeBrand.enum.d.ts +6 -0
- package/dist/collect/TestTreeNodeBrand.enum.js +7 -0
- package/dist/collect/TestTreeNodeFlags.enum.d.ts +6 -0
- package/dist/collect/TestTreeNodeFlags.enum.js +7 -0
- package/dist/collect/index.d.ts +6 -0
- package/dist/collect/index.js +6 -0
- package/dist/config/CommandParser.d.ts +7 -0
- package/dist/config/CommandParser.js +107 -0
- package/dist/config/Config.d.ts +18 -0
- package/dist/config/Config.js +59 -0
- package/dist/config/ConfigDiagnosticText.d.ts +19 -0
- package/dist/config/ConfigDiagnosticText.js +57 -0
- package/dist/config/ConfigParser.d.ts +10 -0
- package/dist/config/ConfigParser.js +165 -0
- package/dist/config/Directive.d.ts +9 -0
- package/dist/config/Directive.js +119 -0
- package/dist/config/DirectiveDiagnosticText.d.ts +5 -0
- package/dist/config/DirectiveDiagnosticText.js +11 -0
- package/dist/config/OptionBrand.enum.d.ts +8 -0
- package/dist/config/OptionBrand.enum.js +9 -0
- package/dist/config/OptionGroup.enum.d.ts +5 -0
- package/dist/config/OptionGroup.enum.js +6 -0
- package/dist/config/Options.d.ts +29 -0
- package/dist/config/Options.js +290 -0
- package/dist/config/Target.d.ts +7 -0
- package/dist/config/Target.js +47 -0
- package/dist/config/defaultOptions.d.ts +2 -0
- package/dist/config/defaultOptions.js +14 -0
- package/dist/config/index.d.ts +8 -0
- package/dist/config/index.js +7 -0
- package/dist/config/types.d.ts +55 -0
- package/dist/config/types.js +1 -0
- package/dist/diagnostic/Diagnostic.d.ts +19 -0
- package/dist/diagnostic/Diagnostic.js +51 -0
- package/dist/diagnostic/DiagnosticCategory.enum.d.ts +4 -0
- package/dist/diagnostic/DiagnosticCategory.enum.js +5 -0
- package/dist/diagnostic/DiagnosticOrigin.d.ts +13 -0
- package/dist/diagnostic/DiagnosticOrigin.js +27 -0
- package/dist/diagnostic/helpers.d.ts +6 -0
- package/dist/diagnostic/helpers.js +74 -0
- package/dist/diagnostic/index.d.ts +5 -0
- package/dist/diagnostic/index.js +4 -0
- package/dist/diagnostic/types.d.ts +2 -0
- package/dist/diagnostic/types.js +1 -0
- package/dist/editor/TextEditor.d.ts +15 -0
- package/dist/editor/TextEditor.js +88 -0
- package/dist/editor/index.d.ts +2 -0
- package/dist/editor/index.js +1 -0
- package/dist/editor/types.d.ts +4 -0
- package/dist/editor/types.js +1 -0
- package/dist/environment/Environment.d.ts +5 -0
- package/dist/environment/Environment.js +89 -0
- package/dist/environment/environmentOptions.d.ts +1 -0
- package/dist/environment/environmentOptions.js +2 -0
- package/dist/environment/index.d.ts +2 -0
- package/dist/environment/index.js +1 -0
- package/dist/environment/types.d.ts +10 -0
- package/dist/environment/types.js +1 -0
- package/dist/events/EventEmitter.d.ts +14 -0
- package/dist/events/EventEmitter.js +42 -0
- package/dist/events/index.d.ts +2 -0
- package/dist/events/index.js +1 -0
- package/dist/events/types.d.ts +88 -0
- package/dist/events/types.js +1 -0
- package/dist/expect/AbilityMatcherBase.d.ts +16 -0
- package/dist/expect/AbilityMatcherBase.js +52 -0
- package/dist/expect/Ensure.d.ts +10 -0
- package/dist/expect/Ensure.js +51 -0
- package/dist/expect/ExpectDiagnosticText.d.ts +29 -0
- package/dist/expect/ExpectDiagnosticText.js +87 -0
- package/dist/expect/ExpectService.d.ts +21 -0
- package/dist/expect/ExpectService.js +90 -0
- package/dist/expect/RelationMatcherBase.d.ts +12 -0
- package/dist/expect/RelationMatcherBase.js +16 -0
- package/dist/expect/ToAcceptProps.d.ts +10 -0
- package/dist/expect/ToAcceptProps.js +52 -0
- package/dist/expect/ToBe.d.ts +13 -0
- package/dist/expect/ToBe.js +18 -0
- package/dist/expect/ToBeApplicable.d.ts +10 -0
- package/dist/expect/ToBeApplicable.js +72 -0
- package/dist/expect/ToBeAssignableFrom.d.ts +9 -0
- package/dist/expect/ToBeAssignableFrom.js +12 -0
- package/dist/expect/ToBeAssignableTo.d.ts +9 -0
- package/dist/expect/ToBeAssignableTo.js +12 -0
- package/dist/expect/ToBeCallableWith.d.ts +11 -0
- package/dist/expect/ToBeCallableWith.js +29 -0
- package/dist/expect/ToBeConstructableWith.d.ts +11 -0
- package/dist/expect/ToBeConstructableWith.js +29 -0
- package/dist/expect/ToBeInstantiableWith.d.ts +10 -0
- package/dist/expect/ToBeInstantiableWith.js +31 -0
- package/dist/expect/ToHaveProperty.d.ts +10 -0
- package/dist/expect/ToHaveProperty.js +59 -0
- package/dist/expect/ToRaiseError.d.ts +9 -0
- package/dist/expect/ToRaiseError.js +82 -0
- package/dist/expect/index.d.ts +2 -0
- package/dist/expect/index.js +1 -0
- package/dist/expect/types.d.ts +7 -0
- package/dist/expect/types.js +1 -0
- package/dist/file/FilePosition.d.ts +7 -0
- package/dist/file/FilePosition.js +16 -0
- package/dist/file/index.d.ts +1 -0
- package/dist/file/index.js +1 -0
- package/dist/glob/Braces.d.ts +4 -0
- package/dist/glob/Braces.js +56 -0
- package/dist/glob/Glob.d.ts +4 -0
- package/dist/glob/Glob.js +47 -0
- package/dist/glob/index.d.ts +1 -0
- package/dist/glob/index.js +1 -0
- package/dist/handlers/CancellationHandler.d.ts +7 -0
- package/dist/handlers/CancellationHandler.js +15 -0
- package/dist/handlers/ExitCodeHandler.d.ts +7 -0
- package/dist/handlers/ExitCodeHandler.js +20 -0
- package/dist/handlers/ResultHandler.d.ts +5 -0
- package/dist/handlers/ResultHandler.js +206 -0
- package/dist/handlers/index.d.ts +3 -0
- package/dist/handlers/index.js +3 -0
- package/dist/index.cjs +5 -5
- package/dist/index.d.cts +40 -45
- package/dist/index.d.ts +40 -45
- package/dist/index.js +1 -2
- package/dist/input/InputService.d.ts +6 -0
- package/dist/input/InputService.js +16 -0
- package/dist/input/index.d.ts +1 -0
- package/dist/input/index.js +1 -0
- package/dist/json/JsonNode.d.ts +11 -0
- package/dist/json/JsonNode.js +28 -0
- package/dist/json/JsonScanner.d.ts +14 -0
- package/dist/json/JsonScanner.js +105 -0
- package/dist/json/index.d.ts +3 -0
- package/dist/json/index.js +2 -0
- package/dist/json/types.d.ts +1 -0
- package/dist/json/types.js +1 -0
- package/dist/layers/AbilityLayer.d.ts +10 -0
- package/dist/layers/AbilityLayer.js +186 -0
- package/dist/layers/Layers.d.ts +11 -0
- package/dist/layers/Layers.js +47 -0
- package/dist/layers/SuppressedLayer.d.ts +11 -0
- package/dist/layers/SuppressedLayer.js +93 -0
- package/dist/layers/index.d.ts +2 -0
- package/dist/layers/index.js +1 -0
- package/dist/layers/types.d.ts +8 -0
- package/dist/layers/types.js +1 -0
- package/dist/output/CodeFrameText.d.ts +10 -0
- package/dist/output/CodeFrameText.js +71 -0
- package/dist/output/OutputService.d.ts +13 -0
- package/dist/output/OutputService.js +38 -0
- package/dist/output/StreamController.d.ts +10 -0
- package/dist/output/StreamController.js +16 -0
- package/dist/output/addsText.d.ts +4 -0
- package/dist/output/addsText.js +8 -0
- package/dist/output/describeNameText.d.ts +2 -0
- package/dist/output/describeNameText.js +5 -0
- package/dist/output/diagnosticText.d.ts +4 -0
- package/dist/output/diagnosticText.js +23 -0
- package/dist/output/dotText.d.ts +3 -0
- package/dist/output/dotText.js +11 -0
- package/dist/output/fileStatusText.d.ts +4 -0
- package/dist/output/fileStatusText.js +26 -0
- package/dist/output/formattedText.d.ts +2 -0
- package/dist/output/formattedText.js +19 -0
- package/dist/output/helpText.d.ts +3 -0
- package/dist/output/helpText.js +52 -0
- package/dist/output/helpers.d.ts +5 -0
- package/dist/output/helpers.js +23 -0
- package/dist/output/index.d.ts +16 -0
- package/dist/output/index.js +15 -0
- package/dist/output/prologueText.d.ts +2 -0
- package/dist/output/prologueText.js +5 -0
- package/dist/output/summaryText.d.ts +12 -0
- package/dist/output/summaryText.js +31 -0
- package/dist/output/testNameText.d.ts +3 -0
- package/dist/output/testNameText.js +24 -0
- package/dist/output/types.d.ts +5 -0
- package/dist/output/types.js +1 -0
- package/dist/output/usesText.d.ts +5 -0
- package/dist/output/usesText.js +22 -0
- package/dist/output/waitingForFileChangesText.d.ts +2 -0
- package/dist/output/waitingForFileChangesText.js +5 -0
- package/dist/output/watchUsageText.d.ts +2 -0
- package/dist/output/watchUsageText.js +12 -0
- package/dist/path/Path.d.ts +7 -0
- package/dist/path/Path.js +28 -0
- package/dist/path/index.d.ts +1 -0
- package/dist/path/index.js +1 -0
- package/dist/project/CompatMappedDiagnostic.d.ts +12 -0
- package/dist/project/CompatMappedDiagnostic.js +25 -0
- package/dist/project/CompatProjectService.d.ts +19 -0
- package/dist/project/CompatProjectService.js +188 -0
- package/dist/project/FileMapService.d.ts +6 -0
- package/dist/project/FileMapService.js +14 -0
- package/dist/project/NativeMappedDiagnostic.d.ts +14 -0
- package/dist/project/NativeMappedDiagnostic.js +29 -0
- package/dist/project/NativeProjectService.d.ts +21 -0
- package/dist/project/NativeProjectService.js +216 -0
- package/dist/project/ProjectConfigService.d.ts +8 -0
- package/dist/project/ProjectConfigService.js +73 -0
- package/dist/project/index.d.ts +3 -0
- package/dist/project/index.js +2 -0
- package/dist/project/types.d.ts +7 -0
- package/dist/project/types.js +1 -0
- package/dist/reject/Reject.d.ts +9 -0
- package/dist/reject/Reject.js +43 -0
- package/dist/reject/RejectDiagnosticText.d.ts +5 -0
- package/dist/reject/RejectDiagnosticText.js +16 -0
- package/dist/reject/helpers.d.ts +1 -0
- package/dist/reject/helpers.js +3 -0
- package/dist/reject/index.d.ts +1 -0
- package/dist/reject/index.js +1 -0
- package/dist/reporters/BaseReporter.d.ts +7 -0
- package/dist/reporters/BaseReporter.js +6 -0
- package/dist/reporters/DotReporter.d.ts +6 -0
- package/dist/reporters/DotReporter.js +51 -0
- package/dist/reporters/FileView.d.ts +13 -0
- package/dist/reporters/FileView.js +33 -0
- package/dist/reporters/ListReporter.d.ts +6 -0
- package/dist/reporters/ListReporter.js +125 -0
- package/dist/reporters/SetupReporter.d.ts +4 -0
- package/dist/reporters/SetupReporter.js +21 -0
- package/dist/reporters/SummaryReporter.d.ts +5 -0
- package/dist/reporters/SummaryReporter.js +19 -0
- package/dist/reporters/WatchReporter.d.ts +5 -0
- package/dist/reporters/WatchReporter.js +21 -0
- package/dist/reporters/index.d.ts +7 -0
- package/dist/reporters/index.js +6 -0
- package/dist/reporters/types.d.ts +5 -0
- package/dist/reporters/types.js +1 -0
- package/dist/result/DescribeResult.d.ts +9 -0
- package/dist/result/DescribeResult.js +11 -0
- package/dist/result/ExpectResult.d.ts +10 -0
- package/dist/result/ExpectResult.js +11 -0
- package/dist/result/FileResult.d.ts +15 -0
- package/dist/result/FileResult.js +13 -0
- package/dist/result/ProjectConfigKind.enum.d.ts +6 -0
- package/dist/result/ProjectConfigKind.enum.js +7 -0
- package/dist/result/ProjectResult.d.ts +8 -0
- package/dist/result/ProjectResult.js +9 -0
- package/dist/result/Result.d.ts +13 -0
- package/dist/result/Result.js +14 -0
- package/dist/result/ResultStatus.enum.d.ts +10 -0
- package/dist/result/ResultStatus.enum.js +11 -0
- package/dist/result/SuppressedResult.d.ts +5 -0
- package/dist/result/SuppressedResult.js +6 -0
- package/dist/result/TargetResult.d.ts +11 -0
- package/dist/result/TargetResult.js +12 -0
- package/dist/result/TestResult.d.ts +13 -0
- package/dist/result/TestResult.js +13 -0
- package/dist/result/helpers.d.ts +7 -0
- package/dist/result/helpers.js +21 -0
- package/dist/result/index.d.ts +11 -0
- package/dist/result/index.js +10 -0
- package/dist/result/types.d.ts +31 -0
- package/dist/result/types.js +1 -0
- package/dist/runner/FileRunner.d.ts +10 -0
- package/dist/runner/FileRunner.js +93 -0
- package/dist/runner/FixmeDiagnosticText.d.ts +4 -0
- package/dist/runner/FixmeDiagnosticText.js +8 -0
- package/dist/runner/FixmeService.d.ts +9 -0
- package/dist/runner/FixmeService.js +51 -0
- package/dist/runner/RunModeFlags.enum.d.ts +7 -0
- package/dist/runner/RunModeFlags.enum.js +8 -0
- package/dist/runner/Runner.d.ts +9 -0
- package/dist/runner/Runner.js +101 -0
- package/dist/runner/TestTreeWalker.d.ts +19 -0
- package/dist/runner/TestTreeWalker.js +169 -0
- package/dist/runner/index.d.ts +1 -0
- package/dist/runner/index.js +1 -0
- package/dist/scribbler/Color.enum.d.ts +10 -0
- package/dist/scribbler/Color.enum.js +11 -0
- package/dist/scribbler/Line.d.ts +9 -0
- package/dist/scribbler/Line.js +5 -0
- package/dist/scribbler/Scribbler.d.ts +10 -0
- package/dist/scribbler/Scribbler.js +53 -0
- package/dist/scribbler/Text.d.ts +9 -0
- package/dist/scribbler/Text.js +8 -0
- package/dist/scribbler/index.d.ts +5 -0
- package/dist/scribbler/index.js +4 -0
- package/dist/scribbler/jsxRuntime.d.ts +4 -0
- package/dist/scribbler/jsxRuntime.js +4 -0
- package/dist/scribbler/types.d.ts +19 -0
- package/dist/scribbler/types.js +1 -0
- package/dist/select/Select.d.ts +7 -0
- package/dist/select/Select.js +91 -0
- package/dist/select/SelectDiagnosticText.d.ts +6 -0
- package/dist/select/SelectDiagnosticText.js +24 -0
- package/dist/select/index.d.ts +2 -0
- package/dist/select/index.js +2 -0
- package/dist/store/Fetcher.d.ts +8 -0
- package/dist/store/Fetcher.js +52 -0
- package/dist/store/Lock.d.ts +5 -0
- package/dist/store/Lock.js +17 -0
- package/dist/store/LockService.d.ts +8 -0
- package/dist/store/LockService.js +36 -0
- package/dist/store/Manifest.d.ts +35 -0
- package/dist/store/Manifest.js +58 -0
- package/dist/store/ManifestService.d.ts +10 -0
- package/dist/store/ManifestService.js +129 -0
- package/dist/store/PackageService.d.ts +8 -0
- package/dist/store/PackageService.js +69 -0
- package/dist/store/Store.d.ts +12 -0
- package/dist/store/Store.js +103 -0
- package/dist/store/StoreDiagnosticText.d.ts +12 -0
- package/dist/store/StoreDiagnosticText.js +36 -0
- package/dist/store/TarReader.d.ts +9 -0
- package/dist/store/TarReader.js +56 -0
- package/dist/store/helpers.d.ts +1 -0
- package/dist/store/helpers.js +3 -0
- package/dist/store/index.d.ts +1 -0
- package/dist/store/index.js +1 -0
- package/dist/structure/ComparisonResult.enum.d.ts +5 -0
- package/dist/structure/ComparisonResult.enum.js +6 -0
- package/dist/structure/Structure.d.ts +24 -0
- package/dist/structure/Structure.js +481 -0
- package/dist/structure/index.d.ts +1 -0
- package/dist/structure/index.js +1 -0
- package/dist/suppressed/SuppressedDiagnosticText.d.ts +6 -0
- package/dist/suppressed/SuppressedDiagnosticText.js +18 -0
- package/dist/suppressed/SuppressedService.d.ts +5 -0
- package/dist/suppressed/SuppressedService.js +61 -0
- package/dist/suppressed/index.d.ts +1 -0
- package/dist/suppressed/index.js +1 -0
- package/dist/tag.d.ts +1 -3
- package/dist/tag.js +2 -5
- package/dist/text/TextFile.d.ts +11 -0
- package/dist/text/TextFile.js +41 -0
- package/dist/text/TextFileService.d.ts +10 -0
- package/dist/text/TextFileService.js +31 -0
- package/dist/text/index.d.ts +3 -0
- package/dist/text/index.js +2 -0
- package/dist/text/types.d.ts +5 -0
- package/dist/text/types.js +1 -0
- package/dist/token/CancellationReason.enum.d.ts +6 -0
- package/dist/token/CancellationReason.enum.js +7 -0
- package/dist/token/CancellationToken.d.ts +8 -0
- package/dist/token/CancellationToken.js +22 -0
- package/dist/token/index.d.ts +2 -0
- package/dist/token/index.js +2 -0
- package/dist/typescript/BaseAdapter.d.ts +36 -0
- package/dist/typescript/BaseAdapter.js +83 -0
- package/dist/typescript/CompatTypeScript.d.ts +21 -0
- package/dist/typescript/CompatTypeScript.js +37 -0
- package/dist/typescript/NativeTypeScript.d.ts +24 -0
- package/dist/typescript/NativeTypeScript.js +44 -0
- package/dist/typescript/index.d.ts +3 -0
- package/dist/typescript/index.js +2 -0
- package/dist/typescript/types.d.ts +69 -0
- package/dist/typescript/types.js +1 -0
- package/dist/version/Version.d.ts +6 -0
- package/dist/version/Version.js +30 -0
- package/dist/version/index.d.ts +1 -0
- package/dist/version/index.js +1 -0
- package/dist/watch/Debounce.d.ts +9 -0
- package/dist/watch/Debounce.js +27 -0
- package/dist/watch/FileWatcher.d.ts +5 -0
- package/dist/watch/FileWatcher.js +12 -0
- package/dist/watch/WatchService.d.ts +8 -0
- package/dist/watch/WatchService.js +96 -0
- package/dist/watch/Watcher.d.ts +10 -0
- package/dist/watch/Watcher.js +31 -0
- package/dist/watch/index.d.ts +3 -0
- package/dist/watch/index.js +3 -0
- package/package.json +9 -1
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Checker } from "#checker";
|
|
2
|
+
import type { ExpectNode } from "#collect";
|
|
3
|
+
import type { ResolvedConfig } from "#config";
|
|
4
|
+
import { Diagnostic, type DiagnosticsHandler } from "#diagnostic";
|
|
5
|
+
import type * as ts from "#typescript";
|
|
6
|
+
import type { MatchResult } from "./types.js";
|
|
7
|
+
export declare class ExpectService {
|
|
8
|
+
#private;
|
|
9
|
+
private toAcceptProps;
|
|
10
|
+
private toBe;
|
|
11
|
+
private toBeApplicable;
|
|
12
|
+
private toBeAssignableFrom;
|
|
13
|
+
private toBeAssignableTo;
|
|
14
|
+
private toBeCallableWith;
|
|
15
|
+
private toBeConstructableWith;
|
|
16
|
+
private toBeInstantiableWith;
|
|
17
|
+
private toHaveProperty;
|
|
18
|
+
private toRaiseError;
|
|
19
|
+
constructor(ts: ts.TypeScript, program: ts.Program, checker: Checker, resolvedConfig: ResolvedConfig);
|
|
20
|
+
match(expectNode: ExpectNode, onDiagnostics: DiagnosticsHandler<Diagnostic | Array<Diagnostic>>): MatchResult | undefined;
|
|
21
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { Diagnostic, DiagnosticOrigin } from "#diagnostic";
|
|
2
|
+
import { Reject } from "#reject";
|
|
3
|
+
import { Ensure } from "./Ensure.js";
|
|
4
|
+
import { ExpectDiagnosticText } from "./ExpectDiagnosticText.js";
|
|
5
|
+
import { ToAcceptProps } from "./ToAcceptProps.js";
|
|
6
|
+
import { ToBe } from "./ToBe.js";
|
|
7
|
+
import { ToBeApplicable } from "./ToBeApplicable.js";
|
|
8
|
+
import { ToBeAssignableFrom } from "./ToBeAssignableFrom.js";
|
|
9
|
+
import { ToBeAssignableTo } from "./ToBeAssignableTo.js";
|
|
10
|
+
import { ToBeCallableWith } from "./ToBeCallableWith.js";
|
|
11
|
+
import { ToBeConstructableWith } from "./ToBeConstructableWith.js";
|
|
12
|
+
import { ToBeInstantiableWith } from "./ToBeInstantiableWith.js";
|
|
13
|
+
import { ToHaveProperty } from "./ToHaveProperty.js";
|
|
14
|
+
import { ToRaiseError } from "./ToRaiseError.js";
|
|
15
|
+
export class ExpectService {
|
|
16
|
+
#ensure;
|
|
17
|
+
#reject;
|
|
18
|
+
toAcceptProps;
|
|
19
|
+
toBe;
|
|
20
|
+
toBeApplicable;
|
|
21
|
+
toBeAssignableFrom;
|
|
22
|
+
toBeAssignableTo;
|
|
23
|
+
toBeCallableWith;
|
|
24
|
+
toBeConstructableWith;
|
|
25
|
+
toBeInstantiableWith;
|
|
26
|
+
toHaveProperty;
|
|
27
|
+
toRaiseError;
|
|
28
|
+
constructor(ts, program, checker, resolvedConfig) {
|
|
29
|
+
this.#ensure = new Ensure(ts, program);
|
|
30
|
+
this.#reject = new Reject(ts, checker, resolvedConfig);
|
|
31
|
+
this.toAcceptProps = new ToAcceptProps(ts, checker);
|
|
32
|
+
this.toBe = new ToBe(ts, program, checker);
|
|
33
|
+
this.toBeApplicable = new ToBeApplicable(ts, checker);
|
|
34
|
+
this.toBeAssignableFrom = new ToBeAssignableFrom(checker);
|
|
35
|
+
this.toBeAssignableTo = new ToBeAssignableTo(checker);
|
|
36
|
+
this.toBeCallableWith = new ToBeCallableWith(ts, checker);
|
|
37
|
+
this.toBeConstructableWith = new ToBeConstructableWith(ts, checker);
|
|
38
|
+
this.toBeInstantiableWith = new ToBeInstantiableWith(ts, checker);
|
|
39
|
+
this.toHaveProperty = new ToHaveProperty(ts, checker);
|
|
40
|
+
this.toRaiseError = new ToRaiseError(ts);
|
|
41
|
+
}
|
|
42
|
+
match(expectNode, onDiagnostics) {
|
|
43
|
+
const matcherNameText = expectNode.matcherNameNode.name.text;
|
|
44
|
+
if (matcherNameText === "toAcceptProps" && !this.#ensure.jsxSetup(expectNode.matcherNameNode.name, onDiagnostics)) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (!this.#ensure.argumentOrTypeArgument(expectNode.source[0], expectNode.node.expression, onDiagnostics)) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (!(matcherNameText === "toBeInstantiableWith" || (matcherNameText === "toRaiseError" && !expectNode.isNot)) &&
|
|
51
|
+
this.#reject.argumentType([expectNode.source[0], expectNode.target?.[0]], onDiagnostics)) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
switch (matcherNameText) {
|
|
55
|
+
case "toAcceptProps":
|
|
56
|
+
case "toBe":
|
|
57
|
+
case "toBeAssignableFrom":
|
|
58
|
+
case "toBeAssignableTo":
|
|
59
|
+
if (!this.#ensure.argumentOrTypeArgument(expectNode.target?.[0], expectNode.matcherNameNode.name, onDiagnostics)) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
return this[matcherNameText].match(expectNode, expectNode.source[0], expectNode.target[0], onDiagnostics);
|
|
63
|
+
case "toBeApplicable":
|
|
64
|
+
return this.toBeApplicable.match(expectNode, expectNode.source[0], onDiagnostics);
|
|
65
|
+
case "toBeCallableWith":
|
|
66
|
+
case "toBeConstructableWith":
|
|
67
|
+
case "toRaiseError":
|
|
68
|
+
return this[matcherNameText].match(expectNode, expectNode.source[0], expectNode.target, onDiagnostics);
|
|
69
|
+
case "toBeInstantiableWith": {
|
|
70
|
+
if (!this.#ensure.typeArgument(expectNode.target?.[0], expectNode.matcherNameNode.name, onDiagnostics)) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
return this.toBeInstantiableWith.match(expectNode, expectNode.source[0], expectNode.target[0], onDiagnostics);
|
|
74
|
+
}
|
|
75
|
+
case "toHaveProperty":
|
|
76
|
+
if (!this.#ensure.argument(expectNode.target?.[0], expectNode.matcherNameNode.name, onDiagnostics)) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
return this.toHaveProperty.match(expectNode, expectNode.source[0], expectNode.target[0], onDiagnostics);
|
|
80
|
+
default:
|
|
81
|
+
this.#onMatcherIsNotSupported(matcherNameText, expectNode, onDiagnostics);
|
|
82
|
+
}
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
#onMatcherIsNotSupported(matcherNameText, expectNode, onDiagnostics) {
|
|
86
|
+
const text = ExpectDiagnosticText.matcherIsNotSupported(matcherNameText);
|
|
87
|
+
const origin = DiagnosticOrigin.fromNode(expectNode.matcherNameNode.name);
|
|
88
|
+
onDiagnostics(Diagnostic.error(text, origin));
|
|
89
|
+
}
|
|
90
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Checker } from "#checker";
|
|
2
|
+
import type { ExpectNode } from "#collect";
|
|
3
|
+
import { Diagnostic } from "#diagnostic";
|
|
4
|
+
import type { ArgumentNode, MatchResult } from "./types.js";
|
|
5
|
+
export declare abstract class RelationMatcherBase {
|
|
6
|
+
protected checker: Checker;
|
|
7
|
+
constructor(checker: Checker);
|
|
8
|
+
abstract explainText(sourceTypeText: string, targetTypeText: string): string;
|
|
9
|
+
abstract explainNotText(sourceTypeText: string, targetTypeText: string): string;
|
|
10
|
+
protected explain(expectNode: ExpectNode, sourceNode: ArgumentNode, targetNode: ArgumentNode): Diagnostic[];
|
|
11
|
+
abstract match(expectNode: ExpectNode, sourceNode: ArgumentNode, targetNode: ArgumentNode): MatchResult;
|
|
12
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Diagnostic, DiagnosticOrigin } from "#diagnostic";
|
|
2
|
+
export class RelationMatcherBase {
|
|
3
|
+
checker;
|
|
4
|
+
constructor(checker) {
|
|
5
|
+
this.checker = checker;
|
|
6
|
+
}
|
|
7
|
+
explain(expectNode, sourceNode, targetNode) {
|
|
8
|
+
const sourceTypeText = this.checker.typeToString(this.checker.getType(sourceNode));
|
|
9
|
+
const targetTypeText = this.checker.typeToString(this.checker.getType(targetNode));
|
|
10
|
+
const text = expectNode.isNot
|
|
11
|
+
? this.explainText(sourceTypeText, targetTypeText)
|
|
12
|
+
: this.explainNotText(sourceTypeText, targetTypeText);
|
|
13
|
+
const origin = DiagnosticOrigin.fromNode(targetNode, expectNode);
|
|
14
|
+
return [Diagnostic.error(text, origin)];
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ExpectNode } from "#collect";
|
|
2
|
+
import { Diagnostic, type DiagnosticsHandler } from "#diagnostic";
|
|
3
|
+
import { AbilityMatcherBase } from "./AbilityMatcherBase.js";
|
|
4
|
+
import { ExpectDiagnosticText } from "./ExpectDiagnosticText.js";
|
|
5
|
+
import type { ArgumentNode, MatchResult } from "./types.js";
|
|
6
|
+
export declare class ToAcceptProps extends AbilityMatcherBase {
|
|
7
|
+
explainText: typeof ExpectDiagnosticText.acceptsProps;
|
|
8
|
+
explainNotText: typeof ExpectDiagnosticText.doesNotAcceptProps;
|
|
9
|
+
match(expectNode: ExpectNode, sourceNode: ArgumentNode, targetNode: ArgumentNode, onDiagnostics: DiagnosticsHandler<Array<Diagnostic>>): MatchResult | undefined;
|
|
10
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Diagnostic, DiagnosticOrigin } from "#diagnostic";
|
|
2
|
+
import { AbilityMatcherBase } from "./AbilityMatcherBase.js";
|
|
3
|
+
import { ExpectDiagnosticText } from "./ExpectDiagnosticText.js";
|
|
4
|
+
export class ToAcceptProps extends AbilityMatcherBase {
|
|
5
|
+
explainText = ExpectDiagnosticText.acceptsProps;
|
|
6
|
+
explainNotText = ExpectDiagnosticText.doesNotAcceptProps;
|
|
7
|
+
match(expectNode, sourceNode, targetNode, onDiagnostics) {
|
|
8
|
+
const diagnostics = [];
|
|
9
|
+
const sourceType = this.checker.getType(sourceNode);
|
|
10
|
+
if (!this.ts.isCapitaizedIdentifierLike(sourceNode) ||
|
|
11
|
+
!(this.checker.hasCallSignatures(sourceType) || this.checker.hasConstructSignatures(sourceType))) {
|
|
12
|
+
const expectedText = !this.ts.isIdentifierLike(sourceNode)
|
|
13
|
+
? "an identifier of a JSX component"
|
|
14
|
+
: "an identifier that begins with an uppercase letter";
|
|
15
|
+
const text = this.ts.belongsToArgumentList(sourceNode)
|
|
16
|
+
? ExpectDiagnosticText.argumentMustBe(expectedText)
|
|
17
|
+
: ExpectDiagnosticText.typeArgumentMustBe(expectedText);
|
|
18
|
+
const origin = DiagnosticOrigin.fromNode(sourceNode);
|
|
19
|
+
diagnostics.push(Diagnostic.error(text, origin));
|
|
20
|
+
}
|
|
21
|
+
if (!this.ts.isObjectLiteralExpression(targetNode)) {
|
|
22
|
+
const expectedText = "an object literal with key-value pairs";
|
|
23
|
+
const text = ExpectDiagnosticText.argumentMustBe(expectedText);
|
|
24
|
+
const origin = DiagnosticOrigin.fromNode(targetNode);
|
|
25
|
+
diagnostics.push(Diagnostic.error(text, origin));
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
for (const property of targetNode.properties) {
|
|
29
|
+
if (!(this.ts.isPropertyAssignment(property) || this.ts.isSpreadAssignment(property))) {
|
|
30
|
+
const text = "Each property must be a key-value pair or a spread element.";
|
|
31
|
+
const origin = DiagnosticOrigin.fromNode(property);
|
|
32
|
+
diagnostics.push(Diagnostic.error(text, origin));
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
if (this.ts.isPropertyAssignment(property) &&
|
|
36
|
+
!(this.ts.isIdentifier(property.name) || this.ts.isStringLiteral(property.name))) {
|
|
37
|
+
const text = "Property keys must be static identifiers or string literals.";
|
|
38
|
+
const origin = DiagnosticOrigin.fromNode(property.name);
|
|
39
|
+
diagnostics.push(Diagnostic.error(text, origin));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (diagnostics.length > 0) {
|
|
44
|
+
onDiagnostics(diagnostics);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
explain: () => this.explain(expectNode, sourceNode, targetNode),
|
|
49
|
+
isMatch: expectNode.abilityDiagnostics.size === 0,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Checker } from "#checker";
|
|
2
|
+
import type { ExpectNode } from "#collect";
|
|
3
|
+
import type * as ts from "#typescript";
|
|
4
|
+
import { ExpectDiagnosticText } from "./ExpectDiagnosticText.js";
|
|
5
|
+
import { RelationMatcherBase } from "./RelationMatcherBase.js";
|
|
6
|
+
import type { ArgumentNode, MatchResult } from "./types.js";
|
|
7
|
+
export declare class ToBe extends RelationMatcherBase {
|
|
8
|
+
#private;
|
|
9
|
+
constructor(ts: ts.TypeScript, program: ts.Program, checker: Checker);
|
|
10
|
+
explainText: typeof ExpectDiagnosticText.isTheSame;
|
|
11
|
+
explainNotText: typeof ExpectDiagnosticText.isNotTheSame;
|
|
12
|
+
match(expectNode: ExpectNode, sourceNode: ArgumentNode, targetNode: ArgumentNode): MatchResult;
|
|
13
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Structure } from "#structure";
|
|
2
|
+
import { ExpectDiagnosticText } from "./ExpectDiagnosticText.js";
|
|
3
|
+
import { RelationMatcherBase } from "./RelationMatcherBase.js";
|
|
4
|
+
export class ToBe extends RelationMatcherBase {
|
|
5
|
+
#structure;
|
|
6
|
+
constructor(ts, program, checker) {
|
|
7
|
+
super(checker);
|
|
8
|
+
this.#structure = new Structure(ts, program, checker);
|
|
9
|
+
}
|
|
10
|
+
explainText = ExpectDiagnosticText.isTheSame;
|
|
11
|
+
explainNotText = ExpectDiagnosticText.isNotTheSame;
|
|
12
|
+
match(expectNode, sourceNode, targetNode) {
|
|
13
|
+
return {
|
|
14
|
+
explain: () => this.explain(expectNode, sourceNode, targetNode),
|
|
15
|
+
isMatch: this.#structure.compare(this.checker.getType(sourceNode), this.checker.getType(targetNode)),
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Checker } from "#checker";
|
|
2
|
+
import type { ExpectNode } from "#collect";
|
|
3
|
+
import { Diagnostic, type DiagnosticsHandler } from "#diagnostic";
|
|
4
|
+
import type * as ts from "#typescript";
|
|
5
|
+
import type { ArgumentNode, MatchResult } from "./types.js";
|
|
6
|
+
export declare class ToBeApplicable {
|
|
7
|
+
#private;
|
|
8
|
+
constructor(ts: ts.TypeScript, checker: Checker);
|
|
9
|
+
match(expectNode: ExpectNode, sourceNode: ArgumentNode, onDiagnostics: DiagnosticsHandler<Array<Diagnostic>>): MatchResult | undefined;
|
|
10
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { Diagnostic, DiagnosticOrigin, getDiagnosticMessageText } from "#diagnostic";
|
|
2
|
+
import { ExpectDiagnosticText } from "./ExpectDiagnosticText.js";
|
|
3
|
+
export class ToBeApplicable {
|
|
4
|
+
#checker;
|
|
5
|
+
#ts;
|
|
6
|
+
constructor(ts, checker) {
|
|
7
|
+
this.#ts = ts;
|
|
8
|
+
this.#checker = checker;
|
|
9
|
+
}
|
|
10
|
+
#resolveTargetText(node) {
|
|
11
|
+
let text = "";
|
|
12
|
+
switch (node.kind) {
|
|
13
|
+
case this.#ts.SyntaxKind.ClassDeclaration:
|
|
14
|
+
text = "class";
|
|
15
|
+
break;
|
|
16
|
+
case this.#ts.SyntaxKind.MethodDeclaration:
|
|
17
|
+
text = "method";
|
|
18
|
+
break;
|
|
19
|
+
case this.#ts.SyntaxKind.PropertyDeclaration:
|
|
20
|
+
text = node.modifiers?.some((modifier) => modifier.kind === this.#ts.SyntaxKind.AccessorKeyword)
|
|
21
|
+
? "accessor"
|
|
22
|
+
: "field";
|
|
23
|
+
break;
|
|
24
|
+
case this.#ts.SyntaxKind.GetAccessor:
|
|
25
|
+
text = "getter";
|
|
26
|
+
break;
|
|
27
|
+
case this.#ts.SyntaxKind.SetAccessor:
|
|
28
|
+
text = "setter";
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
if (text.length > 0) {
|
|
32
|
+
text = ` to this ${text}`;
|
|
33
|
+
}
|
|
34
|
+
return text;
|
|
35
|
+
}
|
|
36
|
+
#explain(expectNode) {
|
|
37
|
+
const targetText = this.#resolveTargetText(expectNode.matcherNode.parent);
|
|
38
|
+
const diagnostics = [];
|
|
39
|
+
if (expectNode.abilityDiagnostics.size > 0) {
|
|
40
|
+
const origin = DiagnosticOrigin.fromAssertion(expectNode);
|
|
41
|
+
for (const diagnostic of expectNode.abilityDiagnostics) {
|
|
42
|
+
const text = [ExpectDiagnosticText.cannotBeApplied(targetText), ...getDiagnosticMessageText(diagnostic)];
|
|
43
|
+
let related;
|
|
44
|
+
if (diagnostic.relatedInformation != null) {
|
|
45
|
+
related = Diagnostic.fromDiagnostics(diagnostic.relatedInformation);
|
|
46
|
+
}
|
|
47
|
+
diagnostics.push(Diagnostic.error(text, origin).add({ related }));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
const origin = DiagnosticOrigin.fromAssertion(expectNode);
|
|
52
|
+
diagnostics.push(Diagnostic.error(ExpectDiagnosticText.canBeApplied(targetText), origin));
|
|
53
|
+
}
|
|
54
|
+
return diagnostics;
|
|
55
|
+
}
|
|
56
|
+
match(expectNode, sourceNode, onDiagnostics) {
|
|
57
|
+
const type = this.#checker.getType(sourceNode);
|
|
58
|
+
if (!this.#checker.hasCallSignatures(type)) {
|
|
59
|
+
const expectedText = "of a function type";
|
|
60
|
+
const text = this.#ts.belongsToArgumentList(sourceNode)
|
|
61
|
+
? ExpectDiagnosticText.argumentMustBe(expectedText)
|
|
62
|
+
: ExpectDiagnosticText.typeArgumentMustBe(expectedText);
|
|
63
|
+
const origin = DiagnosticOrigin.fromNode(sourceNode);
|
|
64
|
+
onDiagnostics([Diagnostic.error(text, origin)]);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
explain: () => this.#explain(expectNode),
|
|
69
|
+
isMatch: expectNode.abilityDiagnostics.size === 0,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ExpectNode } from "#collect";
|
|
2
|
+
import { ExpectDiagnosticText } from "./ExpectDiagnosticText.js";
|
|
3
|
+
import { RelationMatcherBase } from "./RelationMatcherBase.js";
|
|
4
|
+
import type { ArgumentNode, MatchResult } from "./types.js";
|
|
5
|
+
export declare class ToBeAssignableFrom extends RelationMatcherBase {
|
|
6
|
+
explainText: typeof ExpectDiagnosticText.isAssignableFrom;
|
|
7
|
+
explainNotText: typeof ExpectDiagnosticText.isNotAssignableFrom;
|
|
8
|
+
match(expectNode: ExpectNode, sourceNode: ArgumentNode, targetNode: ArgumentNode): MatchResult;
|
|
9
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ExpectDiagnosticText } from "./ExpectDiagnosticText.js";
|
|
2
|
+
import { RelationMatcherBase } from "./RelationMatcherBase.js";
|
|
3
|
+
export class ToBeAssignableFrom extends RelationMatcherBase {
|
|
4
|
+
explainText = ExpectDiagnosticText.isAssignableFrom;
|
|
5
|
+
explainNotText = ExpectDiagnosticText.isNotAssignableFrom;
|
|
6
|
+
match(expectNode, sourceNode, targetNode) {
|
|
7
|
+
return {
|
|
8
|
+
explain: () => this.explain(expectNode, sourceNode, targetNode),
|
|
9
|
+
isMatch: this.checker.isTypeAssignableTo(this.checker.getType(targetNode), this.checker.getType(sourceNode)),
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ExpectNode } from "#collect";
|
|
2
|
+
import { ExpectDiagnosticText } from "./ExpectDiagnosticText.js";
|
|
3
|
+
import { RelationMatcherBase } from "./RelationMatcherBase.js";
|
|
4
|
+
import type { ArgumentNode, MatchResult } from "./types.js";
|
|
5
|
+
export declare class ToBeAssignableTo extends RelationMatcherBase {
|
|
6
|
+
explainText: typeof ExpectDiagnosticText.isAssignableTo;
|
|
7
|
+
explainNotText: typeof ExpectDiagnosticText.isNotAssignableTo;
|
|
8
|
+
match(expectNode: ExpectNode, sourceNode: ArgumentNode, targetNode: ArgumentNode): MatchResult;
|
|
9
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ExpectDiagnosticText } from "./ExpectDiagnosticText.js";
|
|
2
|
+
import { RelationMatcherBase } from "./RelationMatcherBase.js";
|
|
3
|
+
export class ToBeAssignableTo extends RelationMatcherBase {
|
|
4
|
+
explainText = ExpectDiagnosticText.isAssignableTo;
|
|
5
|
+
explainNotText = ExpectDiagnosticText.isNotAssignableTo;
|
|
6
|
+
match(expectNode, sourceNode, targetNode) {
|
|
7
|
+
return {
|
|
8
|
+
explain: () => this.explain(expectNode, sourceNode, targetNode),
|
|
9
|
+
isMatch: this.checker.isTypeAssignableTo(this.checker.getType(sourceNode), this.checker.getType(targetNode)),
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ExpectNode } from "#collect";
|
|
2
|
+
import { Diagnostic, type DiagnosticsHandler } from "#diagnostic";
|
|
3
|
+
import type * as ts from "#typescript";
|
|
4
|
+
import { AbilityMatcherBase } from "./AbilityMatcherBase.js";
|
|
5
|
+
import { ExpectDiagnosticText } from "./ExpectDiagnosticText.js";
|
|
6
|
+
import type { ArgumentNode, MatchResult } from "./types.js";
|
|
7
|
+
export declare class ToBeCallableWith extends AbilityMatcherBase {
|
|
8
|
+
explainText: typeof ExpectDiagnosticText.isCallable;
|
|
9
|
+
explainNotText: typeof ExpectDiagnosticText.isNotCallable;
|
|
10
|
+
match(expectNode: ExpectNode, sourceNode: ArgumentNode, targetNodes: ts.NodeArray<ArgumentNode>, onDiagnostics: DiagnosticsHandler<Array<Diagnostic>>): MatchResult | undefined;
|
|
11
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Diagnostic, DiagnosticOrigin } from "#diagnostic";
|
|
2
|
+
import { AbilityMatcherBase } from "./AbilityMatcherBase.js";
|
|
3
|
+
import { ExpectDiagnosticText } from "./ExpectDiagnosticText.js";
|
|
4
|
+
export class ToBeCallableWith extends AbilityMatcherBase {
|
|
5
|
+
explainText = ExpectDiagnosticText.isCallable;
|
|
6
|
+
explainNotText = ExpectDiagnosticText.isNotCallable;
|
|
7
|
+
match(expectNode, sourceNode, targetNodes, onDiagnostics) {
|
|
8
|
+
const sourceType = this.checker.getType(sourceNode);
|
|
9
|
+
if (!this.checker.hasCallSignatures(sourceType)) {
|
|
10
|
+
const text = [];
|
|
11
|
+
if (this.ts.belongsToArgumentList(sourceNode)) {
|
|
12
|
+
text.push(ExpectDiagnosticText.argumentMustBe("a callable expression"));
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
text.push(ExpectDiagnosticText.typeArgumentMustBe("a callable type"));
|
|
16
|
+
}
|
|
17
|
+
if (this.checker.hasConstructSignatures(sourceType)) {
|
|
18
|
+
text.push(ExpectDiagnosticText.didYouMeanToUse("the '.toBeConstructableWith()' matcher"));
|
|
19
|
+
}
|
|
20
|
+
const origin = DiagnosticOrigin.fromNode(sourceNode);
|
|
21
|
+
onDiagnostics([Diagnostic.error(text, origin)]);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
explain: () => this.explain(expectNode, sourceNode, targetNodes, () => this.getArgumentCountText(targetNodes)),
|
|
26
|
+
isMatch: expectNode.abilityDiagnostics.size === 0,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ExpectNode } from "#collect";
|
|
2
|
+
import { Diagnostic, type DiagnosticsHandler } from "#diagnostic";
|
|
3
|
+
import type * as ts from "#typescript";
|
|
4
|
+
import { AbilityMatcherBase } from "./AbilityMatcherBase.js";
|
|
5
|
+
import { ExpectDiagnosticText } from "./ExpectDiagnosticText.js";
|
|
6
|
+
import type { ArgumentNode, MatchResult } from "./types.js";
|
|
7
|
+
export declare class ToBeConstructableWith extends AbilityMatcherBase {
|
|
8
|
+
explainText: typeof ExpectDiagnosticText.isConstructable;
|
|
9
|
+
explainNotText: typeof ExpectDiagnosticText.isNotConstructable;
|
|
10
|
+
match(expectNode: ExpectNode, sourceNode: ArgumentNode, targetNodes: ts.NodeArray<ArgumentNode>, onDiagnostics: DiagnosticsHandler<Array<Diagnostic>>): MatchResult | undefined;
|
|
11
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Diagnostic, DiagnosticOrigin } from "#diagnostic";
|
|
2
|
+
import { AbilityMatcherBase } from "./AbilityMatcherBase.js";
|
|
3
|
+
import { ExpectDiagnosticText } from "./ExpectDiagnosticText.js";
|
|
4
|
+
export class ToBeConstructableWith extends AbilityMatcherBase {
|
|
5
|
+
explainText = ExpectDiagnosticText.isConstructable;
|
|
6
|
+
explainNotText = ExpectDiagnosticText.isNotConstructable;
|
|
7
|
+
match(expectNode, sourceNode, targetNodes, onDiagnostics) {
|
|
8
|
+
const sourceType = this.checker.getType(sourceNode);
|
|
9
|
+
if (!this.checker.hasConstructSignatures(sourceType)) {
|
|
10
|
+
const text = [];
|
|
11
|
+
if (this.ts.belongsToArgumentList(sourceNode)) {
|
|
12
|
+
text.push(ExpectDiagnosticText.argumentMustBe("a constructable expression"));
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
text.push(ExpectDiagnosticText.typeArgumentMustBe("a constructable type"));
|
|
16
|
+
}
|
|
17
|
+
if (this.checker.hasCallSignatures(sourceType)) {
|
|
18
|
+
text.push(ExpectDiagnosticText.didYouMeanToUse("the '.toBeCallableWith()' matcher"));
|
|
19
|
+
}
|
|
20
|
+
const origin = DiagnosticOrigin.fromNode(sourceNode);
|
|
21
|
+
onDiagnostics([Diagnostic.error(text, origin)]);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
explain: () => this.explain(expectNode, sourceNode, targetNodes, () => this.getArgumentCountText(targetNodes)),
|
|
26
|
+
isMatch: expectNode.abilityDiagnostics.size === 0,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ExpectNode } from "#collect";
|
|
2
|
+
import { Diagnostic, type DiagnosticsHandler } from "#diagnostic";
|
|
3
|
+
import { AbilityMatcherBase } from "./AbilityMatcherBase.js";
|
|
4
|
+
import { ExpectDiagnosticText } from "./ExpectDiagnosticText.js";
|
|
5
|
+
import type { ArgumentNode, MatchResult } from "./types.js";
|
|
6
|
+
export declare class ToBeInstantiableWith extends AbilityMatcherBase {
|
|
7
|
+
explainText: typeof ExpectDiagnosticText.isInstantiable;
|
|
8
|
+
explainNotText: typeof ExpectDiagnosticText.isNotInstantiable;
|
|
9
|
+
match(expectNode: ExpectNode, sourceNode: ArgumentNode, targetNode: ArgumentNode, onDiagnostics: DiagnosticsHandler<Array<Diagnostic>>): MatchResult | undefined;
|
|
10
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Diagnostic, DiagnosticOrigin } from "#diagnostic";
|
|
2
|
+
import { AbilityMatcherBase } from "./AbilityMatcherBase.js";
|
|
3
|
+
import { ExpectDiagnosticText } from "./ExpectDiagnosticText.js";
|
|
4
|
+
export class ToBeInstantiableWith extends AbilityMatcherBase {
|
|
5
|
+
explainText = ExpectDiagnosticText.isInstantiable;
|
|
6
|
+
explainNotText = ExpectDiagnosticText.isNotInstantiable;
|
|
7
|
+
match(expectNode, sourceNode, targetNode, onDiagnostics) {
|
|
8
|
+
if (!this.ts.isIdentifierLike(sourceNode)) {
|
|
9
|
+
let text;
|
|
10
|
+
if (this.ts.belongsToArgumentList(sourceNode)) {
|
|
11
|
+
text = ExpectDiagnosticText.argumentMustBe("an instantiable expression");
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
text = ExpectDiagnosticText.typeArgumentMustBe("an instantiable type");
|
|
15
|
+
}
|
|
16
|
+
const origin = DiagnosticOrigin.fromNode(sourceNode);
|
|
17
|
+
onDiagnostics([Diagnostic.error(text, origin)]);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
if (!this.ts.isTupleTypeNode(targetNode)) {
|
|
21
|
+
const text = ExpectDiagnosticText.typeArgumentMustBe("a tuple type");
|
|
22
|
+
const origin = DiagnosticOrigin.fromNode(targetNode);
|
|
23
|
+
onDiagnostics([Diagnostic.error(text, origin)]);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
explain: () => this.explain(expectNode, sourceNode, targetNode, () => this.getTypeArgumentCountText(targetNode)),
|
|
28
|
+
isMatch: expectNode.abilityDiagnostics.size === 0,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Checker } from "#checker";
|
|
2
|
+
import type { ExpectNode } from "#collect";
|
|
3
|
+
import { Diagnostic, type DiagnosticsHandler } from "#diagnostic";
|
|
4
|
+
import type * as ts from "#typescript";
|
|
5
|
+
import type { ArgumentNode, MatchResult } from "./types.js";
|
|
6
|
+
export declare class ToHaveProperty {
|
|
7
|
+
#private;
|
|
8
|
+
constructor(ts: ts.TypeScript, checker: Checker);
|
|
9
|
+
match(expectNode: ExpectNode, sourceNode: ArgumentNode, targetNode: ArgumentNode, onDiagnostics: DiagnosticsHandler<Array<Diagnostic>>): MatchResult | undefined;
|
|
10
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Diagnostic, DiagnosticOrigin } from "#diagnostic";
|
|
2
|
+
import { ExpectDiagnosticText } from "./ExpectDiagnosticText.js";
|
|
3
|
+
export class ToHaveProperty {
|
|
4
|
+
#checker;
|
|
5
|
+
#ts;
|
|
6
|
+
constructor(ts, checker) {
|
|
7
|
+
this.#ts = ts;
|
|
8
|
+
this.#checker = checker;
|
|
9
|
+
}
|
|
10
|
+
#explain(expectNode, sourceNode, targetNode) {
|
|
11
|
+
const sourceType = this.#checker.getType(sourceNode);
|
|
12
|
+
const sourceTypeText = this.#checker.typeToString(sourceType);
|
|
13
|
+
const targetType = this.#checker.getType(targetNode);
|
|
14
|
+
let propertyNameText;
|
|
15
|
+
if (targetType.flags & this.#ts.TypeFlags.EnumLiteral) {
|
|
16
|
+
propertyNameText = `[${this.#checker.typeToString(targetType)}]`;
|
|
17
|
+
}
|
|
18
|
+
else if (targetType.flags & (this.#ts.TypeFlags.StringLiteral | this.#ts.TypeFlags.NumberLiteral)) {
|
|
19
|
+
propertyNameText = targetType.value.toString();
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
const symbol = this.#checker.getSymbol(targetType);
|
|
23
|
+
propertyNameText = `[${symbol?.name}]`;
|
|
24
|
+
}
|
|
25
|
+
const origin = DiagnosticOrigin.fromNode(targetNode, expectNode);
|
|
26
|
+
return expectNode.isNot
|
|
27
|
+
? [Diagnostic.error(ExpectDiagnosticText.hasProperty(sourceTypeText, propertyNameText), origin)]
|
|
28
|
+
: [Diagnostic.error(ExpectDiagnosticText.doesNotHaveProperty(sourceTypeText, propertyNameText), origin)];
|
|
29
|
+
}
|
|
30
|
+
match(expectNode, sourceNode, targetNode, onDiagnostics) {
|
|
31
|
+
const diagnostics = [];
|
|
32
|
+
const sourceType = this.#checker.getType(sourceNode);
|
|
33
|
+
if (sourceType.flags & (this.#ts.TypeFlags.Any | this.#ts.TypeFlags.Never) ||
|
|
34
|
+
!this.#checker.isTypeAssignableTo(sourceType, this.#checker.getNonPrimitiveType())) {
|
|
35
|
+
const expectedText = "of an object type";
|
|
36
|
+
const text = this.#ts.belongsToArgumentList(sourceNode)
|
|
37
|
+
? ExpectDiagnosticText.argumentMustBe(expectedText)
|
|
38
|
+
: ExpectDiagnosticText.typeArgumentMustBe(expectedText);
|
|
39
|
+
const origin = DiagnosticOrigin.fromNode(sourceNode);
|
|
40
|
+
diagnostics.push(Diagnostic.error(text, origin));
|
|
41
|
+
}
|
|
42
|
+
const targetType = this.#checker.getType(targetNode);
|
|
43
|
+
if (!(targetType.flags &
|
|
44
|
+
(this.#ts.TypeFlags.StringLiteral | this.#ts.TypeFlags.NumberLiteral | this.#ts.TypeFlags.UniqueESSymbol))) {
|
|
45
|
+
const expectedText = "a string, number or symbol";
|
|
46
|
+
const text = ExpectDiagnosticText.argumentMustBe(expectedText);
|
|
47
|
+
const origin = DiagnosticOrigin.fromNode(targetNode);
|
|
48
|
+
diagnostics.push(Diagnostic.error(text, origin));
|
|
49
|
+
}
|
|
50
|
+
if (diagnostics.length > 0) {
|
|
51
|
+
onDiagnostics(diagnostics);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
explain: () => this.#explain(expectNode, sourceNode, targetNode),
|
|
56
|
+
isMatch: expectNode.abilityDiagnostics.size === 0,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ExpectNode } from "#collect";
|
|
2
|
+
import { Diagnostic, type DiagnosticsHandler } from "#diagnostic";
|
|
3
|
+
import type * as ts from "#typescript";
|
|
4
|
+
import type { ArgumentNode, MatchResult } from "./types.js";
|
|
5
|
+
export declare class ToRaiseError {
|
|
6
|
+
#private;
|
|
7
|
+
constructor(ts: ts.TypeScript);
|
|
8
|
+
match(expectNode: ExpectNode, sourceNode: ArgumentNode, targetNodes: ts.NodeArray<ArgumentNode>, onDiagnostics: DiagnosticsHandler<Array<Diagnostic>>): MatchResult | undefined;
|
|
9
|
+
}
|