add initial macOS support #40
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import 'mocha';
|
||||
import { expect } from 'chai';
|
||||
import { ProjectInformation } from '@/domain/ProjectInformation';
|
||||
import { ICategory } from '@/domain/ICategory';
|
||||
import { OperatingSystem } from '@/domain/OperatingSystem';
|
||||
import { IScriptingDefinition } from '@/domain/IScriptingDefinition';
|
||||
|
||||
@@ -3,16 +3,15 @@ import 'mocha';
|
||||
import { expect } from 'chai';
|
||||
import { Script } from '@/domain/Script';
|
||||
import { RecommendationLevel } from '@/domain/RecommendationLevel';
|
||||
import { ScriptCode } from '@/domain/ScriptCode';
|
||||
import { IScriptCode } from '@/domain/IScriptCode';
|
||||
import { ScriptCodeStub } from '../stubs/ScriptCodeStub';
|
||||
|
||||
describe('Script', () => {
|
||||
describe('ctor', () => {
|
||||
describe('scriptCode', () => {
|
||||
it('sets as expected', () => {
|
||||
// arrange
|
||||
const name = 'test-script';
|
||||
const expected = new ScriptCode(name, 'expected-execute', 'expected-revert');
|
||||
const expected = new ScriptCodeStub();
|
||||
const sut = new ScriptBuilder()
|
||||
.withCode(expected)
|
||||
.build();
|
||||
@@ -110,12 +109,14 @@ describe('Script', () => {
|
||||
|
||||
class ScriptBuilder {
|
||||
private name = 'test-script';
|
||||
private code: IScriptCode = new ScriptCode(this.name, 'code', 'revert-code');
|
||||
private code: IScriptCode = new ScriptCodeStub();
|
||||
private level = RecommendationLevel.Standard;
|
||||
private documentationUrls: readonly string[] = undefined;
|
||||
|
||||
public withCodes(code: string, revertCode = ''): ScriptBuilder {
|
||||
this.code = new ScriptCode(this.name, code, revertCode);
|
||||
this.code = new ScriptCodeStub()
|
||||
.withExecute(code)
|
||||
.withRevert(revertCode);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@ import 'mocha';
|
||||
import { expect } from 'chai';
|
||||
import { ScriptCode } from '@/domain/ScriptCode';
|
||||
import { IScriptCode } from '@/domain/IScriptCode';
|
||||
import { ILanguageSyntax } from '@/domain/ScriptCode';
|
||||
import { LanguageSyntaxStub } from '../stubs/LanguageSyntaxStub';
|
||||
|
||||
describe('ScriptCode', () => {
|
||||
describe('scriptName', () => {
|
||||
@@ -10,7 +12,9 @@ describe('ScriptCode', () => {
|
||||
const expectedError = 'name is undefined';
|
||||
const name = undefined;
|
||||
// act
|
||||
const act = () => new ScriptCode(name, 'non-empty-code', '');
|
||||
const act = () => new ScriptCodeBuilder()
|
||||
.withName(name)
|
||||
.build();
|
||||
// assert
|
||||
expect(act).to.throw(expectedError);
|
||||
});
|
||||
@@ -48,7 +52,11 @@ describe('ScriptCode', () => {
|
||||
for (const testCase of testCases) {
|
||||
it(testCase.name, () => {
|
||||
// act
|
||||
const act = () => new ScriptCode(scriptName, testCase.code.execute, testCase.code.revert);
|
||||
const act = () => new ScriptCodeBuilder()
|
||||
.withName(scriptName)
|
||||
.withExecute( testCase.code.execute)
|
||||
.withRevert(testCase.code.revert)
|
||||
.build();
|
||||
// assert
|
||||
expect(act).to.throw(testCase.expectedError);
|
||||
});
|
||||
@@ -72,15 +80,21 @@ describe('ScriptCode', () => {
|
||||
// act
|
||||
const actions = [];
|
||||
for (const testCase of testCases) {
|
||||
const substituteScriptName = (name) => testCase.expectedMessage.replace('$scriptName', name);
|
||||
const substituteScriptName = (name: string) => testCase.expectedMessage.replace('$scriptName', name);
|
||||
actions.push(...[
|
||||
{
|
||||
act: () => new ScriptCode(scriptName, testCase.code, undefined),
|
||||
act: () => new ScriptCodeBuilder()
|
||||
.withName(scriptName)
|
||||
.withExecute(testCase.code)
|
||||
.build(),
|
||||
testName: `execute: ${testCase.testName}`,
|
||||
expectedMessage: substituteScriptName(scriptName),
|
||||
},
|
||||
{
|
||||
act: () => new ScriptCode(scriptName, 'valid code', testCase.code),
|
||||
act: () => new ScriptCodeBuilder()
|
||||
.withName(scriptName)
|
||||
.withRevert(testCase.code)
|
||||
.build(),
|
||||
testName: `revert: ${testCase.testName}`,
|
||||
expectedMessage: substituteScriptName(`${scriptName} (revert)`),
|
||||
},
|
||||
@@ -96,26 +110,29 @@ describe('ScriptCode', () => {
|
||||
});
|
||||
describe('sets as expected with valid "execute" or "revert"', () => {
|
||||
// arrange
|
||||
const syntax = new LanguageSyntaxStub()
|
||||
.withCommonCodeParts(')', 'else', '(')
|
||||
.withCommentDelimiters('#', '//');
|
||||
const testCases = [
|
||||
{
|
||||
testName: 'code is a valid string',
|
||||
code: 'valid code',
|
||||
},
|
||||
{
|
||||
testName: 'code consists of frequent code parts',
|
||||
code: ') else (',
|
||||
testName: 'code consists of common code parts',
|
||||
code: syntax.commonCodeParts.join(' '),
|
||||
},
|
||||
{
|
||||
testName: 'code is a frequent code part',
|
||||
code: ')',
|
||||
testName: 'code is a common code part',
|
||||
code: syntax.commonCodeParts[0],
|
||||
},
|
||||
{
|
||||
testName: 'code with duplicated comment lines (::)',
|
||||
code: ':: comment\n:: comment',
|
||||
testName: `code with duplicated comment lines (${syntax.commentDelimiters[0]})`,
|
||||
code: `${syntax.commentDelimiters[0]} comment\n${syntax.commentDelimiters[0]} comment`,
|
||||
},
|
||||
{
|
||||
testName: 'code with duplicated comment lines (REM)',
|
||||
code: 'REM comment\nREM comment',
|
||||
testName: `code with duplicated comment lines (${syntax.commentDelimiters[1]})`,
|
||||
code: `${syntax.commentDelimiters[1]} comment\n${syntax.commentDelimiters[1]} comment`,
|
||||
},
|
||||
];
|
||||
// act
|
||||
@@ -124,12 +141,20 @@ describe('ScriptCode', () => {
|
||||
actions.push(...[
|
||||
{
|
||||
testName: `execute: ${testCase.testName}`,
|
||||
act: () => createSut(testCase.code),
|
||||
act: () =>
|
||||
new ScriptCodeBuilder()
|
||||
.withSyntax(syntax)
|
||||
.withExecute(testCase.code)
|
||||
.build(),
|
||||
expect: (sut: IScriptCode) => sut.execute === testCase.code,
|
||||
},
|
||||
{
|
||||
testName: `revert: ${testCase.testName}`,
|
||||
act: () => createSut('different code', testCase.code),
|
||||
act: () =>
|
||||
new ScriptCodeBuilder()
|
||||
.withSyntax(syntax)
|
||||
.withRevert(testCase.code)
|
||||
.build(),
|
||||
expect: (sut: IScriptCode) => sut.revert === testCase.code,
|
||||
},
|
||||
]);
|
||||
@@ -145,6 +170,34 @@ describe('ScriptCode', () => {
|
||||
});
|
||||
});
|
||||
|
||||
function createSut(code: string, revert = ''): ScriptCode {
|
||||
return new ScriptCode('test-code', code, revert);
|
||||
class ScriptCodeBuilder {
|
||||
public execute = 'default-execute-code';
|
||||
public revert = '';
|
||||
public scriptName = 'default-script-name';
|
||||
public syntax: ILanguageSyntax = new LanguageSyntaxStub();
|
||||
|
||||
public withName(name: string) {
|
||||
this.scriptName = name;
|
||||
return this;
|
||||
}
|
||||
public withExecute(execute: string) {
|
||||
this.execute = execute;
|
||||
return this;
|
||||
}
|
||||
public withRevert(revert: string) {
|
||||
this.revert = revert;
|
||||
return this;
|
||||
}
|
||||
public withSyntax(syntax: ILanguageSyntax) {
|
||||
this.syntax = syntax;
|
||||
return this;
|
||||
}
|
||||
|
||||
public build(): ScriptCode {
|
||||
return new ScriptCode(
|
||||
this.execute,
|
||||
this.revert,
|
||||
this.scriptName,
|
||||
this.syntax);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ import { expect } from 'chai';
|
||||
import { ScriptingDefinition } from '@/domain/ScriptingDefinition';
|
||||
import { ScriptingLanguage } from '@/domain/ScriptingLanguage';
|
||||
import { getEnumValues } from '@/application/Common/Enum';
|
||||
import { OperatingSystem } from '@/domain/OperatingSystem';
|
||||
|
||||
describe('ScriptingDefinition', () => {
|
||||
describe('language', () => {
|
||||
@@ -38,7 +37,7 @@ describe('ScriptingDefinition', () => {
|
||||
// arrange
|
||||
const testCases = new Map<ScriptingLanguage, string>([
|
||||
[ScriptingLanguage.batchfile, 'bat'],
|
||||
[ScriptingLanguage.bash, 'sh'],
|
||||
[ScriptingLanguage.shellscript, 'sh'],
|
||||
]);
|
||||
Array.from(testCases.entries()).forEach((test) => {
|
||||
const language = test[0];
|
||||
@@ -108,7 +107,7 @@ describe('ScriptingDefinition', () => {
|
||||
});
|
||||
|
||||
class ScriptingDefinitionBuilder {
|
||||
private language = ScriptingLanguage.bash;
|
||||
private language = ScriptingLanguage.shellscript;
|
||||
private startCode = 'REM start-code';
|
||||
private endCode = 'REM end-code';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user