Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

split.asynct.js 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. var es = require('event-stream')
  2. , it = require('it-is').style('colour')
  3. , d = require('ubelt')
  4. , split = require('..')
  5. , join = require('path').join
  6. , fs = require('fs')
  7. , Stream = require('stream').Stream
  8. , Readable = require('stream').Readable
  9. , spec = require('stream-spec')
  10. , through = require('through')
  11. , stringStream = require('string-to-stream')
  12. exports ['split() works like String#split'] = function (test) {
  13. var readme = join(__filename)
  14. , expected = fs.readFileSync(readme, 'utf-8').split('\n')
  15. , cs = split()
  16. , actual = []
  17. , ended = false
  18. , x = spec(cs).through()
  19. var a = new Stream ()
  20. a.write = function (l) {
  21. actual.push(l.trim())
  22. }
  23. a.end = function () {
  24. ended = true
  25. expected.forEach(function (v,k) {
  26. //String.split will append an empty string ''
  27. //if the string ends in a split pattern.
  28. //es.split doesn't which was breaking this test.
  29. //clearly, appending the empty string is correct.
  30. //tests are passing though. which is the current job.
  31. if(v)
  32. it(actual[k]).like(v)
  33. })
  34. //give the stream time to close
  35. process.nextTick(function () {
  36. test.done()
  37. x.validate()
  38. })
  39. }
  40. a.writable = true
  41. fs.createReadStream(readme, {flags: 'r'}).pipe(cs)
  42. cs.pipe(a)
  43. }
  44. exports ['split() takes mapper function'] = function (test) {
  45. var readme = join(__filename)
  46. , expected = fs.readFileSync(readme, 'utf-8').split('\n')
  47. , cs = split(function (line) { return line.toUpperCase() })
  48. , actual = []
  49. , ended = false
  50. , x = spec(cs).through()
  51. var a = new Stream ()
  52. a.write = function (l) {
  53. actual.push(l.trim())
  54. }
  55. a.end = function () {
  56. ended = true
  57. expected.forEach(function (v,k) {
  58. //String.split will append an empty string ''
  59. //if the string ends in a split pattern.
  60. //es.split doesn't which was breaking this test.
  61. //clearly, appending the empty string is correct.
  62. //tests are passing though. which is the current job.
  63. if(v)
  64. it(actual[k]).equal(v.trim().toUpperCase())
  65. })
  66. //give the stream time to close
  67. process.nextTick(function () {
  68. test.done()
  69. x.validate()
  70. })
  71. }
  72. a.writable = true
  73. fs.createReadStream(readme, {flags: 'r'}).pipe(cs)
  74. cs.pipe(a)
  75. }
  76. exports ['split() works with empty string chunks'] = function (test) {
  77. var str = ' foo'
  78. , expected = str.split(/[\s]*/).reduce(splitBy(/[\s]*/), [])
  79. , cs1 = split(/[\s]*/)
  80. , cs2 = split(/[\s]*/)
  81. , actual = []
  82. , ended = false
  83. , x = spec(cs1).through()
  84. , y = spec(cs2).through()
  85. var a = new Stream ()
  86. a.write = function (l) {
  87. actual.push(l.trim())
  88. }
  89. a.end = function () {
  90. ended = true
  91. expected.forEach(function (v,k) {
  92. //String.split will append an empty string ''
  93. //if the string ends in a split pattern.
  94. //es.split doesn't which was breaking this test.
  95. //clearly, appending the empty string is correct.
  96. //tests are passing though. which is the current job.
  97. if(v)
  98. it(actual[k]).like(v)
  99. })
  100. //give the stream time to close
  101. process.nextTick(function () {
  102. test.done()
  103. x.validate()
  104. y.validate()
  105. })
  106. }
  107. a.writable = true
  108. cs1.pipe(cs2)
  109. cs2.pipe(a)
  110. cs1.write(str)
  111. cs1.end()
  112. }
  113. function splitBy (delimiter) {
  114. return function (arr, piece) {
  115. return arr.concat(piece.split(delimiter))
  116. }
  117. }