diff options
author | Matt Godbolt <matt@godbolt.org> | 2017-12-10 16:52:53 -0600 |
---|---|---|
committer | Matt Godbolt <matt@godbolt.org> | 2017-12-10 16:53:00 -0600 |
commit | a272ea9ffcbc287f7d760657276e8600fb1dc12a (patch) | |
tree | 90f2d45f02e5694be041af7b88e2f2ec9d084fc9 /lib/utils.js | |
parent | 92fb800b2234cbba91b0a6a3334592641ea76e08 (diff) | |
download | compiler-explorer-a272ea9ffcbc287f7d760657276e8600fb1dc12a.tar.gz compiler-explorer-a272ea9ffcbc287f7d760657276e8600fb1dc12a.zip |
Add utils tests, update filter-tests
Diffstat (limited to 'lib/utils.js')
-rw-r--r-- | lib/utils.js | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/lib/utils.js b/lib/utils.js index e9432b248..8e4da75ee 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -22,13 +22,16 @@ // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE // POSSIBILITY OF SUCH DAMAGE. -var _ = require('underscore-node'); +const _ = require('underscore-node'); -var tabsRe = /\t/g; -var lineRe = /\r?\n/; +const tabsRe = /\t/g; +const lineRe = /\r?\n/; function splitLines(text) { - return text.split(lineRe); + const result = text.split(lineRe); + if (result.length > 0 && result[result.length - 1] === '') + return result.slice(0, result.length - 1); + return result; } exports.splitLines = splitLines; @@ -40,11 +43,10 @@ function eachLine(text, func, context) { exports.eachLine = eachLine; function expandTabs(line) { - "use strict"; - var extraChars = 0; + let extraChars = 0; return line.replace(tabsRe, function (match, offset) { - var total = offset + extraChars; - var spacesNeeded = (total + 8) & 7; + const total = offset + extraChars; + const spacesNeeded = (total + 8) & 7; extraChars += spacesNeeded - 1; return " ".substr(spacesNeeded); }); @@ -53,13 +55,13 @@ function expandTabs(line) { exports.expandTabs = expandTabs; function parseOutput(lines, inputFilename) { - var re = /^\s*<source>[:(]([0-9]+)(:([0-9]+):)?[):]*\s*(.*)/; - var result = []; + const re = /^\s*<source>[:(]([0-9]+)(:([0-9]+):)?[):]*\s*(.*)/; + const result = []; eachLine(lines, function (line) { - if (inputFilename) line = line.replace(inputFilename, '<source>'); + if (inputFilename) line = line.split(inputFilename).join('<source>'); if (line !== "" && line.indexOf("fixme:") !== 0) { - var lineObj = {text: line}; - var match = line.match(re); + const lineObj = {text: line}; + const match = line.match(re); if (match) { lineObj.tag = { line: parseInt(match[1]), |