Debian Codegraph @

www/public/test/core/tokenizer.js

raw symbols SCIP
1 describe('Core htmx tokenizer tests', function() {
2 beforeEach(function() {
3 this.server = makeServer()
4 clearWorkArea()
5 })
6 afterEach(function() {
7 this.server.restore()
8 clearWorkArea()
9 })
10
11 function tokenize(str) {
12 return htmx._('tokenizeString')(str)
13 }
14
15 function tokenizeTest(str, result) {
16 return tokenize(str).should.deep.equal(result)
17 }
18
19 it('tokenizes properly', function() {
20 tokenizeTest('', [])
21 tokenizeTest(' ', [' ', ' '])
22 tokenizeTest('(', ['('])
23 tokenizeTest('()', ['(', ')'])
24 tokenizeTest('(,)', ['(', ',', ')'])
25 tokenizeTest(' ( ) ', [' ', '(', ' ', ')', ' '])
26 tokenizeTest(' && ) ', [' ', '&', '&', ' ', ')', ' '])
27 tokenizeTest(" && ) 'asdf'", [' ', '&', '&', ' ', ')', ' ', "'asdf'"])
28 tokenizeTest(" && ) ',asdf'", [' ', '&', '&', ' ', ')', ' ', "',asdf'"])
29 tokenizeTest('",asdf"', ['",asdf"'])
30 tokenizeTest('&& ) ",asdf"', ['&', '&', ' ', ')', ' ', '",asdf"'])
31 tokenizeTest('",as\\"df"', ['",as\\"df"'])
32 })
33
34 it('generates conditionals property', function() {
35 var tokens = tokenize('[code==4||(code==5&&foo==true)]')
36 var conditional = htmx._('maybeGenerateConditional')(null, tokens)
37 var func = eval(conditional)
38 func({ code: 5, foo: true }).should.equal(true)
39 func({ code: 5, foo: false }).should.equal(false)
40 func({ code: 4, foo: false }).should.equal(true)
41 func({ code: 3, foo: true }).should.equal(false)
42 })
43 })