-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
70 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
coverage/ | ||
nlcst-affix-emoticon-modifier.js | ||
nlcst-affix-emoticon-modifier.min.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,69 @@ | ||
'use strict'; | ||
'use strict' | ||
|
||
var test = require('tape'); | ||
var unified = require('unified'); | ||
var english = require('retext-english'); | ||
var emojiModifier = require('nlcst-emoji-modifier'); | ||
var emoticonModifier = require('nlcst-emoticon-modifier'); | ||
var remove = require('unist-util-remove-position'); | ||
var modifier = require('..'); | ||
var test = require('tape') | ||
var unified = require('unified') | ||
var english = require('retext-english') | ||
var emojiModifier = require('nlcst-emoji-modifier') | ||
var emoticonModifier = require('nlcst-emoticon-modifier') | ||
var remove = require('unist-util-remove-position') | ||
var modifier = require('..') | ||
|
||
var lollipop = require('./fixtures/lollipop'); | ||
var smile = require('./fixtures/smile'); | ||
var lollipop = require('./fixtures/lollipop') | ||
var smile = require('./fixtures/smile') | ||
|
||
test('nlcst-affix-emoticon-modifier()', function (t) { | ||
test('nlcst-affix-emoticon-modifier()', function(t) { | ||
t.throws( | ||
function () { | ||
modifier({}); | ||
function() { | ||
modifier({}) | ||
}, | ||
/Missing children in `parent`/, | ||
'should throw when not given a parent' | ||
); | ||
) | ||
|
||
t.deepEqual( | ||
process('Lol! :lollipop: That’s cool.'), | ||
lollipop, | ||
'should merge at sentence-start (1)' | ||
); | ||
) | ||
|
||
t.deepEqual( | ||
process('Lol! :lollipop: That’s cool.', true), | ||
remove(lollipop, true), | ||
'should merge at sentence-start (1, positionless)' | ||
); | ||
) | ||
|
||
t.deepEqual( | ||
process('Lol! :) That’s cool.'), | ||
smile, | ||
'should merge at sentence-start (2)' | ||
); | ||
) | ||
|
||
t.deepEqual( | ||
process('Lol! :) That’s cool.', true), | ||
remove(smile, true), | ||
'should merge at sentence-start (2, positionless)' | ||
); | ||
) | ||
|
||
t.end(); | ||
}); | ||
t.end() | ||
}) | ||
|
||
/* Short-cut to access the CST. */ | ||
function process(fixture, positionless) { | ||
var processor = unified().use(english).use(plugin).freeze(); | ||
var processor = unified() | ||
.use(english) | ||
.use(plugin) | ||
.freeze() | ||
|
||
if (positionless) { | ||
processor.Parser.prototype.position = false; | ||
processor.Parser.prototype.position = false | ||
} | ||
|
||
return processor.runSync(processor.parse(fixture)); | ||
return processor.runSync(processor.parse(fixture)) | ||
} | ||
|
||
/* Add modifier to processor. */ | ||
function plugin() { | ||
this.Parser.prototype.useFirst('tokenizeSentence', emojiModifier); | ||
this.Parser.prototype.useFirst('tokenizeSentence', emoticonModifier); | ||
this.Parser.prototype.useFirst('tokenizeParagraph', modifier); | ||
this.Parser.prototype.useFirst('tokenizeSentence', emojiModifier) | ||
this.Parser.prototype.useFirst('tokenizeSentence', emoticonModifier) | ||
this.Parser.prototype.useFirst('tokenizeParagraph', modifier) | ||
} |