Add more and unify tests for absent object cases

- Unify test data for nonexistence of an object/string and collection.
- Introduce more test through adding missing test data to existing tests.
- Improve logic for checking absence of values to match tests.
- Add missing tests for absent value validation.
- Update documentation to include shared test functionality.
This commit is contained in:
undergroundwires
2022-01-21 22:34:11 +01:00
parent 0e52a99efa
commit 44d79e2c9a
100 changed files with 1380 additions and 976 deletions

View File

@@ -10,6 +10,7 @@ import { EnumParserStub } from '@tests/unit/stubs/EnumParserStub';
import { ScriptCodeStub } from '@tests/unit/stubs/ScriptCodeStub';
import { CategoryCollectionParseContextStub } from '@tests/unit/stubs/CategoryCollectionParseContextStub';
import { LanguageSyntaxStub } from '@tests/unit/stubs/LanguageSyntaxStub';
import { itEachAbsentObjectValue, itEachAbsentStringValue } from '@tests/unit/shared/TestCases/AbsentTests';
describe('ScriptParser', () => {
describe('parseScript', () => {
@@ -37,15 +38,17 @@ describe('ScriptParser', () => {
expect(actual.documentationUrls).to.deep.equal(expected);
});
describe('invalid script', () => {
it('throws when script is undefined', () => {
// arrange
const expectedError = 'undefined script';
const parseContext = new CategoryCollectionParseContextStub();
const script = undefined;
// act
const act = () => parseScript(script, parseContext);
// assert
expect(act).to.throw(expectedError);
describe('throws when script is absent', () => {
itEachAbsentObjectValue((absentValue) => {
// arrange
const expectedError = 'missing script';
const parseContext = new CategoryCollectionParseContextStub();
const script = absentValue;
// act
const act = () => parseScript(script, parseContext);
// assert
expect(act).to.throw(expectedError);
});
});
it('throws when both function call and code are defined', () => {
// arrange
@@ -83,13 +86,12 @@ describe('ScriptParser', () => {
});
});
describe('level', () => {
it('accepts undefined level', () => {
const undefinedLevels: string[] = ['', undefined];
undefinedLevels.forEach((undefinedLevel) => {
describe('accepts absent level', () => {
itEachAbsentStringValue((absentValue) => {
// arrange
const parseContext = new CategoryCollectionParseContextStub();
const script = ScriptDataStub.createWithCode()
.withRecommend(undefinedLevel);
.withRecommend(absentValue);
// act
const actual = parseScript(script, parseContext);
// assert
@@ -140,15 +142,17 @@ describe('ScriptParser', () => {
expect(actual).to.equal(expected);
});
describe('compiler', () => {
it('throws when context is not defined', () => {
// arrange
const expectedMessage = 'undefined context';
const script = ScriptDataStub.createWithCode();
const context: ICategoryCollectionParseContext = undefined;
// act
const act = () => parseScript(script, context);
// assert
expect(act).to.throw(expectedMessage);
describe('throws when context is not defined', () => {
itEachAbsentObjectValue((absentValue) => {
// arrange
const expectedMessage = 'missing context';
const script = ScriptDataStub.createWithCode();
const context: ICategoryCollectionParseContext = absentValue;
// act
const act = () => parseScript(script, context);
// assert
expect(act).to.throw(expectedMessage);
});
});
it('gets code from compiler', () => {
// arrange