1 Star 0 Fork 0

animalcoder/Vue

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
basic.js 3.91 KB
一键复制 编辑 原始数据 按行查看 历史
animalcoder 提交于 2020-03-23 09:59 +08:00 . Vue6
var Stream = require('stream')
var tap = require('tap')
var MS = require('../mute.js')
// some marker objects
var END = {}
var PAUSE = {}
var RESUME = {}
function PassThrough () {
Stream.call(this)
this.readable = this.writable = true
}
PassThrough.prototype = Object.create(Stream.prototype, {
constructor: {
value: PassThrough
},
write: {
value: function (c) {
this.emit('data', c)
return true
}
},
end: {
value: function (c) {
if (c) this.write(c)
this.emit('end')
}
},
pause: {
value: function () {
this.emit('pause')
}
},
resume: {
value: function () {
this.emit('resume')
}
}
})
tap.test('incoming', function (t) {
var ms = new MS
var str = new PassThrough
str.pipe(ms)
var expect = ['foo', 'boo', END]
ms.on('data', function (c) {
t.equal(c, expect.shift())
})
ms.on('end', function () {
t.equal(END, expect.shift())
t.end()
})
str.write('foo')
ms.mute()
str.write('bar')
ms.unmute()
str.write('boo')
ms.mute()
str.write('blaz')
str.end('grelb')
})
tap.test('outgoing', function (t) {
var ms = new MS
var str = new PassThrough
ms.pipe(str)
var expect = ['foo', 'boo', END]
str.on('data', function (c) {
t.equal(c, expect.shift())
})
str.on('end', function () {
t.equal(END, expect.shift())
t.end()
})
ms.write('foo')
ms.mute()
ms.write('bar')
ms.unmute()
ms.write('boo')
ms.mute()
ms.write('blaz')
ms.end('grelb')
})
tap.test('isTTY', function (t) {
var str = new PassThrough
str.isTTY = true
str.columns=80
str.rows=24
var ms = new MS
t.equal(ms.isTTY, false)
t.equal(ms.columns, undefined)
t.equal(ms.rows, undefined)
ms.pipe(str)
t.equal(ms.isTTY, true)
t.equal(ms.columns, 80)
t.equal(ms.rows, 24)
str.isTTY = false
t.equal(ms.isTTY, false)
t.equal(ms.columns, 80)
t.equal(ms.rows, 24)
str.isTTY = true
t.equal(ms.isTTY, true)
t.equal(ms.columns, 80)
t.equal(ms.rows, 24)
ms.isTTY = false
t.equal(ms.isTTY, false)
t.equal(ms.columns, 80)
t.equal(ms.rows, 24)
ms = new MS
t.equal(ms.isTTY, false)
str.pipe(ms)
t.equal(ms.isTTY, true)
str.isTTY = false
t.equal(ms.isTTY, false)
str.isTTY = true
t.equal(ms.isTTY, true)
ms.isTTY = false
t.equal(ms.isTTY, false)
t.end()
})
tap.test('pause/resume incoming', function (t) {
var str = new PassThrough
var ms = new MS
str.on('pause', function () {
t.equal(PAUSE, expect.shift())
})
str.on('resume', function () {
t.equal(RESUME, expect.shift())
})
var expect = [PAUSE, RESUME, PAUSE, RESUME]
str.pipe(ms)
ms.pause()
ms.resume()
ms.pause()
ms.resume()
t.equal(expect.length, 0, 'saw all events')
t.end()
})
tap.test('replace with *', function (t) {
var str = new PassThrough
var ms = new MS({replace: '*'})
str.pipe(ms)
var expect = ['foo', '*****', 'bar', '***', 'baz', 'boo', '**', '****']
ms.on('data', function (c) {
t.equal(c, expect.shift())
})
str.write('foo')
ms.mute()
str.write('12345')
ms.unmute()
str.write('bar')
ms.mute()
str.write('baz')
ms.unmute()
str.write('baz')
str.write('boo')
ms.mute()
str.write('xy')
str.write('xyzΩ')
t.equal(expect.length, 0)
t.end()
})
tap.test('replace with ~YARG~', function (t) {
var str = new PassThrough
var ms = new MS({replace: '~YARG~'})
str.pipe(ms)
var expect = ['foo', '~YARG~~YARG~~YARG~~YARG~~YARG~', 'bar',
'~YARG~~YARG~~YARG~', 'baz', 'boo', '~YARG~~YARG~',
'~YARG~~YARG~~YARG~~YARG~']
ms.on('data', function (c) {
t.equal(c, expect.shift())
})
// also throw some unicode in there, just for good measure.
str.write('foo')
ms.mute()
str.write('ΩΩ')
ms.unmute()
str.write('bar')
ms.mute()
str.write('Ω')
ms.unmute()
str.write('baz')
str.write('boo')
ms.mute()
str.write('Ω')
str.write('ΩΩ')
t.equal(expect.length, 0)
t.end()
})
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/animalcoder/Vue.git
git@gitee.com:animalcoder/Vue.git
animalcoder
Vue
Vue
master

搜索帮助