Skip to content

Commit

Permalink
Fix #11
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagodp committed Jun 6, 2018
1 parent ef8b862 commit 1e8dd91
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 10 deletions.
4 changes: 3 additions & 1 deletion dist/modules/testcase/TCDocGen.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class TCDocGen {
let docImport = {
nodeType: NodeTypes_1.NodeTypes.IMPORT,
location: {
column: 0,
column: 1,
line: startLine
},
value: filePath
Expand Down Expand Up @@ -128,6 +128,8 @@ class TCDocGen {
}
// Header
tc.location.line = line++;
// Solves the problem of references
tc.sentences = deepcopy(tc.sentences); // DEEP COPY
// Sentences
for (let sentence of tc.sentences || []) {
sentence.location.line = line++;
Expand Down
55 changes: 51 additions & 4 deletions dist/modules/testcase/TestCaseFileGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,34 @@ class TestCaseFileGenerator {
if (!ignoreHeader) {
lines.push.apply(lines, this.fileHeader);
}
let lineNumber = 1 + lines.length;
// Generate language, if declared
if (doc.language) {
// Get dictionary
dict = this.dictionaryForLanguage(doc.language.value, errors) || this._dict;
lines.push(this.generateLanguageLine(doc.language.value, dict));
// Transform to text
let line = this.generateLanguageLine(doc.language.value, dict);
// Adjust location
doc.language.location = {
line: lineNumber++,
column: 1 + line.length - line.trimLeft().length
};
lines.push(line);
lines.push(''); // empty line
}
lineNumber++;
// Imports
for (let imp of doc.imports || []) {
lines.push(this.generateImportLine(imp.value, dict));
// Transform to text
let line = this.generateImportLine(imp.value, dict);
// Adjust location
imp.location = {
line: lineNumber++,
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 @@ -62,18 +80,47 @@ class TestCaseFileGenerator {
}
// Tags
for (let tag of testCase.tags || []) {
lines.push(this.generateTagLine(tag.name, tag.content));
// Transform to text
let line = this.generateTagLine(tag.name, tag.content);
// Adjust location
tag.location = {
line: lineNumber++,
column: 1 + line.length - line.trimLeft().length
};
lines.push(line);
}
// Header
lines.push(this.generateTestCaseHeader(testCase.name, dict));
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
};
}
else {
testCase.location = {
line: testCase.tags[testCase.tags.length - 1].location.line - 1,
column: 1 + line.length - line.trimLeft().length
};
lineNumber++;
}
lineNumber++;
// Sentences
for (let sentence of testCase.sentences || []) {
// Transform to text
let ind = indentation;
if (NodeTypes_1.NodeTypes.STEP_AND === sentence.nodeType) {
ind += indentation;
}
let line = ind + sentence.content +
(!sentence.comment ? '' : ' ' + Symbols_1.Symbols.COMMENT_PREFIX + sentence.comment);
// Adjust location
sentence.location = {
line: lineNumber++,
column: 1 + line.length - line.trimLeft().length
};
lines.push(line);
}
}
Expand Down
5 changes: 4 additions & 1 deletion modules/testcase/TCDocGen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export class TCDocGen {
let docImport: Import = {
nodeType: NodeTypes.IMPORT,
location: {
column: 0,
column: 1,
line: startLine
},
value: filePath
Expand Down Expand Up @@ -165,6 +165,9 @@ export class TCDocGen {
// Header
tc.location.line = line++;

// Solves the problem of references
tc.sentences = deepcopy( tc.sentences ); // DEEP COPY

// Sentences
for ( let sentence of tc.sentences || [] ) {
sentence.location.line = line++;
Expand Down
70 changes: 66 additions & 4 deletions modules/testcase/TestCaseFileGenerator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Document } from "../ast/Document";
import { Location } from "../ast/Location";
import { LanguageContentLoader } from "../dict/LanguageContentLoader";
import { KeywordDictionary } from "../dict/KeywordDictionary";
import { EnglishKeywordDictionary } from "../dict/EnglishKeywordDictionary";
Expand Down Expand Up @@ -54,18 +55,42 @@ export class TestCaseFileGenerator {
if ( ! ignoreHeader ) {
lines.push.apply( lines, this.fileHeader );
}
let lineNumber = 1 + lines.length;

// Generate language, if declared
if ( doc.language ) {

// Get dictionary
dict = this.dictionaryForLanguage( doc.language.value, errors ) || this._dict;
lines.push( this.generateLanguageLine( doc.language.value, dict ) );
// Transform to text
let line = this.generateLanguageLine( doc.language.value, dict );

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

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

// Imports
for ( let imp of doc.imports || [] ) {
lines.push( this.generateImportLine( imp.value, dict ) );

// Transform to text
let line = this.generateImportLine( imp.value, dict );

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

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

// Test Cases
let lastTagsContent: string = '';
Expand All @@ -84,14 +109,45 @@ export class TestCaseFileGenerator {

// Tags
for ( let tag of testCase.tags || [] ) {
lines.push( this.generateTagLine( tag.name, tag.content ) );

// Transform to text
let line = this.generateTagLine( tag.name, tag.content );

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

lines.push( line );
}

// Header
lines.push( this.generateTestCaseHeader( testCase.name, dict ) );
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++
}

lineNumber++;

// Sentences
for ( let sentence of testCase.sentences || [] ) {

// Transform to text

let ind = indentation;
if ( NodeTypes.STEP_AND === sentence.nodeType ) {
ind += indentation;
Expand All @@ -100,6 +156,12 @@ export class TestCaseFileGenerator {
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
} as Location;

lines.push( line );
}
}
Expand Down

0 comments on commit 1e8dd91

Please sign in to comment.