A templating language that looks like Lisp and compiles to HTML
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

parserTest.js 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. const test = require('tape')
  2. const helpers = require('./helpers')
  3. const AST = require('../src/ast/index')
  4. const tt = require('../src/tokenTypes')
  5. test('parses token stream into a tree', t => {
  6. t.plan(1)
  7. const tree = helpers.parse(`
  8. (div :class "foobar"
  9. (p :class (cond #t "primary" "secondary")))
  10. `)
  11. t.deepEqual(tree, [
  12. new AST.Application({
  13. functionName: new AST.Identifier({ name: 'div' }),
  14. args: [
  15. new AST.Attribute({
  16. name: 'class',
  17. value: new AST.String({ value: 'foobar' }),
  18. }),
  19. new AST.Application({
  20. functionName: new AST.Identifier({ name: 'p' }),
  21. args: [
  22. new AST.Attribute({
  23. name: 'class',
  24. value: new AST.Application({
  25. functionName: new AST.Identifier({ name: 'cond' }),
  26. args: [
  27. new AST.Boolean({ value: true }),
  28. new AST.String({ value: 'primary' }),
  29. new AST.String({ value: 'secondary' }),
  30. ],
  31. }),
  32. }),
  33. ],
  34. }),
  35. ],
  36. }),
  37. ])
  38. })
  39. test('allow empty strings', t => {
  40. t.plan(1)
  41. const tree = helpers.parse('(p "")')
  42. t.deepEqual(tree, [
  43. new AST.Application({
  44. functionName: new AST.Identifier({ name: 'p' }),
  45. args: [new AST.String({ value: '' })],
  46. }),
  47. ])
  48. })