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:
@@ -13,9 +13,29 @@
|
|||||||
|
|
||||||
- Tests each component in isolation.
|
- Tests each component in isolation.
|
||||||
- Defined in [`./tests/unit`](./../tests/unit).
|
- Defined in [`./tests/unit`](./../tests/unit).
|
||||||
- They follow same folder structure as [`./src`](./../src).
|
|
||||||
|
|
||||||
### Naming
|
### Unit tests structure
|
||||||
|
|
||||||
|
- [`./src/`](./../src/)
|
||||||
|
- Includes code that will be tested tested.
|
||||||
|
- [`./tests/unit/`](./../tests/unit/)
|
||||||
|
- Includes test code.
|
||||||
|
- Tests follow same folder structure as [`./src/`](./../src).
|
||||||
|
- E.g. if system under test lies in [`./src/application/ApplicationFactory.ts`](./../src/application/ApplicationFactory.ts) then its tests would be in test would be at [`./tests/unit/application/ApplicationFactory.spec.ts`](./../tests/unit/application/ApplicationFactory.spec.ts).
|
||||||
|
- [`shared/`](./../tests/unit/shared/)
|
||||||
|
- Includes common functionality that's shared across unit tests.
|
||||||
|
- [`Assertions/`](./../tests/unit/shared/Assertions):
|
||||||
|
- Common assertions that extend [Chai Assertion Library](https://www.chaijs.com/).
|
||||||
|
- Asserting functions should start with `expect` prefix.
|
||||||
|
- [`TestCases/`](./../tests/unit/shared/TestCases/)
|
||||||
|
- Shared test cases.
|
||||||
|
- Test runner functions that uses `it()` from Mocha test [Mocha test framework](https://mochajs.org/) should be prefixed with `it.`
|
||||||
|
- E.g. `itEachAbsentCollectionValue()`.
|
||||||
|
- [`stubs/`](./../tests/unit/stubs)
|
||||||
|
- Includes stubs to be able to test classes in isolation.
|
||||||
|
- They implement dummy behavior to be functional with optionally spying or mocking functions.
|
||||||
|
|
||||||
|
### Unit tests naming
|
||||||
|
|
||||||
- Each test suite first describe the system under test.
|
- Each test suite first describe the system under test.
|
||||||
- E.g. tests for class `Application` is categorized under `Application`.
|
- E.g. tests for class `Application` is categorized under `Application`.
|
||||||
@@ -35,11 +55,6 @@
|
|||||||
- Should elicit some sort of response.
|
- Should elicit some sort of response.
|
||||||
- Starts with comment line `// assert`.
|
- Starts with comment line `// assert`.
|
||||||
|
|
||||||
### Stubs
|
|
||||||
|
|
||||||
- Stubs are defined in [`./tests/stubs`](./../tests/unit/stubs).
|
|
||||||
- They implement dummy behavior to be functional.
|
|
||||||
|
|
||||||
## Integration tests
|
## Integration tests
|
||||||
|
|
||||||
- Tests functionality of a component in combination with others (not isolated).
|
- Tests functionality of a component in combination with others (not isolated).
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ export class ApplicationFactory implements IApplicationFactory {
|
|||||||
|
|
||||||
protected constructor(costlyGetter: ApplicationGetterType) {
|
protected constructor(costlyGetter: ApplicationGetterType) {
|
||||||
if (!costlyGetter) {
|
if (!costlyGetter) {
|
||||||
throw new Error('undefined getter');
|
throw new Error('missing getter');
|
||||||
}
|
}
|
||||||
this.getter = new AsyncLazy<IApplication>(() => Promise.resolve(costlyGetter()));
|
this.getter = new AsyncLazy<IApplication>(() => Promise.resolve(costlyGetter()));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// Compares to Array<T> objects for equality, ignoring order
|
// Compares to Array<T> objects for equality, ignoring order
|
||||||
export function scrambledEqual<T>(array1: readonly T[], array2: readonly T[]) {
|
export function scrambledEqual<T>(array1: readonly T[], array2: readonly T[]) {
|
||||||
if (!array1) { throw new Error('undefined first array'); }
|
if (!array1) { throw new Error('missing first array'); }
|
||||||
if (!array2) { throw new Error('undefined second array'); }
|
if (!array2) { throw new Error('missing second array'); }
|
||||||
const sortedArray1 = sort(array1);
|
const sortedArray1 = sort(array1);
|
||||||
const sortedArray2 = sort(array2);
|
const sortedArray2 = sort(array2);
|
||||||
return sequenceEqual(sortedArray1, sortedArray2);
|
return sequenceEqual(sortedArray1, sortedArray2);
|
||||||
@@ -12,8 +12,8 @@ export function scrambledEqual<T>(array1: readonly T[], array2: readonly T[]) {
|
|||||||
|
|
||||||
// Compares to Array<T> objects for equality in same order
|
// Compares to Array<T> objects for equality in same order
|
||||||
export function sequenceEqual<T>(array1: readonly T[], array2: readonly T[]) {
|
export function sequenceEqual<T>(array1: readonly T[], array2: readonly T[]) {
|
||||||
if (!array1) { throw new Error('undefined first array'); }
|
if (!array1) { throw new Error('missing first array'); }
|
||||||
if (!array2) { throw new Error('undefined second array'); }
|
if (!array2) { throw new Error('missing second array'); }
|
||||||
if (array1.length !== array2.length) {
|
if (array1.length !== array2.length) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ function parseEnumValue<T extends EnumType, TEnumValue extends EnumType>(
|
|||||||
enumVariable: EnumVariable<T, TEnumValue>,
|
enumVariable: EnumVariable<T, TEnumValue>,
|
||||||
): TEnumValue {
|
): TEnumValue {
|
||||||
if (!value) {
|
if (!value) {
|
||||||
throw new Error(`undefined ${enumName}`);
|
throw new Error(`missing ${enumName}`);
|
||||||
}
|
}
|
||||||
if (typeof value !== 'string') {
|
if (typeof value !== 'string') {
|
||||||
throw new Error(`unexpected type of ${enumName}: "${typeof value}"`);
|
throw new Error(`unexpected type of ${enumName}: "${typeof value}"`);
|
||||||
@@ -54,8 +54,8 @@ export function assertInRange<T extends EnumType, TEnumValue extends EnumType>(
|
|||||||
value: TEnumValue,
|
value: TEnumValue,
|
||||||
enumVariable: EnumVariable<T, TEnumValue>,
|
enumVariable: EnumVariable<T, TEnumValue>,
|
||||||
) {
|
) {
|
||||||
if (value === undefined) {
|
if (value === undefined || value === null) {
|
||||||
throw new Error('undefined enum value');
|
throw new Error('absent enum value');
|
||||||
}
|
}
|
||||||
if (!(value in enumVariable)) {
|
if (!(value in enumVariable)) {
|
||||||
throw new RangeError(`enum value "${value}" is out of range`);
|
throw new RangeError(`enum value "${value}" is out of range`);
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ export abstract class ScriptingLanguageFactory<T> implements IScriptingLanguageF
|
|||||||
protected registerGetter(language: ScriptingLanguage, getter: Getter<T>) {
|
protected registerGetter(language: ScriptingLanguage, getter: Getter<T>) {
|
||||||
assertInRange(language, ScriptingLanguage);
|
assertInRange(language, ScriptingLanguage);
|
||||||
if (!getter) {
|
if (!getter) {
|
||||||
throw new Error('undefined getter');
|
throw new Error('missing getter');
|
||||||
}
|
}
|
||||||
if (this.getters.has(language)) {
|
if (this.getters.has(language)) {
|
||||||
throw new Error(`${ScriptingLanguage[language]} is already registered`);
|
throw new Error(`${ScriptingLanguage[language]} is already registered`);
|
||||||
|
|||||||
@@ -27,12 +27,12 @@ export class ApplicationContext implements IApplicationContext {
|
|||||||
initialContext: OperatingSystem,
|
initialContext: OperatingSystem,
|
||||||
) {
|
) {
|
||||||
validateApp(app);
|
validateApp(app);
|
||||||
assertInRange(initialContext, OperatingSystem);
|
|
||||||
this.states = initializeStates(app);
|
this.states = initializeStates(app);
|
||||||
this.changeContext(initialContext);
|
this.changeContext(initialContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
public changeContext(os: OperatingSystem): void {
|
public changeContext(os: OperatingSystem): void {
|
||||||
|
assertInRange(os, OperatingSystem);
|
||||||
if (this.currentOs === os) {
|
if (this.currentOs === os) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -51,7 +51,7 @@ export class ApplicationContext implements IApplicationContext {
|
|||||||
|
|
||||||
function validateApp(app: IApplication) {
|
function validateApp(app: IApplication) {
|
||||||
if (!app) {
|
if (!app) {
|
||||||
throw new Error('undefined app');
|
throw new Error('missing app');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ export async function buildContext(
|
|||||||
factory: IApplicationFactory = ApplicationFactory.Current,
|
factory: IApplicationFactory = ApplicationFactory.Current,
|
||||||
environment = Environment.CurrentEnvironment,
|
environment = Environment.CurrentEnvironment,
|
||||||
): Promise<IApplicationContext> {
|
): Promise<IApplicationContext> {
|
||||||
if (!factory) { throw new Error('undefined factory'); }
|
if (!factory) { throw new Error('missing factory'); }
|
||||||
if (!environment) { throw new Error('undefined environment'); }
|
if (!environment) { throw new Error('missing environment'); }
|
||||||
const app = await factory.getApp();
|
const app = await factory.getApp();
|
||||||
const os = getInitialOs(app, environment);
|
const os = getInitialOs(app, environment);
|
||||||
return new ApplicationContext(app, os);
|
return new ApplicationContext(app, os);
|
||||||
|
|||||||
@@ -21,9 +21,9 @@ export class ApplicationCode implements IApplicationCode {
|
|||||||
private readonly scriptingDefinition: IScriptingDefinition,
|
private readonly scriptingDefinition: IScriptingDefinition,
|
||||||
private readonly generator: IUserScriptGenerator = new UserScriptGenerator(),
|
private readonly generator: IUserScriptGenerator = new UserScriptGenerator(),
|
||||||
) {
|
) {
|
||||||
if (!userSelection) { throw new Error('userSelection is null or undefined'); }
|
if (!userSelection) { throw new Error('missing userSelection'); }
|
||||||
if (!scriptingDefinition) { throw new Error('scriptingDefinition is null or undefined'); }
|
if (!scriptingDefinition) { throw new Error('missing scriptingDefinition'); }
|
||||||
if (!generator) { throw new Error('generator is null or undefined'); }
|
if (!generator) { throw new Error('missing generator'); }
|
||||||
this.setCode(userSelection.selectedScripts);
|
this.setCode(userSelection.selectedScripts);
|
||||||
userSelection.changed.on((scripts) => {
|
userSelection.changed.on((scripts) => {
|
||||||
this.setCode(scripts);
|
this.setCode(scripts);
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ export class UserScriptGenerator implements IUserScriptGenerator {
|
|||||||
selectedScripts: ReadonlyArray<SelectedScript>,
|
selectedScripts: ReadonlyArray<SelectedScript>,
|
||||||
scriptingDefinition: IScriptingDefinition,
|
scriptingDefinition: IScriptingDefinition,
|
||||||
): IUserScript {
|
): IUserScript {
|
||||||
if (!selectedScripts) { throw new Error('undefined scripts'); }
|
if (!selectedScripts) { throw new Error('missing scripts'); }
|
||||||
if (!scriptingDefinition) { throw new Error('undefined definition'); }
|
if (!scriptingDefinition) { throw new Error('missing definition'); }
|
||||||
if (!selectedScripts.length) {
|
if (!selectedScripts.length) {
|
||||||
return { code: '', scriptPositions: new Map<SelectedScript, ICodePosition>() };
|
return { code: '', scriptPositions: new Map<SelectedScript, ICodePosition>() };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ export class DetectorBuilder {
|
|||||||
|
|
||||||
private detect(userAgent: string): OperatingSystem {
|
private detect(userAgent: string): OperatingSystem {
|
||||||
if (!userAgent) {
|
if (!userAgent) {
|
||||||
throw new Error('User agent is null or undefined');
|
throw new Error('missing userAgent');
|
||||||
}
|
}
|
||||||
if (this.existingPartsInUserAgent.some((part) => !userAgent.includes(part))) {
|
if (this.existingPartsInUserAgent.some((part) => !userAgent.includes(part))) {
|
||||||
return undefined;
|
return undefined;
|
||||||
|
|||||||
@@ -32,10 +32,10 @@ const PreParsedCollections: readonly CollectionData [] = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
function validateCollectionsData(collections: readonly CollectionData[]) {
|
function validateCollectionsData(collections: readonly CollectionData[]) {
|
||||||
if (!collections.length) {
|
if (!collections || !collections.length) {
|
||||||
throw new Error('no collection provided');
|
throw new Error('missing collections');
|
||||||
}
|
}
|
||||||
if (collections.some((collection) => !collection)) {
|
if (collections.some((collection) => !collection)) {
|
||||||
throw new Error('undefined collection provided');
|
throw new Error('missing collection provided');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ export function parseCategoryCollection(
|
|||||||
|
|
||||||
function validate(content: CollectionData): void {
|
function validate(content: CollectionData): void {
|
||||||
if (!content) {
|
if (!content) {
|
||||||
throw new Error('content is null or undefined');
|
throw new Error('missing content');
|
||||||
}
|
}
|
||||||
if (!content.actions || content.actions.length <= 0) {
|
if (!content.actions || content.actions.length <= 0) {
|
||||||
throw new Error('content does not define any action');
|
throw new Error('content does not define any action');
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ export function parseCategory(
|
|||||||
category: CategoryData,
|
category: CategoryData,
|
||||||
context: ICategoryCollectionParseContext,
|
context: ICategoryCollectionParseContext,
|
||||||
): Category {
|
): Category {
|
||||||
if (!context) { throw new Error('undefined context'); }
|
if (!context) { throw new Error('missing context'); }
|
||||||
ensureValid(category);
|
ensureValid(category);
|
||||||
const children: ICategoryChildren = {
|
const children: ICategoryChildren = {
|
||||||
subCategories: new Array<Category>(),
|
subCategories: new Array<Category>(),
|
||||||
@@ -33,7 +33,7 @@ export function parseCategory(
|
|||||||
|
|
||||||
function ensureValid(category: CategoryData) {
|
function ensureValid(category: CategoryData) {
|
||||||
if (!category) {
|
if (!category) {
|
||||||
throw Error('category is null or undefined');
|
throw Error('missing category');
|
||||||
}
|
}
|
||||||
if (!category.children || category.children.length === 0) {
|
if (!category.children || category.children.length === 0) {
|
||||||
throw Error(`category has no children: "${category.category}"`);
|
throw Error(`category has no children: "${category.category}"`);
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { DocumentableData, DocumentationUrlsData } from 'js-yaml-loader!@/*';
|
|||||||
|
|
||||||
export function parseDocUrls(documentable: DocumentableData): ReadonlyArray<string> {
|
export function parseDocUrls(documentable: DocumentableData): ReadonlyArray<string> {
|
||||||
if (!documentable) {
|
if (!documentable) {
|
||||||
throw new Error('documentable is null or undefined');
|
throw new Error('missing documentable');
|
||||||
}
|
}
|
||||||
const { docs } = documentable;
|
const { docs } = documentable;
|
||||||
if (!docs || !docs.length) {
|
if (!docs || !docs.length) {
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ export class CategoryCollectionParseContext implements ICategoryCollectionParseC
|
|||||||
scripting: IScriptingDefinition,
|
scripting: IScriptingDefinition,
|
||||||
syntaxFactory: ISyntaxFactory = new SyntaxFactory(),
|
syntaxFactory: ISyntaxFactory = new SyntaxFactory(),
|
||||||
) {
|
) {
|
||||||
if (!scripting) { throw new Error('undefined scripting'); }
|
if (!scripting) { throw new Error('missing scripting'); }
|
||||||
this.syntax = syntaxFactory.create(scripting.language);
|
this.syntax = syntaxFactory.create(scripting.language);
|
||||||
this.compiler = new ScriptCompiler(functionsData, this.syntax);
|
this.compiler = new ScriptCompiler(functionsData, this.syntax);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,23 +8,25 @@ import { ExpressionEvaluationContext, IExpressionEvaluationContext } from './Exp
|
|||||||
|
|
||||||
export type ExpressionEvaluator = (context: IExpressionEvaluationContext) => string;
|
export type ExpressionEvaluator = (context: IExpressionEvaluationContext) => string;
|
||||||
export class Expression implements IExpression {
|
export class Expression implements IExpression {
|
||||||
|
public readonly parameters: IReadOnlyFunctionParameterCollection;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
public readonly position: ExpressionPosition,
|
public readonly position: ExpressionPosition,
|
||||||
public readonly evaluator: ExpressionEvaluator,
|
public readonly evaluator: ExpressionEvaluator,
|
||||||
public readonly parameters
|
parameters?: IReadOnlyFunctionParameterCollection,
|
||||||
: IReadOnlyFunctionParameterCollection = new FunctionParameterCollection(),
|
|
||||||
) {
|
) {
|
||||||
if (!position) {
|
if (!position) {
|
||||||
throw new Error('undefined position');
|
throw new Error('missing position');
|
||||||
}
|
}
|
||||||
if (!evaluator) {
|
if (!evaluator) {
|
||||||
throw new Error('undefined evaluator');
|
throw new Error('missing evaluator');
|
||||||
}
|
}
|
||||||
|
this.parameters = parameters ?? new FunctionParameterCollection();
|
||||||
}
|
}
|
||||||
|
|
||||||
public evaluate(context: IExpressionEvaluationContext): string {
|
public evaluate(context: IExpressionEvaluationContext): string {
|
||||||
if (!context) {
|
if (!context) {
|
||||||
throw new Error('undefined context');
|
throw new Error('missing context');
|
||||||
}
|
}
|
||||||
validateThatAllRequiredParametersAreSatisfied(this.parameters, context.args);
|
validateThatAllRequiredParametersAreSatisfied(this.parameters, context.args);
|
||||||
const args = filterUnusedArguments(this.parameters, context.args);
|
const args = filterUnusedArguments(this.parameters, context.args);
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ export class ExpressionEvaluationContext implements IExpressionEvaluationContext
|
|||||||
public readonly pipelineCompiler: IPipelineCompiler = new PipelineCompiler(),
|
public readonly pipelineCompiler: IPipelineCompiler = new PipelineCompiler(),
|
||||||
) {
|
) {
|
||||||
if (!args) {
|
if (!args) {
|
||||||
throw new Error('undefined args, send empty collection instead');
|
throw new Error('missing args, send empty collection instead.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ export class ExpressionsCompiler implements IExpressionsCompiler {
|
|||||||
args: IReadOnlyFunctionCallArgumentCollection,
|
args: IReadOnlyFunctionCallArgumentCollection,
|
||||||
): string {
|
): string {
|
||||||
if (!args) {
|
if (!args) {
|
||||||
throw new Error('undefined args, send empty collection instead');
|
throw new Error('missing args, send empty collection instead.');
|
||||||
}
|
}
|
||||||
if (!code) {
|
if (!code) {
|
||||||
return code;
|
return code;
|
||||||
|
|||||||
@@ -10,8 +10,11 @@ const Parsers = [
|
|||||||
|
|
||||||
export class CompositeExpressionParser implements IExpressionParser {
|
export class CompositeExpressionParser implements IExpressionParser {
|
||||||
public constructor(private readonly leafs: readonly IExpressionParser[] = Parsers) {
|
public constructor(private readonly leafs: readonly IExpressionParser[] = Parsers) {
|
||||||
|
if (!leafs) {
|
||||||
|
throw new Error('missing leafs');
|
||||||
|
}
|
||||||
if (leafs.some((leaf) => !leaf)) {
|
if (leafs.some((leaf) => !leaf)) {
|
||||||
throw new Error('undefined leaf');
|
throw new Error('missing leaf');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ export abstract class RegexParser implements IExpressionParser {
|
|||||||
|
|
||||||
private* findRegexExpressions(code: string): Iterable<IExpression> {
|
private* findRegexExpressions(code: string): Iterable<IExpression> {
|
||||||
if (!code) {
|
if (!code) {
|
||||||
throw new Error('undefined code');
|
throw new Error('missing code');
|
||||||
}
|
}
|
||||||
const matches = code.matchAll(this.regex);
|
const matches = code.matchAll(this.regex);
|
||||||
for (const match of matches) {
|
for (const match of matches) {
|
||||||
|
|||||||
@@ -4,7 +4,10 @@ export class EscapeDoubleQuotes implements IPipe {
|
|||||||
public readonly name: string = 'escapeDoubleQuotes';
|
public readonly name: string = 'escapeDoubleQuotes';
|
||||||
|
|
||||||
public apply(raw: string): string {
|
public apply(raw: string): string {
|
||||||
return raw?.replaceAll('"', '"^""');
|
if (!raw) {
|
||||||
|
return raw;
|
||||||
|
}
|
||||||
|
return raw.replaceAll('"', '"^""');
|
||||||
/* eslint-disable max-len */
|
/* eslint-disable max-len */
|
||||||
/*
|
/*
|
||||||
"^"" is the most robust and stable choice.
|
"^"" is the most robust and stable choice.
|
||||||
|
|||||||
@@ -15,8 +15,11 @@ export class PipeFactory implements IPipeFactory {
|
|||||||
private readonly pipes = new Map<string, IPipe>();
|
private readonly pipes = new Map<string, IPipe>();
|
||||||
|
|
||||||
constructor(pipes: readonly IPipe[] = RegisteredPipes) {
|
constructor(pipes: readonly IPipe[] = RegisteredPipes) {
|
||||||
|
if (!pipes) {
|
||||||
|
throw new Error('missing pipes');
|
||||||
|
}
|
||||||
if (pipes.some((pipe) => !pipe)) {
|
if (pipes.some((pipe) => !pipe)) {
|
||||||
throw new Error('undefined pipe in list');
|
throw new Error('missing pipe in list');
|
||||||
}
|
}
|
||||||
for (const pipe of pipes) {
|
for (const pipe of pipes) {
|
||||||
this.registerPipe(pipe);
|
this.registerPipe(pipe);
|
||||||
|
|||||||
@@ -23,8 +23,8 @@ function extractPipeNames(pipeline: string): string[] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function ensureValidArguments(value: string, pipeline: string) {
|
function ensureValidArguments(value: string, pipeline: string) {
|
||||||
if (!value) { throw new Error('undefined value'); }
|
if (!value) { throw new Error('missing value'); }
|
||||||
if (!pipeline) { throw new Error('undefined pipeline'); }
|
if (!pipeline) { throw new Error('missing pipeline'); }
|
||||||
if (!pipeline.trimStart().startsWith('|')) {
|
if (!pipeline.trimStart().startsWith('|')) {
|
||||||
throw new Error('pipeline does not start with pipe');
|
throw new Error('pipeline does not start with pipe');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ export class FunctionCallArgument implements IFunctionCallArgument {
|
|||||||
) {
|
) {
|
||||||
ensureValidParameterName(parameterName);
|
ensureValidParameterName(parameterName);
|
||||||
if (!argumentValue) {
|
if (!argumentValue) {
|
||||||
throw new Error(`undefined argument value for "${parameterName}"`);
|
throw new Error(`missing argument value for "${parameterName}"`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ export class FunctionCallArgumentCollection implements IFunctionCallArgumentColl
|
|||||||
|
|
||||||
public addArgument(argument: IFunctionCallArgument): void {
|
public addArgument(argument: IFunctionCallArgument): void {
|
||||||
if (!argument) {
|
if (!argument) {
|
||||||
throw new Error('undefined argument');
|
throw new Error('missing argument');
|
||||||
}
|
}
|
||||||
if (this.hasArgument(argument.parameterName)) {
|
if (this.hasArgument(argument.parameterName)) {
|
||||||
throw new Error(`argument value for parameter ${argument.parameterName} is already provided`);
|
throw new Error(`argument value for parameter ${argument.parameterName} is already provided`);
|
||||||
@@ -20,14 +20,14 @@ export class FunctionCallArgumentCollection implements IFunctionCallArgumentColl
|
|||||||
|
|
||||||
public hasArgument(parameterName: string): boolean {
|
public hasArgument(parameterName: string): boolean {
|
||||||
if (!parameterName) {
|
if (!parameterName) {
|
||||||
throw new Error('undefined parameter name');
|
throw new Error('missing parameter name');
|
||||||
}
|
}
|
||||||
return this.arguments.has(parameterName);
|
return this.arguments.has(parameterName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public getArgument(parameterName: string): IFunctionCallArgument {
|
public getArgument(parameterName: string): IFunctionCallArgument {
|
||||||
if (!parameterName) {
|
if (!parameterName) {
|
||||||
throw new Error('undefined parameter name');
|
throw new Error('missing parameter name');
|
||||||
}
|
}
|
||||||
const arg = this.arguments.get(parameterName);
|
const arg = this.arguments.get(parameterName);
|
||||||
if (!arg) {
|
if (!arg) {
|
||||||
|
|||||||
@@ -22,9 +22,9 @@ export class FunctionCallCompiler implements IFunctionCallCompiler {
|
|||||||
calls: IFunctionCall[],
|
calls: IFunctionCall[],
|
||||||
functions: ISharedFunctionCollection,
|
functions: ISharedFunctionCollection,
|
||||||
): ICompiledCode {
|
): ICompiledCode {
|
||||||
if (!functions) { throw new Error('undefined functions'); }
|
if (!functions) { throw new Error('missing functions'); }
|
||||||
if (!calls) { throw new Error('undefined calls'); }
|
if (!calls) { throw new Error('missing calls'); }
|
||||||
if (calls.some((f) => !f)) { throw new Error('undefined function call'); }
|
if (calls.some((f) => !f)) { throw new Error('missing function call'); }
|
||||||
const context: ICompilationContext = {
|
const context: ICompilationContext = {
|
||||||
allFunctions: functions,
|
allFunctions: functions,
|
||||||
callSequence: calls,
|
callSequence: calls,
|
||||||
|
|||||||
@@ -7,10 +7,10 @@ export class FunctionCall implements IFunctionCall {
|
|||||||
public readonly args: IReadOnlyFunctionCallArgumentCollection,
|
public readonly args: IReadOnlyFunctionCallArgumentCollection,
|
||||||
) {
|
) {
|
||||||
if (!functionName) {
|
if (!functionName) {
|
||||||
throw new Error('empty function name in function call');
|
throw new Error('missing function name in function call');
|
||||||
}
|
}
|
||||||
if (!args) {
|
if (!args) {
|
||||||
throw new Error('undefined args');
|
throw new Error('missing args');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { FunctionCall } from './FunctionCall';
|
|||||||
|
|
||||||
export function parseFunctionCalls(calls: FunctionCallsData): IFunctionCall[] {
|
export function parseFunctionCalls(calls: FunctionCallsData): IFunctionCall[] {
|
||||||
if (calls === undefined) {
|
if (calls === undefined) {
|
||||||
throw new Error('undefined call data');
|
throw new Error('missing call data');
|
||||||
}
|
}
|
||||||
const sequence = getCallSequence(calls);
|
const sequence = getCallSequence(calls);
|
||||||
return sequence.map((call) => parseFunctionCall(call));
|
return sequence.map((call) => parseFunctionCall(call));
|
||||||
@@ -24,7 +24,7 @@ function getCallSequence(calls: FunctionCallsData): FunctionCallData[] {
|
|||||||
|
|
||||||
function parseFunctionCall(call: FunctionCallData): IFunctionCall {
|
function parseFunctionCall(call: FunctionCallData): IFunctionCall {
|
||||||
if (!call) {
|
if (!call) {
|
||||||
throw new Error('undefined function call');
|
throw new Error('missing call data');
|
||||||
}
|
}
|
||||||
const callArgs = parseArgs(call.parameters);
|
const callArgs = parseArgs(call.parameters);
|
||||||
return new FunctionCall(call.function, callArgs);
|
return new FunctionCall(call.function, callArgs);
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ export class FunctionParameterCollection implements IFunctionParameterCollection
|
|||||||
|
|
||||||
private ensureValidParameter(parameter: IFunctionParameter) {
|
private ensureValidParameter(parameter: IFunctionParameter) {
|
||||||
if (!parameter) {
|
if (!parameter) {
|
||||||
throw new Error('undefined parameter');
|
throw new Error('missing parameter');
|
||||||
}
|
}
|
||||||
if (this.includesName(parameter.name)) {
|
if (this.includesName(parameter.name)) {
|
||||||
throw new Error(`duplicate parameter name: "${parameter.name}"`);
|
throw new Error(`duplicate parameter name: "${parameter.name}"`);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
export function ensureValidParameterName(parameterName: string) {
|
export function ensureValidParameterName(parameterName: string) {
|
||||||
if (!parameterName) {
|
if (!parameterName) {
|
||||||
throw new Error('undefined parameter name');
|
throw new Error('missing parameter name');
|
||||||
}
|
}
|
||||||
if (!parameterName.match(/^[0-9a-zA-Z]+$/)) {
|
if (!parameterName.match(/^[0-9a-zA-Z]+$/)) {
|
||||||
throw new Error(`parameter name must be alphanumeric but it was "${parameterName}"`);
|
throw new Error(`parameter name must be alphanumeric but it was "${parameterName}"`);
|
||||||
|
|||||||
@@ -9,11 +9,8 @@ export function createCallerFunction(
|
|||||||
parameters: IReadOnlyFunctionParameterCollection,
|
parameters: IReadOnlyFunctionParameterCollection,
|
||||||
callSequence: readonly IFunctionCall[],
|
callSequence: readonly IFunctionCall[],
|
||||||
): ISharedFunction {
|
): ISharedFunction {
|
||||||
if (!callSequence) {
|
if (!callSequence || !callSequence.length) {
|
||||||
throw new Error(`undefined call sequence in function "${name}"`);
|
throw new Error(`missing call sequence in function "${name}"`);
|
||||||
}
|
|
||||||
if (!callSequence.length) {
|
|
||||||
throw new Error(`empty call sequence in function "${name}"`);
|
|
||||||
}
|
}
|
||||||
return new SharedFunction(name, parameters, callSequence, FunctionBodyType.Calls);
|
return new SharedFunction(name, parameters, callSequence, FunctionBodyType.Calls);
|
||||||
}
|
}
|
||||||
@@ -43,8 +40,8 @@ class SharedFunction implements ISharedFunction {
|
|||||||
content: IFunctionCode | readonly IFunctionCall[],
|
content: IFunctionCode | readonly IFunctionCall[],
|
||||||
bodyType: FunctionBodyType,
|
bodyType: FunctionBodyType,
|
||||||
) {
|
) {
|
||||||
if (!name) { throw new Error('undefined function name'); }
|
if (!name) { throw new Error('missing function name'); }
|
||||||
if (!parameters) { throw new Error('undefined parameters'); }
|
if (!parameters) { throw new Error('missing parameters'); }
|
||||||
this.body = {
|
this.body = {
|
||||||
type: bodyType,
|
type: bodyType,
|
||||||
code: bodyType === FunctionBodyType.Code ? content as IFunctionCode : undefined,
|
code: bodyType === FunctionBodyType.Code ? content as IFunctionCode : undefined,
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ export class SharedFunctionCollection implements ISharedFunctionCollection {
|
|||||||
private readonly functionsByName = new Map<string, ISharedFunction>();
|
private readonly functionsByName = new Map<string, ISharedFunction>();
|
||||||
|
|
||||||
public addFunction(func: ISharedFunction): void {
|
public addFunction(func: ISharedFunction): void {
|
||||||
if (!func) { throw new Error('undefined function'); }
|
if (!func) { throw new Error('missing function'); }
|
||||||
if (this.has(func.name)) {
|
if (this.has(func.name)) {
|
||||||
throw new Error(`function with name ${func.name} already exists`);
|
throw new Error(`function with name ${func.name} already exists`);
|
||||||
}
|
}
|
||||||
@@ -13,7 +13,7 @@ export class SharedFunctionCollection implements ISharedFunctionCollection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public getFunctionByName(name: string): ISharedFunction {
|
public getFunctionByName(name: string): ISharedFunction {
|
||||||
if (!name) { throw Error('undefined function name'); }
|
if (!name) { throw Error('missing function name'); }
|
||||||
const func = this.functionsByName.get(name);
|
const func = this.functionsByName.get(name);
|
||||||
if (!func) {
|
if (!func) {
|
||||||
throw new Error(`called function is not defined "${name}"`);
|
throw new Error(`called function is not defined "${name}"`);
|
||||||
|
|||||||
@@ -18,12 +18,12 @@ export class ScriptCompiler implements IScriptCompiler {
|
|||||||
private readonly callCompiler: IFunctionCallCompiler = FunctionCallCompiler.instance,
|
private readonly callCompiler: IFunctionCallCompiler = FunctionCallCompiler.instance,
|
||||||
sharedFunctionsParser: ISharedFunctionsParser = SharedFunctionsParser.instance,
|
sharedFunctionsParser: ISharedFunctionsParser = SharedFunctionsParser.instance,
|
||||||
) {
|
) {
|
||||||
if (!syntax) { throw new Error('undefined syntax'); }
|
if (!syntax) { throw new Error('missing syntax'); }
|
||||||
this.functions = sharedFunctionsParser.parseFunctions(functions);
|
this.functions = sharedFunctionsParser.parseFunctions(functions);
|
||||||
}
|
}
|
||||||
|
|
||||||
public canCompile(script: ScriptData): boolean {
|
public canCompile(script: ScriptData): boolean {
|
||||||
if (!script) { throw new Error('undefined script'); }
|
if (!script) { throw new Error('missing script'); }
|
||||||
if (!script.call) {
|
if (!script.call) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -31,7 +31,7 @@ export class ScriptCompiler implements IScriptCompiler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public compile(script: ScriptData): IScriptCode {
|
public compile(script: ScriptData): IScriptCode {
|
||||||
if (!script) { throw new Error('undefined script'); }
|
if (!script) { throw new Error('missing script'); }
|
||||||
try {
|
try {
|
||||||
const calls = parseFunctionCalls(script.call);
|
const calls = parseFunctionCalls(script.call);
|
||||||
const compiledCode = this.callCompiler.compileCall(calls, this.functions);
|
const compiledCode = this.callCompiler.compileCall(calls, this.functions);
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ export function parseScript(
|
|||||||
levelParser = createEnumParser(RecommendationLevel),
|
levelParser = createEnumParser(RecommendationLevel),
|
||||||
): Script {
|
): Script {
|
||||||
validateScript(data);
|
validateScript(data);
|
||||||
if (!context) { throw new Error('undefined context'); }
|
if (!context) { throw new Error('missing context'); }
|
||||||
const script = new Script(
|
const script = new Script(
|
||||||
/* name: */ data.name,
|
/* name: */ data.name,
|
||||||
/* code: */ parseCode(data, context),
|
/* code: */ parseCode(data, context),
|
||||||
@@ -51,7 +51,7 @@ function ensureNotBothCallAndCode(script: ScriptData) {
|
|||||||
|
|
||||||
function validateScript(script: ScriptData) {
|
function validateScript(script: ScriptData) {
|
||||||
if (!script) {
|
if (!script) {
|
||||||
throw new Error('undefined script');
|
throw new Error('missing script');
|
||||||
}
|
}
|
||||||
if (!script.code && !script.call) {
|
if (!script.code && !script.call) {
|
||||||
throw new Error('must define either "call" or "code"');
|
throw new Error('must define either "call" or "code"');
|
||||||
|
|||||||
@@ -16,8 +16,8 @@ export class CodeSubstituter implements ICodeSubstituter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public substitute(code: string, info: IProjectInformation): string {
|
public substitute(code: string, info: IProjectInformation): string {
|
||||||
if (!code) { throw new Error('undefined code'); }
|
if (!code) { throw new Error('missing code'); }
|
||||||
if (!info) { throw new Error('undefined info'); }
|
if (!info) { throw new Error('missing info'); }
|
||||||
const args = new FunctionCallArgumentCollection();
|
const args = new FunctionCallArgumentCollection();
|
||||||
const substitute = (name: string, value: string) => args
|
const substitute = (name: string, value: string) => args
|
||||||
.addArgument(new FunctionCallArgument(name, value));
|
.addArgument(new FunctionCallArgument(name, value));
|
||||||
|
|||||||
@@ -18,8 +18,8 @@ export class ScriptingDefinitionParser {
|
|||||||
definition: ScriptingDefinitionData,
|
definition: ScriptingDefinitionData,
|
||||||
info: IProjectInformation,
|
info: IProjectInformation,
|
||||||
): IScriptingDefinition {
|
): IScriptingDefinition {
|
||||||
if (!info) { throw new Error('undefined info'); }
|
if (!info) { throw new Error('missing info'); }
|
||||||
if (!definition) { throw new Error('undefined definition'); }
|
if (!definition) { throw new Error('missing definition'); }
|
||||||
const language = this.languageParser.parseEnum(definition.language, 'language');
|
const language = this.languageParser.parseEnum(definition.language, 'language');
|
||||||
const startCode = this.codeSubstituter.substitute(definition.startCode, info);
|
const startCode = this.codeSubstituter.substitute(definition.startCode, info);
|
||||||
const endCode = this.codeSubstituter.substitute(definition.endCode, info);
|
const endCode = this.codeSubstituter.substitute(definition.endCode, info);
|
||||||
|
|||||||
@@ -23,19 +23,16 @@ export class Application implements IApplication {
|
|||||||
|
|
||||||
function validateInformation(info: IProjectInformation) {
|
function validateInformation(info: IProjectInformation) {
|
||||||
if (!info) {
|
if (!info) {
|
||||||
throw new Error('undefined project information');
|
throw new Error('missing project information');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function validateCollections(collections: readonly ICategoryCollection[]) {
|
function validateCollections(collections: readonly ICategoryCollection[]) {
|
||||||
if (!collections) {
|
if (!collections || !collections.length) {
|
||||||
throw new Error('undefined collections');
|
throw new Error('missing collections');
|
||||||
}
|
|
||||||
if (collections.length === 0) {
|
|
||||||
throw new Error('no collection in the list');
|
|
||||||
}
|
}
|
||||||
if (collections.filter((c) => !c).length > 0) {
|
if (collections.filter((c) => !c).length > 0) {
|
||||||
throw new Error('undefined collection in the list');
|
throw new Error('missing collection in the list');
|
||||||
}
|
}
|
||||||
const osList = collections.map((c) => c.os);
|
const osList = collections.map((c) => c.os);
|
||||||
const duplicates = getDuplicates(osList);
|
const duplicates = getDuplicates(osList);
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ function parseScriptsRecursively(category: ICategory): ReadonlyArray<IScript> {
|
|||||||
|
|
||||||
function validateCategory(category: ICategory) {
|
function validateCategory(category: ICategory) {
|
||||||
if (!category.name) {
|
if (!category.name) {
|
||||||
throw new Error('undefined or empty name');
|
throw new Error('missing name');
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
(!category.subCategories || category.subCategories.length === 0)
|
(!category.subCategories || category.subCategories.length === 0)
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ export class CategoryCollection implements ICategoryCollection {
|
|||||||
public readonly scripting: IScriptingDefinition,
|
public readonly scripting: IScriptingDefinition,
|
||||||
) {
|
) {
|
||||||
if (!scripting) {
|
if (!scripting) {
|
||||||
throw new Error('undefined scripting definition');
|
throw new Error('missing scripting definition');
|
||||||
}
|
}
|
||||||
this.queryable = makeQueryable(actions);
|
this.queryable = makeQueryable(actions);
|
||||||
assertInRange(os, OperatingSystem);
|
assertInRange(os, OperatingSystem);
|
||||||
@@ -34,12 +34,7 @@ export class CategoryCollection implements ICategoryCollection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public getScriptsByLevel(level: RecommendationLevel): readonly IScript[] {
|
public getScriptsByLevel(level: RecommendationLevel): readonly IScript[] {
|
||||||
if (level === undefined) {
|
assertInRange(level, RecommendationLevel);
|
||||||
throw new Error('undefined level');
|
|
||||||
}
|
|
||||||
if (!(level in RecommendationLevel)) {
|
|
||||||
throw new Error(`invalid level: ${level}`);
|
|
||||||
}
|
|
||||||
return this.queryable.scriptsByLevel.get(level);
|
return this.queryable.scriptsByLevel.get(level);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ export class Script extends BaseEntity<string> implements IScript {
|
|||||||
) {
|
) {
|
||||||
super(name);
|
super(name);
|
||||||
if (!code) {
|
if (!code) {
|
||||||
throw new Error(`undefined code (script: ${name})`);
|
throw new Error(`missing code (script: ${name})`);
|
||||||
}
|
}
|
||||||
validateLevel(level);
|
validateLevel(level);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ export class ScriptCode implements IScriptCode {
|
|||||||
public readonly revert: string,
|
public readonly revert: string,
|
||||||
syntax: ILanguageSyntax,
|
syntax: ILanguageSyntax,
|
||||||
) {
|
) {
|
||||||
if (!syntax) { throw new Error('undefined syntax'); }
|
if (!syntax) { throw new Error('missing syntax'); }
|
||||||
validateCode(execute, syntax);
|
validateCode(execute, syntax);
|
||||||
validateRevertCode(revert, execute, syntax);
|
validateRevertCode(revert, execute, syntax);
|
||||||
}
|
}
|
||||||
@@ -33,7 +33,7 @@ function validateRevertCode(revertCode: string, execute: string, syntax: ILangua
|
|||||||
|
|
||||||
function validateCode(code: string, syntax: ILanguageSyntax): void {
|
function validateCode(code: string, syntax: ILanguageSyntax): void {
|
||||||
if (!code || code.length === 0) {
|
if (!code || code.length === 0) {
|
||||||
throw new Error('code is empty or undefined');
|
throw new Error('missing code');
|
||||||
}
|
}
|
||||||
ensureNoEmptyLines(code);
|
ensureNoEmptyLines(code);
|
||||||
ensureCodeHasUniqueLines(code, syntax);
|
ensureCodeHasUniqueLines(code, syntax);
|
||||||
|
|||||||
@@ -28,6 +28,6 @@ function findExtension(language: ScriptingLanguage): string {
|
|||||||
|
|
||||||
function validateCode(code: string, name: string) {
|
function validateCode(code: string, name: string) {
|
||||||
if (!code) {
|
if (!code) {
|
||||||
throw new Error(`undefined ${name}`);
|
throw new Error(`missing ${name}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ function getExecuteCommand(scriptPath: string, environment: Environment): string
|
|||||||
case OperatingSystem.Windows:
|
case OperatingSystem.Windows:
|
||||||
return scriptPath;
|
return scriptPath;
|
||||||
default:
|
default:
|
||||||
throw Error('undefined os');
|
throw Error(`unsupported os: ${OperatingSystem[environment.os]}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ implements IRepository<TKey, TEntity> {
|
|||||||
|
|
||||||
public addItem(item: TEntity): void {
|
public addItem(item: TEntity): void {
|
||||||
if (!item) {
|
if (!item) {
|
||||||
throw new Error('item is null or undefined');
|
throw new Error('missing item');
|
||||||
}
|
}
|
||||||
if (this.exists(item.id)) {
|
if (this.exists(item.id)) {
|
||||||
throw new Error(`Cannot add (id: ${item.id}) as it is already exists`);
|
throw new Error(`Cannot add (id: ${item.id}) as it is already exists`);
|
||||||
@@ -37,7 +37,7 @@ implements IRepository<TKey, TEntity> {
|
|||||||
|
|
||||||
public addOrUpdateItem(item: TEntity): void {
|
public addOrUpdateItem(item: TEntity): void {
|
||||||
if (!item) {
|
if (!item) {
|
||||||
throw new Error('item is null or undefined');
|
throw new Error('missing item');
|
||||||
}
|
}
|
||||||
if (this.exists(item.id)) {
|
if (this.exists(item.id)) {
|
||||||
this.removeItem(item.id);
|
this.removeItem(item.id);
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ export enum SelectionType {
|
|||||||
|
|
||||||
export class SelectionTypeHandler {
|
export class SelectionTypeHandler {
|
||||||
constructor(private readonly state: ICategoryCollectionState) {
|
constructor(private readonly state: ICategoryCollectionState) {
|
||||||
if (!state) { throw new Error('undefined state'); }
|
if (!state) { throw new Error('missing state'); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public selectType(type: SelectionType) {
|
public selectType(type: SelectionType) {
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ export default class SelectableTree extends Vue { // Stateless to make it easier
|
|||||||
@Watch('initialNodes', { immediate: true })
|
@Watch('initialNodes', { immediate: true })
|
||||||
public async updateNodes(nodes: readonly INode[]) {
|
public async updateNodes(nodes: readonly INode[]) {
|
||||||
if (!nodes) {
|
if (!nodes) {
|
||||||
throw new Error('undefined initial nodes');
|
throw new Error('missing initial nodes');
|
||||||
}
|
}
|
||||||
const initialNodes = nodes.map((node) => toNewLiquorTreeNode(node));
|
const initialNodes = nodes.map((node) => toNewLiquorTreeNode(node));
|
||||||
if (this.selectedNodeIds) {
|
if (this.selectedNodeIds) {
|
||||||
|
|||||||
@@ -38,10 +38,10 @@ class Throttler implements IThrottler {
|
|||||||
private readonly waitInMs: number,
|
private readonly waitInMs: number,
|
||||||
private readonly callback: CallbackType,
|
private readonly callback: CallbackType,
|
||||||
) {
|
) {
|
||||||
if (!timer) { throw new Error('undefined timer'); }
|
if (!timer) { throw new Error('missing timer'); }
|
||||||
if (!waitInMs) { throw new Error('no delay to throttle'); }
|
if (!waitInMs) { throw new Error('missing delay'); }
|
||||||
if (waitInMs < 0) { throw new Error('negative delay'); }
|
if (waitInMs < 0) { throw new Error('negative delay'); }
|
||||||
if (!callback) { throw new Error('undefined callback'); }
|
if (!callback) { throw new Error('missing callback'); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public invoke(...args: unknown[]): void {
|
public invoke(...args: unknown[]): void {
|
||||||
|
|||||||
@@ -2,17 +2,20 @@ import 'mocha';
|
|||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
import { ApplicationFactory, ApplicationGetterType } from '@/application/ApplicationFactory';
|
import { ApplicationFactory, ApplicationGetterType } from '@/application/ApplicationFactory';
|
||||||
import { ApplicationStub } from '@tests/unit/stubs/ApplicationStub';
|
import { ApplicationStub } from '@tests/unit/stubs/ApplicationStub';
|
||||||
|
import { itEachAbsentObjectValue } from '@tests/unit/shared/TestCases/AbsentTests';
|
||||||
|
|
||||||
describe('ApplicationFactory', () => {
|
describe('ApplicationFactory', () => {
|
||||||
describe('ctor', () => {
|
describe('ctor', () => {
|
||||||
it('throws if getter is undefined', () => {
|
describe('throws if getter is absent', () => {
|
||||||
// arrange
|
itEachAbsentObjectValue((absentValue) => {
|
||||||
const expectedError = 'undefined getter';
|
// arrange
|
||||||
const getter = undefined;
|
const expectedError = 'missing getter';
|
||||||
// act
|
const getter: ApplicationGetterType = absentValue;
|
||||||
const act = () => new SystemUnderTest(getter);
|
// act
|
||||||
// assert
|
const act = () => new SystemUnderTest(getter);
|
||||||
expect(act).to.throw(expectedError);
|
// assert
|
||||||
|
expect(act).to.throw(expectedError);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('getApp', () => {
|
describe('getApp', () => {
|
||||||
|
|||||||
@@ -1,20 +1,35 @@
|
|||||||
import 'mocha';
|
import 'mocha';
|
||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
import { scrambledEqual, sequenceEqual } from '@/application/Common/Array';
|
import { scrambledEqual, sequenceEqual } from '@/application/Common/Array';
|
||||||
|
import { itEachAbsentObjectValue } from '@tests/unit/shared/TestCases/AbsentTests';
|
||||||
import { ComparerTestScenario } from './Array.ComparerTestScenario';
|
import { ComparerTestScenario } from './Array.ComparerTestScenario';
|
||||||
|
|
||||||
describe('Array', () => {
|
describe('Array', () => {
|
||||||
describe('scrambledEqual', () => {
|
describe('scrambledEqual', () => {
|
||||||
describe('throws if arguments are undefined', () => {
|
describe('throws if arguments are absent', () => {
|
||||||
it('first argument is undefined', () => {
|
describe('first argument is absent', () => {
|
||||||
const expectedError = 'undefined first array';
|
itEachAbsentObjectValue((absentValue) => {
|
||||||
const act = () => scrambledEqual(undefined, []);
|
// arrange
|
||||||
expect(act).to.throw(expectedError);
|
const expectedError = 'missing first array';
|
||||||
|
const firstArray = absentValue;
|
||||||
|
const secondArray = [];
|
||||||
|
// act
|
||||||
|
const act = () => scrambledEqual(firstArray, secondArray);
|
||||||
|
// assert
|
||||||
|
expect(act).to.throw(expectedError);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
it('second arguments is undefined', () => {
|
describe('second argument is absent', () => {
|
||||||
const expectedError = 'undefined second array';
|
itEachAbsentObjectValue((absentValue) => {
|
||||||
const act = () => scrambledEqual([], undefined);
|
// arrange
|
||||||
expect(act).to.throw(expectedError);
|
const expectedError = 'missing second array';
|
||||||
|
const firstArray = [];
|
||||||
|
const secondArray = absentValue;
|
||||||
|
// act
|
||||||
|
const act = () => scrambledEqual(firstArray, secondArray);
|
||||||
|
// assert
|
||||||
|
expect(act).to.throw(expectedError);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('returns as expected', () => {
|
describe('returns as expected', () => {
|
||||||
@@ -35,16 +50,30 @@ describe('Array', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('sequenceEqual', () => {
|
describe('sequenceEqual', () => {
|
||||||
describe('throws if arguments are undefined', () => {
|
describe('throws if arguments are absent', () => {
|
||||||
it('first argument is undefined', () => {
|
describe('first argument is absent', () => {
|
||||||
const expectedError = 'undefined first array';
|
itEachAbsentObjectValue((absentValue) => {
|
||||||
const act = () => sequenceEqual(undefined, []);
|
// arrange
|
||||||
expect(act).to.throw(expectedError);
|
const expectedError = 'missing first array';
|
||||||
|
const firstArray = absentValue;
|
||||||
|
const secondArray = [];
|
||||||
|
// act
|
||||||
|
const act = () => sequenceEqual(firstArray, secondArray);
|
||||||
|
// assert
|
||||||
|
expect(act).to.throw(expectedError);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
it('second arguments is undefined', () => {
|
describe('second argument is absent', () => {
|
||||||
const expectedError = 'undefined second array';
|
itEachAbsentObjectValue((absentValue) => {
|
||||||
const act = () => sequenceEqual([], undefined);
|
// arrange
|
||||||
expect(act).to.throw(expectedError);
|
const expectedError = 'missing second array';
|
||||||
|
const firstArray = [];
|
||||||
|
const secondArray = absentValue;
|
||||||
|
// act
|
||||||
|
const act = () => sequenceEqual(firstArray, secondArray);
|
||||||
|
// assert
|
||||||
|
expect(act).to.throw(expectedError);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('returns as expected', () => {
|
describe('returns as expected', () => {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import {
|
|||||||
getEnumNames, getEnumValues, createEnumParser, assertInRange,
|
getEnumNames, getEnumValues, createEnumParser, assertInRange,
|
||||||
} from '@/application/Common/Enum';
|
} from '@/application/Common/Enum';
|
||||||
import { scrambledEqual } from '@/application/Common/Array';
|
import { scrambledEqual } from '@/application/Common/Array';
|
||||||
|
import { AbsentStringTestCases } from '@tests/unit/shared/TestCases/AbsentTests';
|
||||||
import { EnumRangeTestRunner } from './EnumRangeTestRunner';
|
import { EnumRangeTestRunner } from './EnumRangeTestRunner';
|
||||||
|
|
||||||
describe('Enum', () => {
|
describe('Enum', () => {
|
||||||
@@ -37,16 +38,11 @@ describe('Enum', () => {
|
|||||||
// arrange
|
// arrange
|
||||||
const enumName = 'ParsableEnum';
|
const enumName = 'ParsableEnum';
|
||||||
const testCases = [
|
const testCases = [
|
||||||
{
|
...AbsentStringTestCases.map((test) => ({
|
||||||
name: 'undefined',
|
name: test.valueName,
|
||||||
value: undefined,
|
value: test.absentValue,
|
||||||
expectedError: `undefined ${enumName}`,
|
expectedError: `missing ${enumName}`,
|
||||||
},
|
})),
|
||||||
{
|
|
||||||
name: 'empty',
|
|
||||||
value: '',
|
|
||||||
expectedError: `undefined ${enumName}`,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name: 'out of range',
|
name: 'out of range',
|
||||||
value: 'value3',
|
value: 'value3',
|
||||||
@@ -105,7 +101,7 @@ describe('Enum', () => {
|
|||||||
// assert
|
// assert
|
||||||
new EnumRangeTestRunner(act)
|
new EnumRangeTestRunner(act)
|
||||||
.testOutOfRangeThrows()
|
.testOutOfRangeThrows()
|
||||||
.testUndefinedValueThrows()
|
.testAbsentValueThrows()
|
||||||
.testValidValueDoesNotThrow(validValue);
|
.testValidValueDoesNotThrow(validValue);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import 'mocha';
|
import 'mocha';
|
||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
import { EnumType } from '@/application/Common/Enum';
|
import { EnumType } from '@/application/Common/Enum';
|
||||||
|
import { itEachAbsentObjectValue } from '@tests/unit/shared/TestCases/AbsentTests';
|
||||||
|
|
||||||
export class EnumRangeTestRunner<TEnumValue extends EnumType> {
|
export class EnumRangeTestRunner<TEnumValue extends EnumType> {
|
||||||
constructor(private readonly runner: (value: TEnumValue) => void) {
|
constructor(private readonly runner: (value: TEnumValue) => void) {
|
||||||
@@ -19,15 +20,17 @@ export class EnumRangeTestRunner<TEnumValue extends EnumType> {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public testUndefinedValueThrows() {
|
public testAbsentValueThrows() {
|
||||||
it('throws when value is undefined', () => {
|
describe('throws when value is absent', () => {
|
||||||
// arrange
|
itEachAbsentObjectValue((absentValue) => {
|
||||||
const value = undefined;
|
// arrange
|
||||||
const expectedError = 'undefined enum value';
|
const value = absentValue;
|
||||||
// act
|
const expectedError = 'absent enum value';
|
||||||
const act = () => this.runner(value);
|
// act
|
||||||
// assert
|
const act = () => this.runner(value);
|
||||||
expect(act).to.throw(expectedError);
|
// assert
|
||||||
|
expect(act).to.throw(expectedError);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -45,7 +48,7 @@ export class EnumRangeTestRunner<TEnumValue extends EnumType> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public testValidValueDoesNotThrow(validValue: TEnumValue) {
|
public testValidValueDoesNotThrow(validValue: TEnumValue) {
|
||||||
it('throws when value is undefined', () => {
|
it('does not throw with valid value', () => {
|
||||||
// arrange
|
// arrange
|
||||||
const value = validValue;
|
const value = validValue;
|
||||||
// act
|
// act
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { expect } from 'chai';
|
|||||||
import { ScriptingLanguage } from '@/domain/ScriptingLanguage';
|
import { ScriptingLanguage } from '@/domain/ScriptingLanguage';
|
||||||
import { ScriptingLanguageFactory } from '@/application/Common/ScriptingLanguage/ScriptingLanguageFactory';
|
import { ScriptingLanguageFactory } from '@/application/Common/ScriptingLanguage/ScriptingLanguageFactory';
|
||||||
import { EnumRangeTestRunner } from '@tests/unit/application/Common/EnumRangeTestRunner';
|
import { EnumRangeTestRunner } from '@tests/unit/application/Common/EnumRangeTestRunner';
|
||||||
|
import { itEachAbsentObjectValue } from '@tests/unit/shared/TestCases/AbsentTests';
|
||||||
import { ScriptingLanguageFactoryTestRunner } from './ScriptingLanguageFactoryTestRunner';
|
import { ScriptingLanguageFactoryTestRunner } from './ScriptingLanguageFactoryTestRunner';
|
||||||
|
|
||||||
class ScriptingLanguageConcrete extends ScriptingLanguageFactory<number> {
|
class ScriptingLanguageConcrete extends ScriptingLanguageFactory<number> {
|
||||||
@@ -16,32 +17,34 @@ describe('ScriptingLanguageFactory', () => {
|
|||||||
describe('validates language', () => {
|
describe('validates language', () => {
|
||||||
// arrange
|
// arrange
|
||||||
const validValue = ScriptingLanguage.batchfile;
|
const validValue = ScriptingLanguage.batchfile;
|
||||||
const getter = () => undefined;
|
const getter = () => 1;
|
||||||
const sut = new ScriptingLanguageConcrete();
|
const sut = new ScriptingLanguageConcrete();
|
||||||
// act
|
// act
|
||||||
const act = (language: ScriptingLanguage) => sut.registerGetter(language, getter);
|
const act = (language: ScriptingLanguage) => sut.registerGetter(language, getter);
|
||||||
// assert
|
// assert
|
||||||
new EnumRangeTestRunner(act)
|
new EnumRangeTestRunner(act)
|
||||||
.testOutOfRangeThrows()
|
.testOutOfRangeThrows()
|
||||||
.testUndefinedValueThrows()
|
.testAbsentValueThrows()
|
||||||
.testValidValueDoesNotThrow(validValue);
|
.testValidValueDoesNotThrow(validValue);
|
||||||
});
|
});
|
||||||
it('throw when getter is undefined', () => {
|
describe('describe when getter is absent', () => {
|
||||||
// arrange
|
itEachAbsentObjectValue((absentValue) => {
|
||||||
const expectedError = 'undefined getter';
|
// arrange
|
||||||
const language = ScriptingLanguage.batchfile;
|
const expectedError = 'missing getter';
|
||||||
const getter = undefined;
|
const language = ScriptingLanguage.batchfile;
|
||||||
const sut = new ScriptingLanguageConcrete();
|
const getter = absentValue;
|
||||||
// act
|
const sut = new ScriptingLanguageConcrete();
|
||||||
const act = () => sut.registerGetter(language, getter);
|
// act
|
||||||
// assert
|
const act = () => sut.registerGetter(language, getter);
|
||||||
expect(act).to.throw(expectedError);
|
// assert
|
||||||
|
expect(act).to.throw(expectedError);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
it('throw when language is already registered', () => {
|
it('throw when language is already registered', () => {
|
||||||
// arrange
|
// arrange
|
||||||
const language = ScriptingLanguage.batchfile;
|
const language = ScriptingLanguage.batchfile;
|
||||||
const expectedError = `${ScriptingLanguage[language]} is already registered`;
|
const expectedError = `${ScriptingLanguage[language]} is already registered`;
|
||||||
const getter = () => undefined;
|
const getter = () => 1;
|
||||||
const sut = new ScriptingLanguageConcrete();
|
const sut = new ScriptingLanguageConcrete();
|
||||||
// act
|
// act
|
||||||
sut.registerGetter(language, getter);
|
sut.registerGetter(language, getter);
|
||||||
@@ -51,9 +54,12 @@ describe('ScriptingLanguageFactory', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('create', () => {
|
describe('create', () => {
|
||||||
|
// arrange
|
||||||
const sut = new ScriptingLanguageConcrete();
|
const sut = new ScriptingLanguageConcrete();
|
||||||
sut.registerGetter(ScriptingLanguage.batchfile, () => undefined);
|
|
||||||
const runner = new ScriptingLanguageFactoryTestRunner();
|
const runner = new ScriptingLanguageFactoryTestRunner();
|
||||||
|
// act
|
||||||
|
sut.registerGetter(ScriptingLanguage.batchfile, () => 1);
|
||||||
|
// assert
|
||||||
runner.testCreateMethod(sut);
|
runner.testCreateMethod(sut);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ export class ScriptingLanguageFactoryTestRunner<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public testCreateMethod(sut: IScriptingLanguageFactory<T>) {
|
public testCreateMethod(sut: IScriptingLanguageFactory<T>) {
|
||||||
if (!sut) { throw new Error('undefined sut'); }
|
if (!sut) { throw new Error('missing sut'); }
|
||||||
testLanguageValidation(sut);
|
testLanguageValidation(sut);
|
||||||
testExpectedInstanceTypes(sut, this.expectedTypes);
|
testExpectedInstanceTypes(sut, this.expectedTypes);
|
||||||
}
|
}
|
||||||
@@ -46,7 +46,7 @@ function testLanguageValidation<T>(sut: IScriptingLanguageFactory<T>) {
|
|||||||
// assert
|
// assert
|
||||||
new EnumRangeTestRunner(act)
|
new EnumRangeTestRunner(act)
|
||||||
.testOutOfRangeThrows()
|
.testOutOfRangeThrows()
|
||||||
.testUndefinedValueThrows()
|
.testAbsentValueThrows()
|
||||||
.testValidValueDoesNotThrow(validValue);
|
.testValidValueDoesNotThrow(validValue);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import { IApplication } from '@/domain/IApplication';
|
|||||||
import { ApplicationStub } from '@tests/unit/stubs/ApplicationStub';
|
import { ApplicationStub } from '@tests/unit/stubs/ApplicationStub';
|
||||||
import { CategoryCollectionStub } from '@tests/unit/stubs/CategoryCollectionStub';
|
import { CategoryCollectionStub } from '@tests/unit/stubs/CategoryCollectionStub';
|
||||||
import { EnumRangeTestRunner } from '@tests/unit/application/Common/EnumRangeTestRunner';
|
import { EnumRangeTestRunner } from '@tests/unit/application/Common/EnumRangeTestRunner';
|
||||||
|
import { itEachAbsentObjectValue } from '@tests/unit/shared/TestCases/AbsentTests';
|
||||||
|
|
||||||
describe('ApplicationContext', () => {
|
describe('ApplicationContext', () => {
|
||||||
describe('changeContext', () => {
|
describe('changeContext', () => {
|
||||||
@@ -125,18 +126,33 @@ describe('ApplicationContext', () => {
|
|||||||
expect(duplicates.length).to.be.equal(0);
|
expect(duplicates.length).to.be.equal(0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
describe('throws with invalid os', () => {
|
||||||
|
new EnumRangeTestRunner((os: OperatingSystem) => {
|
||||||
|
// arrange
|
||||||
|
const sut = new ObservableApplicationContextFactory()
|
||||||
|
.construct();
|
||||||
|
// act
|
||||||
|
sut.changeContext(os);
|
||||||
|
})
|
||||||
|
// assert
|
||||||
|
.testOutOfRangeThrows()
|
||||||
|
.testAbsentValueThrows()
|
||||||
|
.testInvalidValueThrows(OperatingSystem.Android, 'os "Android" is not defined in application');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
describe('ctor', () => {
|
describe('ctor', () => {
|
||||||
describe('app', () => {
|
describe('app', () => {
|
||||||
it('throw when app is undefined', () => {
|
describe('throw when app is missing', () => {
|
||||||
// arrange
|
itEachAbsentObjectValue((absentValue) => {
|
||||||
const expectedError = 'undefined app';
|
// arrange
|
||||||
const app = undefined;
|
const expectedError = 'missing app';
|
||||||
const os = OperatingSystem.Windows;
|
const app = absentValue;
|
||||||
// act
|
const os = OperatingSystem.Windows;
|
||||||
const act = () => new ApplicationContext(app, os);
|
// act
|
||||||
// assert
|
const act = () => new ApplicationContext(app, os);
|
||||||
expect(act).to.throw(expectedError);
|
// assert
|
||||||
|
expect(act).to.throw(expectedError);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('collection', () => {
|
describe('collection', () => {
|
||||||
@@ -188,7 +204,7 @@ describe('ApplicationContext', () => {
|
|||||||
// assert
|
// assert
|
||||||
new EnumRangeTestRunner(act)
|
new EnumRangeTestRunner(act)
|
||||||
.testOutOfRangeThrows()
|
.testOutOfRangeThrows()
|
||||||
.testUndefinedValueThrows()
|
.testAbsentValueThrows()
|
||||||
.testInvalidValueThrows(OperatingSystem.Android, 'os "Android" is not defined in application');
|
.testInvalidValueThrows(OperatingSystem.Android, 'os "Android" is not defined in application');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import { IApplication } from '@/domain/IApplication';
|
|||||||
import { EnvironmentStub } from '@tests/unit/stubs/EnvironmentStub';
|
import { EnvironmentStub } from '@tests/unit/stubs/EnvironmentStub';
|
||||||
import { ApplicationStub } from '@tests/unit/stubs/ApplicationStub';
|
import { ApplicationStub } from '@tests/unit/stubs/ApplicationStub';
|
||||||
import { CategoryCollectionStub } from '@tests/unit/stubs/CategoryCollectionStub';
|
import { CategoryCollectionStub } from '@tests/unit/stubs/CategoryCollectionStub';
|
||||||
|
import { expectThrowsAsync } from '@tests/unit/shared/Assertions/ExpectThrowsAsync';
|
||||||
|
|
||||||
describe('ApplicationContextFactory', () => {
|
describe('ApplicationContextFactory', () => {
|
||||||
describe('buildContext', () => {
|
describe('buildContext', () => {
|
||||||
@@ -23,6 +24,15 @@ describe('ApplicationContextFactory', () => {
|
|||||||
// assert
|
// assert
|
||||||
expect(expected).to.equal(context.app);
|
expect(expected).to.equal(context.app);
|
||||||
});
|
});
|
||||||
|
it('throws when null', async () => {
|
||||||
|
// arrange
|
||||||
|
const expectedError = 'missing factory';
|
||||||
|
const factory = null;
|
||||||
|
// act
|
||||||
|
const act = async () => { await buildContext(factory); };
|
||||||
|
// assert
|
||||||
|
expectThrowsAsync(act, expectedError);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
describe('environment', () => {
|
describe('environment', () => {
|
||||||
describe('sets initial OS as expected', () => {
|
describe('sets initial OS as expected', () => {
|
||||||
@@ -69,6 +79,16 @@ describe('ApplicationContextFactory', () => {
|
|||||||
expect(expectedOs).to.equal(actual, `Expected: ${OperatingSystem[expectedOs]}, actual: ${OperatingSystem[actual]}`);
|
expect(expectedOs).to.equal(actual, `Expected: ${OperatingSystem[expectedOs]}, actual: ${OperatingSystem[actual]}`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
it('throws when null', async () => {
|
||||||
|
// arrange
|
||||||
|
const expectedError = 'missing environment';
|
||||||
|
const factory = mockFactoryWithApp(undefined);
|
||||||
|
const environment = null;
|
||||||
|
// act
|
||||||
|
const act = async () => { await buildContext(factory, environment); };
|
||||||
|
// assert
|
||||||
|
expectThrowsAsync(act, expectedError);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ import { ScriptingDefinitionStub } from '@tests/unit/stubs/ScriptingDefinitionSt
|
|||||||
import { CategoryStub } from '@tests/unit/stubs/CategoryStub';
|
import { CategoryStub } from '@tests/unit/stubs/CategoryStub';
|
||||||
import { ScriptStub } from '@tests/unit/stubs/ScriptStub';
|
import { ScriptStub } from '@tests/unit/stubs/ScriptStub';
|
||||||
import { CategoryCollectionStub } from '@tests/unit/stubs/CategoryCollectionStub';
|
import { CategoryCollectionStub } from '@tests/unit/stubs/CategoryCollectionStub';
|
||||||
|
import { itEachAbsentObjectValue } from '@tests/unit/shared/TestCases/AbsentTests';
|
||||||
|
import { UserSelectionStub } from '@tests/unit/stubs/UserSelectionStub';
|
||||||
|
|
||||||
describe('ApplicationCode', () => {
|
describe('ApplicationCode', () => {
|
||||||
describe('ctor', () => {
|
describe('ctor', () => {
|
||||||
@@ -46,6 +48,41 @@ describe('ApplicationCode', () => {
|
|||||||
// assert
|
// assert
|
||||||
expect(actual).to.equal(expected.code);
|
expect(actual).to.equal(expected.code);
|
||||||
});
|
});
|
||||||
|
describe('throws when userSelection is missing', () => {
|
||||||
|
itEachAbsentObjectValue((absentValue) => {
|
||||||
|
// arrange
|
||||||
|
const expectedError = 'missing userSelection';
|
||||||
|
const userSelection = absentValue;
|
||||||
|
const definition = new ScriptingDefinitionStub();
|
||||||
|
// act
|
||||||
|
const act = () => new ApplicationCode(userSelection, definition);
|
||||||
|
// assert
|
||||||
|
expect(act).to.throw(expectedError);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe('throws when scriptingDefinition is missing', () => {
|
||||||
|
itEachAbsentObjectValue((absentValue) => {
|
||||||
|
// arrange
|
||||||
|
const expectedError = 'missing scriptingDefinition';
|
||||||
|
const userSelection = new UserSelectionStub([]);
|
||||||
|
const definition = absentValue;
|
||||||
|
// act
|
||||||
|
const act = () => new ApplicationCode(userSelection, definition);
|
||||||
|
// assert
|
||||||
|
expect(act).to.throw(expectedError);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('throws when generator is missing', () => {
|
||||||
|
// arrange
|
||||||
|
const expectedError = 'missing generator';
|
||||||
|
const userSelection = new UserSelectionStub([]);
|
||||||
|
const definition = new ScriptingDefinitionStub();
|
||||||
|
const generator = null;
|
||||||
|
// act
|
||||||
|
const act = () => new ApplicationCode(userSelection, definition, generator);
|
||||||
|
// assert
|
||||||
|
expect(act).to.throw(expectedError);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
describe('changed event', () => {
|
describe('changed event', () => {
|
||||||
describe('code', () => {
|
describe('code', () => {
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import { ICodeBuilderFactory } from '@/application/Context/State/Code/Generation
|
|||||||
import { ICodeBuilder } from '@/application/Context/State/Code/Generation/ICodeBuilder';
|
import { ICodeBuilder } from '@/application/Context/State/Code/Generation/ICodeBuilder';
|
||||||
import { ScriptStub } from '@tests/unit/stubs/ScriptStub';
|
import { ScriptStub } from '@tests/unit/stubs/ScriptStub';
|
||||||
import { ScriptingDefinitionStub } from '@tests/unit/stubs/ScriptingDefinitionStub';
|
import { ScriptingDefinitionStub } from '@tests/unit/stubs/ScriptingDefinitionStub';
|
||||||
|
import { itEachAbsentObjectValue, itEachAbsentStringValue } from '@tests/unit/shared/TestCases/AbsentTests';
|
||||||
|
import { SelectedScriptStub } from '@tests/unit/stubs/SelectedScriptStub';
|
||||||
|
|
||||||
describe('UserScriptGenerator', () => {
|
describe('UserScriptGenerator', () => {
|
||||||
describe('scriptingDefinition', () => {
|
describe('scriptingDefinition', () => {
|
||||||
@@ -18,8 +20,7 @@ describe('UserScriptGenerator', () => {
|
|||||||
.withCode('code\nmulti-lined')
|
.withCode('code\nmulti-lined')
|
||||||
.toSelectedScript();
|
.toSelectedScript();
|
||||||
const definition = new ScriptingDefinitionStub()
|
const definition = new ScriptingDefinitionStub()
|
||||||
.withStartCode(startCode)
|
.withStartCode(startCode);
|
||||||
.withEndCode(undefined);
|
|
||||||
const expectedStart = `${startCode}\n`;
|
const expectedStart = `${startCode}\n`;
|
||||||
// act
|
// act
|
||||||
const code = sut.buildCode([script], definition);
|
const code = sut.buildCode([script], definition);
|
||||||
@@ -27,24 +28,25 @@ describe('UserScriptGenerator', () => {
|
|||||||
const actual = code.code;
|
const actual = code.code;
|
||||||
expect(actual.startsWith(expectedStart));
|
expect(actual.startsWith(expectedStart));
|
||||||
});
|
});
|
||||||
it('is not prepended if empty', () => {
|
describe('is not prepended if empty', () => {
|
||||||
// arrange
|
itEachAbsentStringValue((absentValue) => {
|
||||||
const codeBuilderStub = new CodeBuilderStub();
|
// arrange
|
||||||
const sut = new UserScriptGenerator(mockCodeBuilderFactory(codeBuilderStub));
|
const codeBuilderStub = new CodeBuilderStub();
|
||||||
const script = new ScriptStub('id')
|
const sut = new UserScriptGenerator(mockCodeBuilderFactory(codeBuilderStub));
|
||||||
.withCode('code\nmulti-lined')
|
const script = new ScriptStub('id')
|
||||||
.toSelectedScript();
|
.withCode('code\nmulti-lined')
|
||||||
const definition = new ScriptingDefinitionStub()
|
.toSelectedScript();
|
||||||
.withStartCode(undefined)
|
const definition = new ScriptingDefinitionStub()
|
||||||
.withEndCode(undefined);
|
.withStartCode(absentValue);
|
||||||
const expectedStart = codeBuilderStub
|
const expectedStart = codeBuilderStub
|
||||||
.appendFunction(script.script.name, script.script.code.execute)
|
.appendFunction(script.script.name, script.script.code.execute)
|
||||||
.toString();
|
.toString();
|
||||||
// act
|
// act
|
||||||
const code = sut.buildCode([script], definition);
|
const code = sut.buildCode([script], definition);
|
||||||
// assert
|
// assert
|
||||||
const actual = code.code;
|
const actual = code.code;
|
||||||
expect(actual.startsWith(expectedStart));
|
expect(actual.startsWith(expectedStart));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('endCode', () => {
|
describe('endCode', () => {
|
||||||
@@ -64,23 +66,38 @@ describe('UserScriptGenerator', () => {
|
|||||||
const actual = code.code;
|
const actual = code.code;
|
||||||
expect(actual.endsWith(expectedEnd));
|
expect(actual.endsWith(expectedEnd));
|
||||||
});
|
});
|
||||||
it('is not appended if empty', () => {
|
describe('is not appended if empty', () => {
|
||||||
|
itEachAbsentStringValue((absentValue) => {
|
||||||
|
// arrange
|
||||||
|
const codeBuilderStub = new CodeBuilderStub();
|
||||||
|
const sut = new UserScriptGenerator(mockCodeBuilderFactory(codeBuilderStub));
|
||||||
|
const script = new ScriptStub('id')
|
||||||
|
.withCode('code\nmulti-lined')
|
||||||
|
.toSelectedScript();
|
||||||
|
const expectedEnd = codeBuilderStub
|
||||||
|
.appendFunction(script.script.name, script.script.code.execute)
|
||||||
|
.toString();
|
||||||
|
const definition = new ScriptingDefinitionStub()
|
||||||
|
.withEndCode(absentValue);
|
||||||
|
// act
|
||||||
|
const code = sut.buildCode([script], definition);
|
||||||
|
// assert
|
||||||
|
const actual = code.code;
|
||||||
|
expect(actual.endsWith(expectedEnd));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe('throws when absent', () => {
|
||||||
|
itEachAbsentObjectValue((absentValue) => {
|
||||||
// arrange
|
// arrange
|
||||||
const codeBuilderStub = new CodeBuilderStub();
|
const expectedError = 'missing definition';
|
||||||
const sut = new UserScriptGenerator(mockCodeBuilderFactory(codeBuilderStub));
|
const sut = new UserScriptGenerator();
|
||||||
const script = new ScriptStub('id')
|
const scriptingDefinition = absentValue;
|
||||||
.withCode('code\nmulti-lined')
|
const selectedScripts = [new SelectedScriptStub('a')];
|
||||||
.toSelectedScript();
|
|
||||||
const expectedEnd = codeBuilderStub
|
|
||||||
.appendFunction(script.script.name, script.script.code.execute)
|
|
||||||
.toString();
|
|
||||||
const definition = new ScriptingDefinitionStub()
|
|
||||||
.withEndCode(undefined);
|
|
||||||
// act
|
// act
|
||||||
const code = sut.buildCode([script], definition);
|
const act = () => sut.buildCode(selectedScripts, scriptingDefinition);
|
||||||
// assert
|
// assert
|
||||||
const actual = code.code;
|
expect(act).to.throw(expectedError);
|
||||||
expect(actual.endsWith(expectedEnd));
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -200,6 +217,21 @@ describe('UserScriptGenerator', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
describe('selectedScripts', () => {
|
||||||
|
describe('throws when absent', () => {
|
||||||
|
itEachAbsentObjectValue((absentValue) => {
|
||||||
|
// arrange
|
||||||
|
const expectedError = 'missing scripts';
|
||||||
|
const sut = new UserScriptGenerator();
|
||||||
|
const scriptingDefinition = new ScriptingDefinitionStub();
|
||||||
|
const selectedScripts = absentValue;
|
||||||
|
// act
|
||||||
|
const act = () => sut.buildCode(selectedScripts, scriptingDefinition);
|
||||||
|
// assert
|
||||||
|
expect(act).to.throw(expectedError);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
function mockCodeBuilderFactory(mock: ICodeBuilder): ICodeBuilderFactory {
|
function mockCodeBuilderFactory(mock: ICodeBuilder): ICodeBuilderFactory {
|
||||||
|
|||||||
@@ -2,17 +2,21 @@ import 'mocha';
|
|||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
import { OperatingSystem } from '@/domain/OperatingSystem';
|
import { OperatingSystem } from '@/domain/OperatingSystem';
|
||||||
import { BrowserOsDetector } from '@/application/Environment/BrowserOs/BrowserOsDetector';
|
import { BrowserOsDetector } from '@/application/Environment/BrowserOs/BrowserOsDetector';
|
||||||
|
import { itEachAbsentStringValue } from '@tests/unit/shared/TestCases/AbsentTests';
|
||||||
import { BrowserOsTestCases } from './BrowserOsTestCases';
|
import { BrowserOsTestCases } from './BrowserOsTestCases';
|
||||||
|
|
||||||
describe('BrowserOsDetector', () => {
|
describe('BrowserOsDetector', () => {
|
||||||
it('returns undefined when user agent is undefined', () => {
|
describe('returns undefined when user agent is absent', () => {
|
||||||
// arrange
|
itEachAbsentStringValue((absentValue) => {
|
||||||
const expected = undefined;
|
// arrange
|
||||||
const sut = new BrowserOsDetector();
|
const expected = undefined;
|
||||||
// act
|
const userAgent = absentValue;
|
||||||
const actual = sut.detect(undefined);
|
const sut = new BrowserOsDetector();
|
||||||
// assert
|
// act
|
||||||
expect(actual).to.equal(expected);
|
const actual = sut.detect(userAgent);
|
||||||
|
// assert
|
||||||
|
expect(actual).to.equal(expected);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
it('detects as expected', () => {
|
it('detects as expected', () => {
|
||||||
BrowserOsTestCases.forEach((testCase) => {
|
BrowserOsTestCases.forEach((testCase) => {
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import { getEnumValues } from '@/application/Common/Enum';
|
|||||||
import { CategoryCollectionStub } from '@tests/unit/stubs/CategoryCollectionStub';
|
import { CategoryCollectionStub } from '@tests/unit/stubs/CategoryCollectionStub';
|
||||||
import { getProcessEnvironmentStub } from '@tests/unit/stubs/ProcessEnvironmentStub';
|
import { getProcessEnvironmentStub } from '@tests/unit/stubs/ProcessEnvironmentStub';
|
||||||
import { CollectionDataStub } from '@tests/unit/stubs/CollectionDataStub';
|
import { CollectionDataStub } from '@tests/unit/stubs/CollectionDataStub';
|
||||||
|
import { getAbsentCollectionTestCases, AbsentObjectTestCases } from '@tests/unit/shared/TestCases/AbsentTests';
|
||||||
|
|
||||||
describe('ApplicationParser', () => {
|
describe('ApplicationParser', () => {
|
||||||
describe('parseApplication', () => {
|
describe('parseApplication', () => {
|
||||||
@@ -112,21 +113,23 @@ describe('ApplicationParser', () => {
|
|||||||
describe('throws when data is invalid', () => {
|
describe('throws when data is invalid', () => {
|
||||||
// arrange
|
// arrange
|
||||||
const testCases = [
|
const testCases = [
|
||||||
{
|
...getAbsentCollectionTestCases<CollectionData>().map((testCase) => ({
|
||||||
expectedError: 'no collection provided',
|
name: `given absent collection "${testCase.valueName}"`,
|
||||||
data: [],
|
value: testCase.absentValue,
|
||||||
},
|
expectedError: 'missing collections',
|
||||||
{
|
})).filter((test) => test.value !== undefined /* the default value is set */),
|
||||||
expectedError: 'undefined collection provided',
|
...AbsentObjectTestCases.map((testCase) => ({
|
||||||
data: [new CollectionDataStub(), undefined],
|
name: `given absent item "${testCase.valueName}"`,
|
||||||
},
|
value: [testCase.absentValue],
|
||||||
|
expectedError: 'missing collection provided',
|
||||||
|
})),
|
||||||
];
|
];
|
||||||
for (const testCase of testCases) {
|
for (const testCase of testCases) {
|
||||||
it(testCase.expectedError, () => {
|
it(testCase.name, () => {
|
||||||
const parserMock = new CategoryCollectionParserSpy().mockParser();
|
const parserMock = new CategoryCollectionParserSpy().mockParser();
|
||||||
const env = getProcessEnvironmentStub();
|
const env = getProcessEnvironmentStub();
|
||||||
// act
|
// act
|
||||||
const act = () => parseApplication(parserMock, env, testCase.data);
|
const act = () => parseApplication(parserMock, env, testCase.value);
|
||||||
// assert
|
// assert
|
||||||
expect(act).to.throw(testCase.expectedError);
|
expect(act).to.throw(testCase.expectedError);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -15,30 +15,35 @@ import { CategoryDataStub } from '@tests/unit/stubs/CategoryDataStub';
|
|||||||
import { ScriptDataStub } from '@tests/unit/stubs/ScriptDataStub';
|
import { ScriptDataStub } from '@tests/unit/stubs/ScriptDataStub';
|
||||||
import { FunctionDataStub } from '@tests/unit/stubs/FunctionDataStub';
|
import { FunctionDataStub } from '@tests/unit/stubs/FunctionDataStub';
|
||||||
import { FunctionCallDataStub } from '@tests/unit/stubs/FunctionCallDataStub';
|
import { FunctionCallDataStub } from '@tests/unit/stubs/FunctionCallDataStub';
|
||||||
|
import { itEachAbsentObjectValue } from '@tests/unit/shared/TestCases/AbsentTests';
|
||||||
|
|
||||||
describe('CategoryCollectionParser', () => {
|
describe('CategoryCollectionParser', () => {
|
||||||
describe('parseCategoryCollection', () => {
|
describe('parseCategoryCollection', () => {
|
||||||
it('throws when undefined', () => {
|
describe('throws with absent content', () => {
|
||||||
// arrange
|
itEachAbsentObjectValue((absentValue) => {
|
||||||
const expectedError = 'content is null or undefined';
|
|
||||||
const info = new ProjectInformationStub();
|
|
||||||
// act
|
|
||||||
const act = () => parseCategoryCollection(undefined, info);
|
|
||||||
// assert
|
|
||||||
expect(act).to.throw(expectedError);
|
|
||||||
});
|
|
||||||
describe('actions', () => {
|
|
||||||
it('throws when undefined actions', () => {
|
|
||||||
// arrange
|
// arrange
|
||||||
const expectedError = 'content does not define any action';
|
const expectedError = 'missing content';
|
||||||
const collection = new CollectionDataStub()
|
|
||||||
.withActions(undefined);
|
|
||||||
const info = new ProjectInformationStub();
|
const info = new ProjectInformationStub();
|
||||||
// act
|
// act
|
||||||
const act = () => parseCategoryCollection(collection, info);
|
const act = () => parseCategoryCollection(absentValue, info);
|
||||||
// assert
|
// assert
|
||||||
expect(act).to.throw(expectedError);
|
expect(act).to.throw(expectedError);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
describe('actions', () => {
|
||||||
|
describe('throws with absent actions', () => {
|
||||||
|
itEachAbsentObjectValue((absentValue) => {
|
||||||
|
// arrange
|
||||||
|
const expectedError = 'content does not define any action';
|
||||||
|
const collection = new CollectionDataStub()
|
||||||
|
.withActions(absentValue);
|
||||||
|
const info = new ProjectInformationStub();
|
||||||
|
// act
|
||||||
|
const act = () => parseCategoryCollection(collection, info);
|
||||||
|
// assert
|
||||||
|
expect(act).to.throw(expectedError);
|
||||||
|
});
|
||||||
|
});
|
||||||
it('throws when has no actions', () => {
|
it('throws when has no actions', () => {
|
||||||
// arrange
|
// arrange
|
||||||
const expectedError = 'content does not define any action';
|
const expectedError = 'content does not define any action';
|
||||||
|
|||||||
@@ -8,53 +8,44 @@ import { ScriptDataStub } from '@tests/unit/stubs/ScriptDataStub';
|
|||||||
import { CategoryCollectionParseContextStub } from '@tests/unit/stubs/CategoryCollectionParseContextStub';
|
import { CategoryCollectionParseContextStub } from '@tests/unit/stubs/CategoryCollectionParseContextStub';
|
||||||
import { LanguageSyntaxStub } from '@tests/unit/stubs/LanguageSyntaxStub';
|
import { LanguageSyntaxStub } from '@tests/unit/stubs/LanguageSyntaxStub';
|
||||||
import { CategoryDataStub } from '@tests/unit/stubs/CategoryDataStub';
|
import { CategoryDataStub } from '@tests/unit/stubs/CategoryDataStub';
|
||||||
|
import { itEachAbsentCollectionValue, itEachAbsentObjectValue, itEachAbsentStringValue } from '@tests/unit/shared/TestCases/AbsentTests';
|
||||||
|
|
||||||
describe('CategoryParser', () => {
|
describe('CategoryParser', () => {
|
||||||
describe('parseCategory', () => {
|
describe('parseCategory', () => {
|
||||||
describe('invalid category', () => {
|
describe('invalid category', () => {
|
||||||
it('throws when undefined', () => {
|
describe('throws when category data is absent', () => {
|
||||||
// arrange
|
itEachAbsentObjectValue((absentValue) => {
|
||||||
const expectedMessage = 'category is null or undefined';
|
// arrange
|
||||||
const category = undefined;
|
const expectedMessage = 'missing category';
|
||||||
const context = new CategoryCollectionParseContextStub();
|
const category = absentValue;
|
||||||
// act
|
const context = new CategoryCollectionParseContextStub();
|
||||||
const act = () => parseCategory(category, context);
|
// act
|
||||||
// assert
|
const act = () => parseCategory(category, context);
|
||||||
expect(act).to.throw(expectedMessage);
|
// assert
|
||||||
|
expect(act).to.throw(expectedMessage);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
it('throws when children are empty', () => {
|
describe('throws when category children is absent', () => {
|
||||||
// arrange
|
itEachAbsentCollectionValue((absentValue) => {
|
||||||
const categoryName = 'test';
|
// arrange
|
||||||
const expectedMessage = `category has no children: "${categoryName}"`;
|
const categoryName = 'test';
|
||||||
const category = new CategoryDataStub()
|
const expectedMessage = `category has no children: "${categoryName}"`;
|
||||||
.withName(categoryName)
|
|
||||||
.withChildren([]);
|
|
||||||
const context = new CategoryCollectionParseContextStub();
|
|
||||||
// act
|
|
||||||
const act = () => parseCategory(category, context);
|
|
||||||
// assert
|
|
||||||
expect(act).to.throw(expectedMessage);
|
|
||||||
});
|
|
||||||
it('throws when children are undefined', () => {
|
|
||||||
// arrange
|
|
||||||
const categoryName = 'test';
|
|
||||||
const expectedMessage = `category has no children: "${categoryName}"`;
|
|
||||||
const category = new CategoryDataStub()
|
|
||||||
.withName(categoryName)
|
|
||||||
.withChildren(undefined);
|
|
||||||
const context = new CategoryCollectionParseContextStub();
|
|
||||||
// act
|
|
||||||
const act = () => parseCategory(category, context);
|
|
||||||
// assert
|
|
||||||
expect(act).to.throw(expectedMessage);
|
|
||||||
});
|
|
||||||
it('throws when name is empty or undefined', () => {
|
|
||||||
// arrange
|
|
||||||
const expectedMessage = 'category has no name';
|
|
||||||
const invalidNames = ['', undefined];
|
|
||||||
invalidNames.forEach((invalidName) => {
|
|
||||||
const category = new CategoryDataStub()
|
const category = new CategoryDataStub()
|
||||||
.withName(invalidName);
|
.withName(categoryName)
|
||||||
|
.withChildren(absentValue);
|
||||||
|
const context = new CategoryCollectionParseContextStub();
|
||||||
|
// act
|
||||||
|
const act = () => parseCategory(category, context);
|
||||||
|
// assert
|
||||||
|
expect(act).to.throw(expectedMessage);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe('throws when name is absent', () => {
|
||||||
|
itEachAbsentStringValue((absentValue) => {
|
||||||
|
// arrange
|
||||||
|
const expectedMessage = 'category has no name';
|
||||||
|
const category = new CategoryDataStub()
|
||||||
|
.withName(absentValue);
|
||||||
const context = new CategoryCollectionParseContextStub();
|
const context = new CategoryCollectionParseContextStub();
|
||||||
// act
|
// act
|
||||||
const act = () => parseCategory(category, context);
|
const act = () => parseCategory(category, context);
|
||||||
@@ -63,15 +54,17 @@ describe('CategoryParser', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('throws when context is undefined', () => {
|
describe('throws when context is absent', () => {
|
||||||
// arrange
|
itEachAbsentObjectValue((absentValue) => {
|
||||||
const expectedError = 'undefined context';
|
// arrange
|
||||||
const context = undefined;
|
const expectedError = 'missing context';
|
||||||
const category = new CategoryDataStub();
|
const context = absentValue;
|
||||||
// act
|
const category = new CategoryDataStub();
|
||||||
const act = () => parseCategory(category, context);
|
// act
|
||||||
// assert
|
const act = () => parseCategory(category, context);
|
||||||
expect(act).to.throw(expectedError);
|
// assert
|
||||||
|
expect(act).to.throw(expectedError);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
it('returns expected docs', () => {
|
it('returns expected docs', () => {
|
||||||
// arrange
|
// arrange
|
||||||
|
|||||||
@@ -2,11 +2,19 @@ import 'mocha';
|
|||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
import { DocumentableData } from 'js-yaml-loader!@/*';
|
import { DocumentableData } from 'js-yaml-loader!@/*';
|
||||||
import { parseDocUrls } from '@/application/Parser/DocumentationParser';
|
import { parseDocUrls } from '@/application/Parser/DocumentationParser';
|
||||||
|
import { itEachAbsentObjectValue } from '@tests/unit/shared/TestCases/AbsentTests';
|
||||||
|
|
||||||
describe('DocumentationParser', () => {
|
describe('DocumentationParser', () => {
|
||||||
describe('parseDocUrls', () => {
|
describe('parseDocUrls', () => {
|
||||||
it('throws when undefined', () => {
|
describe('throws when absent', () => {
|
||||||
expect(() => parseDocUrls(undefined)).to.throw('documentable is null or undefined');
|
itEachAbsentObjectValue((absentValue) => {
|
||||||
|
// arrange
|
||||||
|
const expectedError = 'missing documentable';
|
||||||
|
// act
|
||||||
|
const act = () => parseDocUrls(absentValue);
|
||||||
|
// assert
|
||||||
|
expect(act).to.throw(expectedError);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
it('returns empty when empty', () => {
|
it('returns empty when empty', () => {
|
||||||
// arrange
|
// arrange
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import 'mocha';
|
import 'mocha';
|
||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
import { FunctionData } from 'js-yaml-loader!@/*';
|
|
||||||
import { ISyntaxFactory } from '@/application/Parser/Script/Syntax/ISyntaxFactory';
|
import { ISyntaxFactory } from '@/application/Parser/Script/Syntax/ISyntaxFactory';
|
||||||
import { ScriptingLanguage } from '@/domain/ScriptingLanguage';
|
import { ScriptingLanguage } from '@/domain/ScriptingLanguage';
|
||||||
import { CategoryCollectionParseContext } from '@/application/Parser/Script/CategoryCollectionParseContext';
|
import { CategoryCollectionParseContext } from '@/application/Parser/Script/CategoryCollectionParseContext';
|
||||||
@@ -9,32 +8,36 @@ import { ScriptCompiler } from '@/application/Parser/Script/Compiler/ScriptCompi
|
|||||||
import { LanguageSyntaxStub } from '@tests/unit/stubs/LanguageSyntaxStub';
|
import { LanguageSyntaxStub } from '@tests/unit/stubs/LanguageSyntaxStub';
|
||||||
import { ScriptingDefinitionStub } from '@tests/unit/stubs/ScriptingDefinitionStub';
|
import { ScriptingDefinitionStub } from '@tests/unit/stubs/ScriptingDefinitionStub';
|
||||||
import { FunctionDataStub } from '@tests/unit/stubs/FunctionDataStub';
|
import { FunctionDataStub } from '@tests/unit/stubs/FunctionDataStub';
|
||||||
|
import { itEachAbsentCollectionValue, itEachAbsentObjectValue } from '@tests/unit/shared/TestCases/AbsentTests';
|
||||||
|
|
||||||
describe('CategoryCollectionParseContext', () => {
|
describe('CategoryCollectionParseContext', () => {
|
||||||
describe('ctor', () => {
|
describe('ctor', () => {
|
||||||
describe('functionsData', () => {
|
describe('functionsData', () => {
|
||||||
it('can create with empty values', () => {
|
describe('can create with absent data', () => {
|
||||||
// arrange
|
itEachAbsentCollectionValue((absentValue) => {
|
||||||
const testData: FunctionData[][] = [undefined, []];
|
// arrange
|
||||||
const scripting = new ScriptingDefinitionStub();
|
const scripting = new ScriptingDefinitionStub();
|
||||||
for (const functionsData of testData) {
|
// act
|
||||||
|
const act = () => new CategoryCollectionParseContext(absentValue, scripting);
|
||||||
|
// assert
|
||||||
|
expect(act).to.not.throw();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe('scripting', () => {
|
||||||
|
describe('throws when missing', () => {
|
||||||
|
itEachAbsentObjectValue((absentValue) => {
|
||||||
|
// arrange
|
||||||
|
const expectedError = 'missing scripting';
|
||||||
|
const scripting = absentValue;
|
||||||
|
const functionsData = [FunctionDataStub.createWithCode()];
|
||||||
// act
|
// act
|
||||||
const act = () => new CategoryCollectionParseContext(functionsData, scripting);
|
const act = () => new CategoryCollectionParseContext(functionsData, scripting);
|
||||||
// assert
|
// assert
|
||||||
expect(act).to.not.throw();
|
expect(act).to.throw(expectedError);
|
||||||
}
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('scripting', () => {
|
|
||||||
// arrange
|
|
||||||
const expectedError = 'undefined scripting';
|
|
||||||
const scripting = undefined;
|
|
||||||
const functionsData = [FunctionDataStub.createWithCode()];
|
|
||||||
// act
|
|
||||||
const act = () => new CategoryCollectionParseContext(functionsData, scripting);
|
|
||||||
// assert
|
|
||||||
expect(act).to.throw(expectedError);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
describe('compiler', () => {
|
describe('compiler', () => {
|
||||||
it('constructed as expected', () => {
|
it('constructed as expected', () => {
|
||||||
|
|||||||
@@ -10,20 +10,24 @@ import { ExpressionEvaluationContextStub } from '@tests/unit/stubs/ExpressionEva
|
|||||||
import { IPipelineCompiler } from '@/application/Parser/Script/Compiler/Expressions/Pipes/IPipelineCompiler';
|
import { IPipelineCompiler } from '@/application/Parser/Script/Compiler/Expressions/Pipes/IPipelineCompiler';
|
||||||
import { PipelineCompilerStub } from '@tests/unit/stubs/PipelineCompilerStub';
|
import { PipelineCompilerStub } from '@tests/unit/stubs/PipelineCompilerStub';
|
||||||
import { IReadOnlyFunctionParameterCollection } from '@/application/Parser/Script/Compiler/Function/Parameter/IFunctionParameterCollection';
|
import { IReadOnlyFunctionParameterCollection } from '@/application/Parser/Script/Compiler/Function/Parameter/IFunctionParameterCollection';
|
||||||
|
import { AbsentObjectTestCases, itEachAbsentObjectValue } from '@tests/unit/shared/TestCases/AbsentTests';
|
||||||
|
import { IExpressionEvaluationContext } from '@/application/Parser/Script/Compiler/Expressions/Expression/ExpressionEvaluationContext';
|
||||||
|
|
||||||
describe('Expression', () => {
|
describe('Expression', () => {
|
||||||
describe('ctor', () => {
|
describe('ctor', () => {
|
||||||
describe('position', () => {
|
describe('position', () => {
|
||||||
it('throws if undefined', () => {
|
describe('throws when missing', () => {
|
||||||
// arrange
|
itEachAbsentObjectValue((absentValue) => {
|
||||||
const expectedError = 'undefined position';
|
// arrange
|
||||||
const position = undefined;
|
const expectedError = 'missing position';
|
||||||
// act
|
const position = absentValue;
|
||||||
const act = () => new ExpressionBuilder()
|
// act
|
||||||
.withPosition(position)
|
const act = () => new ExpressionBuilder()
|
||||||
.build();
|
.withPosition(position)
|
||||||
// assert
|
.build();
|
||||||
expect(act).to.throw(expectedError);
|
// assert
|
||||||
|
expect(act).to.throw(expectedError);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
it('sets as expected', () => {
|
it('sets as expected', () => {
|
||||||
// arrange
|
// arrange
|
||||||
@@ -37,17 +41,19 @@ describe('Expression', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('parameters', () => {
|
describe('parameters', () => {
|
||||||
it('defaults to empty array if undefined', () => {
|
describe('defaults to empty array if absent', () => {
|
||||||
// arrange
|
itEachAbsentObjectValue((absentValue) => {
|
||||||
const parameters = undefined;
|
// arrange
|
||||||
// act
|
const parameters = absentValue;
|
||||||
const actual = new ExpressionBuilder()
|
// act
|
||||||
.withParameters(parameters)
|
const actual = new ExpressionBuilder()
|
||||||
.build();
|
.withParameters(parameters)
|
||||||
// assert
|
.build();
|
||||||
expect(actual.parameters);
|
// assert
|
||||||
expect(actual.parameters.all);
|
expect(actual.parameters);
|
||||||
expect(actual.parameters.all.length).to.equal(0);
|
expect(actual.parameters.all);
|
||||||
|
expect(actual.parameters.all.length).to.equal(0);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
it('sets as expected', () => {
|
it('sets as expected', () => {
|
||||||
// arrange
|
// arrange
|
||||||
@@ -63,37 +69,44 @@ describe('Expression', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('evaluator', () => {
|
describe('evaluator', () => {
|
||||||
it('throws if undefined', () => {
|
describe('throws if missing', () => {
|
||||||
// arrange
|
itEachAbsentObjectValue((absentValue) => {
|
||||||
const expectedError = 'undefined evaluator';
|
// arrange
|
||||||
const evaluator = undefined;
|
const expectedError = 'missing evaluator';
|
||||||
// act
|
const evaluator = absentValue;
|
||||||
const act = () => new ExpressionBuilder()
|
// act
|
||||||
.withEvaluator(evaluator)
|
const act = () => new ExpressionBuilder()
|
||||||
.build();
|
.withEvaluator(evaluator)
|
||||||
// assert
|
.build();
|
||||||
expect(act).to.throw(expectedError);
|
// assert
|
||||||
|
expect(act).to.throw(expectedError);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('evaluate', () => {
|
describe('evaluate', () => {
|
||||||
describe('throws with invalid arguments', () => {
|
describe('throws with invalid arguments', () => {
|
||||||
const testCases = [
|
const testCases: readonly {
|
||||||
{
|
name: string,
|
||||||
name: 'throws if arguments is undefined',
|
context: IExpressionEvaluationContext,
|
||||||
context: undefined,
|
expectedError: string,
|
||||||
expectedError: 'undefined context',
|
sutBuilder?: (builder: ExpressionBuilder) => ExpressionBuilder,
|
||||||
},
|
}[] = [
|
||||||
|
...AbsentObjectTestCases.map((testCase) => ({
|
||||||
|
name: `throws if arguments is ${testCase.valueName}`,
|
||||||
|
context: testCase.absentValue,
|
||||||
|
expectedError: 'missing context',
|
||||||
|
})),
|
||||||
{
|
{
|
||||||
name: 'throws when some of the required args are not provided',
|
name: 'throws when some of the required args are not provided',
|
||||||
sut: (i: ExpressionBuilder) => i.withParameterNames(['a', 'b', 'c'], false),
|
sutBuilder: (i: ExpressionBuilder) => i.withParameterNames(['a', 'b', 'c'], false),
|
||||||
context: new ExpressionEvaluationContextStub()
|
context: new ExpressionEvaluationContextStub()
|
||||||
.withArgs(new FunctionCallArgumentCollectionStub().withArgument('b', 'provided')),
|
.withArgs(new FunctionCallArgumentCollectionStub().withArgument('b', 'provided')),
|
||||||
expectedError: 'argument values are provided for required parameters: "a", "c"',
|
expectedError: 'argument values are provided for required parameters: "a", "c"',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'throws when none of the required args are not provided',
|
name: 'throws when none of the required args are not provided',
|
||||||
sut: (i: ExpressionBuilder) => i.withParameterNames(['a', 'b'], false),
|
sutBuilder: (i: ExpressionBuilder) => i.withParameterNames(['a', 'b'], false),
|
||||||
context: new ExpressionEvaluationContextStub()
|
context: new ExpressionEvaluationContextStub()
|
||||||
.withArgs(new FunctionCallArgumentCollectionStub().withArgument('c', 'unrelated')),
|
.withArgs(new FunctionCallArgumentCollectionStub().withArgument('c', 'unrelated')),
|
||||||
expectedError: 'argument values are provided for required parameters: "a", "b"',
|
expectedError: 'argument values are provided for required parameters: "a", "b"',
|
||||||
@@ -103,8 +116,8 @@ describe('Expression', () => {
|
|||||||
it(testCase.name, () => {
|
it(testCase.name, () => {
|
||||||
// arrange
|
// arrange
|
||||||
const sutBuilder = new ExpressionBuilder();
|
const sutBuilder = new ExpressionBuilder();
|
||||||
if (testCase.sut) {
|
if (testCase.sutBuilder) {
|
||||||
testCase.sut(sutBuilder);
|
testCase.sutBuilder(sutBuilder);
|
||||||
}
|
}
|
||||||
const sut = sutBuilder.build();
|
const sut = sutBuilder.build();
|
||||||
// act
|
// act
|
||||||
|
|||||||
@@ -5,19 +5,23 @@ import { IReadOnlyFunctionCallArgumentCollection } from '@/application/Parser/Sc
|
|||||||
import { IPipelineCompiler } from '@/application/Parser/Script/Compiler/Expressions/Pipes/IPipelineCompiler';
|
import { IPipelineCompiler } from '@/application/Parser/Script/Compiler/Expressions/Pipes/IPipelineCompiler';
|
||||||
import { FunctionCallArgumentCollectionStub } from '@tests/unit/stubs/FunctionCallArgumentCollectionStub';
|
import { FunctionCallArgumentCollectionStub } from '@tests/unit/stubs/FunctionCallArgumentCollectionStub';
|
||||||
import { PipelineCompilerStub } from '@tests/unit/stubs/PipelineCompilerStub';
|
import { PipelineCompilerStub } from '@tests/unit/stubs/PipelineCompilerStub';
|
||||||
|
import { itEachAbsentObjectValue } from '@tests/unit/shared/TestCases/AbsentTests';
|
||||||
|
|
||||||
describe('ExpressionEvaluationContext', () => {
|
describe('ExpressionEvaluationContext', () => {
|
||||||
describe('ctor', () => {
|
describe('ctor', () => {
|
||||||
describe('args', () => {
|
describe('args', () => {
|
||||||
it('throws if args are undefined', () => {
|
describe('throws if args is missing', () => {
|
||||||
// arrange
|
itEachAbsentObjectValue((absentValue) => {
|
||||||
const expectedError = 'undefined args';
|
// arrange
|
||||||
const builder = new ExpressionEvaluationContextBuilder()
|
const expectedError = 'missing args, send empty collection instead.';
|
||||||
.withArgs(undefined);
|
const args = absentValue;
|
||||||
// act
|
// act
|
||||||
const act = () => builder.build();
|
const act = () => new ExpressionEvaluationContextBuilder()
|
||||||
// assert
|
.withArgs(args)
|
||||||
expect(act).throw(expectedError);
|
.build();
|
||||||
|
// assert
|
||||||
|
expect(act).throw(expectedError);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
it('sets as expected', () => {
|
it('sets as expected', () => {
|
||||||
// arrange
|
// arrange
|
||||||
|
|||||||
@@ -5,30 +5,21 @@ import { IExpressionParser } from '@/application/Parser/Script/Compiler/Expressi
|
|||||||
import { ExpressionStub } from '@tests/unit/stubs/ExpressionStub';
|
import { ExpressionStub } from '@tests/unit/stubs/ExpressionStub';
|
||||||
import { ExpressionParserStub } from '@tests/unit/stubs/ExpressionParserStub';
|
import { ExpressionParserStub } from '@tests/unit/stubs/ExpressionParserStub';
|
||||||
import { FunctionCallArgumentCollectionStub } from '@tests/unit/stubs/FunctionCallArgumentCollectionStub';
|
import { FunctionCallArgumentCollectionStub } from '@tests/unit/stubs/FunctionCallArgumentCollectionStub';
|
||||||
|
import { itEachAbsentObjectValue, itEachAbsentStringValue } from '@tests/unit/shared/TestCases/AbsentTests';
|
||||||
|
|
||||||
describe('ExpressionsCompiler', () => {
|
describe('ExpressionsCompiler', () => {
|
||||||
describe('compileExpressions', () => {
|
describe('compileExpressions', () => {
|
||||||
describe('returns code when it is empty or undefined', () => {
|
describe('returns code when it is absent', () => {
|
||||||
// arrange
|
itEachAbsentStringValue((absentValue) => {
|
||||||
const testCases = [{
|
// arrange
|
||||||
name: 'empty',
|
const expected = absentValue;
|
||||||
value: '',
|
const sut = new SystemUnderTest();
|
||||||
}, {
|
const args = new FunctionCallArgumentCollectionStub();
|
||||||
name: 'undefined',
|
// act
|
||||||
value: undefined,
|
const value = sut.compileExpressions(absentValue, args);
|
||||||
},
|
// assert
|
||||||
];
|
expect(value).to.equal(expected);
|
||||||
for (const test of testCases) {
|
});
|
||||||
it(`given ${test.name}`, () => {
|
|
||||||
const expected = test.value;
|
|
||||||
const sut = new SystemUnderTest();
|
|
||||||
const args = new FunctionCallArgumentCollectionStub();
|
|
||||||
// act
|
|
||||||
const value = sut.compileExpressions(test.value, args);
|
|
||||||
// assert
|
|
||||||
expect(value).to.equal(expected);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
describe('combines expressions as expected', () => {
|
describe('combines expressions as expected', () => {
|
||||||
// arrange
|
// arrange
|
||||||
@@ -100,16 +91,18 @@ describe('ExpressionsCompiler', () => {
|
|||||||
expect(expressions[1].callHistory).to.have.lengthOf(1);
|
expect(expressions[1].callHistory).to.have.lengthOf(1);
|
||||||
expect(expressions[1].callHistory[0].args).to.equal(expected);
|
expect(expressions[1].callHistory[0].args).to.equal(expected);
|
||||||
});
|
});
|
||||||
it('throws if arguments is undefined', () => {
|
describe('throws if arguments is missing', () => {
|
||||||
// arrange
|
itEachAbsentObjectValue((absentValue) => {
|
||||||
const expectedError = 'undefined args, send empty collection instead';
|
// arrange
|
||||||
const args = undefined;
|
const expectedError = 'missing args, send empty collection instead.';
|
||||||
const expressionParserMock = new ExpressionParserStub();
|
const args = absentValue;
|
||||||
const sut = new SystemUnderTest(expressionParserMock);
|
const expressionParserMock = new ExpressionParserStub();
|
||||||
// act
|
const sut = new SystemUnderTest(expressionParserMock);
|
||||||
const act = () => sut.compileExpressions('code', args);
|
// act
|
||||||
// assert
|
const act = () => sut.compileExpressions('code', args);
|
||||||
expect(act).to.throw(expectedError);
|
// assert
|
||||||
|
expect(act).to.throw(expectedError);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('throws when expected argument is not provided but used in code', () => {
|
describe('throws when expected argument is not provided but used in code', () => {
|
||||||
|
|||||||
@@ -4,18 +4,30 @@ import { IExpression } from '@/application/Parser/Script/Compiler/Expressions/Ex
|
|||||||
import { IExpressionParser } from '@/application/Parser/Script/Compiler/Expressions/Parser/IExpressionParser';
|
import { IExpressionParser } from '@/application/Parser/Script/Compiler/Expressions/Parser/IExpressionParser';
|
||||||
import { CompositeExpressionParser } from '@/application/Parser/Script/Compiler/Expressions/Parser/CompositeExpressionParser';
|
import { CompositeExpressionParser } from '@/application/Parser/Script/Compiler/Expressions/Parser/CompositeExpressionParser';
|
||||||
import { ExpressionStub } from '@tests/unit/stubs/ExpressionStub';
|
import { ExpressionStub } from '@tests/unit/stubs/ExpressionStub';
|
||||||
|
import { itEachAbsentObjectValue } from '@tests/unit/shared/TestCases/AbsentTests';
|
||||||
|
|
||||||
describe('CompositeExpressionParser', () => {
|
describe('CompositeExpressionParser', () => {
|
||||||
describe('ctor', () => {
|
describe('ctor', () => {
|
||||||
it('throws if one of the parsers is undefined', () => {
|
it('throws if null parsers given', () => {
|
||||||
// arrange
|
// arrange
|
||||||
const expectedError = 'undefined leaf';
|
const expectedError = 'missing leafs';
|
||||||
const parsers: readonly IExpressionParser[] = [undefined, mockParser()];
|
const parsers = null;
|
||||||
// act
|
// act
|
||||||
const act = () => new CompositeExpressionParser(parsers);
|
const act = () => new CompositeExpressionParser(parsers);
|
||||||
// assert
|
// assert
|
||||||
expect(act).to.throw(expectedError);
|
expect(act).to.throw(expectedError);
|
||||||
});
|
});
|
||||||
|
describe('throws if one of the parsers is undefined', () => {
|
||||||
|
itEachAbsentObjectValue((absentValue) => {
|
||||||
|
// arrange
|
||||||
|
const expectedError = 'missing leaf';
|
||||||
|
const parsers: readonly IExpressionParser[] = [absentValue, mockParser()];
|
||||||
|
// act
|
||||||
|
const act = () => new CompositeExpressionParser(parsers);
|
||||||
|
// assert
|
||||||
|
expect(act).to.throw(expectedError);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
describe('findExpressions', () => {
|
describe('findExpressions', () => {
|
||||||
describe('returns result from parsers as expected', () => {
|
describe('returns result from parsers as expected', () => {
|
||||||
|
|||||||
@@ -4,32 +4,20 @@ import { ExpressionEvaluator } from '@/application/Parser/Script/Compiler/Expres
|
|||||||
import { IPrimitiveExpression, RegexParser } from '@/application/Parser/Script/Compiler/Expressions/Parser/Regex/RegexParser';
|
import { IPrimitiveExpression, RegexParser } from '@/application/Parser/Script/Compiler/Expressions/Parser/Regex/RegexParser';
|
||||||
import { ExpressionPosition } from '@/application/Parser/Script/Compiler/Expressions/Expression/ExpressionPosition';
|
import { ExpressionPosition } from '@/application/Parser/Script/Compiler/Expressions/Expression/ExpressionPosition';
|
||||||
import { FunctionParameterStub } from '@tests/unit/stubs/FunctionParameterStub';
|
import { FunctionParameterStub } from '@tests/unit/stubs/FunctionParameterStub';
|
||||||
|
import { itEachAbsentStringValue } from '@tests/unit/shared/TestCases/AbsentTests';
|
||||||
|
|
||||||
describe('RegexParser', () => {
|
describe('RegexParser', () => {
|
||||||
describe('findExpressions', () => {
|
describe('findExpressions', () => {
|
||||||
describe('throws when code is unexpected', () => {
|
describe('throws when code is absent', () => {
|
||||||
// arrange
|
itEachAbsentStringValue((absentValue) => {
|
||||||
const testCases = [
|
// arrange
|
||||||
{
|
const expectedError = 'missing code';
|
||||||
name: 'undefined',
|
const sut = new RegexParserConcrete(/unimportant/);
|
||||||
value: undefined,
|
// act
|
||||||
expectedError: 'undefined code',
|
const act = () => sut.findExpressions(absentValue);
|
||||||
},
|
// assert
|
||||||
{
|
expect(act).to.throw(expectedError);
|
||||||
name: 'empty',
|
});
|
||||||
value: '',
|
|
||||||
expectedError: 'undefined code',
|
|
||||||
},
|
|
||||||
];
|
|
||||||
for (const testCase of testCases) {
|
|
||||||
it(`given ${testCase.name}`, () => {
|
|
||||||
const sut = new RegexParserConcrete(/unimportant/);
|
|
||||||
// act
|
|
||||||
const act = () => sut.findExpressions(testCase.value);
|
|
||||||
// assert
|
|
||||||
expect(act).to.throw(testCase.expectedError);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
it('throws when position is invalid', () => {
|
it('throws when position is invalid', () => {
|
||||||
// arrange
|
// arrange
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import 'mocha';
|
import 'mocha';
|
||||||
import { EscapeDoubleQuotes } from '@/application/Parser/Script/Compiler/Expressions/Pipes/PipeDefinitions/EscapeDoubleQuotes';
|
import { EscapeDoubleQuotes } from '@/application/Parser/Script/Compiler/Expressions/Pipes/PipeDefinitions/EscapeDoubleQuotes';
|
||||||
|
import { AbsentStringTestCases } from '@tests/unit/shared/TestCases/AbsentTests';
|
||||||
import { runPipeTests } from './PipeTestRunner';
|
import { runPipeTests } from './PipeTestRunner';
|
||||||
|
|
||||||
describe('EscapeDoubleQuotes', () => {
|
describe('EscapeDoubleQuotes', () => {
|
||||||
@@ -22,10 +23,10 @@ describe('EscapeDoubleQuotes', () => {
|
|||||||
input: '""hello world""',
|
input: '""hello world""',
|
||||||
expectedOutput: '"^"""^""hello world"^"""^""',
|
expectedOutput: '"^"""^""hello world"^"""^""',
|
||||||
},
|
},
|
||||||
{
|
...AbsentStringTestCases.map((testCase) => ({
|
||||||
name: 'returns undefined when if input is undefined',
|
name: 'returns as it is when if input is missing',
|
||||||
input: undefined,
|
input: testCase.absentValue,
|
||||||
expectedOutput: undefined,
|
expectedOutput: testCase.absentValue,
|
||||||
},
|
})),
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import 'mocha';
|
|||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
import { PipeFactory } from '@/application/Parser/Script/Compiler/Expressions/Pipes/PipeFactory';
|
import { PipeFactory } from '@/application/Parser/Script/Compiler/Expressions/Pipes/PipeFactory';
|
||||||
import { PipeStub } from '@tests/unit/stubs/PipeStub';
|
import { PipeStub } from '@tests/unit/stubs/PipeStub';
|
||||||
|
import { AbsentStringTestCases, itEachAbsentObjectValue } from '@tests/unit/shared/TestCases/AbsentTests';
|
||||||
|
|
||||||
describe('PipeFactory', () => {
|
describe('PipeFactory', () => {
|
||||||
describe('ctor', () => {
|
describe('ctor', () => {
|
||||||
@@ -19,10 +20,21 @@ describe('PipeFactory', () => {
|
|||||||
// expect
|
// expect
|
||||||
expect(act).to.throw(expectedError);
|
expect(act).to.throw(expectedError);
|
||||||
});
|
});
|
||||||
it('throws when a pipe is undefined', () => {
|
describe('throws when a pipe is missing', () => {
|
||||||
|
itEachAbsentObjectValue((absentValue) => {
|
||||||
|
// arrange
|
||||||
|
const expectedError = 'missing pipe in list';
|
||||||
|
const pipes = [new PipeStub(), absentValue];
|
||||||
|
// act
|
||||||
|
const act = () => new PipeFactory(pipes);
|
||||||
|
// expect
|
||||||
|
expect(act).to.throw(expectedError);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('throws when pipes are null', () => {
|
||||||
// arrange
|
// arrange
|
||||||
const expectedError = 'undefined pipe in list';
|
const expectedError = 'missing pipes';
|
||||||
const pipes = [new PipeStub(), undefined];
|
const pipes = null;
|
||||||
// act
|
// act
|
||||||
const act = () => new PipeFactory(pipes);
|
const act = () => new PipeFactory(pipes);
|
||||||
// expect
|
// expect
|
||||||
@@ -70,44 +82,34 @@ describe('PipeFactory', () => {
|
|||||||
|
|
||||||
function testPipeNameValidation(testRunner: (invalidName: string) => void) {
|
function testPipeNameValidation(testRunner: (invalidName: string) => void) {
|
||||||
const testCases = [
|
const testCases = [
|
||||||
{
|
// Validate missing value
|
||||||
exceptionBuilder: () => 'empty pipe name',
|
...AbsentStringTestCases.map((testCase) => ({
|
||||||
values: [null, undefined, ''],
|
name: `empty pipe name (${testCase.valueName})`,
|
||||||
},
|
value: testCase.absentValue,
|
||||||
{
|
expectedError: 'empty pipe name',
|
||||||
exceptionBuilder: (name: string) => `Pipe name should be camelCase: "${name}"`,
|
})),
|
||||||
values: [
|
// Validate camelCase
|
||||||
'PascalCase',
|
...[
|
||||||
'snake-case',
|
'PascalCase',
|
||||||
'includesNumb3rs',
|
'snake-case',
|
||||||
'includes Whitespace',
|
'includesNumb3rs',
|
||||||
'noSpec\'ial',
|
'includes Whitespace',
|
||||||
],
|
'noSpec\'ial',
|
||||||
},
|
].map((nonCamelCaseValue) => ({
|
||||||
|
name: `non camel case value (${nonCamelCaseValue})`,
|
||||||
|
value: nonCamelCaseValue,
|
||||||
|
expectedError: `Pipe name should be camelCase: "${nonCamelCaseValue}"`,
|
||||||
|
})),
|
||||||
];
|
];
|
||||||
for (const testCase of testCases) {
|
for (const testCase of testCases) {
|
||||||
for (const invalidName of testCase.values) {
|
it(testCase.name, () => {
|
||||||
it(`invalid name (${printValue(invalidName)}) throws`, () => {
|
// arrange
|
||||||
// arrange
|
const invalidName = testCase.value;
|
||||||
const expectedError = testCase.exceptionBuilder(invalidName);
|
const { expectedError } = testCase;
|
||||||
// act
|
// act
|
||||||
const act = () => testRunner(invalidName);
|
const act = () => testRunner(invalidName);
|
||||||
// expect
|
// expect
|
||||||
expect(act).to.throw(expectedError);
|
expect(act).to.throw(expectedError);
|
||||||
});
|
});
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function printValue(value: string) {
|
|
||||||
switch (value) {
|
|
||||||
case undefined:
|
|
||||||
return 'undefined';
|
|
||||||
case null:
|
|
||||||
return 'null';
|
|
||||||
case '':
|
|
||||||
return 'empty';
|
|
||||||
default:
|
|
||||||
return value;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { IPipelineCompiler } from '@/application/Parser/Script/Compiler/Expressi
|
|||||||
import { IPipeFactory } from '@/application/Parser/Script/Compiler/Expressions/Pipes/PipeFactory';
|
import { IPipeFactory } from '@/application/Parser/Script/Compiler/Expressions/Pipes/PipeFactory';
|
||||||
import { PipeStub } from '@tests/unit/stubs/PipeStub';
|
import { PipeStub } from '@tests/unit/stubs/PipeStub';
|
||||||
import { PipeFactoryStub } from '@tests/unit/stubs/PipeFactoryStub';
|
import { PipeFactoryStub } from '@tests/unit/stubs/PipeFactoryStub';
|
||||||
|
import { AbsentStringTestCases } from '@tests/unit/shared/TestCases/AbsentTests';
|
||||||
|
|
||||||
describe('PipelineCompiler', () => {
|
describe('PipelineCompiler', () => {
|
||||||
describe('compile', () => {
|
describe('compile', () => {
|
||||||
@@ -15,26 +16,16 @@ describe('PipelineCompiler', () => {
|
|||||||
expectedError: string;
|
expectedError: string;
|
||||||
}
|
}
|
||||||
const testCases: ITestCase[] = [
|
const testCases: ITestCase[] = [
|
||||||
{
|
...AbsentStringTestCases.map((testCase) => ({
|
||||||
name: '"value" is empty',
|
name: `"value" is ${testCase.valueName}`,
|
||||||
act: (test) => test.withValue(''),
|
act: (test) => test.withValue(testCase.absentValue),
|
||||||
expectedError: 'undefined value',
|
expectedError: 'missing value',
|
||||||
},
|
})),
|
||||||
{
|
...AbsentStringTestCases.map((testCase) => ({
|
||||||
name: '"value" is undefined',
|
name: `"pipeline" is ${testCase.valueName}`,
|
||||||
act: (test) => test.withValue(undefined),
|
act: (test) => test.withPipeline(testCase.absentValue),
|
||||||
expectedError: 'undefined value',
|
expectedError: 'missing pipeline',
|
||||||
},
|
})),
|
||||||
{
|
|
||||||
name: '"pipeline" is empty',
|
|
||||||
act: (test) => test.withPipeline(''),
|
|
||||||
expectedError: 'undefined pipeline',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: '"pipeline" is undefined',
|
|
||||||
act: (test) => test.withPipeline(undefined),
|
|
||||||
expectedError: 'undefined pipeline',
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name: '"pipeline" does not start with pipe',
|
name: '"pipeline" does not start with pipe',
|
||||||
act: (test) => test.withPipeline('pipeline |'),
|
act: (test) => test.withPipeline('pipeline |'),
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import 'mocha';
|
import 'mocha';
|
||||||
import { ExpressionPosition } from '@/application/Parser/Script/Compiler/Expressions/Expression/ExpressionPosition';
|
import { ExpressionPosition } from '@/application/Parser/Script/Compiler/Expressions/Expression/ExpressionPosition';
|
||||||
import { WithParser } from '@/application/Parser/Script/Compiler/Expressions/SyntaxParsers/WithParser';
|
import { WithParser } from '@/application/Parser/Script/Compiler/Expressions/SyntaxParsers/WithParser';
|
||||||
|
import { AbsentStringTestCases } from '@tests/unit/shared/TestCases/AbsentTests';
|
||||||
import { SyntaxParserTestsRunner } from './SyntaxParserTestsRunner';
|
import { SyntaxParserTestsRunner } from './SyntaxParserTestsRunner';
|
||||||
|
|
||||||
describe('WithParser', () => {
|
describe('WithParser', () => {
|
||||||
@@ -84,20 +85,13 @@ describe('WithParser', () => {
|
|||||||
describe('renders scope conditionally', () => {
|
describe('renders scope conditionally', () => {
|
||||||
describe('does not render scope if argument is undefined', () => {
|
describe('does not render scope if argument is undefined', () => {
|
||||||
runner.expectResults(
|
runner.expectResults(
|
||||||
{
|
...AbsentStringTestCases.map((testCase) => ({
|
||||||
name: 'does not render when value is undefined',
|
name: `does not render when value is "${testCase.valueName}"`,
|
||||||
code: '{{ with $parameter }}dark{{ end }} ',
|
code: '{{ with $parameter }}dark{{ end }} ',
|
||||||
args: (args) => args
|
args: (args) => args
|
||||||
.withArgument('parameter', undefined),
|
.withArgument('parameter', testCase.absentValue),
|
||||||
expected: [''],
|
expected: [''],
|
||||||
},
|
})),
|
||||||
{
|
|
||||||
name: 'does not render when value is empty',
|
|
||||||
code: '{{ with $parameter }}dark {{.}}{{ end }}',
|
|
||||||
args: (args) => args
|
|
||||||
.withArgument('parameter', ''),
|
|
||||||
expected: [''],
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name: 'does not render when argument is not provided',
|
name: 'does not render when argument is not provided',
|
||||||
code: '{{ with $parameter }}dark{{ end }}',
|
code: '{{ with $parameter }}dark{{ end }}',
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import 'mocha';
|
import 'mocha';
|
||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
import { FunctionCallArgument } from '@/application/Parser/Script/Compiler/Function/Call/Argument/FunctionCallArgument';
|
import { FunctionCallArgument } from '@/application/Parser/Script/Compiler/Function/Call/Argument/FunctionCallArgument';
|
||||||
|
import { itEachAbsentStringValue } from '@tests/unit/shared/TestCases/AbsentTests';
|
||||||
import { testParameterName } from '../../../ParameterNameTestRunner';
|
import { testParameterName } from '../../../ParameterNameTestRunner';
|
||||||
|
|
||||||
describe('FunctionCallArgument', () => {
|
describe('FunctionCallArgument', () => {
|
||||||
@@ -13,18 +14,20 @@ describe('FunctionCallArgument', () => {
|
|||||||
.parameterName,
|
.parameterName,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
it('throws if argument value is undefined', () => {
|
describe('throws if argument value is absent', () => {
|
||||||
// arrange
|
itEachAbsentStringValue((absentValue) => {
|
||||||
const parameterName = 'paramName';
|
// arrange
|
||||||
const expectedError = `undefined argument value for "${parameterName}"`;
|
const parameterName = 'paramName';
|
||||||
const argumentValue = undefined;
|
const expectedError = `missing argument value for "${parameterName}"`;
|
||||||
// act
|
const argumentValue = absentValue;
|
||||||
const act = () => new FunctionCallArgumentBuilder()
|
// act
|
||||||
.withParameterName(parameterName)
|
const act = () => new FunctionCallArgumentBuilder()
|
||||||
.withArgumentValue(argumentValue)
|
.withParameterName(parameterName)
|
||||||
.build();
|
.withArgumentValue(argumentValue)
|
||||||
// assert
|
.build();
|
||||||
expect(act).to.throw(expectedError);
|
// assert
|
||||||
|
expect(act).to.throw(expectedError);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -2,18 +2,21 @@ import 'mocha';
|
|||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
import { FunctionCallArgumentCollection } from '@/application/Parser/Script/Compiler/Function/Call/Argument/FunctionCallArgumentCollection';
|
import { FunctionCallArgumentCollection } from '@/application/Parser/Script/Compiler/Function/Call/Argument/FunctionCallArgumentCollection';
|
||||||
import { FunctionCallArgumentStub } from '@tests/unit/stubs/FunctionCallArgumentStub';
|
import { FunctionCallArgumentStub } from '@tests/unit/stubs/FunctionCallArgumentStub';
|
||||||
|
import { itEachAbsentObjectValue, itEachAbsentStringValue } from '@tests/unit/shared/TestCases/AbsentTests';
|
||||||
|
|
||||||
describe('FunctionCallArgumentCollection', () => {
|
describe('FunctionCallArgumentCollection', () => {
|
||||||
describe('addArgument', () => {
|
describe('addArgument', () => {
|
||||||
it('throws if argument is undefined', () => {
|
describe('throws if argument is missing', () => {
|
||||||
// arrange
|
itEachAbsentObjectValue((absentValue) => {
|
||||||
const errorMessage = 'undefined argument';
|
// arrange
|
||||||
const arg = undefined;
|
const errorMessage = 'missing argument';
|
||||||
const sut = new FunctionCallArgumentCollection();
|
const arg = absentValue;
|
||||||
// act
|
const sut = new FunctionCallArgumentCollection();
|
||||||
const act = () => sut.addArgument(arg);
|
// act
|
||||||
// assert
|
const act = () => sut.addArgument(arg);
|
||||||
expect(act).to.throw(errorMessage);
|
// assert
|
||||||
|
expect(act).to.throw(errorMessage);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
it('throws if parameter value is already provided', () => {
|
it('throws if parameter value is already provided', () => {
|
||||||
// arrange
|
// arrange
|
||||||
@@ -58,17 +61,17 @@ describe('FunctionCallArgumentCollection', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('getArgument', () => {
|
describe('getArgument', () => {
|
||||||
it('throws if parameter name is undefined', () => {
|
describe('throws if parameter name is absent', () => {
|
||||||
// arrange
|
itEachAbsentStringValue((absentValue) => {
|
||||||
const expectedError = 'undefined parameter name';
|
// arrange
|
||||||
const undefinedValues = ['', undefined];
|
const expectedError = 'missing parameter name';
|
||||||
for (const undefinedValue of undefinedValues) {
|
|
||||||
const sut = new FunctionCallArgumentCollection();
|
const sut = new FunctionCallArgumentCollection();
|
||||||
|
const parameterName = absentValue;
|
||||||
// act
|
// act
|
||||||
const act = () => sut.getArgument(undefinedValue);
|
const act = () => sut.getArgument(parameterName);
|
||||||
// assert
|
// assert
|
||||||
expect(act).to.throw(expectedError);
|
expect(act).to.throw(expectedError);
|
||||||
}
|
});
|
||||||
});
|
});
|
||||||
it('throws if argument does not exist', () => {
|
it('throws if argument does not exist', () => {
|
||||||
// arrange
|
// arrange
|
||||||
@@ -94,17 +97,17 @@ describe('FunctionCallArgumentCollection', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('hasArgument', () => {
|
describe('hasArgument', () => {
|
||||||
it('throws if parameter name is undefined', () => {
|
describe('throws if parameter name is missing', () => {
|
||||||
// arrange
|
itEachAbsentStringValue((absentValue) => {
|
||||||
const expectedError = 'undefined parameter name';
|
// arrange
|
||||||
const undefinedValues = ['', undefined];
|
const expectedError = 'missing parameter name';
|
||||||
for (const undefinedValue of undefinedValues) {
|
const parameterName = absentValue;
|
||||||
const sut = new FunctionCallArgumentCollection();
|
const sut = new FunctionCallArgumentCollection();
|
||||||
// act
|
// act
|
||||||
const act = () => sut.hasArgument(undefinedValue);
|
const act = () => sut.hasArgument(parameterName);
|
||||||
// assert
|
// assert
|
||||||
expect(act).to.throw(expectedError);
|
expect(act).to.throw(expectedError);
|
||||||
}
|
});
|
||||||
});
|
});
|
||||||
describe('returns as expected', () => {
|
describe('returns as expected', () => {
|
||||||
// arrange
|
// arrange
|
||||||
|
|||||||
@@ -10,35 +10,40 @@ import { SharedFunctionStub } from '@tests/unit/stubs/SharedFunctionStub';
|
|||||||
import { FunctionCallArgumentCollectionStub } from '@tests/unit/stubs/FunctionCallArgumentCollectionStub';
|
import { FunctionCallArgumentCollectionStub } from '@tests/unit/stubs/FunctionCallArgumentCollectionStub';
|
||||||
import { FunctionCallStub } from '@tests/unit/stubs/FunctionCallStub';
|
import { FunctionCallStub } from '@tests/unit/stubs/FunctionCallStub';
|
||||||
import { ExpressionsCompilerStub } from '@tests/unit/stubs/ExpressionsCompilerStub';
|
import { ExpressionsCompilerStub } from '@tests/unit/stubs/ExpressionsCompilerStub';
|
||||||
|
import { itEachAbsentObjectValue } from '@tests/unit/shared/TestCases/AbsentTests';
|
||||||
|
|
||||||
describe('FunctionCallCompiler', () => {
|
describe('FunctionCallCompiler', () => {
|
||||||
describe('compileCall', () => {
|
describe('compileCall', () => {
|
||||||
describe('parameter validation', () => {
|
describe('parameter validation', () => {
|
||||||
describe('call', () => {
|
describe('call', () => {
|
||||||
it('throws with undefined call', () => {
|
describe('throws with missing call', () => {
|
||||||
// arrange
|
itEachAbsentObjectValue((absentValue) => {
|
||||||
const expectedError = 'undefined calls';
|
// arrange
|
||||||
const call = undefined;
|
const expectedError = 'missing calls';
|
||||||
const functions = new SharedFunctionCollectionStub();
|
const call = absentValue;
|
||||||
const sut = new MockableFunctionCallCompiler();
|
const functions = new SharedFunctionCollectionStub();
|
||||||
// act
|
const sut = new MockableFunctionCallCompiler();
|
||||||
const act = () => sut.compileCall(call, functions);
|
// act
|
||||||
// assert
|
const act = () => sut.compileCall(call, functions);
|
||||||
expect(act).to.throw(expectedError);
|
// assert
|
||||||
|
expect(act).to.throw(expectedError);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
it('throws if call sequence has undefined call', () => {
|
describe('throws if call sequence has absent call', () => {
|
||||||
// arrange
|
itEachAbsentObjectValue((absentValue) => {
|
||||||
const expectedError = 'undefined function call';
|
// arrange
|
||||||
const call = [
|
const expectedError = 'missing function call';
|
||||||
new FunctionCallStub(),
|
const call = [
|
||||||
undefined,
|
new FunctionCallStub(),
|
||||||
];
|
absentValue,
|
||||||
const functions = new SharedFunctionCollectionStub();
|
];
|
||||||
const sut = new MockableFunctionCallCompiler();
|
const functions = new SharedFunctionCollectionStub();
|
||||||
// act
|
const sut = new MockableFunctionCallCompiler();
|
||||||
const act = () => sut.compileCall(call, functions);
|
// act
|
||||||
// assert
|
const act = () => sut.compileCall(call, functions);
|
||||||
expect(act).to.throw(expectedError);
|
// assert
|
||||||
|
expect(act).to.throw(expectedError);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
describe('throws if call parameters does not match function parameters', () => {
|
describe('throws if call parameters does not match function parameters', () => {
|
||||||
// arrange
|
// arrange
|
||||||
@@ -109,16 +114,18 @@ describe('FunctionCallCompiler', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('functions', () => {
|
describe('functions', () => {
|
||||||
it('throws with undefined functions', () => {
|
describe('throws with missing functions', () => {
|
||||||
// arrange
|
itEachAbsentObjectValue((absentValue) => {
|
||||||
const expectedError = 'undefined functions';
|
// arrange
|
||||||
const call = new FunctionCallStub();
|
const expectedError = 'missing functions';
|
||||||
const functions = undefined;
|
const call = new FunctionCallStub();
|
||||||
const sut = new MockableFunctionCallCompiler();
|
const functions = absentValue;
|
||||||
// act
|
const sut = new MockableFunctionCallCompiler();
|
||||||
const act = () => sut.compileCall([call], functions);
|
// act
|
||||||
// assert
|
const act = () => sut.compileCall([call], functions);
|
||||||
expect(act).to.throw(expectedError);
|
// assert
|
||||||
|
expect(act).to.throw(expectedError);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
it('throws if function does not exist', () => {
|
it('throws if function does not exist', () => {
|
||||||
// arrange
|
// arrange
|
||||||
|
|||||||
@@ -3,20 +3,23 @@ import { expect } from 'chai';
|
|||||||
import { FunctionCall } from '@/application/Parser/Script/Compiler/Function/Call/FunctionCall';
|
import { FunctionCall } from '@/application/Parser/Script/Compiler/Function/Call/FunctionCall';
|
||||||
import { IReadOnlyFunctionCallArgumentCollection } from '@/application/Parser/Script/Compiler/Function/Call/Argument/IFunctionCallArgumentCollection';
|
import { IReadOnlyFunctionCallArgumentCollection } from '@/application/Parser/Script/Compiler/Function/Call/Argument/IFunctionCallArgumentCollection';
|
||||||
import { FunctionCallArgumentCollectionStub } from '@tests/unit/stubs/FunctionCallArgumentCollectionStub';
|
import { FunctionCallArgumentCollectionStub } from '@tests/unit/stubs/FunctionCallArgumentCollectionStub';
|
||||||
|
import { itEachAbsentObjectValue, itEachAbsentStringValue } from '@tests/unit/shared/TestCases/AbsentTests';
|
||||||
|
|
||||||
describe('FunctionCall', () => {
|
describe('FunctionCall', () => {
|
||||||
describe('ctor', () => {
|
describe('ctor', () => {
|
||||||
describe('args', () => {
|
describe('args', () => {
|
||||||
it('throws when args is undefined', () => {
|
describe('throws when args is missing', () => {
|
||||||
// arrange
|
itEachAbsentObjectValue((absentValue) => {
|
||||||
const expectedError = 'undefined args';
|
// arrange
|
||||||
const args = undefined;
|
const expectedError = 'missing args';
|
||||||
// act
|
const args = absentValue;
|
||||||
const act = () => new FunctionCallBuilder()
|
// act
|
||||||
.withArgs(args)
|
const act = () => new FunctionCallBuilder()
|
||||||
.build();
|
.withArgs(args)
|
||||||
// assert
|
.build();
|
||||||
expect(act).to.throw(expectedError);
|
// assert
|
||||||
|
expect(act).to.throw(expectedError);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
it('sets args as expected', () => {
|
it('sets args as expected', () => {
|
||||||
// arrange
|
// arrange
|
||||||
@@ -31,16 +34,18 @@ describe('FunctionCall', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('functionName', () => {
|
describe('functionName', () => {
|
||||||
it('throws when function name is undefined', () => {
|
describe('throws when function name is missing', () => {
|
||||||
// arrange
|
itEachAbsentStringValue((absentValue) => {
|
||||||
const expectedError = 'empty function name in function call';
|
// arrange
|
||||||
const functionName = undefined;
|
const expectedError = 'missing function name in function call';
|
||||||
// act
|
const functionName = absentValue;
|
||||||
const act = () => new FunctionCallBuilder()
|
// act
|
||||||
.withFunctionName(functionName)
|
const act = () => new FunctionCallBuilder()
|
||||||
.build();
|
.withFunctionName(functionName)
|
||||||
// assert
|
.build();
|
||||||
expect(act).to.throw(expectedError);
|
// assert
|
||||||
|
expect(act).to.throw(expectedError);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
it('sets function name as expected', () => {
|
it('sets function name as expected', () => {
|
||||||
// arrange
|
// arrange
|
||||||
|
|||||||
@@ -2,17 +2,20 @@ import 'mocha';
|
|||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
import { parseFunctionCalls } from '@/application/Parser/Script/Compiler/Function/Call/FunctionCallParser';
|
import { parseFunctionCalls } from '@/application/Parser/Script/Compiler/Function/Call/FunctionCallParser';
|
||||||
import { FunctionCallDataStub } from '@tests/unit/stubs/FunctionCallDataStub';
|
import { FunctionCallDataStub } from '@tests/unit/stubs/FunctionCallDataStub';
|
||||||
|
import { itEachAbsentObjectValue, itEachAbsentStringValue } from '@tests/unit/shared/TestCases/AbsentTests';
|
||||||
|
|
||||||
describe('FunctionCallParser', () => {
|
describe('FunctionCallParser', () => {
|
||||||
describe('parseFunctionCalls', () => {
|
describe('parseFunctionCalls', () => {
|
||||||
it('throws with undefined call', () => {
|
describe('throws with missing call data', () => {
|
||||||
// arrange
|
itEachAbsentObjectValue((absentValue) => {
|
||||||
const expectedError = 'undefined call data';
|
// arrange
|
||||||
const call = undefined;
|
const expectedError = 'missing call data';
|
||||||
// act
|
const call = absentValue;
|
||||||
const act = () => parseFunctionCalls(call);
|
// act
|
||||||
// assert
|
const act = () => parseFunctionCalls(call);
|
||||||
expect(act).to.throw(expectedError);
|
// assert
|
||||||
|
expect(act).to.throw(expectedError);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
it('throws if call is not an object', () => {
|
it('throws if call is not an object', () => {
|
||||||
// arrange
|
// arrange
|
||||||
@@ -25,29 +28,33 @@ describe('FunctionCallParser', () => {
|
|||||||
expect(act).to.throw(expectedError);
|
expect(act).to.throw(expectedError);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('throws if call sequence has undefined call', () => {
|
describe('throws if call sequence has undefined call', () => {
|
||||||
// arrange
|
itEachAbsentObjectValue((absentValue) => {
|
||||||
const expectedError = 'undefined function call';
|
// arrange
|
||||||
const data = [
|
const expectedError = 'missing call data';
|
||||||
new FunctionCallDataStub(),
|
const data = [
|
||||||
undefined,
|
new FunctionCallDataStub(),
|
||||||
];
|
absentValue,
|
||||||
// act
|
];
|
||||||
const act = () => parseFunctionCalls(data);
|
// act
|
||||||
// assert
|
const act = () => parseFunctionCalls(data);
|
||||||
expect(act).to.throw(expectedError);
|
// assert
|
||||||
|
expect(act).to.throw(expectedError);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
it('throws if call sequence has undefined function name', () => {
|
describe('throws if call sequence has undefined function name', () => {
|
||||||
// arrange
|
itEachAbsentStringValue((absentValue) => {
|
||||||
const expectedError = 'empty function name in function call';
|
// arrange
|
||||||
const data = [
|
const expectedError = 'missing function name in function call';
|
||||||
new FunctionCallDataStub().withName('function-name'),
|
const data = [
|
||||||
new FunctionCallDataStub().withName(undefined),
|
new FunctionCallDataStub().withName('function-name'),
|
||||||
];
|
new FunctionCallDataStub().withName(absentValue),
|
||||||
// act
|
];
|
||||||
const act = () => parseFunctionCalls(data);
|
// act
|
||||||
// assert
|
const act = () => parseFunctionCalls(data);
|
||||||
expect(act).to.throw(expectedError);
|
// assert
|
||||||
|
expect(act).to.throw(expectedError);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
it('parses single call as expected', () => {
|
it('parses single call as expected', () => {
|
||||||
// arrange
|
// arrange
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import 'mocha';
|
|||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
import { FunctionParameterCollection } from '@/application/Parser/Script/Compiler/Function/Parameter/FunctionParameterCollection';
|
import { FunctionParameterCollection } from '@/application/Parser/Script/Compiler/Function/Parameter/FunctionParameterCollection';
|
||||||
import { FunctionParameterStub } from '@tests/unit/stubs/FunctionParameterStub';
|
import { FunctionParameterStub } from '@tests/unit/stubs/FunctionParameterStub';
|
||||||
|
import { itEachAbsentObjectValue } from '@tests/unit/shared/TestCases/AbsentTests';
|
||||||
|
|
||||||
describe('FunctionParameterCollection', () => {
|
describe('FunctionParameterCollection', () => {
|
||||||
it('all returns added parameters as expected', () => {
|
it('all returns added parameters as expected', () => {
|
||||||
@@ -34,15 +35,17 @@ describe('FunctionParameterCollection', () => {
|
|||||||
expect(act).to.throw(expectedError);
|
expect(act).to.throw(expectedError);
|
||||||
});
|
});
|
||||||
describe('addParameter', () => {
|
describe('addParameter', () => {
|
||||||
it('throws if parameter is undefined', () => {
|
describe('throws if parameter is undefined', () => {
|
||||||
// arrange
|
itEachAbsentObjectValue((absentValue) => {
|
||||||
const expectedError = 'undefined parameter';
|
// arrange
|
||||||
const value = undefined;
|
const expectedError = 'missing parameter';
|
||||||
const sut = new FunctionParameterCollection();
|
const value = absentValue;
|
||||||
// act
|
const sut = new FunctionParameterCollection();
|
||||||
const act = () => sut.addParameter(value);
|
// act
|
||||||
// assert
|
const act = () => sut.addParameter(value);
|
||||||
expect(act).to.throw(expectedError);
|
// assert
|
||||||
|
expect(act).to.throw(expectedError);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -6,6 +6,10 @@ import { createCallerFunction, createFunctionWithInlineCode } from '@/applicatio
|
|||||||
import { IFunctionCall } from '@/application/Parser/Script/Compiler/Function/Call/IFunctionCall';
|
import { IFunctionCall } from '@/application/Parser/Script/Compiler/Function/Call/IFunctionCall';
|
||||||
import { FunctionCallStub } from '@tests/unit/stubs/FunctionCallStub';
|
import { FunctionCallStub } from '@tests/unit/stubs/FunctionCallStub';
|
||||||
import { FunctionBodyType, ISharedFunction } from '@/application/Parser/Script/Compiler/Function/ISharedFunction';
|
import { FunctionBodyType, ISharedFunction } from '@/application/Parser/Script/Compiler/Function/ISharedFunction';
|
||||||
|
import {
|
||||||
|
AbsentStringTestCases, itEachAbsentCollectionValue, itEachAbsentObjectValue,
|
||||||
|
itEachAbsentStringValue,
|
||||||
|
} from '@tests/unit/shared/TestCases/AbsentTests';
|
||||||
|
|
||||||
describe('SharedFunction', () => {
|
describe('SharedFunction', () => {
|
||||||
describe('name', () => {
|
describe('name', () => {
|
||||||
@@ -20,18 +24,17 @@ describe('SharedFunction', () => {
|
|||||||
// assert
|
// assert
|
||||||
expect(sut.name).equal(expected);
|
expect(sut.name).equal(expected);
|
||||||
});
|
});
|
||||||
it('throws if empty or undefined', () => {
|
it('throws when absent', () => {
|
||||||
// arrange
|
itEachAbsentStringValue((absentValue) => {
|
||||||
const expectedError = 'undefined function name';
|
// arrange
|
||||||
const invalidValues = [undefined, ''];
|
const expectedError = 'missing function name';
|
||||||
for (const invalidValue of invalidValues) {
|
|
||||||
const builder = new SharedFunctionBuilder()
|
const builder = new SharedFunctionBuilder()
|
||||||
.withName(invalidValue);
|
.withName(absentValue);
|
||||||
// act
|
// act
|
||||||
const act = () => build(builder);
|
const act = () => build(builder);
|
||||||
// assert
|
// assert
|
||||||
expect(act).to.throw(expectedError);
|
expect(act).to.throw(expectedError);
|
||||||
}
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -48,16 +51,18 @@ describe('SharedFunction', () => {
|
|||||||
// assert
|
// assert
|
||||||
expect(sut.parameters).equal(expected);
|
expect(sut.parameters).equal(expected);
|
||||||
});
|
});
|
||||||
it('throws if undefined', () => {
|
describe('throws if missing', () => {
|
||||||
// arrange
|
itEachAbsentObjectValue((absentValue) => {
|
||||||
const expectedError = 'undefined parameters';
|
// arrange
|
||||||
const parameters = undefined;
|
const expectedError = 'missing parameters';
|
||||||
const builder = new SharedFunctionBuilder()
|
const parameters = absentValue;
|
||||||
.withParameters(parameters);
|
const builder = new SharedFunctionBuilder()
|
||||||
// act
|
.withParameters(parameters);
|
||||||
const act = () => build(builder);
|
// act
|
||||||
// assert
|
const act = () => build(builder);
|
||||||
expect(act).to.throw(expectedError);
|
// assert
|
||||||
|
expect(act).to.throw(expectedError);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -74,12 +79,12 @@ describe('SharedFunction', () => {
|
|||||||
// assert
|
// assert
|
||||||
expect(sut.body.code.do).equal(expected);
|
expect(sut.body.code.do).equal(expected);
|
||||||
});
|
});
|
||||||
it('throws if empty or undefined', () => {
|
describe('throws if absent', () => {
|
||||||
// arrange
|
itEachAbsentStringValue((absentValue) => {
|
||||||
const functionName = 'expected-function-name';
|
// arrange
|
||||||
const expectedError = `undefined code in function "${functionName}"`;
|
const functionName = 'expected-function-name';
|
||||||
const invalidValues = [undefined, ''];
|
const expectedError = `undefined code in function "${functionName}"`;
|
||||||
for (const invalidValue of invalidValues) {
|
const invalidValue = absentValue;
|
||||||
// act
|
// act
|
||||||
const act = () => new SharedFunctionBuilder()
|
const act = () => new SharedFunctionBuilder()
|
||||||
.withName(functionName)
|
.withName(functionName)
|
||||||
@@ -87,13 +92,16 @@ describe('SharedFunction', () => {
|
|||||||
.createFunctionWithInlineCode();
|
.createFunctionWithInlineCode();
|
||||||
// assert
|
// assert
|
||||||
expect(act).to.throw(expectedError);
|
expect(act).to.throw(expectedError);
|
||||||
}
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('revertCode', () => {
|
describe('revertCode', () => {
|
||||||
it('sets as expected', () => {
|
it('sets as expected', () => {
|
||||||
// arrange
|
// arrange
|
||||||
const testData = ['expected-revert-code', undefined, ''];
|
const testData = [
|
||||||
|
'expected-revert-code',
|
||||||
|
...AbsentStringTestCases.map((testCase) => testCase.absentValue),
|
||||||
|
];
|
||||||
for (const data of testData) {
|
for (const data of testData) {
|
||||||
// act
|
// act
|
||||||
const sut = new SharedFunctionBuilder()
|
const sut = new SharedFunctionBuilder()
|
||||||
@@ -138,31 +146,20 @@ describe('SharedFunction', () => {
|
|||||||
// assert
|
// assert
|
||||||
expect(sut.body.calls).equal(expected);
|
expect(sut.body.calls).equal(expected);
|
||||||
});
|
});
|
||||||
it('throws if undefined', () => {
|
describe('throws if missing', () => {
|
||||||
// arrange
|
itEachAbsentCollectionValue((absentValue) => {
|
||||||
const functionName = 'invalidFunction';
|
// arrange
|
||||||
const callSequence = undefined;
|
const functionName = 'invalidFunction';
|
||||||
const expectedError = `undefined call sequence in function "${functionName}"`;
|
const callSequence = absentValue;
|
||||||
// act
|
const expectedError = `missing call sequence in function "${functionName}"`;
|
||||||
const act = () => new SharedFunctionBuilder()
|
// act
|
||||||
.withName(functionName)
|
const act = () => new SharedFunctionBuilder()
|
||||||
.withCallSequence(callSequence)
|
.withName(functionName)
|
||||||
.createCallerFunction();
|
.withCallSequence(callSequence)
|
||||||
// assert
|
.createCallerFunction();
|
||||||
expect(act).to.throw(expectedError);
|
// assert
|
||||||
});
|
expect(act).to.throw(expectedError);
|
||||||
it('throws if empty', () => {
|
});
|
||||||
// arrange
|
|
||||||
const functionName = 'invalidFunction';
|
|
||||||
const callSequence = [];
|
|
||||||
const expectedError = `empty call sequence in function "${functionName}"`;
|
|
||||||
// act
|
|
||||||
const act = () => new SharedFunctionBuilder()
|
|
||||||
.withName(functionName)
|
|
||||||
.withCallSequence(callSequence)
|
|
||||||
.createCallerFunction();
|
|
||||||
// assert
|
|
||||||
expect(act).to.throw(expectedError);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('sets type as expected', () => {
|
it('sets type as expected', () => {
|
||||||
|
|||||||
@@ -4,18 +4,21 @@ import { SharedFunctionCollection } from '@/application/Parser/Script/Compiler/F
|
|||||||
import { SharedFunctionStub } from '@tests/unit/stubs/SharedFunctionStub';
|
import { SharedFunctionStub } from '@tests/unit/stubs/SharedFunctionStub';
|
||||||
import { FunctionBodyType } from '@/application/Parser/Script/Compiler/Function/ISharedFunction';
|
import { FunctionBodyType } from '@/application/Parser/Script/Compiler/Function/ISharedFunction';
|
||||||
import { FunctionCallStub } from '@tests/unit/stubs/FunctionCallStub';
|
import { FunctionCallStub } from '@tests/unit/stubs/FunctionCallStub';
|
||||||
|
import { itEachAbsentObjectValue, itEachAbsentStringValue } from '@tests/unit/shared/TestCases/AbsentTests';
|
||||||
|
|
||||||
describe('SharedFunctionCollection', () => {
|
describe('SharedFunctionCollection', () => {
|
||||||
describe('addFunction', () => {
|
describe('addFunction', () => {
|
||||||
it('throws if function is undefined', () => {
|
describe('throws if function is missing', () => {
|
||||||
// arrange
|
itEachAbsentObjectValue((absentValue) => {
|
||||||
const expectedError = 'undefined function';
|
// arrange
|
||||||
const func = undefined;
|
const expectedError = 'missing function';
|
||||||
const sut = new SharedFunctionCollection();
|
const func = absentValue;
|
||||||
// act
|
const sut = new SharedFunctionCollection();
|
||||||
const act = () => sut.addFunction(func);
|
// act
|
||||||
// assert
|
const act = () => sut.addFunction(func);
|
||||||
expect(act).to.throw(expectedError);
|
// assert
|
||||||
|
expect(act).to.throw(expectedError);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
it('throws if function with same name already exists', () => {
|
it('throws if function with same name already exists', () => {
|
||||||
// arrange
|
// arrange
|
||||||
@@ -32,18 +35,16 @@ describe('SharedFunctionCollection', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('getFunctionByName', () => {
|
describe('getFunctionByName', () => {
|
||||||
it('throws if name is undefined', () => {
|
describe('throws if name is absent', () => {
|
||||||
// arrange
|
itEachAbsentStringValue((absentValue) => {
|
||||||
const expectedError = 'undefined function name';
|
// arrange
|
||||||
const invalidValues = [undefined, ''];
|
const expectedError = 'missing function name';
|
||||||
const sut = new SharedFunctionCollection();
|
const sut = new SharedFunctionCollection();
|
||||||
for (const invalidValue of invalidValues) {
|
|
||||||
const name = invalidValue;
|
|
||||||
// act
|
// act
|
||||||
const act = () => sut.getFunctionByName(name);
|
const act = () => sut.getFunctionByName(absentValue);
|
||||||
// assert
|
// assert
|
||||||
expect(act).to.throw(expectedError);
|
expect(act).to.throw(expectedError);
|
||||||
}
|
});
|
||||||
});
|
});
|
||||||
it('throws if function does not exist', () => {
|
it('throws if function does not exist', () => {
|
||||||
// arrange
|
// arrange
|
||||||
|
|||||||
@@ -7,19 +7,22 @@ import { FunctionDataStub } from '@tests/unit/stubs/FunctionDataStub';
|
|||||||
import { ParameterDefinitionDataStub } from '@tests/unit/stubs/ParameterDefinitionDataStub';
|
import { ParameterDefinitionDataStub } from '@tests/unit/stubs/ParameterDefinitionDataStub';
|
||||||
import { FunctionParameter } from '@/application/Parser/Script/Compiler/Function/Parameter/FunctionParameter';
|
import { FunctionParameter } from '@/application/Parser/Script/Compiler/Function/Parameter/FunctionParameter';
|
||||||
import { FunctionCallDataStub } from '@tests/unit/stubs/FunctionCallDataStub';
|
import { FunctionCallDataStub } from '@tests/unit/stubs/FunctionCallDataStub';
|
||||||
|
import { itEachAbsentCollectionValue, itEachAbsentObjectValue } from '@tests/unit/shared/TestCases/AbsentTests';
|
||||||
|
|
||||||
describe('SharedFunctionsParser', () => {
|
describe('SharedFunctionsParser', () => {
|
||||||
describe('parseFunctions', () => {
|
describe('parseFunctions', () => {
|
||||||
describe('validates functions', () => {
|
describe('validates functions', () => {
|
||||||
it('throws if one of the functions is undefined', () => {
|
describe('throws if one of the functions is undefined', () => {
|
||||||
// arrange
|
itEachAbsentObjectValue((absentValue) => {
|
||||||
const expectedError = 'some functions are undefined';
|
// arrange
|
||||||
const functions = [FunctionDataStub.createWithCode(), undefined];
|
const expectedError = 'some functions are undefined';
|
||||||
const sut = new SharedFunctionsParser();
|
const functions = [FunctionDataStub.createWithCode(), absentValue];
|
||||||
// act
|
const sut = new SharedFunctionsParser();
|
||||||
const act = () => sut.parseFunctions(functions);
|
// act
|
||||||
// assert
|
const act = () => sut.parseFunctions(functions);
|
||||||
expect(act).to.throw(expectedError);
|
// assert
|
||||||
|
expect(act).to.throw(expectedError);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
it('throws when functions have same names', () => {
|
it('throws when functions have same names', () => {
|
||||||
// arrange
|
// arrange
|
||||||
@@ -143,17 +146,14 @@ describe('SharedFunctionsParser', () => {
|
|||||||
expect(act).to.throw(expectedError);
|
expect(act).to.throw(expectedError);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('empty functions', () => {
|
describe('given empty functions, returns empty collection', () => {
|
||||||
it('returns empty collection', () => {
|
itEachAbsentCollectionValue((absentValue) => {
|
||||||
// arrange
|
// arrange
|
||||||
const emptyValues = [[], undefined];
|
|
||||||
const sut = new SharedFunctionsParser();
|
const sut = new SharedFunctionsParser();
|
||||||
for (const emptyFunctions of emptyValues) {
|
// act
|
||||||
// act
|
const actual = sut.parseFunctions(absentValue);
|
||||||
const actual = sut.parseFunctions(emptyFunctions);
|
// assert
|
||||||
// assert
|
expect(actual).to.not.equal(undefined);
|
||||||
expect(actual).to.not.equal(undefined);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('function with inline code', () => {
|
describe('function with inline code', () => {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import 'mocha';
|
import 'mocha';
|
||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
|
import { AbsentStringTestCases } from '@tests/unit/shared/TestCases/AbsentTests';
|
||||||
|
|
||||||
export function testParameterName(action: (parameterName: string) => string) {
|
export function testParameterName(action: (parameterName: string) => string) {
|
||||||
describe('name', () => {
|
describe('name', () => {
|
||||||
@@ -22,16 +23,11 @@ export function testParameterName(action: (parameterName: string) => string) {
|
|||||||
describe('throws if invalid', () => {
|
describe('throws if invalid', () => {
|
||||||
// arrange
|
// arrange
|
||||||
const testCases = [
|
const testCases = [
|
||||||
{
|
...AbsentStringTestCases.map((test) => ({
|
||||||
name: 'undefined',
|
name: test.valueName,
|
||||||
value: undefined,
|
value: test.absentValue,
|
||||||
expectedError: 'undefined parameter name',
|
expectedError: 'missing parameter name',
|
||||||
},
|
})),
|
||||||
{
|
|
||||||
name: 'empty',
|
|
||||||
value: '',
|
|
||||||
expectedError: 'undefined parameter name',
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name: 'has @',
|
name: 'has @',
|
||||||
value: 'b@d',
|
value: 'b@d',
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import 'mocha';
|
import 'mocha';
|
||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
import { FunctionData } from 'js-yaml-loader!@/*';
|
import { FunctionData } from 'js-yaml-loader!@/*';
|
||||||
import { ILanguageSyntax } from '@/domain/ScriptCode';
|
import { ILanguageSyntax, ScriptCode } from '@/domain/ScriptCode';
|
||||||
import { ScriptCompiler } from '@/application/Parser/Script/Compiler/ScriptCompiler';
|
import { ScriptCompiler } from '@/application/Parser/Script/Compiler/ScriptCompiler';
|
||||||
import { ISharedFunctionsParser } from '@/application/Parser/Script/Compiler/Function/ISharedFunctionsParser';
|
import { ISharedFunctionsParser } from '@/application/Parser/Script/Compiler/Function/ISharedFunctionsParser';
|
||||||
import { ICompiledCode } from '@/application/Parser/Script/Compiler/Function/Call/Compiler/ICompiledCode';
|
import { ICompiledCode } from '@/application/Parser/Script/Compiler/Function/Call/Compiler/ICompiledCode';
|
||||||
@@ -14,33 +14,39 @@ import { SharedFunctionsParserStub } from '@tests/unit/stubs/SharedFunctionsPars
|
|||||||
import { SharedFunctionCollectionStub } from '@tests/unit/stubs/SharedFunctionCollectionStub';
|
import { SharedFunctionCollectionStub } from '@tests/unit/stubs/SharedFunctionCollectionStub';
|
||||||
import { parseFunctionCalls } from '@/application/Parser/Script/Compiler/Function/Call/FunctionCallParser';
|
import { parseFunctionCalls } from '@/application/Parser/Script/Compiler/Function/Call/FunctionCallParser';
|
||||||
import { FunctionCallDataStub } from '@tests/unit/stubs/FunctionCallDataStub';
|
import { FunctionCallDataStub } from '@tests/unit/stubs/FunctionCallDataStub';
|
||||||
|
import { itEachAbsentObjectValue } from '@tests/unit/shared/TestCases/AbsentTests';
|
||||||
|
|
||||||
describe('ScriptCompiler', () => {
|
describe('ScriptCompiler', () => {
|
||||||
describe('ctor', () => {
|
describe('ctor', () => {
|
||||||
it('throws if syntax is undefined', () => {
|
describe('throws if syntax is missing', () => {
|
||||||
// arrange
|
itEachAbsentObjectValue((absentValue) => {
|
||||||
const expectedError = 'undefined syntax';
|
// arrange
|
||||||
// act
|
const expectedError = 'missing syntax';
|
||||||
const act = () => new ScriptCompilerBuilder()
|
const syntax = absentValue;
|
||||||
.withSomeFunctions()
|
// act
|
||||||
.withSyntax(undefined)
|
const act = () => new ScriptCompilerBuilder()
|
||||||
.build();
|
.withSomeFunctions()
|
||||||
// assert
|
.withSyntax(syntax)
|
||||||
expect(act).to.throw(expectedError);
|
.build();
|
||||||
|
// assert
|
||||||
|
expect(act).to.throw(expectedError);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('canCompile', () => {
|
describe('canCompile', () => {
|
||||||
it('throws if script is undefined', () => {
|
describe('throws if script is missing', () => {
|
||||||
// arrange
|
itEachAbsentObjectValue((absentValue) => {
|
||||||
const expectedError = 'undefined script';
|
// arrange
|
||||||
const argument = undefined;
|
const expectedError = 'missing script';
|
||||||
const builder = new ScriptCompilerBuilder()
|
const argument = absentValue;
|
||||||
.withEmptyFunctions()
|
const builder = new ScriptCompilerBuilder()
|
||||||
.build();
|
.withEmptyFunctions()
|
||||||
// act
|
.build();
|
||||||
const act = () => builder.canCompile(argument);
|
// act
|
||||||
// assert
|
const act = () => builder.canCompile(argument);
|
||||||
expect(act).to.throw(expectedError);
|
// assert
|
||||||
|
expect(act).to.throw(expectedError);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
it('returns true if "call" is defined', () => {
|
it('returns true if "call" is defined', () => {
|
||||||
// arrange
|
// arrange
|
||||||
@@ -66,17 +72,19 @@ describe('ScriptCompiler', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('compile', () => {
|
describe('compile', () => {
|
||||||
it('throws if script is undefined', () => {
|
describe('throws if script is missing', () => {
|
||||||
// arrange
|
itEachAbsentObjectValue((absentValue) => {
|
||||||
const expectedError = 'undefined script';
|
// arrange
|
||||||
const argument = undefined;
|
const expectedError = 'missing script';
|
||||||
const builder = new ScriptCompilerBuilder()
|
const argument = absentValue;
|
||||||
.withEmptyFunctions()
|
const builder = new ScriptCompilerBuilder()
|
||||||
.build();
|
.withEmptyFunctions()
|
||||||
// act
|
.build();
|
||||||
const act = () => builder.compile(argument);
|
// act
|
||||||
// assert
|
const act = () => builder.compile(argument);
|
||||||
expect(act).to.throw(expectedError);
|
// assert
|
||||||
|
expect(act).to.throw(expectedError);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
it('returns code as expected', () => {
|
it('returns code as expected', () => {
|
||||||
// arrange
|
// arrange
|
||||||
@@ -148,15 +156,21 @@ describe('ScriptCompiler', () => {
|
|||||||
it('rethrows error from ScriptCode with script name', () => {
|
it('rethrows error from ScriptCode with script name', () => {
|
||||||
// arrange
|
// arrange
|
||||||
const scriptName = 'scriptName';
|
const scriptName = 'scriptName';
|
||||||
const expectedError = `Script "${scriptName}" code is empty or undefined`;
|
const syntax = new LanguageSyntaxStub();
|
||||||
|
const invalidCode: ICompiledCode = { code: undefined, revertCode: undefined };
|
||||||
|
const realExceptionMessage = collectExceptionMessage(
|
||||||
|
() => new ScriptCode(invalidCode.code, invalidCode.revertCode, syntax),
|
||||||
|
);
|
||||||
|
const expectedError = `Script "${scriptName}" ${realExceptionMessage}`;
|
||||||
const callCompiler: IFunctionCallCompiler = {
|
const callCompiler: IFunctionCallCompiler = {
|
||||||
compileCall: () => ({ code: undefined, revertCode: undefined }),
|
compileCall: () => invalidCode,
|
||||||
};
|
};
|
||||||
const scriptData = ScriptDataStub.createWithCall()
|
const scriptData = ScriptDataStub.createWithCall()
|
||||||
.withName(scriptName);
|
.withName(scriptName);
|
||||||
const sut = new ScriptCompilerBuilder()
|
const sut = new ScriptCompilerBuilder()
|
||||||
.withSomeFunctions()
|
.withSomeFunctions()
|
||||||
.withFunctionCallCompiler(callCompiler)
|
.withFunctionCallCompiler(callCompiler)
|
||||||
|
.withSyntax(syntax)
|
||||||
.build();
|
.build();
|
||||||
// act
|
// act
|
||||||
const act = () => sut.compile(scriptData);
|
const act = () => sut.compile(scriptData);
|
||||||
@@ -230,3 +244,13 @@ class ScriptCompilerBuilder {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function collectExceptionMessage(action: () => unknown) {
|
||||||
|
let message = '';
|
||||||
|
try {
|
||||||
|
action();
|
||||||
|
} catch (e) {
|
||||||
|
message = e.message;
|
||||||
|
}
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import { EnumParserStub } from '@tests/unit/stubs/EnumParserStub';
|
|||||||
import { ScriptCodeStub } from '@tests/unit/stubs/ScriptCodeStub';
|
import { ScriptCodeStub } from '@tests/unit/stubs/ScriptCodeStub';
|
||||||
import { CategoryCollectionParseContextStub } from '@tests/unit/stubs/CategoryCollectionParseContextStub';
|
import { CategoryCollectionParseContextStub } from '@tests/unit/stubs/CategoryCollectionParseContextStub';
|
||||||
import { LanguageSyntaxStub } from '@tests/unit/stubs/LanguageSyntaxStub';
|
import { LanguageSyntaxStub } from '@tests/unit/stubs/LanguageSyntaxStub';
|
||||||
|
import { itEachAbsentObjectValue, itEachAbsentStringValue } from '@tests/unit/shared/TestCases/AbsentTests';
|
||||||
|
|
||||||
describe('ScriptParser', () => {
|
describe('ScriptParser', () => {
|
||||||
describe('parseScript', () => {
|
describe('parseScript', () => {
|
||||||
@@ -37,15 +38,17 @@ describe('ScriptParser', () => {
|
|||||||
expect(actual.documentationUrls).to.deep.equal(expected);
|
expect(actual.documentationUrls).to.deep.equal(expected);
|
||||||
});
|
});
|
||||||
describe('invalid script', () => {
|
describe('invalid script', () => {
|
||||||
it('throws when script is undefined', () => {
|
describe('throws when script is absent', () => {
|
||||||
// arrange
|
itEachAbsentObjectValue((absentValue) => {
|
||||||
const expectedError = 'undefined script';
|
// arrange
|
||||||
const parseContext = new CategoryCollectionParseContextStub();
|
const expectedError = 'missing script';
|
||||||
const script = undefined;
|
const parseContext = new CategoryCollectionParseContextStub();
|
||||||
// act
|
const script = absentValue;
|
||||||
const act = () => parseScript(script, parseContext);
|
// act
|
||||||
// assert
|
const act = () => parseScript(script, parseContext);
|
||||||
expect(act).to.throw(expectedError);
|
// assert
|
||||||
|
expect(act).to.throw(expectedError);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
it('throws when both function call and code are defined', () => {
|
it('throws when both function call and code are defined', () => {
|
||||||
// arrange
|
// arrange
|
||||||
@@ -83,13 +86,12 @@ describe('ScriptParser', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('level', () => {
|
describe('level', () => {
|
||||||
it('accepts undefined level', () => {
|
describe('accepts absent level', () => {
|
||||||
const undefinedLevels: string[] = ['', undefined];
|
itEachAbsentStringValue((absentValue) => {
|
||||||
undefinedLevels.forEach((undefinedLevel) => {
|
|
||||||
// arrange
|
// arrange
|
||||||
const parseContext = new CategoryCollectionParseContextStub();
|
const parseContext = new CategoryCollectionParseContextStub();
|
||||||
const script = ScriptDataStub.createWithCode()
|
const script = ScriptDataStub.createWithCode()
|
||||||
.withRecommend(undefinedLevel);
|
.withRecommend(absentValue);
|
||||||
// act
|
// act
|
||||||
const actual = parseScript(script, parseContext);
|
const actual = parseScript(script, parseContext);
|
||||||
// assert
|
// assert
|
||||||
@@ -140,15 +142,17 @@ describe('ScriptParser', () => {
|
|||||||
expect(actual).to.equal(expected);
|
expect(actual).to.equal(expected);
|
||||||
});
|
});
|
||||||
describe('compiler', () => {
|
describe('compiler', () => {
|
||||||
it('throws when context is not defined', () => {
|
describe('throws when context is not defined', () => {
|
||||||
// arrange
|
itEachAbsentObjectValue((absentValue) => {
|
||||||
const expectedMessage = 'undefined context';
|
// arrange
|
||||||
const script = ScriptDataStub.createWithCode();
|
const expectedMessage = 'missing context';
|
||||||
const context: ICategoryCollectionParseContext = undefined;
|
const script = ScriptDataStub.createWithCode();
|
||||||
// act
|
const context: ICategoryCollectionParseContext = absentValue;
|
||||||
const act = () => parseScript(script, context);
|
// act
|
||||||
// assert
|
const act = () => parseScript(script, context);
|
||||||
expect(act).to.throw(expectedMessage);
|
// assert
|
||||||
|
expect(act).to.throw(expectedMessage);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
it('gets code from compiler', () => {
|
it('gets code from compiler', () => {
|
||||||
// arrange
|
// arrange
|
||||||
|
|||||||
@@ -4,29 +4,36 @@ import { CodeSubstituter } from '@/application/Parser/ScriptingDefinition/CodeSu
|
|||||||
import { IExpressionsCompiler } from '@/application/Parser/Script/Compiler/Expressions/IExpressionsCompiler';
|
import { IExpressionsCompiler } from '@/application/Parser/Script/Compiler/Expressions/IExpressionsCompiler';
|
||||||
import { ProjectInformationStub } from '@tests/unit/stubs/ProjectInformationStub';
|
import { ProjectInformationStub } from '@tests/unit/stubs/ProjectInformationStub';
|
||||||
import { ExpressionsCompilerStub } from '@tests/unit/stubs/ExpressionsCompilerStub';
|
import { ExpressionsCompilerStub } from '@tests/unit/stubs/ExpressionsCompilerStub';
|
||||||
|
import { AbsentObjectTestCases, AbsentStringTestCases } from '@tests/unit/shared/TestCases/AbsentTests';
|
||||||
|
|
||||||
describe('CodeSubstituter', () => {
|
describe('CodeSubstituter', () => {
|
||||||
describe('throws with invalid parameters', () => {
|
describe('throws with invalid parameters', () => {
|
||||||
// arrange
|
// arrange
|
||||||
const testCases = [{
|
const testCases = [
|
||||||
expectedError: 'undefined code',
|
...AbsentStringTestCases.map((testCase) => ({
|
||||||
parameters: {
|
name: `given code: ${testCase.valueName}`,
|
||||||
code: undefined,
|
expectedError: 'missing code',
|
||||||
info: new ProjectInformationStub(),
|
parameters: {
|
||||||
},
|
code: testCase.absentValue,
|
||||||
},
|
info: new ProjectInformationStub(),
|
||||||
{
|
},
|
||||||
expectedError: 'undefined info',
|
})),
|
||||||
parameters: {
|
...AbsentObjectTestCases.map((testCase) => ({
|
||||||
code: 'non empty code',
|
name: `given info: ${testCase.valueName}`,
|
||||||
info: undefined,
|
expectedError: 'missing info',
|
||||||
},
|
parameters: {
|
||||||
}];
|
code: 'non empty code',
|
||||||
|
info: testCase.absentValue,
|
||||||
|
},
|
||||||
|
})),
|
||||||
|
];
|
||||||
for (const testCase of testCases) {
|
for (const testCase of testCases) {
|
||||||
it(`throws "${testCase.expectedError}" as expected`, () => {
|
it(`${testCase.name} throws "${testCase.expectedError}"`, () => {
|
||||||
|
// arrange
|
||||||
const sut = new CodeSubstituterBuilder().build();
|
const sut = new CodeSubstituterBuilder().build();
|
||||||
|
const { code, info } = testCase.parameters;
|
||||||
// act
|
// act
|
||||||
const act = () => sut.substitute(testCase.parameters.code, testCase.parameters.info);
|
const act = () => sut.substitute(code, info);
|
||||||
// assert
|
// assert
|
||||||
expect(act).to.throw(testCase.expectedError);
|
expect(act).to.throw(testCase.expectedError);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -9,30 +9,37 @@ import { ProjectInformationStub } from '@tests/unit/stubs/ProjectInformationStub
|
|||||||
import { EnumParserStub } from '@tests/unit/stubs/EnumParserStub';
|
import { EnumParserStub } from '@tests/unit/stubs/EnumParserStub';
|
||||||
import { ScriptingDefinitionDataStub } from '@tests/unit/stubs/ScriptingDefinitionDataStub';
|
import { ScriptingDefinitionDataStub } from '@tests/unit/stubs/ScriptingDefinitionDataStub';
|
||||||
import { CodeSubstituterStub } from '@tests/unit/stubs/CodeSubstituterStub';
|
import { CodeSubstituterStub } from '@tests/unit/stubs/CodeSubstituterStub';
|
||||||
|
import { itEachAbsentObjectValue } from '@tests/unit/shared/TestCases/AbsentTests';
|
||||||
|
|
||||||
describe('ScriptingDefinitionParser', () => {
|
describe('ScriptingDefinitionParser', () => {
|
||||||
describe('parseScriptingDefinition', () => {
|
describe('parseScriptingDefinition', () => {
|
||||||
it('throws when info is undefined', () => {
|
describe('throws when info is missing', () => {
|
||||||
// arrange
|
itEachAbsentObjectValue((absentValue) => {
|
||||||
const info = undefined;
|
// arrange
|
||||||
const definition = new ScriptingDefinitionDataStub();
|
const expectedError = 'missing info';
|
||||||
const sut = new ScriptingDefinitionParserBuilder()
|
const info = absentValue;
|
||||||
.build();
|
const definition = new ScriptingDefinitionDataStub();
|
||||||
// act
|
const sut = new ScriptingDefinitionParserBuilder()
|
||||||
const act = () => sut.parse(definition, info);
|
.build();
|
||||||
// assert
|
// act
|
||||||
expect(act).to.throw('undefined info');
|
const act = () => sut.parse(definition, info);
|
||||||
|
// assert
|
||||||
|
expect(act).to.throw(expectedError);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
it('throws when definition is undefined', () => {
|
describe('throws when definition is missing', () => {
|
||||||
// arrange
|
itEachAbsentObjectValue((absentValue) => {
|
||||||
const info = new ProjectInformationStub();
|
// arrange
|
||||||
const definition = undefined;
|
const expectedError = 'missing definition';
|
||||||
const sut = new ScriptingDefinitionParserBuilder()
|
const info = new ProjectInformationStub();
|
||||||
.build();
|
const definition = absentValue;
|
||||||
// act
|
const sut = new ScriptingDefinitionParserBuilder()
|
||||||
const act = () => sut.parse(definition, info);
|
.build();
|
||||||
// assert
|
// act
|
||||||
expect(act).to.throw('undefined definition');
|
const act = () => sut.parse(definition, info);
|
||||||
|
// assert
|
||||||
|
expect(act).to.throw(expectedError);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
describe('language', () => {
|
describe('language', () => {
|
||||||
it('parses as expected', () => {
|
it('parses as expected', () => {
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import { Application } from '@/domain/Application';
|
|||||||
import { OperatingSystem } from '@/domain/OperatingSystem';
|
import { OperatingSystem } from '@/domain/OperatingSystem';
|
||||||
import { CategoryCollectionStub } from '@tests/unit/stubs/CategoryCollectionStub';
|
import { CategoryCollectionStub } from '@tests/unit/stubs/CategoryCollectionStub';
|
||||||
import { ProjectInformationStub } from '@tests/unit/stubs/ProjectInformationStub';
|
import { ProjectInformationStub } from '@tests/unit/stubs/ProjectInformationStub';
|
||||||
|
import { AbsentObjectTestCases, getAbsentCollectionTestCases, itEachAbsentObjectValue } from '@tests/unit/shared/TestCases/AbsentTests';
|
||||||
|
import { ICategoryCollection } from '@/domain/ICategoryCollection';
|
||||||
|
|
||||||
describe('Application', () => {
|
describe('Application', () => {
|
||||||
describe('getCollection', () => {
|
describe('getCollection', () => {
|
||||||
@@ -33,15 +35,17 @@ describe('Application', () => {
|
|||||||
});
|
});
|
||||||
describe('ctor', () => {
|
describe('ctor', () => {
|
||||||
describe('info', () => {
|
describe('info', () => {
|
||||||
it('throws if undefined', () => {
|
describe('throws if missing', () => {
|
||||||
// arrange
|
itEachAbsentObjectValue((absentValue) => {
|
||||||
const expectedError = 'undefined project information';
|
// arrange
|
||||||
const info = undefined;
|
const expectedError = 'missing project information';
|
||||||
const collections = [new CategoryCollectionStub()];
|
const info = absentValue;
|
||||||
// act
|
const collections = [new CategoryCollectionStub()];
|
||||||
const act = () => new Application(info, collections);
|
// act
|
||||||
// assert
|
const act = () => new Application(info, collections);
|
||||||
expect(act).to.throw(expectedError);
|
// assert
|
||||||
|
expect(act).to.throw(expectedError);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
it('sets as expected', () => {
|
it('sets as expected', () => {
|
||||||
// arrange
|
// arrange
|
||||||
@@ -56,22 +60,21 @@ describe('Application', () => {
|
|||||||
describe('collections', () => {
|
describe('collections', () => {
|
||||||
describe('throws on invalid value', () => {
|
describe('throws on invalid value', () => {
|
||||||
// arrange
|
// arrange
|
||||||
const testCases = [
|
const testCases: readonly {
|
||||||
{
|
name: string,
|
||||||
name: 'undefined',
|
expectedError: string,
|
||||||
expectedError: 'undefined collections',
|
value: readonly ICategoryCollection[],
|
||||||
value: undefined,
|
}[] = [
|
||||||
},
|
...getAbsentCollectionTestCases<ICategoryCollection>().map((testCase) => ({
|
||||||
{
|
name: testCase.valueName,
|
||||||
name: 'empty',
|
expectedError: 'missing collections',
|
||||||
expectedError: 'no collection in the list',
|
value: testCase.absentValue,
|
||||||
value: [],
|
})),
|
||||||
},
|
...AbsentObjectTestCases.map((testCase) => ({
|
||||||
{
|
name: `${testCase.valueName} value in list`,
|
||||||
name: 'undefined value in list',
|
expectedError: 'missing collection in the list',
|
||||||
expectedError: 'undefined collection in the list',
|
value: [new CategoryCollectionStub(), testCase.absentValue],
|
||||||
value: [new CategoryCollectionStub(), undefined],
|
})),
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name: 'two collections with same OS',
|
name: 'two collections with same OS',
|
||||||
expectedError: 'multiple collections with same os: windows',
|
expectedError: 'multiple collections with same os: windows',
|
||||||
@@ -83,12 +86,14 @@ describe('Application', () => {
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
for (const testCase of testCases) {
|
for (const testCase of testCases) {
|
||||||
const info = new ProjectInformationStub();
|
it(testCase.name, () => {
|
||||||
const collections = testCase.value;
|
const info = new ProjectInformationStub();
|
||||||
// act
|
const collections = testCase.value;
|
||||||
const act = () => new Application(info, collections);
|
// act
|
||||||
// assert
|
const act = () => new Application(info, collections);
|
||||||
expect(act).to.throw(testCase.expectedError);
|
// assert
|
||||||
|
expect(act).to.throw(testCase.expectedError);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
it('sets as expected', () => {
|
it('sets as expected', () => {
|
||||||
|
|||||||
@@ -3,13 +3,20 @@ import { expect } from 'chai';
|
|||||||
import { Category } from '@/domain/Category';
|
import { Category } from '@/domain/Category';
|
||||||
import { CategoryStub } from '@tests/unit/stubs/CategoryStub';
|
import { CategoryStub } from '@tests/unit/stubs/CategoryStub';
|
||||||
import { ScriptStub } from '@tests/unit/stubs/ScriptStub';
|
import { ScriptStub } from '@tests/unit/stubs/ScriptStub';
|
||||||
|
import { itEachAbsentStringValue } from '@tests/unit/shared/TestCases/AbsentTests';
|
||||||
|
|
||||||
describe('Category', () => {
|
describe('Category', () => {
|
||||||
describe('ctor', () => {
|
describe('ctor', () => {
|
||||||
it('throws when name is empty', () => {
|
describe('throws when name is absent', () => {
|
||||||
const expectedError = 'undefined or empty name';
|
itEachAbsentStringValue((absentValue) => {
|
||||||
const construct = () => new Category(5, '', [], [new CategoryStub(5)], []);
|
// arrange
|
||||||
expect(construct).to.throw(expectedError);
|
const expectedError = 'missing name';
|
||||||
|
const name = absentValue;
|
||||||
|
// act
|
||||||
|
const construct = () => new Category(5, name, [], [new CategoryStub(5)], []);
|
||||||
|
// assert
|
||||||
|
expect(construct).to.throw(expectedError);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
it('throws when has no children', () => {
|
it('throws when has no children', () => {
|
||||||
const expectedError = 'A category must have at least one sub-category or script';
|
const expectedError = 'A category must have at least one sub-category or script';
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import { CategoryCollection } from '@/domain/CategoryCollection';
|
|||||||
import { ScriptStub } from '@tests/unit/stubs/ScriptStub';
|
import { ScriptStub } from '@tests/unit/stubs/ScriptStub';
|
||||||
import { CategoryStub } from '@tests/unit/stubs/CategoryStub';
|
import { CategoryStub } from '@tests/unit/stubs/CategoryStub';
|
||||||
import { EnumRangeTestRunner } from '@tests/unit/application/Common/EnumRangeTestRunner';
|
import { EnumRangeTestRunner } from '@tests/unit/application/Common/EnumRangeTestRunner';
|
||||||
|
import { itEachAbsentObjectValue } from '@tests/unit/shared/TestCases/AbsentTests';
|
||||||
|
|
||||||
describe('CategoryCollection', () => {
|
describe('CategoryCollection', () => {
|
||||||
describe('getScriptsByLevel', () => {
|
describe('getScriptsByLevel', () => {
|
||||||
@@ -72,24 +73,18 @@ describe('CategoryCollection', () => {
|
|||||||
// assert
|
// assert
|
||||||
expect(expected).to.deep.equal(actual);
|
expect(expected).to.deep.equal(actual);
|
||||||
});
|
});
|
||||||
it('throws when level is undefined', () => {
|
describe('throws when given invalid level', () => {
|
||||||
// arrange
|
new EnumRangeTestRunner<RecommendationLevel>((level) => {
|
||||||
const sut = new CategoryCollectionBuilder()
|
// arrange
|
||||||
.construct();
|
const sut = new CategoryCollectionBuilder()
|
||||||
// act
|
.construct();
|
||||||
const act = () => sut.getScriptsByLevel(undefined);
|
// act
|
||||||
|
sut.getScriptsByLevel(level);
|
||||||
|
})
|
||||||
// assert
|
// assert
|
||||||
expect(act).to.throw('undefined level');
|
.testAbsentValueThrows()
|
||||||
});
|
.testOutOfRangeThrows()
|
||||||
it('throws when level is out of range', () => {
|
.testValidValueDoesNotThrow(RecommendationLevel.Standard);
|
||||||
// arrange
|
|
||||||
const invalidValue = 66;
|
|
||||||
const sut = new CategoryCollectionBuilder()
|
|
||||||
.construct();
|
|
||||||
// act
|
|
||||||
const act = () => sut.getScriptsByLevel(invalidValue);
|
|
||||||
// assert
|
|
||||||
expect(act).to.throw(`invalid level: ${invalidValue}`);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('actions', () => {
|
describe('actions', () => {
|
||||||
@@ -221,7 +216,7 @@ describe('CategoryCollection', () => {
|
|||||||
// assert
|
// assert
|
||||||
new EnumRangeTestRunner(act)
|
new EnumRangeTestRunner(act)
|
||||||
.testOutOfRangeThrows()
|
.testOutOfRangeThrows()
|
||||||
.testUndefinedValueThrows();
|
.testAbsentValueThrows();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('scriptingDefinition', () => {
|
describe('scriptingDefinition', () => {
|
||||||
@@ -235,17 +230,20 @@ describe('CategoryCollection', () => {
|
|||||||
// assert
|
// assert
|
||||||
expect(sut.scripting).to.deep.equal(expected);
|
expect(sut.scripting).to.deep.equal(expected);
|
||||||
});
|
});
|
||||||
it('cannot construct without initial script', () => {
|
describe('cannot construct without initial script', () => {
|
||||||
// arrange
|
itEachAbsentObjectValue((absentValue) => {
|
||||||
const scriptingDefinition = undefined;
|
// arrange
|
||||||
// act
|
const expectedError = 'missing scripting definition';
|
||||||
function construct() {
|
const scriptingDefinition = absentValue;
|
||||||
return new CategoryCollectionBuilder()
|
// act
|
||||||
.withScripting(scriptingDefinition)
|
function construct() {
|
||||||
.construct();
|
return new CategoryCollectionBuilder()
|
||||||
}
|
.withScripting(scriptingDefinition)
|
||||||
// assert
|
.construct();
|
||||||
expect(construct).to.throw('undefined scripting definition');
|
}
|
||||||
|
// assert
|
||||||
|
expect(construct).to.throw(expectedError);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ describe('ProjectInformation', () => {
|
|||||||
// assert
|
// assert
|
||||||
new EnumRangeTestRunner(act)
|
new EnumRangeTestRunner(act)
|
||||||
.testOutOfRangeThrows()
|
.testOutOfRangeThrows()
|
||||||
.testUndefinedValueThrows()
|
.testAbsentValueThrows()
|
||||||
.testInvalidValueThrows(OperatingSystem.KaiOS, `Unsupported os: ${OperatingSystem[OperatingSystem.KaiOS]}`);
|
.testInvalidValueThrows(OperatingSystem.KaiOS, `Unsupported os: ${OperatingSystem[OperatingSystem.KaiOS]}`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { Script } from '@/domain/Script';
|
|||||||
import { RecommendationLevel } from '@/domain/RecommendationLevel';
|
import { RecommendationLevel } from '@/domain/RecommendationLevel';
|
||||||
import { IScriptCode } from '@/domain/IScriptCode';
|
import { IScriptCode } from '@/domain/IScriptCode';
|
||||||
import { ScriptCodeStub } from '@tests/unit/stubs/ScriptCodeStub';
|
import { ScriptCodeStub } from '@tests/unit/stubs/ScriptCodeStub';
|
||||||
|
import { itEachAbsentObjectValue } from '@tests/unit/shared/TestCases/AbsentTests';
|
||||||
|
|
||||||
describe('Script', () => {
|
describe('Script', () => {
|
||||||
describe('ctor', () => {
|
describe('ctor', () => {
|
||||||
@@ -20,18 +21,20 @@ describe('Script', () => {
|
|||||||
// assert
|
// assert
|
||||||
expect(actual).to.deep.equal(expected);
|
expect(actual).to.deep.equal(expected);
|
||||||
});
|
});
|
||||||
it('throws if undefined', () => {
|
describe('throws when missing', () => {
|
||||||
// arrange
|
itEachAbsentObjectValue((absentValue) => {
|
||||||
const name = 'script-name';
|
// arrange
|
||||||
const expectedError = `undefined code (script: ${name})`;
|
const name = 'script-name';
|
||||||
const code: IScriptCode = undefined;
|
const expectedError = `missing code (script: ${name})`;
|
||||||
// act
|
const code: IScriptCode = absentValue;
|
||||||
const construct = () => new ScriptBuilder()
|
// act
|
||||||
.withName(name)
|
const construct = () => new ScriptBuilder()
|
||||||
.withCode(code)
|
.withName(name)
|
||||||
.build();
|
.withCode(code)
|
||||||
// assert
|
.build();
|
||||||
expect(construct).to.throw(expectedError);
|
// assert
|
||||||
|
expect(construct).to.throw(expectedError);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('canRevert', () => {
|
describe('canRevert', () => {
|
||||||
@@ -114,7 +117,7 @@ class ScriptBuilder {
|
|||||||
|
|
||||||
private level = RecommendationLevel.Standard;
|
private level = RecommendationLevel.Standard;
|
||||||
|
|
||||||
private documentationUrls: readonly string[] = undefined;
|
private documentationUrls: readonly string[];
|
||||||
|
|
||||||
public withCodes(code: string, revertCode = ''): ScriptBuilder {
|
public withCodes(code: string, revertCode = ''): ScriptBuilder {
|
||||||
this.code = new ScriptCodeStub()
|
this.code = new ScriptCodeStub()
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { expect } from 'chai';
|
|||||||
import { ScriptCode, ILanguageSyntax } from '@/domain/ScriptCode';
|
import { ScriptCode, ILanguageSyntax } from '@/domain/ScriptCode';
|
||||||
import { IScriptCode } from '@/domain/IScriptCode';
|
import { IScriptCode } from '@/domain/IScriptCode';
|
||||||
import { LanguageSyntaxStub } from '@tests/unit/stubs/LanguageSyntaxStub';
|
import { LanguageSyntaxStub } from '@tests/unit/stubs/LanguageSyntaxStub';
|
||||||
|
import { AbsentStringTestCases, itEachAbsentObjectValue } from '@tests/unit/shared/TestCases/AbsentTests';
|
||||||
|
|
||||||
describe('ScriptCode', () => {
|
describe('ScriptCode', () => {
|
||||||
describe('code', () => {
|
describe('code', () => {
|
||||||
@@ -17,22 +18,14 @@ describe('ScriptCode', () => {
|
|||||||
},
|
},
|
||||||
expectedError: '(revert): Code itself and its reverting code cannot be the same',
|
expectedError: '(revert): Code itself and its reverting code cannot be the same',
|
||||||
},
|
},
|
||||||
{
|
...AbsentStringTestCases.map((testCase) => ({
|
||||||
name: 'cannot construct with undefined "execute"',
|
name: `cannot construct with ${testCase.valueName} "execute"`,
|
||||||
code: {
|
code: {
|
||||||
execute: undefined,
|
execute: testCase.absentValue,
|
||||||
revert: 'code',
|
revert: 'code',
|
||||||
},
|
},
|
||||||
expectedError: 'code is empty or undefined',
|
expectedError: 'missing code',
|
||||||
},
|
})),
|
||||||
{
|
|
||||||
name: 'cannot construct with empty "execute"',
|
|
||||||
code: {
|
|
||||||
execute: '',
|
|
||||||
revert: 'code',
|
|
||||||
},
|
|
||||||
expectedError: 'code is empty or undefined',
|
|
||||||
},
|
|
||||||
];
|
];
|
||||||
for (const testCase of testCases) {
|
for (const testCase of testCases) {
|
||||||
it(testCase.name, () => {
|
it(testCase.name, () => {
|
||||||
@@ -142,16 +135,18 @@ describe('ScriptCode', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('syntax', () => {
|
describe('syntax', () => {
|
||||||
it('throws if undefined', () => {
|
describe('throws if missing', () => {
|
||||||
// arrange
|
itEachAbsentObjectValue((absentValue) => {
|
||||||
const expectedError = 'undefined syntax';
|
// arrange
|
||||||
const syntax = undefined;
|
const expectedError = 'missing syntax';
|
||||||
// act
|
const syntax = absentValue;
|
||||||
const act = () => new ScriptCodeBuilder()
|
// act
|
||||||
.withSyntax(syntax)
|
const act = () => new ScriptCodeBuilder()
|
||||||
.build();
|
.withSyntax(syntax)
|
||||||
// assert
|
.build();
|
||||||
expect(act).to.throw(expectedError);
|
// assert
|
||||||
|
expect(act).to.throw(expectedError);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { expect } from 'chai';
|
|||||||
import { ScriptingDefinition } from '@/domain/ScriptingDefinition';
|
import { ScriptingDefinition } from '@/domain/ScriptingDefinition';
|
||||||
import { ScriptingLanguage } from '@/domain/ScriptingLanguage';
|
import { ScriptingLanguage } from '@/domain/ScriptingLanguage';
|
||||||
import { getEnumValues } from '@/application/Common/Enum';
|
import { getEnumValues } from '@/application/Common/Enum';
|
||||||
|
import { itEachAbsentStringValue } from '@tests/unit/shared/TestCases/AbsentTests';
|
||||||
|
|
||||||
describe('ScriptingDefinition', () => {
|
describe('ScriptingDefinition', () => {
|
||||||
describe('language', () => {
|
describe('language', () => {
|
||||||
@@ -64,18 +65,18 @@ describe('ScriptingDefinition', () => {
|
|||||||
// assert
|
// assert
|
||||||
expect(sut.startCode).to.equal(expected);
|
expect(sut.startCode).to.equal(expected);
|
||||||
});
|
});
|
||||||
it('throws when undefined', () => {
|
describe('throws when absent', () => {
|
||||||
// arrange
|
itEachAbsentStringValue((absentValue) => {
|
||||||
const expectedError = 'undefined start code';
|
// arrange
|
||||||
const undefinedValues = ['', undefined];
|
const expectedError = 'missing start code';
|
||||||
for (const undefinedValue of undefinedValues) {
|
const undefinedValue = absentValue;
|
||||||
// act
|
// act
|
||||||
const act = () => new ScriptingDefinitionBuilder()
|
const act = () => new ScriptingDefinitionBuilder()
|
||||||
.withStartCode(undefinedValue)
|
.withStartCode(undefinedValue)
|
||||||
.build();
|
.build();
|
||||||
// assert
|
// assert
|
||||||
expect(act).to.throw(expectedError);
|
expect(act).to.throw(expectedError);
|
||||||
}
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('endCode', () => {
|
describe('endCode', () => {
|
||||||
@@ -89,18 +90,18 @@ describe('ScriptingDefinition', () => {
|
|||||||
// assert
|
// assert
|
||||||
expect(sut.endCode).to.equal(expected);
|
expect(sut.endCode).to.equal(expected);
|
||||||
});
|
});
|
||||||
it('throws when undefined', () => {
|
describe('throws when undefined', () => {
|
||||||
// arrange
|
itEachAbsentStringValue((absentValue) => {
|
||||||
const expectedError = 'undefined end code';
|
// arrange
|
||||||
const undefinedValues = ['', undefined];
|
const expectedError = 'missing end code';
|
||||||
for (const undefinedValue of undefinedValues) {
|
const undefinedValue = absentValue;
|
||||||
// act
|
// act
|
||||||
const act = () => new ScriptingDefinitionBuilder()
|
const act = () => new ScriptingDefinitionBuilder()
|
||||||
.withEndCode(undefinedValue)
|
.withEndCode(undefinedValue)
|
||||||
.build();
|
.build();
|
||||||
// assert
|
// assert
|
||||||
expect(act).to.throw(expectedError);
|
expect(act).to.throw(expectedError);
|
||||||
}
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { expect } from 'chai';
|
|||||||
import { EnvironmentStub } from '@tests/unit/stubs/EnvironmentStub';
|
import { EnvironmentStub } from '@tests/unit/stubs/EnvironmentStub';
|
||||||
import { OperatingSystem } from '@/domain/OperatingSystem';
|
import { OperatingSystem } from '@/domain/OperatingSystem';
|
||||||
import { CodeRunner } from '@/infrastructure/CodeRunner';
|
import { CodeRunner } from '@/infrastructure/CodeRunner';
|
||||||
|
import { expectThrowsAsync } from '@tests/unit/shared/Assertions/ExpectThrowsAsync';
|
||||||
|
|
||||||
describe('CodeRunner', () => {
|
describe('CodeRunner', () => {
|
||||||
describe('runCode', () => {
|
describe('runCode', () => {
|
||||||
@@ -116,6 +117,17 @@ describe('CodeRunner', () => {
|
|||||||
.filter((command) => expectedOrder.includes(command));
|
.filter((command) => expectedOrder.includes(command));
|
||||||
expect(expectedOrder).to.deep.equal(actualOrder);
|
expect(expectedOrder).to.deep.equal(actualOrder);
|
||||||
});
|
});
|
||||||
|
it('throws with unsupported os', async () => {
|
||||||
|
// arrange
|
||||||
|
const unknownOs = OperatingSystem.Android;
|
||||||
|
const expectedError = `unsupported os: ${OperatingSystem[unknownOs]}`;
|
||||||
|
const context = new TestContext()
|
||||||
|
.withOs(unknownOs);
|
||||||
|
// act
|
||||||
|
const act = async () => { await context.runCode(); };
|
||||||
|
// assert
|
||||||
|
expectThrowsAsync(act, expectedError);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import 'mocha';
|
|||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
import { NumericEntityStub } from '@tests/unit/stubs/NumericEntityStub';
|
import { NumericEntityStub } from '@tests/unit/stubs/NumericEntityStub';
|
||||||
import { InMemoryRepository } from '@/infrastructure/Repository/InMemoryRepository';
|
import { InMemoryRepository } from '@/infrastructure/Repository/InMemoryRepository';
|
||||||
|
import { itEachAbsentObjectValue } from '@tests/unit/shared/TestCases/AbsentTests';
|
||||||
|
|
||||||
describe('InMemoryRepository', () => {
|
describe('InMemoryRepository', () => {
|
||||||
describe('exists', () => {
|
describe('exists', () => {
|
||||||
@@ -32,24 +33,40 @@ describe('InMemoryRepository', () => {
|
|||||||
// assert
|
// assert
|
||||||
expect(actual).to.deep.equal(expected);
|
expect(actual).to.deep.equal(expected);
|
||||||
});
|
});
|
||||||
it('addItem adds', () => {
|
describe('addItem', () => {
|
||||||
// arrange
|
it('adds', () => {
|
||||||
const sut = new InMemoryRepository<number, NumericEntityStub>();
|
// arrange
|
||||||
const expected = {
|
const sut = new InMemoryRepository<number, NumericEntityStub>();
|
||||||
length: 1,
|
const expected = {
|
||||||
item: new NumericEntityStub(1),
|
length: 1,
|
||||||
};
|
item: new NumericEntityStub(1),
|
||||||
|
};
|
||||||
|
|
||||||
// act
|
// act
|
||||||
sut.addItem(expected.item);
|
sut.addItem(expected.item);
|
||||||
const actual = {
|
const actual = {
|
||||||
length: sut.length,
|
length: sut.length,
|
||||||
item: sut.getItems()[0],
|
item: sut.getItems()[0],
|
||||||
};
|
};
|
||||||
|
|
||||||
// assert
|
// assert
|
||||||
expect(actual.length).to.equal(expected.length);
|
expect(actual.length).to.equal(expected.length);
|
||||||
expect(actual.item).to.deep.equal(expected.item);
|
expect(actual.item).to.deep.equal(expected.item);
|
||||||
|
});
|
||||||
|
describe('throws when item is absent', () => {
|
||||||
|
itEachAbsentObjectValue((absentValue) => {
|
||||||
|
// arrange
|
||||||
|
const expectedError = 'missing item';
|
||||||
|
const sut = new InMemoryRepository<number, NumericEntityStub>();
|
||||||
|
const item = absentValue;
|
||||||
|
|
||||||
|
// act
|
||||||
|
const act = () => sut.addItem(item);
|
||||||
|
|
||||||
|
// assert
|
||||||
|
expect(act).to.throw(expectedError);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
it('removeItem removes', () => {
|
it('removeItem removes', () => {
|
||||||
// arrange
|
// arrange
|
||||||
@@ -100,9 +117,23 @@ describe('InMemoryRepository', () => {
|
|||||||
const actual = sut.getItems();
|
const actual = sut.getItems();
|
||||||
expect(actual).to.deep.equal(expected);
|
expect(actual).to.deep.equal(expected);
|
||||||
});
|
});
|
||||||
|
describe('throws when item is absent', () => {
|
||||||
|
itEachAbsentObjectValue((absentValue) => {
|
||||||
|
// arrange
|
||||||
|
const expectedError = 'missing item';
|
||||||
|
const sut = new InMemoryRepository<number, NumericEntityStub>();
|
||||||
|
const item = absentValue;
|
||||||
|
|
||||||
|
// act
|
||||||
|
const act = () => sut.addOrUpdateItem(item);
|
||||||
|
|
||||||
|
// assert
|
||||||
|
expect(act).to.throw(expectedError);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
describe('getById', () => {
|
describe('getById', () => {
|
||||||
it('gets entity if it exists', () => {
|
it('returns entity if it exists', () => {
|
||||||
// arrange
|
// arrange
|
||||||
const expected = new NumericEntityStub(1).withCustomProperty('bca');
|
const expected = new NumericEntityStub(1).withCustomProperty('bca');
|
||||||
const sut = new InMemoryRepository<number, NumericEntityStub>([
|
const sut = new InMemoryRepository<number, NumericEntityStub>([
|
||||||
@@ -114,7 +145,7 @@ describe('InMemoryRepository', () => {
|
|||||||
// assert
|
// assert
|
||||||
expect(actual).to.deep.equal(expected);
|
expect(actual).to.deep.equal(expected);
|
||||||
});
|
});
|
||||||
it('gets undefined if it does not exist', () => {
|
it('returns undefined if it does not exist', () => {
|
||||||
// arrange
|
// arrange
|
||||||
const sut = new InMemoryRepository<number, NumericEntityStub>([]);
|
const sut = new InMemoryRepository<number, NumericEntityStub>([]);
|
||||||
// act
|
// act
|
||||||
|
|||||||
@@ -3,18 +3,21 @@ import { expect } from 'chai';
|
|||||||
import { SelectionType, SelectionTypeHandler } from '@/presentation/components/Scripts/Menu/Selector/SelectionTypeHandler';
|
import { SelectionType, SelectionTypeHandler } from '@/presentation/components/Scripts/Menu/Selector/SelectionTypeHandler';
|
||||||
import { scrambledEqual } from '@/application/Common/Array';
|
import { scrambledEqual } from '@/application/Common/Array';
|
||||||
import { RecommendationLevel } from '@/domain/RecommendationLevel';
|
import { RecommendationLevel } from '@/domain/RecommendationLevel';
|
||||||
|
import { itEachAbsentObjectValue } from '@tests/unit/shared/TestCases/AbsentTests';
|
||||||
import { SelectionStateTestScenario } from './SelectionStateTestScenario';
|
import { SelectionStateTestScenario } from './SelectionStateTestScenario';
|
||||||
|
|
||||||
describe('SelectionTypeHandler', () => {
|
describe('SelectionTypeHandler', () => {
|
||||||
describe('ctor', () => {
|
describe('ctor', () => {
|
||||||
it('throws when state is undefined', () => {
|
describe('throws when state is missing', () => {
|
||||||
// arrange
|
itEachAbsentObjectValue((absentValue) => {
|
||||||
const expectedError = 'undefined state';
|
// arrange
|
||||||
const state = undefined;
|
const expectedError = 'missing state';
|
||||||
// act
|
const state = absentValue;
|
||||||
const sut = () => new SelectionTypeHandler(state);
|
// act
|
||||||
// assert
|
const sut = () => new SelectionTypeHandler(state);
|
||||||
expect(sut).to.throw(expectedError);
|
// assert
|
||||||
|
expect(sut).to.throw(expectedError);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('selectType', () => {
|
describe('selectType', () => {
|
||||||
|
|||||||
@@ -3,33 +3,62 @@ import { expect } from 'chai';
|
|||||||
import { throttle, ITimer, TimeoutType } from '@/presentation/components/Shared/Throttle';
|
import { throttle, ITimer, TimeoutType } from '@/presentation/components/Shared/Throttle';
|
||||||
import { EventSource } from '@/infrastructure/Events/EventSource';
|
import { EventSource } from '@/infrastructure/Events/EventSource';
|
||||||
import { IEventSubscription } from '@/infrastructure/Events/IEventSource';
|
import { IEventSubscription } from '@/infrastructure/Events/IEventSource';
|
||||||
|
import { AbsentObjectTestCases, itEachAbsentObjectValue } from '@tests/unit/shared/TestCases/AbsentTests';
|
||||||
|
|
||||||
describe('throttle', () => {
|
describe('throttle', () => {
|
||||||
it('throws if callback is undefined', () => {
|
describe('validates parameters', () => {
|
||||||
// arrange
|
describe('throws if callback is absent', () => {
|
||||||
const expectedError = 'undefined callback';
|
itEachAbsentObjectValue((absentValue) => {
|
||||||
const callback = undefined;
|
// arrange
|
||||||
// act
|
const expectedError = 'missing callback';
|
||||||
const act = () => throttle(callback, 500);
|
const callback = absentValue;
|
||||||
// assert
|
|
||||||
expect(act).to.throw(expectedError);
|
|
||||||
});
|
|
||||||
describe('throws if waitInMs is negative or zero', () => {
|
|
||||||
// arrange
|
|
||||||
const testCases = [
|
|
||||||
{ value: 0, expectedError: 'no delay to throttle' },
|
|
||||||
{ value: -2, expectedError: 'negative delay' },
|
|
||||||
];
|
|
||||||
const noopCallback = () => { /* do nothing */ };
|
|
||||||
for (const testCase of testCases) {
|
|
||||||
it(`"${testCase.value}" throws "${testCase.expectedError}"`, () => {
|
|
||||||
// act
|
// act
|
||||||
const waitInMs = testCase.value;
|
const act = () => throttle(callback, 500);
|
||||||
const act = () => throttle(noopCallback, waitInMs);
|
|
||||||
// assert
|
// assert
|
||||||
expect(act).to.throw(testCase.expectedError);
|
expect(act).to.throw(expectedError);
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
describe('throws if waitInMs is negative or zero', () => {
|
||||||
|
// arrange
|
||||||
|
const testCases = [
|
||||||
|
{
|
||||||
|
name: 'given zero',
|
||||||
|
value: 0,
|
||||||
|
expectedError: 'missing delay',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'given negative',
|
||||||
|
value: -2,
|
||||||
|
expectedError: 'negative delay',
|
||||||
|
},
|
||||||
|
...AbsentObjectTestCases.map((testCase) => ({
|
||||||
|
name: `when absent (given ${testCase.valueName})`,
|
||||||
|
value: testCase.absentValue,
|
||||||
|
expectedError: 'missing delay',
|
||||||
|
})),
|
||||||
|
];
|
||||||
|
const noopCallback = () => { /* do nothing */ };
|
||||||
|
for (const testCase of testCases) {
|
||||||
|
it(`"${testCase.name}" throws "${testCase.expectedError}"`, () => {
|
||||||
|
// act
|
||||||
|
const waitInMs = testCase.value;
|
||||||
|
const act = () => throttle(noopCallback, waitInMs);
|
||||||
|
// assert
|
||||||
|
expect(act).to.throw(testCase.expectedError);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
it('throws if timer is null', () => {
|
||||||
|
// arrange
|
||||||
|
const expectedError = 'missing timer';
|
||||||
|
const timer = null;
|
||||||
|
const noopCallback = () => { /* do nothing */ };
|
||||||
|
const waitInMs = 1;
|
||||||
|
// act
|
||||||
|
const act = () => throttle(noopCallback, waitInMs, timer);
|
||||||
|
// assert
|
||||||
|
expect(act).to.throw(expectedError);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
it('should call the callback immediately', () => {
|
it('should call the callback immediately', () => {
|
||||||
// arrange
|
// arrange
|
||||||
|
|||||||
17
tests/unit/shared/Assertions/ExpectThrowsAsync.ts
Normal file
17
tests/unit/shared/Assertions/ExpectThrowsAsync.ts
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import { expect } from 'chai';
|
||||||
|
|
||||||
|
export async function expectThrowsAsync(
|
||||||
|
method: () => Promise<unknown>,
|
||||||
|
errorMessage: string,
|
||||||
|
) {
|
||||||
|
let error: Error;
|
||||||
|
try {
|
||||||
|
await method();
|
||||||
|
} catch (err) {
|
||||||
|
error = err;
|
||||||
|
}
|
||||||
|
expect(error).to.be.an(Error.name);
|
||||||
|
if (errorMessage) {
|
||||||
|
expect(error.message).to.equal(errorMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
68
tests/unit/shared/TestCases/AbsentTests.ts
Normal file
68
tests/unit/shared/TestCases/AbsentTests.ts
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
export function itEachAbsentStringValue(runner: (absentValue: string) => void): void {
|
||||||
|
itEachTestCase(AbsentStringTestCases, runner);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function itEachAbsentObjectValue(runner: (absentValue: AbsentObjectType) => void): void {
|
||||||
|
itEachTestCase(AbsentObjectTestCases, runner);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function itEachAbsentCollectionValue<T>(runner: (absentValue: []) => void): void {
|
||||||
|
itEachTestCase(getAbsentCollectionTestCases<T>(), runner);
|
||||||
|
}
|
||||||
|
|
||||||
|
function itEachTestCase<T>(
|
||||||
|
testCases: readonly IAbsentTestCase<T>[],
|
||||||
|
runner: (absentValue: T) => void,
|
||||||
|
): void {
|
||||||
|
for (const testCase of testCases) {
|
||||||
|
it(`given "${testCase.valueName}"`, () => {
|
||||||
|
runner(testCase.absentValue);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const AbsentObjectTestCases: readonly IAbsentTestCase<AbsentObjectType>[] = [
|
||||||
|
{
|
||||||
|
valueName: 'undefined',
|
||||||
|
absentValue: undefined,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
valueName: 'null',
|
||||||
|
absentValue: null,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
export const AbsentStringTestCases: readonly IAbsentStringCase[] = [
|
||||||
|
{
|
||||||
|
valueName: 'empty',
|
||||||
|
absentValue: '',
|
||||||
|
},
|
||||||
|
...AbsentObjectTestCases,
|
||||||
|
];
|
||||||
|
|
||||||
|
export function getAbsentCollectionTestCases<T>(): readonly IAbsentCollectionCase<T>[] {
|
||||||
|
return [
|
||||||
|
...AbsentObjectTestCases,
|
||||||
|
{
|
||||||
|
valueName: 'empty',
|
||||||
|
absentValue: new Array<T>(),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
type AbsentObjectType = undefined | null;
|
||||||
|
|
||||||
|
interface IAbsentTestCase<T> {
|
||||||
|
valueName: string;
|
||||||
|
absentValue: T;
|
||||||
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
||||||
|
interface IAbsentStringCase extends IAbsentTestCase<string> {
|
||||||
|
// Marker interface
|
||||||
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
||||||
|
interface IAbsentCollectionCase<T> extends IAbsentTestCase<T[]> {
|
||||||
|
// Marker interface
|
||||||
|
}
|
||||||
@@ -14,7 +14,7 @@ export class PipeFactoryStub implements IPipeFactory {
|
|||||||
|
|
||||||
public withPipe(pipe: IPipe) {
|
public withPipe(pipe: IPipe) {
|
||||||
if (!pipe) {
|
if (!pipe) {
|
||||||
throw new Error('undefined pipe');
|
throw new Error('missing pipe');
|
||||||
}
|
}
|
||||||
this.pipes.push(pipe);
|
this.pipes.push(pipe);
|
||||||
return this;
|
return this;
|
||||||
|
|||||||
Reference in New Issue
Block a user