UNPKG

3.79 kBJavaScriptView Raw
1var mocha = require("mocha");
2var assert = require("assert");
3import lang from "../src";
4
5describe('Bot-Lang', function(){
6 var startTime;
7
8 before(function(done){
9 startTime = new Date();
10 done();
11 });
12
13 after(function(done) {
14 console.log('Test duration: ' + (new Date() - startTime) + 'ms');
15 done();
16 })
17
18 describe('Should clean input', function() {
19 it("should not remove +", function() {
20 assert.equal(lang.clean.all("3+4=7"), "3+4=7");
21 });
22
23 it("should remove extra spaces", function() {
24 assert.equal(lang.clean.all("this is spaced out"), "this is spaced out");
25 });
26
27 it("Fix numbers", function() {
28 assert.equal(lang.clean.all("how much is 1,000.00"), "how much is 1000.00");
29 });
30
31 it("Fix Unicode characters", function() {
32 assert.equal(lang.clean.all("What’s up"), "What's up");
33 assert.equal(lang.clean.all("I said “shut up”"), 'I said "shut up"');
34 assert.equal(lang.clean.all("œ"), '');
35 assert.equal(lang.clean.all("😊"), '😊');
36 });
37 });
38
39 describe('Replace Interface', function() {
40 it("should replace subsitutes", function() {
41 assert.equal(lang.replace.all("Nov 1st"), "November 1st");
42 assert.equal(lang.replace.all("Nov 1st I weighed 90 kgs. total"), "November 1st I weighed 90 kilograms total");
43 assert.equal(lang.replace.all("I shared it on FB w/ friends, ie: you"), "I shared it on Facebook with friends, for example : you");
44 });
45
46 it("should expand contractions", function() {
47 assert.equal(lang.replace.all("I'm on the yelow zebra"), "I am on the yellow zebra");
48 assert.equal(lang.replace.all("I'll listen to y'all"), "I will listen to you all");
49 assert.equal(lang.replace.all("do n't make it right"), "do not make it right");
50 assert.equal(lang.replace.all("it's all good"), "it is all good");
51 assert.equal(lang.replace.all("What's up"), "what is up");
52 });
53
54 it("should swap british / canadian words", function() {
55 assert.equal(lang.replace.all("armour axe coloured gold"), "armor ax colored gold");
56 });
57
58 it("should swap unicode emoji's for keywords", function() {
59 assert.equal(lang.replace.emoji("You make me 😊"), "You make me :blush:");
60 });
61
62 it("should fix spelling", function() {
63 assert.equal(lang.replace.all("are we sceduled thrsday for teh restraunt"), "are we scheduled Thursday for the restaurant");
64 });
65
66 it("should remove frivolous words", function() {
67 assert.equal(lang.replace.all("Well , I could not help it, could I"), "I could not help it, could I")
68 });
69
70 it("frivolous - lets not replace everything", function() {
71 assert.equal(lang.replace.frivolous("let me see"), "let me see");
72 assert.equal(lang.replace.frivolous("ahh let me see"), "let me see");
73 });
74
75 it("Spell Fix 2 word combo", function() {
76 assert.equal(lang.replace.all("hwo do you"), "how do you");
77 assert.equal(lang.replace.all("hwo is you"), "who is you");
78 });
79 });
80
81 describe('Tagging Interface', function() {
82 it("should tag input", function() {
83 assert.equal(lang.tag.test("yes", "I am sure"), true);
84 assert.equal(lang.tag.test("yes", "Nope"), false, "yes is not nope");
85 assert.equal(lang.tag.test("no", "Nope"), true);
86 assert.equal(lang.tag.test("apology", "well excuse me princess"), false);
87 assert.equal(lang.tag.test("apology", "excuse me princess"), true);
88 });
89
90 it("should have all", function() {
91 assert.deepEqual(lang.tag.all("eww , shut up , I have to go"), [ 'disgust', 'goodbye', 'stop' ]);
92 });
93
94 it("should have emoji", function() {
95 assert.deepEqual(lang.tag.all(":wave: :one: :heart:"), ['slack_emoji_people', 'slack_emoji_symbols']);
96 });
97 });
98});