Skip to content

Commit

Permalink
Fix #51
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagodp committed Dec 21, 2019
1 parent 2fcea3a commit bbf557d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 46 deletions.
33 changes: 11 additions & 22 deletions dist/modules/testcase/TestCaseFileGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class TestCaseFileGenerator {
if (!ignoreHeader) {
lines.push.apply(lines, this.fileHeader);
}
let lineNumber = 1 + lines.length;
// Generate language, if declared
if (doc.language) {
// Get dictionary
Expand All @@ -47,25 +46,23 @@ class TestCaseFileGenerator {
let line = this.generateLanguageLine(doc.language.value, dict);
// Adjust location
doc.language.location = {
line: lineNumber++,
line: lines.length + 1,
column: 1 + line.length - line.trimLeft().length
};
lines.push(line);
lines.push(''); // empty line
}
lineNumber++;
// Imports
for (let imp of doc.imports || []) {
// Transform to text
let line = this.generateImportLine(imp.value, dict);
// Adjust location
imp.location = {
line: lineNumber++,
line: lines.length + 1,
column: 1 + line.length - line.trimLeft().length
};
lines.push(line);
}
let lastLineNumber = lineNumber;
// Test Cases
let lastTagsContent = '';
for (let testCase of doc.testCases || []) {
Expand All @@ -84,35 +81,27 @@ class TestCaseFileGenerator {
let line = this.generateTagLine(tag.name, tag.content);
// Adjust location
tag.location = {
line: lineNumber++,
line: lines.length + 1,
column: 1 + line.length - line.trimLeft().length
};
lines.push(line);
}
// Header
let line = this.generateTestCaseHeader(testCase.name, dict);
lines.push(line);
// Adjust location
if ((testCase.tags || []).length < 1) {
testCase.location = {
line: lineNumber++,
column: 1 + line.length - line.trimLeft().length
};
if (!testCase.location) {
testCase.location = {};
}
else {
testCase.location = {
line: testCase.tags[testCase.tags.length - 1].location.line - 1,
column: 1 + line.length - line.trimLeft().length
};
lineNumber++;
}
lineNumber++;
testCase.location.column = line.length - line.trimLeft.length;
testCase.location.line = lines.length;
const baseLineNumber = testCase.location.line;
let lineNumber = 1 + baseLineNumber;
// Sentences
for (let sentence of testCase.sentences || []) {
if (!sentence) {
continue;
}
// Transform to text
// Transform into text
let ind = indentation;
if (NodeTypes_1.NodeTypes.STEP_AND === sentence.nodeType) {
ind += indentation;
Expand All @@ -122,7 +111,7 @@ class TestCaseFileGenerator {
// Adjust location
sentence.location = {
line: lineNumber++,
column: 1 + line.length - line.trimLeft().length
column: line.length - line.trimLeft().length
};
lines.push(line);
}
Expand Down
35 changes: 11 additions & 24 deletions modules/testcase/TestCaseFileGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ export class TestCaseFileGenerator {
if ( ! ignoreHeader ) {
lines.push.apply( lines, this.fileHeader );
}
let lineNumber = 1 + lines.length;

// Generate language, if declared
if ( doc.language ) {
Expand All @@ -68,14 +67,13 @@ export class TestCaseFileGenerator {

// Adjust location
doc.language.location = {
line: lineNumber++,
line: lines.length + 1,
column: 1 + line.length - line.trimLeft().length
} as Location;

lines.push( line );
lines.push( '' ); // empty line
}
lineNumber++;

// Imports
for ( let imp of doc.imports || [] ) {
Expand All @@ -85,13 +83,12 @@ export class TestCaseFileGenerator {

// Adjust location
imp.location = {
line: lineNumber++,
line: lines.length + 1,
column: 1 + line.length - line.trimLeft().length
} as Location;

lines.push( line );
}
let lastLineNumber = lineNumber;

// Test Cases
let lastTagsContent: string = '';
Expand All @@ -116,7 +113,7 @@ export class TestCaseFileGenerator {

// Adjust location
tag.location = {
line: lineNumber++,
line: lines.length + 1,
column: 1 + line.length - line.trimLeft().length
} as Location;

Expand All @@ -127,22 +124,14 @@ export class TestCaseFileGenerator {
let line = this.generateTestCaseHeader( testCase.name, dict );
lines.push( line );

// Adjust location
if ( ( testCase.tags || [] ).length < 1 ) {
testCase.location = {
line: lineNumber++,
column: 1 + line.length - line.trimLeft().length
} as Location;
} else {
testCase.location = {
line: testCase.tags[ testCase.tags.length - 1 ].location.line - 1,
column: 1 + line.length - line.trimLeft().length
} as Location;

lineNumber++
if ( ! testCase.location ) {
testCase.location = {} as any;
}
testCase.location.column = line.length - line.trimLeft.length;
testCase.location.line = lines.length;

lineNumber++;
const baseLineNumber = testCase.location.line;
let lineNumber = 1 + baseLineNumber;

// Sentences
for ( let sentence of testCase.sentences || [] ) {
Expand All @@ -151,20 +140,18 @@ export class TestCaseFileGenerator {
continue;
}

// Transform to text

// Transform into text
let ind = indentation;
if ( NodeTypes.STEP_AND === sentence.nodeType ) {
ind += indentation;
}

let line = ind + sentence.content +
( ! sentence.comment ? '' : ' ' + Symbols.COMMENT_PREFIX + sentence.comment );

// Adjust location
sentence.location = {
line: lineNumber++,
column: 1 + line.length - line.trimLeft().length
column: line.length - line.trimLeft().length
} as Location;

lines.push( line );
Expand Down

0 comments on commit bbf557d

Please sign in to comment.