Skip to content

Commit

Permalink
Added external test files for readability and tweaked regex
Browse files Browse the repository at this point in the history
  • Loading branch information
goofballtech committed Jun 26, 2020
1 parent c4cb28a commit 4b4e509
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 19 deletions.
36 changes: 17 additions & 19 deletions source/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ Documentation License: [![Creative Commons License](https://i.creativecommons.or
//#Dependencies
//##Internal
//##Standard
const FileSystem = require('fs');
const FileSystem = require('fs');
const path = require('path')
//##External
const GetStream = require('get-stream');

Expand Down Expand Up @@ -141,7 +142,6 @@ function getDocumentationStringFromSourceString( source_string, options = {} ){
var regex = null;
var matches_iterator = null;
var matches_array = [];
var documentation = '';
const FUNCTION_NAME = 'getDocumentationStringFromSourceString';
Logger.log({process: PROCESS_NAME, module: MODULE_NAME, file: FILENAME, function: FUNCTION_NAME, level: 'debug', message: `received: ${arguments_array}`});
//Variables
Expand All @@ -152,14 +152,10 @@ function getDocumentationStringFromSourceString( source_string, options = {} ){
throw return_error;
}
//Function
regex = new RegExp('/\\*\\*\\n([\\t\\n\\r -~]*?)\\*/', 'gs');
matches_iterator = source_string.matchAll(regex);
matches_array = Array.from(matches_iterator);
regex = new RegExp(/\/\*\*[\W\w\s\r\n*]*?\*\//, 'gs');
matches_iterator = source_string.matchAll(regex);
Logger.log({process: PROCESS_NAME, module: MODULE_NAME, file: FILENAME, function: FUNCTION_NAME, level: 'debug', message: `matches: ${matches_array}`});
for( var index = 0; index < matches_array.length; index++ ){
documentation += matches_array[index][1];
}
_return = documentation;
_return = Array.from(matches_iterator).join('\n').replace(/\/\*\*|\*\/|(?:\r?\n|\r){2,}/g, '')

//Return
Logger.log({process: PROCESS_NAME, module: MODULE_NAME, file: FILENAME, function: FUNCTION_NAME, level: 'debug', message: `returned: ${_return}`});
Expand Down Expand Up @@ -192,9 +188,9 @@ function getDocumentationStringFromSourceString_Test(){
var _return = false;
var return_error = null;
var arg_test = false;
var success_test = false;
var sample_input = 'something\n/**\n* should appear\nalso should appear\n*/\nshould not appear\n/**\nshould appear round two\n*/\nshould not appear\n';
var expected_output = '* should appear\nalso should appear\nshould appear round two\n';
var success_test = false;
var sample_input = FileSystem.readFileSync(path.resolve(__dirname, '../testFiles/testInput.js')).toString()
var expected_output = FileSystem.readFileSync(path.resolve(__dirname, '../testFiles/testOutput.txt')).toString()
var actual_output = '';
//Tests
///Invalid arg test
Expand All @@ -211,8 +207,8 @@ function getDocumentationStringFromSourceString_Test(){
}
}
///success test
try{
actual_output = getDocumentationStringFromSourceString( sample_input );
try {
actual_output = getDocumentationStringFromSourceString( sample_input );
if( actual_output === expected_output ){
success_test = true;
} else{
Expand Down Expand Up @@ -327,7 +323,7 @@ function getDocumentationStringFromSourceBuffer_Test(){
var null_buffer_test = false;
var success_test = false;
var input = null;
var expected_output = '* should appear\nalso should appear\nshould appear round two\n';
var expected_output = FileSystem.readFileSync(path.resolve(__dirname, '../testFiles/testOutput.txt')).toString();
var actual_output = '';
//Tests
test_name = 'invalid arg test';
Expand Down Expand Up @@ -358,8 +354,8 @@ function getDocumentationStringFromSourceBuffer_Test(){
}
}
test_name = 'success test';
try{
input = Buffer.from('something\n/**\n* should appear\nalso should appear\n*/\nshould not appear\n/**\nshould appear round two\n*/\nshould not appear\n', 'utf8');
try {
input = new Buffer.from(FileSystem.readFileSync(path.resolve(__dirname, '../testFiles/testInput.js')), 'utf8')
actual_output = getDocumentationStringFromSourceBuffer( input );
if( actual_output === expected_output ){
success_test = true;
Expand Down Expand Up @@ -498,8 +494,10 @@ async function main_Async_Test(){
var _return = false;
var return_error = null;
//Tests
try{
getDocumentationStringFromSourceString_Test();
try {
console.log('string');
getDocumentationStringFromSourceString_Test();
console.log('buffer');
getDocumentationStringFromSourceBuffer_Test();
} catch(error){
Logger.log({process: PROCESS_NAME, module: MODULE_NAME, file: FILENAME, function: FUNCTION_NAME, level: 'crit', message: `Test failed with error: '${error}'`});
Expand Down
19 changes: 19 additions & 0 deletions testFiles/testInput.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

function DoNothingFunction() {
//data before
}

/**
A test output string for pulling
Documentation Symbols #$/{()}
*/

/** A second test without the line break */

DoNothingFunction()

/**
* A third Thing
*/

// Single line comment, will not output
8 changes: 8 additions & 0 deletions testFiles/testOutput.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

A test output string for pulling
Documentation Symbols #$/{()}

A second test without the line break

* A third Thing

0 comments on commit 4b4e509

Please sign in to comment.