aboutsummaryrefslogtreecommitdiffstats
path: root/vnfmarket/src/main/webapp/vnfmarket/node_modules/i/test/utils/string-test.js
blob: e93223314e37de0e3f4e173e89059ac900897b9b (plain)
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
(function() {
  var assert, vows, util;

  vows = require('vows');

  assert = require('assert');

  util = require('../../lib/util');

  vows.describe('Module core extension String').addBatch({
    'Testing value': {
      topic: 'bullet',
      'join the keys': function(topic) {
        return assert.equal(util.string.value(topic), 'bullet');
      }
    },
    'Testing gsub': {
      topic: 'bullet',
      'when no args': function(topic) {
        return assert.equal(util.string.gsub(topic), 'bullet');
      },
      'when only 1 arg': function(topic) {
        return assert.equal(util.string.gsub(topic, /./), 'bullet');
      },
      'when given proper args': function(topic) {
        return assert.equal(util.string.gsub(topic, /[aeiou]/, '*'), 'b*ll*t');
      },
      'when replacement is a function': {
        'with many groups': function(topic) {
          var str;
          str = util.string.gsub(topic, /([aeiou])(.)/, function($) {
            return "<" + $[1] + ">" + $[2];
          });
          return assert.equal(str, 'b<u>ll<e>t');
        },
        'with no groups': function(topic) {
          var str;
          str = util.string.gsub(topic, /[aeiou]/, function($) {
            return "<" + $[1] + ">";
          });
          return assert.equal(str, 'b<u>ll<e>t');
        }
      },
      'when replacement is special': {
        'with many groups': function(topic) {
          return assert.equal(util.string.gsub(topic, /([aeiou])(.)/, '<$1>$2'), 'b<u>ll<e>t');
        },
        'with no groups': function(topic) {
          return assert.equal(util.string.gsub(topic, /[aeiou]/, '<$1>'), 'b<u>ll<e>t');
        }
      }
    },
    'Testing capitalize': {
      topic: 'employee salary',
      'normal': function(topic) {
        return assert.equal(util.string.capitalize(topic), 'Employee Salary');
      }
    },
    'Testing upcase': {
      topic: 'bullet',
      'only first letter should be upcase': function(topic) {
        return assert.equal(util.string.upcase(topic), 'Bullet');
      },
      'letter after underscore': function(topic) {
        return assert.equal(util.string.upcase('bullet_record'), 'Bullet_Record');
      },
      'letter after slash': function(topic) {
        return assert.equal(util.string.upcase('bullet_record/errors'), 'Bullet_Record/Errors');
      },
      'no letter after space': function(topic) {
        return assert.equal(util.string.upcase('employee salary'), 'Employee salary');
      }
    },
    'Testing downcase': {
      topic: 'BULLET',
      'only first letter should be downcase': function(topic) {
        return assert.equal(util.string.downcase(topic), 'bULLET');
      },
      'letter after underscore': function(topic) {
        return assert.equal(util.string.downcase('BULLET_RECORD'), 'bULLET_rECORD');
      },
      'letter after slash': function(topic) {
        return assert.equal(util.string.downcase('BULLET_RECORD/ERRORS'), 'bULLET_rECORD/eRRORS');
      }
    }
  })["export"](module);

}).call(this);