From 1e8dd915d28524537a9b1dd45dc28040a5df4fb4 Mon Sep 17 00:00:00 2001 From: Thiago Delgado Pinto Date: Tue, 5 Jun 2018 21:00:37 -0300 Subject: [PATCH] Fix #11 --- dist/modules/testcase/TCDocGen.js | 4 +- .../modules/testcase/TestCaseFileGenerator.js | 55 +++++++++++++-- modules/testcase/TCDocGen.ts | 5 +- modules/testcase/TestCaseFileGenerator.ts | 70 +++++++++++++++++-- 4 files changed, 124 insertions(+), 10 deletions(-) diff --git a/dist/modules/testcase/TCDocGen.js b/dist/modules/testcase/TCDocGen.js index 18692688..e32cf116 100644 --- a/dist/modules/testcase/TCDocGen.js +++ b/dist/modules/testcase/TCDocGen.js @@ -93,7 +93,7 @@ class TCDocGen { let docImport = { nodeType: NodeTypes_1.NodeTypes.IMPORT, location: { - column: 0, + column: 1, line: startLine }, value: filePath @@ -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++; diff --git a/dist/modules/testcase/TestCaseFileGenerator.js b/dist/modules/testcase/TestCaseFileGenerator.js index 3798f530..123e2d11 100644 --- a/dist/modules/testcase/TestCaseFileGenerator.js +++ b/dist/modules/testcase/TestCaseFileGenerator.js @@ -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 || []) { @@ -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); } } diff --git a/modules/testcase/TCDocGen.ts b/modules/testcase/TCDocGen.ts index 32d56718..c9f60bed 100644 --- a/modules/testcase/TCDocGen.ts +++ b/modules/testcase/TCDocGen.ts @@ -123,7 +123,7 @@ export class TCDocGen { let docImport: Import = { nodeType: NodeTypes.IMPORT, location: { - column: 0, + column: 1, line: startLine }, value: filePath @@ -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++; diff --git a/modules/testcase/TestCaseFileGenerator.ts b/modules/testcase/TestCaseFileGenerator.ts index e707b233..649b878c 100644 --- a/modules/testcase/TestCaseFileGenerator.ts +++ b/modules/testcase/TestCaseFileGenerator.ts @@ -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"; @@ -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 = ''; @@ -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; @@ -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 ); } }