Skip to content

Instantly share code, notes, and snippets.

@stephenprater
Last active August 29, 2015 13:59
Show Gist options
  • Save stephenprater/10659056 to your computer and use it in GitHub Desktop.
Save stephenprater/10659056 to your computer and use it in GitHub Desktop.
class QueryNode.Literal
constructor: (@arg)->
toJSON:()->
switch typeof(@arg)
when 'string' then "\"#{@arg}\""
when 'number', 'boolean' then @arg
when 'object'
if @arg == null
@arg
else
throw new Error('Literal cannot accept an object')
#test
describe 'QueryNode.Literal', ->
it 'throws an error for objects', ->
j = new QueryNode.Literal({'hey':'you'})
expect(j.toJSON).to.throwError()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment