string.test.js
1.82 KB
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
'use strict';
var string = require('../src/js/string');
describe('type', function() {
it('encodeHTMLEntity()', function() {
var htmlEntityString = '<script> alert(\'test\');</script><a href=\'test\'>',
expectString = '<script> alert('test');</script><a href='test'>';
expect(string.encodeHTMLEntity(htmlEntityString)).toEqual(expectString);
});
it('decodeHTMLEntity()', function() {
var htmlEntityString = 'A 'quote' is <b>bold</b>',
expectString = 'A \'quote\' is <b>bold</b>';
expect(string.decodeHTMLEntity(htmlEntityString)).toEqual(expectString);
});
it('hasEncodableString()', function() {
var s1 = 'te < st',
s2 = 'te > st',
s3 = 'te __ st',
s4 = 'te " st',
s5 = 'te \' st',
s6 = '<script> alert(\'test\');</script><a href=\'test\'>';
expect(string.hasEncodableString(s1)).toBe(true);
expect(string.hasEncodableString(s2)).toBe(true);
expect(string.hasEncodableString(s3)).toBe(false);
expect(string.hasEncodableString(s4)).toBe(true);
expect(string.hasEncodableString(s5)).toBe(true);
expect(string.hasEncodableString(s6)).toBe(true);
});
it('getDuplicatedChar() not include blank', function() {
var str1 = 'abcdefghijk',
str2 = 'fe team',
str3 = 'nhn entertainment',
str4 = 'will be success finally',
str5 = 'kill me heal me',
str6 = 'khan zi';
expect(string.getDuplicatedChar(str1, str2)).toBe('aef');
expect(string.getDuplicatedChar(str1, str3)).toBe('aehi');
expect(string.getDuplicatedChar(str3, str4)).toBe(' aein');
expect(string.getDuplicatedChar(str5, str6)).toBe(' ahik');
});
});