2 var assert, vows, util;
4 vows = require('vows');
6 assert = require('assert');
8 util = require('../../lib/util');
10 vows.describe('Module core extension String').addBatch({
13 'join the keys': function(topic) {
14 return assert.equal(util.string.value(topic), 'bullet');
19 'when no args': function(topic) {
20 return assert.equal(util.string.gsub(topic), 'bullet');
22 'when only 1 arg': function(topic) {
23 return assert.equal(util.string.gsub(topic, /./), 'bullet');
25 'when given proper args': function(topic) {
26 return assert.equal(util.string.gsub(topic, /[aeiou]/, '*'), 'b*ll*t');
28 'when replacement is a function': {
29 'with many groups': function(topic) {
31 str = util.string.gsub(topic, /([aeiou])(.)/, function($) {
32 return "<" + $[1] + ">" + $[2];
34 return assert.equal(str, 'b<u>ll<e>t');
36 'with no groups': function(topic) {
38 str = util.string.gsub(topic, /[aeiou]/, function($) {
39 return "<" + $[1] + ">";
41 return assert.equal(str, 'b<u>ll<e>t');
44 'when replacement is special': {
45 'with many groups': function(topic) {
46 return assert.equal(util.string.gsub(topic, /([aeiou])(.)/, '<$1>$2'), 'b<u>ll<e>t');
48 'with no groups': function(topic) {
49 return assert.equal(util.string.gsub(topic, /[aeiou]/, '<$1>'), 'b<u>ll<e>t');
53 'Testing capitalize': {
54 topic: 'employee salary',
55 'normal': function(topic) {
56 return assert.equal(util.string.capitalize(topic), 'Employee Salary');
61 'only first letter should be upcase': function(topic) {
62 return assert.equal(util.string.upcase(topic), 'Bullet');
64 'letter after underscore': function(topic) {
65 return assert.equal(util.string.upcase('bullet_record'), 'Bullet_Record');
67 'letter after slash': function(topic) {
68 return assert.equal(util.string.upcase('bullet_record/errors'), 'Bullet_Record/Errors');
70 'no letter after space': function(topic) {
71 return assert.equal(util.string.upcase('employee salary'), 'Employee salary');
76 'only first letter should be downcase': function(topic) {
77 return assert.equal(util.string.downcase(topic), 'bULLET');
79 'letter after underscore': function(topic) {
80 return assert.equal(util.string.downcase('BULLET_RECORD'), 'bULLET_rECORD');
82 'letter after slash': function(topic) {
83 return assert.equal(util.string.downcase('BULLET_RECORD/ERRORS'), 'bULLET_rECORD/eRRORS');