forked from processing/p5.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstring_functions.js
177 lines (150 loc) · 4.5 KB
/
string_functions.js
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
suite('String functions', function() {
var myp5;
setup(function(done) {
new p5(function(p) {
p.setup = function() {
myp5 = p;
done();
};
});
});
teardown(function() {
myp5.remove();
});
var result;
suite('p5.prototype.join', function() {
var join = p5.prototype.join;
test('should be a function', function() {
assert.ok(join);
});
test('should return joined string', function() {
var arr = ['foo', 'bar'];
var sep = '-';
result = myp5.join(arr, sep);
assert.equal(result, 'foo-bar');
});
});
suite('p5.prototype.match', function() {
var match = p5.prototype.match;
test('should be a function', function() {
assert.ok(match);
});
test('should return correct index of match strings', function() {
var str = 'Where is the duckling in this ducky duck string?';
var regexp = 'duck';
result = myp5.match(str, regexp);
assert.equal(result.index, 13);
});
});
suite('p5.prototype.matchAll', function() {
var matchAll = p5.prototype.matchAll;
test('should be a function', function() {
assert.ok(matchAll);
});
test('should return correct array of strings', function() {
var str = 'Where is the duckling in this ducky duck string?';
var regexp = 'duck';
result = myp5.matchAll(str, regexp);
assert.equal(result.length, 3);
});
});
suite('p5.prototype.nf', function() {
var nf = p5.prototype.nf;
test('should be a function', function() {
assert.ok(nf);
});
test('should return correct string', function() {
var num = 3.141516;
result = myp5.nf(num, 2);
assert.equal(result, '03.141516');
});
test('should return correct string', function() {
var num = 3.141516;
result = myp5.nf(num, '2', '2'); // automatic conversion?
assert.equal(result, '03.14');
});
});
suite('p5.prototype.nfc', function() {
var nfc = p5.prototype.nfc;
test('should be a function', function() {
assert.ok(nfc);
});
test('should return correct string', function() {
var num = 32000;
result = myp5.nfc(num, 3);
assert.equal(result, '32,000.000');
});
test('should return correct string', function() {
var num = 32000;
result = myp5.nfc(num, '3'); // automatic conversion?
assert.equal(result, '32,000.000');
});
});
suite('p5.prototype.nfp', function() {
var nfp = p5.prototype.nfp;
test('should be a function', function() {
assert.ok(nfp);
});
test('should return correct string', function() {
var num = -32000;
result = myp5.nfp(num, 3);
assert.equal(result, '-32000');
});
test('should return correct string', function() {
var num = 32000;
result = myp5.nfp(num, 3); // automatic conversion?
assert.equal(result, '+32000');
});
});
suite('p5.prototype.nfs', function() {
var nfs = p5.prototype.nfs;
test('should be a function', function() {
assert.ok(nfs);
});
test('should return correct string', function() {
var num = -32000;
result = myp5.nfs(num, 3);
assert.equal(result, '-32000');
});
test('should return correct string', function() {
var num = 32000;
result = myp5.nfs(num, 3); // automatic conversion?
assert.equal(result, ' 32000');
});
});
suite('p5.prototype.split', function() {
var split = p5.prototype.split;
test('should be a function', function() {
assert.ok(split);
});
test('should return correct index of match strings', function() {
var str = 'parsely, sage, rosemary, thyme';
var regexp = ',';
result = myp5.split(str, regexp);
assert.equal(result.length, 4);
});
});
suite('p5.prototype.splitTokens', function() {
var splitTokens = p5.prototype.splitTokens;
test('should be a function', function() {
assert.ok(splitTokens);
});
test('should return correct index of match strings', function() {
var str = 'parsely, sage, rosemary, thyme';
var regexp = ',';
result = myp5.splitTokens(str, regexp);
assert.equal(result.length, 4);
});
});
suite('p5.prototype.trim', function() {
var trim = p5.prototype.trim;
test('should be a function', function() {
assert.ok(trim);
});
test('should return correct strings', function() {
var str = ' oh so roomy ';
result = myp5.trim(str);
assert.equal(result, 'oh so roomy');
});
});
});