asciinema.org/spec/javascripts/player/brush_spec.js.coffee

105 lines
3.1 KiB
CoffeeScript
Raw Normal View History

describe 'Asciinema.Brush', ->
2012-02-05 13:21:10 +00:00
describe '.clearCache', ->
it 'resets cache hash', ->
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
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 ->
Asciinema.Brush.clearCache()
2012-02-05 13:21:10 +00:00
it 'returns new brush instance if not cached', ->
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', ->
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
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', ->
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', ->
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', ->
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', ->
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', ->
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', ->
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', ->
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', ->
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', ->
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', ->
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', ->
brush = new Asciinema.Brush fg: 1
2012-11-23 21:42:39 +00:00
newBrush = brush.applyChanges fg: 2
expect(newBrush.fg).toEqual 2