1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
describe('__parseConfig unit tests', function() {
it('parses simple key-value pair', function () {
let config = htmx.__parseConfig('delay:100ms')
assert.equal(config.delay, '100ms')
})
it('parses boolean true', function () {
let config = htmx.__parseConfig('once')
assert.equal(config.once, true)
})
it('parses boolean false', function () {
let config = htmx.__parseConfig('once:false')
assert.equal(config.once, false)
})
it('parses integer value', function () {
let config = htmx.__parseConfig('count:42')
assert.equal(config.count, 42)
})
it('parses multiple key-value pairs', function () {
let config = htmx.__parseConfig('delay:100ms throttle:200ms')
assert.equal(config.delay, '100ms')
assert.equal(config.throttle, '200ms')
})
it('parses comma-separated pairs', function () {
let config = htmx.__parseConfig('delay:100ms, throttle:200ms')
assert.equal(config.delay, '100ms')
assert.equal(config.throttle, '200ms')
})
it('parses double-quoted string', function () {
let config = htmx.__parseConfig('target:"#foo .bar"')
assert.equal(config.target, '#foo .bar')
})
it('parses single-quoted string', function () {
let config = htmx.__parseConfig("target:'#foo .bar'")
assert.equal(config.target, '#foo .bar')
})
it('parses nested object with dot notation', function () {
let config = htmx.__parseConfig('sse.mode:once')
assert.equal(config.sse.mode, 'once')
})
it('parses multiple nested properties', function () {
let config = htmx.__parseConfig('sse.mode:once sse.maxRetries:5')
assert.equal(config.sse.mode, 'once')
assert.equal(config.sse.maxRetries, 5)
})
it('parses JSON object', function () {
let config = htmx.__parseConfig('{"delay":"100ms","throttle":"200ms"}')
assert.equal(config.delay, '100ms')
assert.equal(config.throttle, '200ms')
})
it('parses JSON with nested object', function () {
let config = htmx.__parseConfig('{"sse":{"mode":"once","maxRetries":5}}')
assert.equal(config.sse.mode, 'once')
assert.equal(config.sse.maxRetries, 5)
})
it('parses JSON with boolean', function () {
let config = htmx.__parseConfig('{"once":true,"changed":false}')
assert.equal(config.once, true)
assert.equal(config.changed, false)
})
it('handles empty string', function () {
let config = htmx.__parseConfig('')
assert.deepEqual(config, {})
})
it('handles whitespace', function () {
let config = htmx.__parseConfig(' delay:100ms ')
assert.equal(config.delay, '100ms')
})
});
|