Skip to content

Commit dc60363

Browse files
authored
Add tests for exported function
Added tests for _sanitizeFontName function to validate font name sanitization rules.
1 parent 1459a39 commit dc60363

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

test/unit/type/p5.Font.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import p5 from '../../../src/app.js';
2+
import {_sanitizeFontName} from '../../../src/type/p5.Font.js';
23

34
suite('p5.Font', function () {
45
var myp5;
@@ -51,3 +52,23 @@ suite('p5.Font', function () {
5152
});
5253
});
5354
});
55+
56+
suite('sanitizeFontName', function () {
57+
test('fully alphabetic or alpha-leading alnum do not need quotes', function () {
58+
assert.equal(_sanitizeFontName('Arial'), 'Arial');
59+
assert.equal(_sanitizeFontName('Family900'), 'Family900');
60+
assert.equal(_sanitizeFontName('A_b-c'), 'A_b-c');
61+
});
62+
63+
test('names starting with a digit need quotes', function () {
64+
assert.equal(_sanitizeFontName('9lives'), "'9lives'");
65+
});
66+
67+
test('names with spaces need quotes', function () {
68+
assert.equal(_sanitizeFontName('My Font'), "'My Font'");
69+
});
70+
71+
test('names with commas need quotes', function () {
72+
assert.equal(_sanitizeFontName('Foo,Bar'), "'Foo,Bar'");
73+
});
74+
});

0 commit comments

Comments
 (0)