2013-09-23 17:05:36 +00:00
|
|
|
describe 'Asciinema.Brush', ->
|
2012-02-05 13:21:10 +00:00
|
|
|
|
|
|
|
describe '.clearCache', ->
|
|
|
|
|
|
|
|
it 'resets cache hash', ->
|
2013-09-23 17:05:36 +00:00
|
|
|
Asciinema.Brush.create()
|
|
|
|
expect(_(Asciinema.Brush.cache).keys().length > 0).toBeTruthy()
|
|
|
|
Asciinema.Brush.clearCache()
|
|
|
|
expect(_(Asciinema.Brush.cache).keys().length).toEqual(0)
|
2012-02-05 13:21:10 +00:00
|
|
|
|
2012-08-28 21:32:01 +00:00
|
|
|
describe '.hash', ->
|
|
|
|
|
|
|
|
it 'returns string with all brush properties', ->
|
|
|
|
attrs =
|
|
|
|
fg : 1
|
|
|
|
bg : 2
|
|
|
|
blink : false
|
|
|
|
bright : true
|
|
|
|
italic : false
|
|
|
|
underline: true
|
2012-11-25 12:02:23 +00:00
|
|
|
reverse : true
|
2012-08-28 21:32:01 +00:00
|
|
|
|
2013-09-23 17:05:36 +00:00
|
|
|
hash = Asciinema.Brush.hash attrs
|
2012-11-25 12:02:23 +00:00
|
|
|
expect(hash).toEqual '1_2_false_true_false_true_true'
|
2012-08-28 21:32:01 +00:00
|
|
|
|
2012-02-05 13:21:10 +00:00
|
|
|
describe '.create', ->
|
|
|
|
|
|
|
|
beforeEach ->
|
2013-09-23 17:05:36 +00:00
|
|
|
Asciinema.Brush.clearCache()
|
2012-02-05 13:21:10 +00:00
|
|
|
|
|
|
|
it 'returns new brush instance if not cached', ->
|
2013-09-23 17:05:36 +00:00
|
|
|
brush = Asciinema.Brush.create({ fg: 1 })
|
|
|
|
expect(brush instanceof Asciinema.Brush).toBeTruthy()
|
2012-02-05 13:21:10 +00:00
|
|
|
|
|
|
|
it 'returns existing brush instance if cached', ->
|
2013-09-23 17:05:36 +00:00
|
|
|
brush = Asciinema.Brush.create({ fg: 1 })
|
|
|
|
otherBrush = Asciinema.Brush.create({ fg: 1, bg: 100 })
|
|
|
|
anotherBrush = Asciinema.Brush.create({ fg: 1 })
|
2012-02-05 13:21:10 +00:00
|
|
|
|
2013-09-23 17:05:36 +00:00
|
|
|
expect(_(Asciinema.Brush.cache).keys().length).toEqual(2)
|
2012-02-05 13:21:10 +00:00
|
|
|
expect(brush is anotherBrush).toBeTruthy()
|
2012-08-28 21:32:01 +00:00
|
|
|
|
|
|
|
describe '#fgColor', ->
|
|
|
|
|
|
|
|
it 'returns 7 if fg is undefined', ->
|
2013-09-23 17:05:36 +00:00
|
|
|
brush = new Asciinema.Brush fg: undefined
|
2012-08-28 21:32:01 +00:00
|
|
|
expect(brush.fgColor()).toEqual 7
|
|
|
|
|
2012-11-23 20:59:09 +00:00
|
|
|
it 'returns fg if bright is off', ->
|
2013-09-23 17:05:36 +00:00
|
|
|
brush = new Asciinema.Brush fg: 3, bright: false
|
2012-11-23 20:59:09 +00:00
|
|
|
expect(brush.fgColor()).toEqual 3
|
|
|
|
|
2012-08-28 21:32:01 +00:00
|
|
|
it 'returns fg+8 if bright is on', ->
|
2013-09-23 17:05:36 +00:00
|
|
|
brush = new Asciinema.Brush fg: 3, bright: true
|
2012-08-28 21:32:01 +00:00
|
|
|
expect(brush.fgColor()).toEqual 11
|
|
|
|
|
2012-11-23 21:42:39 +00:00
|
|
|
it 'returns bg if reverse is on', ->
|
2013-09-23 17:05:36 +00:00
|
|
|
brush = new Asciinema.Brush fg: 1, bg: 2, reverse: true
|
2012-11-23 21:42:39 +00:00
|
|
|
expect(brush.fgColor()).toEqual 2
|
|
|
|
|
2012-08-28 21:32:01 +00:00
|
|
|
describe '#bgColor', ->
|
|
|
|
|
|
|
|
it 'returns 0 if bg is undefined', ->
|
2013-09-23 17:05:36 +00:00
|
|
|
brush = new Asciinema.Brush bg: undefined
|
2012-08-28 21:32:01 +00:00
|
|
|
expect(brush.bgColor()).toEqual 0
|
|
|
|
|
2012-11-23 20:59:09 +00:00
|
|
|
it 'returns bg if blink is off', ->
|
2013-09-23 17:05:36 +00:00
|
|
|
brush = new Asciinema.Brush bg: 4, blink: false
|
2012-11-23 20:59:09 +00:00
|
|
|
expect(brush.bgColor()).toEqual 4
|
|
|
|
|
2012-08-28 21:32:01 +00:00
|
|
|
it 'returns bg+8 if blink is on', ->
|
2013-09-23 17:05:36 +00:00
|
|
|
brush = new Asciinema.Brush bg: 4, blink: true
|
2012-08-28 21:32:01 +00:00
|
|
|
expect(brush.bgColor()).toEqual 12
|
|
|
|
|
2012-11-23 21:42:39 +00:00
|
|
|
it 'returns fg if reverse is on', ->
|
2013-09-23 17:05:36 +00:00
|
|
|
brush = new Asciinema.Brush fg: 1, bg: 2, reverse: true
|
2012-11-23 21:42:39 +00:00
|
|
|
expect(brush.bgColor()).toEqual 1
|
|
|
|
|
2012-08-28 21:32:01 +00:00
|
|
|
describe '#attributes', ->
|
|
|
|
|
2012-11-25 12:02:23 +00:00
|
|
|
it 'includes fg, bg, blink, bright, italic, underline, reverse', ->
|
2013-09-23 17:05:36 +00:00
|
|
|
brush = new Asciinema.Brush
|
2012-08-28 21:32:01 +00:00
|
|
|
attrs = brush.attributes()
|
2012-11-25 12:02:23 +00:00
|
|
|
expectedAttrs =
|
|
|
|
['fg', 'bg', 'blink', 'bright', 'italic', 'underline', 'reverse']
|
2012-08-28 21:32:01 +00:00
|
|
|
|
|
|
|
expect(_(attrs).keys().length).toEqual _(expectedAttrs).keys().length
|
|
|
|
|
|
|
|
for attr in expectedAttrs
|
|
|
|
expect(_(attrs).has(attr)).toBeTruthy()
|
2012-11-23 21:42:39 +00:00
|
|
|
|
|
|
|
describe '#applyChanges', ->
|
|
|
|
|
|
|
|
it 'returns new brush', ->
|
2013-09-23 17:05:36 +00:00
|
|
|
brush = new Asciinema.Brush
|
2012-11-23 21:42:39 +00:00
|
|
|
newBrush = brush.applyChanges fg: 5
|
|
|
|
|
|
|
|
expect(newBrush).toNotEqual brush
|
|
|
|
|
|
|
|
it 'applies changes to attributes', ->
|
2013-09-23 17:05:36 +00:00
|
|
|
brush = new Asciinema.Brush fg: 1
|
2012-11-23 21:42:39 +00:00
|
|
|
newBrush = brush.applyChanges fg: 2
|
|
|
|
|
|
|
|
expect(newBrush.fg).toEqual 2
|