securityos/node_modules/shell-parse/tests/concatenation.js

28 lines
799 B
JavaScript
Raw Permalink Normal View History

2024-09-06 15:32:35 +00:00
var test = require('tape')
var parse = require('../parser')
test('concatenation', function (t) {
var arg = parse('"two "\' strings\'', 'argument')
t.deepEqual(arg,
{ type: 'literal', value: 'two strings' },
'concatenated literals are flattened')
var arg = parse('$var"and a string"', 'argument')
t.deepEqual(arg, {
type: 'concatenation',
pieces: [
{ type: 'variable', name: 'var' },
{ type: 'literal', value: 'and a string' }
]
}, 'can concatenate $var and strings')
var arg = parse('"it\'s easy to switch "\'"back"\'" and "\'"forth"\'',
'argument')
t.deepEqual(arg, {
type: 'literal',
value: 'it\'s easy to switch "back" and "forth"'
}, 'can concatenate alternating quote contexts')
t.end()
})