Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 25 additions & 18 deletions src/web/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,10 @@ function createAff(key: string) {
return ret;
}

async function createCLAS(uri: vscode.Uri) {
const name = await vscode.window.showInputBox({ placeHolder: "cl_name" });
if (name === undefined || name === "") {
return;
}
export function buildClasXml(name: string, withUnitTests: boolean) {
const withUnitTestsXml = withUnitTests ? "\n <WITH_UNIT_TESTS>X</WITH_UNIT_TESTS>" : "";

const dir = await findFolder(uri);
const filename = name.replace(/\//g, "#").toLowerCase() + ".clas";

const uriXML = filename + ".xml";
const dataXML = `<?xml version="1.0" encoding="utf-8"?>
return `<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
Expand All @@ -126,11 +119,31 @@ async function createCLAS(uri: vscode.Uri) {
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>X</UNICODE>
<UNICODE>X</UNICODE>${withUnitTestsXml}
</VSEOCLASS>
</asx:values>
</asx:abap>
</abapGit>`;
}

async function createCLAS(uri: vscode.Uri) {
const name = await vscode.window.showInputBox({ placeHolder: "cl_name" });
if (name === undefined || name === "") {
return;
}

const dir = await findFolder(uri);
const filename = name.replace(/\//g, "#").toLowerCase() + ".clas";

const createTestClass = await vscode.window.showQuickPick(
[{ label: "yes" },
{ label: "no" }],
{ placeHolder: "Add test class include?" }
);
const withUnitTests = createTestClass?.label === "yes";

const uriXML = filename + ".xml";
const dataXML = buildClasXml(name, withUnitTests);
await createFile(dir, uriXML, dataXML);

const uriABAP = filename + ".abap";
Expand All @@ -143,13 +156,7 @@ CLASS ${name.toLowerCase()} IMPLEMENTATION.
ENDCLASS.`;
await createFile(dir, uriABAP, dataABAP);

const createTestClass = await vscode.window.showQuickPick(
[{ label: "yes" },
{ label: "no" }],
{ placeHolder: "Add test class include?" }
);

if (createTestClass?.label === "yes") {
if (withUnitTests) {
const uriTestIncl = filename + ".testclasses" + ".abap";
const dataTestIncl = `*"* use this source file for your ABAP unit test classes`;
await createFile(dir, uriTestIncl, dataTestIncl);
Expand Down
13 changes: 13 additions & 0 deletions src/web/test/suite/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as assert from 'assert';
// You can import and use all API from the 'vscode' module
// as well as import your extension to test it
import * as vscode from 'vscode';
import { buildClasXml } from '../../create';
// import * as myExtension from '../../extension';

suite('Web Extension Test Suite', () => {
Expand All @@ -12,4 +13,16 @@ suite('Web Extension Test Suite', () => {
assert.strictEqual(-1, [1, 2, 3].indexOf(5));
assert.strictEqual(-1, [1, 2, 3].indexOf(0));
});

test('CLAS XML sets testclasses flag when requested', () => {
const xml = buildClasXml('zcl_demo', true);

assert.ok(xml.includes('<WITH_UNIT_TESTS>X</WITH_UNIT_TESTS>'));
});

test('CLAS XML omits testclasses flag when not requested', () => {
const xml = buildClasXml('zcl_demo', false);

assert.ok(!xml.includes('<WITH_UNIT_TESTS>X</WITH_UNIT_TESTS>'));
});
});
Loading