move application.yaml to collections/windows.yaml #40
This commit is contained in:
@@ -2,14 +2,15 @@ import 'mocha';
|
||||
import { expect } from 'chai';
|
||||
import { parseProjectInformation } from '@/application/Parser/ProjectInformationParser';
|
||||
import { CategoryCollectionParserType, parseApplication } from '@/application/Parser/ApplicationParser';
|
||||
import applicationFile, { YamlApplication } from 'js-yaml-loader!@/application/application.yaml';
|
||||
import WindowsData from 'js-yaml-loader!@/application/collections/windows.yaml';
|
||||
import { CollectionData } from 'js-yaml-loader!@/*';
|
||||
import { IProjectInformation } from '@/domain/IProjectInformation';
|
||||
import { ProjectInformation } from '@/domain/ProjectInformation';
|
||||
import { ICategoryCollection } from '@/domain/ICategoryCollection';
|
||||
import { OperatingSystem } from '@/domain/OperatingSystem';
|
||||
import { CategoryCollectionStub } from '../../stubs/CategoryCollectionStub';
|
||||
import { getProcessEnvironmentStub } from '../../stubs/ProcessEnvironmentStub';
|
||||
import { YamlApplicationStub } from '../../stubs/YamlApplicationStub';
|
||||
import { CollectionDataStub } from '../../stubs/CollectionDataStub';
|
||||
|
||||
describe('ApplicationParser', () => {
|
||||
describe('parseApplication', () => {
|
||||
@@ -64,7 +65,7 @@ describe('ApplicationParser', () => {
|
||||
describe('collectionData', () => {
|
||||
it('parsed with expected data', () => {
|
||||
// arrange
|
||||
const expected = new YamlApplicationStub();
|
||||
const expected = new CollectionDataStub();
|
||||
const env = getProcessEnvironmentStub();
|
||||
const parserSpy = new CategoryCollectionParserSpy();
|
||||
const parserMock = parserSpy.mockParser();
|
||||
@@ -73,9 +74,9 @@ describe('ApplicationParser', () => {
|
||||
// assert
|
||||
expect(expected).to.equal(parserSpy.lastArguments.file);
|
||||
});
|
||||
it('defaults to applicationFile', () => {
|
||||
it('defaults to windows data', () => {
|
||||
// arrange
|
||||
const expected = applicationFile;
|
||||
const expected = WindowsData;
|
||||
const parserSpy = new CategoryCollectionParserSpy();
|
||||
const parserMock = parserSpy.mockParser();
|
||||
// act
|
||||
@@ -89,7 +90,7 @@ describe('ApplicationParser', () => {
|
||||
|
||||
class CategoryCollectionParserSpy {
|
||||
public lastArguments: {
|
||||
file: YamlApplication;
|
||||
file: CollectionData;
|
||||
info: ProjectInformation;
|
||||
} = { file: undefined, info: undefined };
|
||||
private result: ICategoryCollection = new CategoryCollectionStub();
|
||||
@@ -99,7 +100,7 @@ class CategoryCollectionParserSpy {
|
||||
return this;
|
||||
}
|
||||
public mockParser(): CategoryCollectionParserType {
|
||||
return (file: YamlApplication, info: IProjectInformation) => {
|
||||
return (file: CollectionData, info: IProjectInformation) => {
|
||||
this.lastArguments.file = file;
|
||||
this.lastArguments.info = info;
|
||||
return this.result;
|
||||
|
||||
@@ -9,7 +9,7 @@ import { parseScriptingDefinition } from '@/application/Parser/ScriptingDefiniti
|
||||
import { mockEnumParser } from '../../stubs/EnumParserStub';
|
||||
import { ProjectInformationStub } from '../../stubs/ProjectInformationStub';
|
||||
import { ScriptCompilerStub } from '../../stubs/ScriptCompilerStub';
|
||||
import { getCategoryStub, YamlApplicationStub } from '../../stubs/YamlApplicationStub';
|
||||
import { getCategoryStub, CollectionDataStub } from '../../stubs/CollectionDataStub';
|
||||
|
||||
describe('CategoryCollectionParser', () => {
|
||||
describe('parseCategoryCollection', () => {
|
||||
@@ -26,7 +26,7 @@ describe('CategoryCollectionParser', () => {
|
||||
it('throws when undefined actions', () => {
|
||||
// arrange
|
||||
const expectedError = 'content does not define any action';
|
||||
const collection = new YamlApplicationStub()
|
||||
const collection = new CollectionDataStub()
|
||||
.withActions(undefined);
|
||||
const info = new ProjectInformationStub();
|
||||
// act
|
||||
@@ -37,7 +37,7 @@ describe('CategoryCollectionParser', () => {
|
||||
it('throws when has no actions', () => {
|
||||
// arrange
|
||||
const expectedError = 'content does not define any action';
|
||||
const collection = new YamlApplicationStub()
|
||||
const collection = new CollectionDataStub()
|
||||
.withActions([]);
|
||||
const info = new ProjectInformationStub();
|
||||
// act
|
||||
@@ -50,7 +50,7 @@ describe('CategoryCollectionParser', () => {
|
||||
const actions = [ getCategoryStub('test1'), getCategoryStub('test2') ];
|
||||
const compiler = new ScriptCompilerStub();
|
||||
const expected = [ parseCategory(actions[0], compiler), parseCategory(actions[1], compiler) ];
|
||||
const collection = new YamlApplicationStub()
|
||||
const collection = new CollectionDataStub()
|
||||
.withActions(actions);
|
||||
const info = new ProjectInformationStub();
|
||||
// act
|
||||
@@ -68,7 +68,7 @@ describe('CategoryCollectionParser', () => {
|
||||
describe('scripting definition', () => {
|
||||
it('parses scripting definition as expected', () => {
|
||||
// arrange
|
||||
const collection = new YamlApplicationStub();
|
||||
const collection = new CollectionDataStub();
|
||||
const information = parseProjectInformation(process.env);
|
||||
const expected = parseScriptingDefinition(collection.scripting, information);
|
||||
// act
|
||||
@@ -83,7 +83,7 @@ describe('CategoryCollectionParser', () => {
|
||||
const expectedOs = OperatingSystem.macOS;
|
||||
const osText = 'macos';
|
||||
const expectedName = 'os';
|
||||
const collection = new YamlApplicationStub()
|
||||
const collection = new CollectionDataStub()
|
||||
.withOs(osText);
|
||||
const parserMock = mockEnumParser(expectedName, osText, expectedOs);
|
||||
const info = new ProjectInformationStub();
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import 'mocha';
|
||||
import { expect } from 'chai';
|
||||
import { parseCategory } from '@/application/Parser/CategoryParser';
|
||||
import { YamlCategory, CategoryOrScript, YamlScript } from 'js-yaml-loader!@/application.yaml';
|
||||
import { CategoryData, CategoryOrScriptData } from 'js-yaml-loader!@/*';
|
||||
import { parseScript } from '@/application/Parser/ScriptParser';
|
||||
import { parseDocUrls } from '@/application/Parser/DocumentationParser';
|
||||
import { ScriptCompilerStub } from '../../stubs/ScriptCompilerStub';
|
||||
import { YamlScriptStub } from '../../stubs/YamlScriptStub';
|
||||
import { ScriptDataStub } from '../../stubs/ScriptDataStub';
|
||||
|
||||
describe('CategoryParser', () => {
|
||||
describe('parseCategory', () => {
|
||||
@@ -24,7 +24,7 @@ describe('CategoryParser', () => {
|
||||
// arrange
|
||||
const categoryName = 'test';
|
||||
const expectedMessage = `category has no children: "${categoryName}"`;
|
||||
const category: YamlCategory = {
|
||||
const category: CategoryData = {
|
||||
category: categoryName,
|
||||
children: [],
|
||||
};
|
||||
@@ -38,7 +38,7 @@ describe('CategoryParser', () => {
|
||||
// arrange
|
||||
const categoryName = 'test';
|
||||
const expectedMessage = `category has no children: "${categoryName}"`;
|
||||
const category: YamlCategory = {
|
||||
const category: CategoryData = {
|
||||
category: categoryName,
|
||||
children: undefined,
|
||||
};
|
||||
@@ -53,7 +53,7 @@ describe('CategoryParser', () => {
|
||||
const expectedMessage = 'category has no name';
|
||||
const invalidNames = ['', undefined];
|
||||
invalidNames.forEach((invalidName) => {
|
||||
const category: YamlCategory = {
|
||||
const category: CategoryData = {
|
||||
category: invalidName,
|
||||
children: getTestChildren(),
|
||||
};
|
||||
@@ -80,7 +80,7 @@ describe('CategoryParser', () => {
|
||||
const url = 'https://privacy.sexy';
|
||||
const expected = parseDocUrls({ docs: url });
|
||||
const compiler = new ScriptCompilerStub();
|
||||
const category: YamlCategory = {
|
||||
const category: CategoryData = {
|
||||
category: 'category name',
|
||||
children: getTestChildren(),
|
||||
docs: url,
|
||||
@@ -93,10 +93,10 @@ describe('CategoryParser', () => {
|
||||
describe('parses expected subscript', () => {
|
||||
it('single script with code', () => {
|
||||
// arrange
|
||||
const script = YamlScriptStub.createWithCode();
|
||||
const script = ScriptDataStub.createWithCode();
|
||||
const compiler = new ScriptCompilerStub();
|
||||
const expected = [ parseScript(script, compiler) ];
|
||||
const category: YamlCategory = {
|
||||
const category: CategoryData = {
|
||||
category: 'category name',
|
||||
children: [ script ],
|
||||
};
|
||||
@@ -107,11 +107,11 @@ describe('CategoryParser', () => {
|
||||
});
|
||||
it('single script with function call', () => {
|
||||
// arrange
|
||||
const script = YamlScriptStub.createWithCall();
|
||||
const script = ScriptDataStub.createWithCall();
|
||||
const compiler = new ScriptCompilerStub()
|
||||
.withCompileAbility(script);
|
||||
const expected = [ parseScript(script, compiler) ];
|
||||
const category: YamlCategory = {
|
||||
const category: CategoryData = {
|
||||
category: 'category name',
|
||||
children: [ script ],
|
||||
};
|
||||
@@ -122,12 +122,12 @@ describe('CategoryParser', () => {
|
||||
});
|
||||
it('multiple scripts with function call and code', () => {
|
||||
// arrange
|
||||
const callableScript = YamlScriptStub.createWithCall();
|
||||
const scripts = [ callableScript, YamlScriptStub.createWithCode() ];
|
||||
const callableScript = ScriptDataStub.createWithCall();
|
||||
const scripts = [ callableScript, ScriptDataStub.createWithCode() ];
|
||||
const compiler = new ScriptCompilerStub()
|
||||
.withCompileAbility(callableScript);
|
||||
const expected = scripts.map((script) => parseScript(script, compiler));
|
||||
const category: YamlCategory = {
|
||||
const category: CategoryData = {
|
||||
category: 'category name',
|
||||
children: scripts,
|
||||
};
|
||||
@@ -139,11 +139,11 @@ describe('CategoryParser', () => {
|
||||
});
|
||||
it('returns expected subcategories', () => {
|
||||
// arrange
|
||||
const expected: YamlCategory[] = [ {
|
||||
const expected: CategoryData[] = [ {
|
||||
category: 'test category',
|
||||
children: [ YamlScriptStub.createWithCode() ],
|
||||
children: [ ScriptDataStub.createWithCode() ],
|
||||
}];
|
||||
const category: YamlCategory = {
|
||||
const category: CategoryData = {
|
||||
category: 'category name',
|
||||
children: expected,
|
||||
};
|
||||
@@ -158,7 +158,7 @@ describe('CategoryParser', () => {
|
||||
});
|
||||
});
|
||||
|
||||
function getValidCategory(): YamlCategory {
|
||||
function getValidCategory(): CategoryData {
|
||||
return {
|
||||
category: 'category name',
|
||||
children: getTestChildren(),
|
||||
@@ -166,8 +166,8 @@ function getValidCategory(): YamlCategory {
|
||||
};
|
||||
}
|
||||
|
||||
function getTestChildren(): ReadonlyArray<CategoryOrScript> {
|
||||
function getTestChildren(): ReadonlyArray<CategoryOrScriptData> {
|
||||
return [
|
||||
YamlScriptStub.createWithCode(),
|
||||
ScriptDataStub.createWithCode(),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import 'mocha';
|
||||
import { expect } from 'chai';
|
||||
import { ScriptCompiler } from '@/application/Parser/Compiler/ScriptCompiler';
|
||||
import { YamlScriptStub } from '../../../stubs/YamlScriptStub';
|
||||
import { YamlFunction, YamlScript, FunctionCall, ScriptFunctionCall, FunctionCallParameters } from 'js-yaml-loader!@/application.yaml';
|
||||
import { ScriptDataStub } from '../../../stubs/ScriptDataStub';
|
||||
import { FunctionData, ScriptData, FunctionCallData, ScriptFunctionCallData, FunctionCallParametersData } from 'js-yaml-loader!@/*';
|
||||
import { IScriptCode } from '@/domain/IScriptCode';
|
||||
import { IScriptCompiler } from '@/application/Parser/Compiler/IScriptCompiler';
|
||||
|
||||
@@ -11,7 +11,7 @@ describe('ScriptCompiler', () => {
|
||||
it('throws when functions have same names', () => {
|
||||
// arrange
|
||||
const expectedError = `duplicate function name: "same-func-name"`;
|
||||
const functions: YamlFunction[] = [ {
|
||||
const functions: FunctionData[] = [ {
|
||||
name: 'same-func-name',
|
||||
code: 'non-empty-code',
|
||||
}, {
|
||||
@@ -25,7 +25,7 @@ describe('ScriptCompiler', () => {
|
||||
});
|
||||
it('throws when function parameters have same names', () => {
|
||||
// arrange
|
||||
const func: YamlFunction = {
|
||||
const func: FunctionData = {
|
||||
name: 'function-name',
|
||||
code: 'non-empty-code',
|
||||
parameters: [ 'duplicate', 'duplicate' ],
|
||||
@@ -40,7 +40,7 @@ describe('ScriptCompiler', () => {
|
||||
it('code', () => {
|
||||
// arrange
|
||||
const expectedError = `duplicate "code" in functions: "duplicate-code"`;
|
||||
const functions: YamlFunction[] = [ {
|
||||
const functions: FunctionData[] = [ {
|
||||
name: 'func-1',
|
||||
code: 'duplicate-code',
|
||||
}, {
|
||||
@@ -55,7 +55,7 @@ describe('ScriptCompiler', () => {
|
||||
it('revertCode', () => {
|
||||
// arrange
|
||||
const expectedError = `duplicate "revertCode" in functions: "duplicate-revert-code"`;
|
||||
const functions: YamlFunction[] = [ {
|
||||
const functions: FunctionData[] = [ {
|
||||
name: 'func-1',
|
||||
code: 'code-1',
|
||||
revertCode: 'duplicate-revert-code',
|
||||
@@ -75,7 +75,7 @@ describe('ScriptCompiler', () => {
|
||||
it('returns true if "call" is defined', () => {
|
||||
// arrange
|
||||
const sut = new ScriptCompiler([]);
|
||||
const script = YamlScriptStub.createWithCall();
|
||||
const script = ScriptDataStub.createWithCall();
|
||||
// act
|
||||
const actual = sut.canCompile(script);
|
||||
// assert
|
||||
@@ -84,7 +84,7 @@ describe('ScriptCompiler', () => {
|
||||
it('returns false if "call" is undefined', () => {
|
||||
// arrange
|
||||
const sut = new ScriptCompiler([]);
|
||||
const script = YamlScriptStub.createWithCode();
|
||||
const script = ScriptDataStub.createWithCode();
|
||||
// act
|
||||
const actual = sut.canCompile(script);
|
||||
// assert
|
||||
@@ -98,7 +98,7 @@ describe('ScriptCompiler', () => {
|
||||
const expectedError = 'cannot compile without shared functions';
|
||||
const functions = [];
|
||||
const sut = new ScriptCompiler(functions);
|
||||
const script = YamlScriptStub.createWithCall();
|
||||
const script = ScriptDataStub.createWithCall();
|
||||
// act
|
||||
const act = () => sut.compile(script);
|
||||
// assert
|
||||
@@ -110,7 +110,7 @@ describe('ScriptCompiler', () => {
|
||||
const invalidValues = [undefined, 'string', 33];
|
||||
const sut = new ScriptCompiler(createFunctions());
|
||||
invalidValues.forEach((invalidValue) => {
|
||||
const script = YamlScriptStub.createWithoutCallOrCodes() // because call ctor overwrites "undefined"
|
||||
const script = ScriptDataStub.createWithoutCallOrCodes() // because call ctor overwrites "undefined"
|
||||
.withCall(invalidValue as any);
|
||||
// act
|
||||
const act = () => sut.compile(script);
|
||||
@@ -124,8 +124,8 @@ describe('ScriptCompiler', () => {
|
||||
const sut = new ScriptCompiler(createFunctions());
|
||||
const nonExistingFunctionName = 'non-existing-func';
|
||||
const expectedError = `called function is not defined "${nonExistingFunctionName}"`;
|
||||
const call: ScriptFunctionCall = { function: nonExistingFunctionName };
|
||||
const script = YamlScriptStub.createWithCall(call);
|
||||
const call: ScriptFunctionCallData = { function: nonExistingFunctionName };
|
||||
const script = ScriptDataStub.createWithCall(call);
|
||||
// act
|
||||
const act = () => sut.compile(script);
|
||||
// assert
|
||||
@@ -135,11 +135,11 @@ describe('ScriptCompiler', () => {
|
||||
// arrange
|
||||
const existingFunctionName = 'existing-func';
|
||||
const sut = new ScriptCompiler(createFunctions(existingFunctionName));
|
||||
const call: ScriptFunctionCall = [
|
||||
const call: ScriptFunctionCallData = [
|
||||
{ function: existingFunctionName },
|
||||
undefined,
|
||||
];
|
||||
const script = YamlScriptStub.createWithCall(call);
|
||||
const script = ScriptDataStub.createWithCall(call);
|
||||
const expectedError = `undefined function call in script "${script.name}"`;
|
||||
// act
|
||||
const act = () => sut.compile(script);
|
||||
@@ -150,10 +150,10 @@ describe('ScriptCompiler', () => {
|
||||
// arrange
|
||||
const existingFunctionName = 'existing-func';
|
||||
const sut = new ScriptCompiler(createFunctions(existingFunctionName));
|
||||
const call: FunctionCall[] = [
|
||||
const call: FunctionCallData[] = [
|
||||
{ function: existingFunctionName },
|
||||
{ function: undefined }];
|
||||
const script = YamlScriptStub.createWithCall(call);
|
||||
const script = ScriptDataStub.createWithCall(call);
|
||||
const expectedError = `empty function name called in script "${script.name}"`;
|
||||
// act
|
||||
const act = () => sut.compile(script);
|
||||
@@ -170,15 +170,15 @@ describe('ScriptCompiler', () => {
|
||||
execute: 'expected-code',
|
||||
revert: 'expected-revert-code',
|
||||
};
|
||||
const func: YamlFunction = {
|
||||
const func: FunctionData = {
|
||||
name: functionName,
|
||||
parameters: [],
|
||||
code: expected.execute,
|
||||
revertCode: expected.revert,
|
||||
};
|
||||
const sut = new ScriptCompiler([func]);
|
||||
const call: FunctionCall = { function: functionName };
|
||||
const script = YamlScriptStub.createWithCall(call);
|
||||
const call: FunctionCallData = { function: functionName };
|
||||
const script = ScriptDataStub.createWithCall(call);
|
||||
// act
|
||||
const actual = sut.compile(script);
|
||||
// assert
|
||||
@@ -186,13 +186,13 @@ describe('ScriptCompiler', () => {
|
||||
});
|
||||
it('builds call sequence as expected', () => {
|
||||
// arrange
|
||||
const firstFunction: YamlFunction = {
|
||||
const firstFunction: FunctionData = {
|
||||
name: 'first-function-name',
|
||||
parameters: [],
|
||||
code: 'first-function-code',
|
||||
revertCode: 'first-function-revert-code',
|
||||
};
|
||||
const secondFunction: YamlFunction = {
|
||||
const secondFunction: FunctionData = {
|
||||
name: 'second-function-name',
|
||||
parameters: [],
|
||||
code: 'second-function-code',
|
||||
@@ -203,11 +203,11 @@ describe('ScriptCompiler', () => {
|
||||
revert: 'first-function-revert-code\nsecond-function-revert-code',
|
||||
};
|
||||
const sut = new ScriptCompiler([firstFunction, secondFunction]);
|
||||
const call: FunctionCall[] = [
|
||||
const call: FunctionCallData[] = [
|
||||
{ function: firstFunction.name },
|
||||
{ function: secondFunction.name },
|
||||
];
|
||||
const script = YamlScriptStub.createWithCall(call);
|
||||
const script = ScriptDataStub.createWithCall(call);
|
||||
// act
|
||||
const actual = sut.compile(script);
|
||||
// assert
|
||||
@@ -277,26 +277,26 @@ describe('ScriptCompiler', () => {
|
||||
|
||||
interface ITestCase {
|
||||
code: string;
|
||||
parameters?: FunctionCallParameters;
|
||||
parameters?: FunctionCallParametersData;
|
||||
}
|
||||
|
||||
class TestEnvironment {
|
||||
public readonly sut: IScriptCompiler;
|
||||
public readonly script: YamlScript;
|
||||
public readonly script: ScriptData;
|
||||
constructor(testCase: ITestCase) {
|
||||
const functionName = 'testFunction';
|
||||
const func: YamlFunction = {
|
||||
const func: FunctionData = {
|
||||
name: functionName,
|
||||
parameters: testCase.parameters ? Object.keys(testCase.parameters) : undefined,
|
||||
code: this.getCode(testCase.code, 'execute'),
|
||||
revertCode: this.getCode(testCase.code, 'revert'),
|
||||
};
|
||||
this.sut = new ScriptCompiler([func]);
|
||||
const call: FunctionCall = {
|
||||
const call: FunctionCallData = {
|
||||
function: functionName,
|
||||
parameters: testCase.parameters,
|
||||
};
|
||||
this.script = YamlScriptStub.createWithCall(call);
|
||||
this.script = ScriptDataStub.createWithCall(call);
|
||||
}
|
||||
public expect(code: string): IScriptCode {
|
||||
return {
|
||||
@@ -309,12 +309,12 @@ class TestEnvironment {
|
||||
}
|
||||
}
|
||||
|
||||
function createFunctions(...names: string[]): YamlFunction[] {
|
||||
function createFunctions(...names: string[]): FunctionData[] {
|
||||
if (!names || names.length === 0) {
|
||||
names = ['test-function'];
|
||||
}
|
||||
return names.map((functionName) => {
|
||||
const func: YamlFunction = {
|
||||
const func: FunctionData = {
|
||||
name: functionName,
|
||||
parameters: [],
|
||||
code: `REM test-code (${functionName})`,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import 'mocha';
|
||||
import { expect } from 'chai';
|
||||
import { YamlDocumentable } from 'js-yaml-loader!@/application.yaml';
|
||||
import { DocumentableData } from 'js-yaml-loader!@/*';
|
||||
import { parseDocUrls } from '@/application/Parser/DocumentationParser';
|
||||
|
||||
describe('DocumentationParser', () => {
|
||||
@@ -10,7 +10,7 @@ describe('DocumentationParser', () => {
|
||||
});
|
||||
it('returns empty when empty', () => {
|
||||
// arrange
|
||||
const empty: YamlDocumentable = { };
|
||||
const empty: DocumentableData = { };
|
||||
// act
|
||||
const actual = parseDocUrls(empty);
|
||||
// assert
|
||||
@@ -20,7 +20,7 @@ describe('DocumentationParser', () => {
|
||||
// arrange
|
||||
const url = 'https://privacy.sexy';
|
||||
const expected = [ url ];
|
||||
const sut: YamlDocumentable = { docs: url };
|
||||
const sut: DocumentableData = { docs: url };
|
||||
// act
|
||||
const actual = parseDocUrls(sut);
|
||||
// assert
|
||||
@@ -29,7 +29,7 @@ describe('DocumentationParser', () => {
|
||||
it('returns all when array', () => {
|
||||
// arrange
|
||||
const expected = [ 'https://privacy.sexy', 'https://github.com/undergroundwires/privacy.sexy' ];
|
||||
const sut: YamlDocumentable = { docs: expected };
|
||||
const sut: DocumentableData = { docs: expected };
|
||||
// act
|
||||
const actual = parseDocUrls(sut);
|
||||
// assert
|
||||
|
||||
@@ -5,7 +5,7 @@ import { parseDocUrls } from '@/application/Parser/DocumentationParser';
|
||||
import { RecommendationLevel } from '@/domain/RecommendationLevel';
|
||||
import { ScriptCode } from '@/domain/ScriptCode';
|
||||
import { ScriptCompilerStub } from '../../stubs/ScriptCompilerStub';
|
||||
import { YamlScriptStub } from '../../stubs/YamlScriptStub';
|
||||
import { ScriptDataStub } from '../../stubs/ScriptDataStub';
|
||||
import { mockEnumParser } from '../../stubs/EnumParserStub';
|
||||
|
||||
describe('ScriptParser', () => {
|
||||
@@ -13,7 +13,7 @@ describe('ScriptParser', () => {
|
||||
it('parses name as expected', () => {
|
||||
// arrange
|
||||
const expected = 'test-expected-name';
|
||||
const script = YamlScriptStub.createWithCode()
|
||||
const script = ScriptDataStub.createWithCode()
|
||||
.withName(expected);
|
||||
const compiler = new ScriptCompilerStub();
|
||||
// act
|
||||
@@ -24,7 +24,7 @@ describe('ScriptParser', () => {
|
||||
it('parses docs as expected', () => {
|
||||
// arrange
|
||||
const docs = [ 'https://expected-doc1.com', 'https://expected-doc2.com' ];
|
||||
const script = YamlScriptStub.createWithCode()
|
||||
const script = ScriptDataStub.createWithCode()
|
||||
.withDocs(docs);
|
||||
const compiler = new ScriptCompilerStub();
|
||||
const expected = parseDocUrls(script);
|
||||
@@ -48,7 +48,7 @@ describe('ScriptParser', () => {
|
||||
// arrange
|
||||
const expectedError = 'cannot define both "call" and "code"';
|
||||
const compiler = new ScriptCompilerStub();
|
||||
const script = YamlScriptStub
|
||||
const script = ScriptDataStub
|
||||
.createWithCall()
|
||||
.withCode('code');
|
||||
// act
|
||||
@@ -60,7 +60,7 @@ describe('ScriptParser', () => {
|
||||
// arrange
|
||||
const expectedError = 'cannot define "revertCode" if "call" is defined';
|
||||
const compiler = new ScriptCompilerStub();
|
||||
const script = YamlScriptStub
|
||||
const script = ScriptDataStub
|
||||
.createWithCall()
|
||||
.withRevertCode('revert-code');
|
||||
// act
|
||||
@@ -72,7 +72,7 @@ describe('ScriptParser', () => {
|
||||
// arrange
|
||||
const expectedError = 'must define either "call" or "code"';
|
||||
const compiler = new ScriptCompilerStub();
|
||||
const script = YamlScriptStub.createWithoutCallOrCodes();
|
||||
const script = ScriptDataStub.createWithoutCallOrCodes();
|
||||
// act
|
||||
const act = () => parseScript(script, compiler);
|
||||
// assert
|
||||
@@ -85,7 +85,7 @@ describe('ScriptParser', () => {
|
||||
undefinedLevels.forEach((undefinedLevel) => {
|
||||
// arrange
|
||||
const compiler = new ScriptCompilerStub();
|
||||
const script = YamlScriptStub.createWithCode()
|
||||
const script = ScriptDataStub.createWithCode()
|
||||
.withRecommend(undefinedLevel);
|
||||
// act
|
||||
const actual = parseScript(script, compiler);
|
||||
@@ -98,7 +98,7 @@ describe('ScriptParser', () => {
|
||||
const expectedLevel = RecommendationLevel.Standard;
|
||||
const expectedName = 'level';
|
||||
const levelText = 'standard';
|
||||
const script = YamlScriptStub.createWithCode()
|
||||
const script = ScriptDataStub.createWithCode()
|
||||
.withRecommend(levelText);
|
||||
const compiler = new ScriptCompilerStub();
|
||||
const parserMock = mockEnumParser(expectedName, levelText, expectedLevel);
|
||||
@@ -112,7 +112,7 @@ describe('ScriptParser', () => {
|
||||
it('parses code as expected', () => {
|
||||
// arrange
|
||||
const expected = 'expected-code';
|
||||
const script = YamlScriptStub
|
||||
const script = ScriptDataStub
|
||||
.createWithCode()
|
||||
.withCode(expected);
|
||||
const compiler = new ScriptCompilerStub();
|
||||
@@ -125,7 +125,7 @@ describe('ScriptParser', () => {
|
||||
it('parses revertCode as expected', () => {
|
||||
// arrange
|
||||
const expected = 'expected-revert-code';
|
||||
const script = YamlScriptStub
|
||||
const script = ScriptDataStub
|
||||
.createWithCode()
|
||||
.withRevertCode(expected);
|
||||
const compiler = new ScriptCompilerStub();
|
||||
@@ -138,7 +138,7 @@ describe('ScriptParser', () => {
|
||||
describe('compiler', () => {
|
||||
it('throws when compiler is not defined', () => {
|
||||
// arrange
|
||||
const script = YamlScriptStub.createWithCode();
|
||||
const script = ScriptDataStub.createWithCode();
|
||||
const compiler = undefined;
|
||||
// act
|
||||
const act = () => parseScript(script, compiler);
|
||||
@@ -148,7 +148,7 @@ describe('ScriptParser', () => {
|
||||
it('gets code from compiler', () => {
|
||||
// arrange
|
||||
const expected = new ScriptCode('test-script', 'code', 'revert-code');
|
||||
const script = YamlScriptStub.createWithCode();
|
||||
const script = ScriptDataStub.createWithCode();
|
||||
const compiler = new ScriptCompilerStub()
|
||||
.withCompileAbility(script, expected);
|
||||
// act
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import 'mocha';
|
||||
import { expect } from 'chai';
|
||||
import { YamlScriptingDefinition } from 'js-yaml-loader!@/application.yaml';
|
||||
import { ScriptingDefinitionData } from 'js-yaml-loader!@/*';
|
||||
import { ScriptingLanguage } from '@/domain/ScriptingLanguage';
|
||||
import { parseScriptingDefinition } from '@/application/Parser/ScriptingDefinitionParser';
|
||||
import { ProjectInformationStub } from './../../stubs/ProjectInformationStub';
|
||||
@@ -139,7 +139,7 @@ class ScriptingDefinitionBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public construct(): YamlScriptingDefinition {
|
||||
public construct(): ScriptingDefinitionData {
|
||||
return {
|
||||
language: this.language,
|
||||
fileExtension: this.fileExtension,
|
||||
|
||||
@@ -1,29 +1,29 @@
|
||||
import { RecommendationLevel } from '@/domain/RecommendationLevel';
|
||||
import { ScriptingLanguage } from '@/domain/ScriptingLanguage';
|
||||
import { YamlCategory, YamlScript, YamlApplication, YamlScriptingDefinition } from 'js-yaml-loader!@/application/application.yaml';
|
||||
import { CategoryData, ScriptData, CollectionData, ScriptingDefinitionData } from 'js-yaml-loader!@/*';
|
||||
|
||||
export class YamlApplicationStub implements YamlApplication {
|
||||
export class CollectionDataStub implements CollectionData {
|
||||
public os = 'windows';
|
||||
public actions: readonly YamlCategory[] = [ getCategoryStub() ];
|
||||
public scripting: YamlScriptingDefinition = getTestDefinitionStub();
|
||||
public actions: readonly CategoryData[] = [ getCategoryStub() ];
|
||||
public scripting: ScriptingDefinitionData = getTestDefinitionStub();
|
||||
|
||||
public withActions(actions: readonly YamlCategory[]): YamlApplicationStub {
|
||||
public withActions(actions: readonly CategoryData[]): CollectionDataStub {
|
||||
this.actions = actions;
|
||||
return this;
|
||||
}
|
||||
|
||||
public withOs(os: string): YamlApplicationStub {
|
||||
public withOs(os: string): CollectionDataStub {
|
||||
this.os = os;
|
||||
return this;
|
||||
}
|
||||
|
||||
public withScripting(scripting: YamlScriptingDefinition): YamlApplicationStub {
|
||||
public withScripting(scripting: ScriptingDefinitionData): CollectionDataStub {
|
||||
this.scripting = scripting;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
export function getCategoryStub(scriptPrefix = 'testScript'): YamlCategory {
|
||||
export function getCategoryStub(scriptPrefix = 'testScript'): CategoryData {
|
||||
return {
|
||||
category: 'category name',
|
||||
children: [
|
||||
@@ -33,7 +33,7 @@ export function getCategoryStub(scriptPrefix = 'testScript'): YamlCategory {
|
||||
};
|
||||
}
|
||||
|
||||
function getTestDefinitionStub(): YamlScriptingDefinition {
|
||||
function getTestDefinitionStub(): ScriptingDefinitionData {
|
||||
return {
|
||||
fileExtension: '.bat',
|
||||
language: ScriptingLanguage[ScriptingLanguage.batchfile],
|
||||
@@ -42,7 +42,7 @@ function getTestDefinitionStub(): YamlScriptingDefinition {
|
||||
};
|
||||
}
|
||||
|
||||
function getScriptStub(scriptName: string, level: RecommendationLevel = RecommendationLevel.Standard): YamlScript {
|
||||
function getScriptStub(scriptName: string, level: RecommendationLevel = RecommendationLevel.Standard): ScriptData {
|
||||
return {
|
||||
name: scriptName,
|
||||
code: 'script code',
|
||||
@@ -1,16 +1,16 @@
|
||||
import { IScriptCompiler } from '@/application/Parser/Compiler/IScriptCompiler';
|
||||
import { IScriptCode } from '@/domain/IScriptCode';
|
||||
import { YamlScript } from 'js-yaml-loader!@/application.yaml';
|
||||
import { ScriptData } from 'js-yaml-loader!@/*';
|
||||
|
||||
export class ScriptCompilerStub implements IScriptCompiler {
|
||||
public compilables = new Map<YamlScript, IScriptCode>();
|
||||
public canCompile(script: YamlScript): boolean {
|
||||
public compilables = new Map<ScriptData, IScriptCode>();
|
||||
public canCompile(script: ScriptData): boolean {
|
||||
return this.compilables.has(script);
|
||||
}
|
||||
public compile(script: YamlScript): IScriptCode {
|
||||
public compile(script: ScriptData): IScriptCode {
|
||||
return this.compilables.get(script);
|
||||
}
|
||||
public withCompileAbility(script: YamlScript, result?: IScriptCode): ScriptCompilerStub {
|
||||
public withCompileAbility(script: ScriptData, result?: IScriptCode): ScriptCompilerStub {
|
||||
this.compilables.set(script, result ||
|
||||
{ execute: `compiled code of ${script.name}`, revert: `compiled revert code of ${script.name}` });
|
||||
return this;
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { RecommendationLevel } from '@/domain/RecommendationLevel';
|
||||
import { ScriptFunctionCall, YamlScript } from 'js-yaml-loader!@/application.yaml';
|
||||
import { ScriptFunctionCallData, ScriptData } from 'js-yaml-loader!@/*';
|
||||
|
||||
export class YamlScriptStub implements YamlScript {
|
||||
public static createWithCode(): YamlScriptStub {
|
||||
return new YamlScriptStub()
|
||||
export class ScriptDataStub implements ScriptData {
|
||||
public static createWithCode(): ScriptDataStub {
|
||||
return new ScriptDataStub()
|
||||
.withCode('stub-code')
|
||||
.withRevertCode('stub-revert-code');
|
||||
}
|
||||
public static createWithCall(call?: ScriptFunctionCall): YamlScriptStub {
|
||||
let instance = new YamlScriptStub();
|
||||
public static createWithCall(call?: ScriptFunctionCallData): ScriptDataStub {
|
||||
let instance = new ScriptDataStub();
|
||||
if (call) {
|
||||
instance = instance.withCall(call);
|
||||
} else {
|
||||
@@ -16,8 +16,8 @@ export class YamlScriptStub implements YamlScript {
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
public static createWithoutCallOrCodes(): YamlScriptStub {
|
||||
return new YamlScriptStub();
|
||||
public static createWithoutCallOrCodes(): ScriptDataStub {
|
||||
return new ScriptDataStub();
|
||||
}
|
||||
|
||||
public name = 'valid-name';
|
||||
@@ -29,38 +29,38 @@ export class YamlScriptStub implements YamlScript {
|
||||
|
||||
private constructor() { }
|
||||
|
||||
public withName(name: string): YamlScriptStub {
|
||||
public withName(name: string): ScriptDataStub {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public withDocs(docs: string[]): YamlScriptStub {
|
||||
public withDocs(docs: string[]): ScriptDataStub {
|
||||
this.docs = docs;
|
||||
return this;
|
||||
}
|
||||
|
||||
public withCode(code: string): YamlScriptStub {
|
||||
public withCode(code: string): ScriptDataStub {
|
||||
this.code = code;
|
||||
return this;
|
||||
}
|
||||
|
||||
public withRevertCode(revertCode: string): YamlScriptStub {
|
||||
public withRevertCode(revertCode: string): ScriptDataStub {
|
||||
this.revertCode = revertCode;
|
||||
return this;
|
||||
}
|
||||
|
||||
public withMockCall(): YamlScriptStub {
|
||||
public withMockCall(): ScriptDataStub {
|
||||
this.call = { function: 'func', parameters: [] };
|
||||
return this;
|
||||
}
|
||||
|
||||
public withCall(call: ScriptFunctionCall): YamlScriptStub {
|
||||
public withCall(call: ScriptFunctionCallData): ScriptDataStub {
|
||||
this.call = call;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public withRecommend(recommend: string): YamlScriptStub {
|
||||
public withRecommend(recommend: string): ScriptDataStub {
|
||||
this.recommend = recommend;
|
||||
return this;
|
||||
}
|
||||
Reference in New Issue
Block a user