This repository has been archived by the owner on Dec 12, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwrapWithAbbreviation.js
66 lines (55 loc) · 3.25 KB
/
wrapWithAbbreviation.js
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
var assert = require('assert');
var editor = require('../stubs/editor');
var parser = require('../../lib/parser/abbreviation');
var action = require('../../lib/action/wrapWithAbbreviation');
var utils = require('../../lib/utils/common');
describe('Wrap With Abbreviation action', function() {
var run = function(abbr, content) {
if (abbr && content) {
content = utils.escapeText(content);
return parser.expand(abbr, {
pastedContent: content,
syntax: 'html',
profile: 'plain'
});
}
editor.setPromptOutput(abbr);
action.wrapWithAbbreviationAction(editor);
};
it('debug', function() {
// assert.equal(run('str', 'test'), '<strong>test</strong>');
// assert.equal(run('cc:ie', 'hello world'), '<!--[if IE]>\n\thello world${0}\n<![endif]-->');
})
it('should work', function() {
editor.replaceContent('<br${0} />');
run('ul>li');
assert.equal(editor.getContent(), '<ul>\n\t<li>\n\t\t<br />\n\t</li>\n</ul>');
// wrap multiple lines
editor.replaceContent('one\ntwo\nthree');
editor.createSelection(0, 13);
run('ul>li.i$*');
assert.equal(editor.getContent(), '<ul>\n\t<li class="i1">one</li>\n\t<li class="i2">two</li>\n\t<li class="i3">three</li>\n</ul>');
assert.equal(run('p.test', 'hello world'), '<p class="test">hello world</p>');
assert.equal(run('p+p.test', 'hello world'), '<p></p><p class="test">hello world</p>');
assert.equal(run('ul#nav.simple>li', 'hello world'), '<ul id="nav" class="simple"><li>hello world</li></ul>');
assert.equal(run('ul#nav.simple>li*2', 'hello world'), '<ul id="nav" class="simple"><li></li><li>hello world</li></ul>');
assert.equal(run('li*', 'one\ntwo\nthree'), '<li>one</li><li>two</li><li>three</li>');
assert.equal(run('ul>li*', 'one\ntwo\nthree'), '<ul><li>one</li><li>two</li><li>three</li></ul>');
assert.equal(run('li*>a', 'one\ntwo\nthree'), '<li><a href="">one</a></li><li><a href="">two</a></li><li><a href="">three</a></li>');
assert.equal(run('li*>a', 'one\n two\n three'), '<li><a href="">one</a></li><li><a href="">two</a></li><li><a href="">three</a></li>', 'Removed indentation of wrapped content');
assert.equal(run('span', '$2'), '<span>\\$2</span>');
assert.equal(run('str', 'test'), '<strong>test</strong>');
assert.equal(run('str>span', 'test'), '<strong><span>test</span></strong>');
// test output placeholders
assert.equal(run('li[title=$#]*>em', 'one\ntwo\nthree'), '<li title="one"><em></em></li><li title="two"><em></em></li><li title="three"><em></em></li>');
assert.equal(run('li[title=$# class=item-$#]*>em{Label: $#}', 'one\ntwo\nthree'), '<li title="one" class="item-one"><em>Label: one</em></li><li title="two" class="item-two"><em>Label: two</em></li><li title="three" class="item-three"><em>Label: three</em></li>');
// wrap with snippet
assert.equal(run('cc:ie', 'hello world'), '<!--[if IE]>\n\thello world${0}\n<![endif]-->');
});
it('should properly wrap URL-like content', function() {
assert.equal(run('a', 'http://emmet.io'), '<a href="http://emmet.io">http://emmet.io</a>');
assert.equal(run('a', 'www.emmet.io'), '<a href="http://www.emmet.io">www.emmet.io</a>');
assert.equal(run('a', 'emmet.io'), '<a href="">emmet.io</a>');
assert.equal(run('a', '[email protected]'), '<a href="mailto:[email protected]">[email protected]</a>');
});
});