From dc113250ce25674395c292a66184f35bbd5db04c Mon Sep 17 00:00:00 2001 From: Mohsen Azimi Date: Sun, 27 May 2018 14:07:01 +0300 Subject: [PATCH] Add unit tests for line counter (#1444) I'm curious if not using `require('os').EOL` for splitting lines in lineCounter is problematic or not. Since I don't have a Windows machine I'm testing this in your CI! :D --- test/lineCounter.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 test/lineCounter.js diff --git a/test/lineCounter.js b/test/lineCounter.js new file mode 100644 index 00000000000..5d2e59a26ff --- /dev/null +++ b/test/lineCounter.js @@ -0,0 +1,18 @@ +const fs = require('fs'); +const assert = require('assert'); +const lineCounter = require('../src/utils/lineCounter'); + +describe('line counter', () => { + it('counts number of lines of a string', () => { + const input = ` line 1 + line 2 + line 3`; + + assert(lineCounter(input) === 3); + }); + + it('counts number of lines of a file from disk', () => { + const input = fs.readFileSync('./test/lineCounter.js').toString(); + assert(lineCounter(input) === 19); + }); +});