pulsar/spec/atom/binding-set-spec.coffee
Corey Johnson & Nathan Sobo 6a25dc00c5 Add BindingSetSpec and change keybinding pattern separator.
Also, we allow chorded bindings to be surrounded in <…> in preparation of key sequences.
2012-01-11 13:16:10 -08:00

35 lines
1.5 KiB
CoffeeScript

$ = require 'jquery'
_ = require 'underscore'
BindingSet = require 'binding-set'
describe "BindingSet", ->
bindingSet = null
beforeEach ->
bindingSet = new BindingSet('*', 'x': 'foo')
describe ".eventMatchesPattern(event, pattern)", ->
event = (key, attrs={}) ->
defaultAttrs =
ctrlKey: false
altKey: false
shiftKey: false
metaKey: false
attrs.which = key.toUpperCase().charCodeAt(0)
$.Event 'keydown', _.extend({}, defaultAttrs, attrs)
it "handles patterns with modifiers", ->
expect(bindingSet.eventMatchesPattern(event('q'), 'q')).toBeTruthy()
expect(bindingSet.eventMatchesPattern(event('0', altKey: true), '<alt-0>')).toBeTruthy()
expect(bindingSet.eventMatchesPattern(event('0', metaKey: true), '<meta-0>')).toBeTruthy()
expect(bindingSet.eventMatchesPattern(event('0', ctrlKey: true), '<ctrl-0>')).toBeTruthy()
expect(bindingSet.eventMatchesPattern(event('a', shiftKey: true), '<shift-a>')).toBeTruthy()
expect(bindingSet.eventMatchesPattern(event('a', shiftKey: true), 'A')).toBeTruthy()
expect(bindingSet.eventMatchesPattern(event('0', altKey: true, ctrlKey: true, metaKey: true, shiftKey: true), '<meta-ctrl-alt-shift-0>')).toBeTruthy()
# # negative examples
expect(bindingSet.eventMatchesPattern(event('a'), '<shift-a>')).toBeFalsy()
expect(bindingSet.eventMatchesPattern(event('a', shiftKey: true), 'a')).toBeFalsy()
expect(bindingSet.eventMatchesPattern(event('d'), 'k')).toBeFalsy()