-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tests for
validateResultsButBased
- Loading branch information
1 parent
545b378
commit b033db7
Showing
1 changed file
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { AssertionError } from 'assert'; | ||
import { Diagnostic } from '../common/diagnostic'; | ||
import { Uri } from '../common/uri/uri'; | ||
import { FileAnalysisResult, ExpectedResults, validateResultsButBased } from './testUtils'; | ||
import { DiagnosticRule } from '../common/diagnosticRules'; | ||
|
||
const fakeUri = {} as Uri; | ||
const fakeDiagnostic = (line: number, code?: DiagnosticRule) => | ||
({ getRule: () => code, range: { start: { line } } } as Diagnostic); | ||
|
||
test('validateResults pass 😀', () => { | ||
const expectedResults: ExpectedResults = { | ||
errors: [{ line: 1 }, { line: 2 }], | ||
}; | ||
const actualResults: FileAnalysisResult[] = [ | ||
{ | ||
errors: [fakeDiagnostic(1), fakeDiagnostic(2)], | ||
fileUri: fakeUri, | ||
warnings: [], | ||
infos: [], | ||
unusedCodes: [], | ||
deprecateds: [], | ||
unreachableCodes: [], | ||
}, | ||
]; | ||
validateResultsButBased(actualResults, expectedResults); | ||
}); | ||
|
||
test('validateResults wrong number of errors', () => { | ||
const expectedResults: ExpectedResults = { | ||
errors: [{ line: 1 }, { line: 2 }], | ||
}; | ||
const actualResults: FileAnalysisResult[] = [ | ||
{ | ||
errors: [fakeDiagnostic(1)], | ||
fileUri: fakeUri, | ||
warnings: [], | ||
infos: [], | ||
unusedCodes: [], | ||
deprecateds: [], | ||
unreachableCodes: [], | ||
}, | ||
]; | ||
expect(() => validateResultsButBased(actualResults, expectedResults)).toThrow(AssertionError); | ||
}); | ||
|
||
test('validateResults wrong line number', () => { | ||
const expectedResults: ExpectedResults = { | ||
errors: [{ line: 2 }], | ||
}; | ||
const actualResults: FileAnalysisResult[] = [ | ||
{ | ||
errors: [fakeDiagnostic(1)], | ||
fileUri: fakeUri, | ||
warnings: [], | ||
infos: [], | ||
unusedCodes: [], | ||
deprecateds: [], | ||
unreachableCodes: [], | ||
}, | ||
]; | ||
expect(() => validateResultsButBased(actualResults, expectedResults)).toThrow(AssertionError); | ||
}); | ||
|
||
test('validateResults wrong code', () => { | ||
const expectedResults: ExpectedResults = { | ||
errors: [{ line: 1, code: DiagnosticRule.reportUnboundVariable }], | ||
}; | ||
const actualResults: FileAnalysisResult[] = [ | ||
{ | ||
errors: [fakeDiagnostic(1, DiagnosticRule.analyzeUnannotatedFunctions)], | ||
fileUri: fakeUri, | ||
warnings: [], | ||
infos: [], | ||
unusedCodes: [], | ||
deprecateds: [], | ||
unreachableCodes: [], | ||
}, | ||
]; | ||
expect(() => validateResultsButBased(actualResults, expectedResults)).toThrow(AssertionError); | ||
}); |