Version 1
[yaffs-website] / node_modules / linerstream / test / split-test.js
diff --git a/node_modules/linerstream/test/split-test.js b/node_modules/linerstream/test/split-test.js
new file mode 100644 (file)
index 0000000..3ef7e3f
--- /dev/null
@@ -0,0 +1,47 @@
+var sinon = require('sinon')
+var fs = require('fs')
+var path = require('path')
+var os = require('os')
+var expect = require('chai').expect
+var Linerstream = require('../')
+
+describe('Split test', function() {
+  describe('given text with line breaks', function() {
+    it('should split on new lines', function(done) {
+      var fixturePath = path.join(__dirname, 'data/newlines-big.txt')
+      var inputStream = fs.createReadStream(fixturePath)
+      var splitter = new Linerstream()
+      expect(splitter).to.exist
+      var output = inputStream.pipe(splitter)
+      var validateLineSpy = sinon.spy(validateLine)
+
+      output.on('finish', finishHandler)
+      output.on('readable', readableHandler)
+
+      function validateLine(line) {
+        expect(line).to.exist
+        expect(line).to.be.a('string')
+        expect(line).to.not.be.empty
+        expect(line).to.not.match(/\n|\r/)
+      }
+
+      function readableHandler() {
+        var data
+        while (true) {
+          data = output.read()
+          if (!data) {
+            break
+          }
+          validateLineSpy(data)
+
+        }
+      }
+
+      function finishHandler() {
+        expect(validateLineSpy.callCount).to.be.above(1)
+        done()
+      }
+
+    })
+  })
+})