333
schangxiang@126.com
2025-09-19 18966e02fb573c7e2bb0c6426ed792b38b910940
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
 
 
'use strict';
 
var figlet = require('../lib/node-figlet'),
    grunt = require('grunt'),
    fs = require('fs'),
    path = require('path'),
    async = require('async');
 
/*
  ======== A Handy Little Nodeunit Reference ========
  https://github.com/caolan/nodeunit
 
  Test methods:
    test.expect(numAssertions)
    test.done()
  Test assertions:
    test.ok(value, [message])
    test.equal(actual, expected, [message])
    test.notEqual(actual, expected, [message])
    test.deepEqual(actual, expected, [message])
    test.notDeepEqual(actual, expected, [message])
    test.strictEqual(actual, expected, [message])
    test.notStrictEqual(actual, expected, [message])
    test.throws(block, [error], [message])
    test.doesNotThrow(block, [error], [message])
    test.ifError(value)
*/
 
exports.figlet = {
    setUp: function(done) {
        // setup here if necessary
        done();
    },
    standard: function(test) {
        test.expect(1);
 
        figlet('FIGlet\nFONTS', {
            font: 'Standard',
            verticalLayout: 'fitted'
        }, function(err, actual) {
            var expected = grunt.file.read('test/expected/standard');
            test.equal(actual, expected, 'Standard font with a vertical layout of "fitted".');
 
            test.done();
        });
    },
    standardSync: function(test) {
        test.expect(1);
 
        var expected = grunt.file.read('test/expected/standard');
        var actual = figlet.textSync('FIGlet\nFONTS', {font: 'Standard', verticalLayout: 'fitted'});
 
        test.equal(actual, expected, 'Standard font with a vertical layout of "fitted".');
 
        test.done();
    },
    standardParse: function(test) {
        test.expect(1);
 
        var expected = grunt.file.read('test/expected/standard');
        var data = fs.readFileSync(path.join(__dirname, '../fonts/Standard.flf'), 'utf8');
        var font = figlet.parseFont('StandardParseFontName', data);
        var actual = figlet.textSync('FIGlet\nFONTS', {font: 'StandardParseFontName', verticalLayout: 'fitted'});
 
        test.equal(actual, expected, 'Standard font with a vertical layout of "fitted" loaded using parseFont().');
 
        test.done();
    },
    graffiti: function(test) {
        test.expect(1);
 
        figlet.text('ABC.123', {
            font: 'Graffiti',
            horizontalLayout: 'fitted'
        }, function(err, actual) {
            var expected = grunt.file.read('test/expected/graffiti');
            test.equal(actual, expected, 'Graffiti font with a horizontal layout of "fitted".');
 
            test.done();
        });
    },
    graffitiSync: function(test) {
        test.expect(1);
 
        var expected = grunt.file.read('test/expected/graffiti');
        var actual = figlet.textSync('ABC.123', {font: 'Graffiti', horizontalLayout: 'fitted'});
        test.equal(actual, expected, 'Graffiti font with a horizontal layout of "fitted".');
 
        test.done();
    },
    dancingFont: function(test) {
        test.expect(1);
 
        figlet.text('pizzapie', {
            font: 'Dancing Font',
            horizontalLayout: 'full'
        }, function(err, actual) {
 
            var expected = grunt.file.read('test/expected/dancingFont');
            test.equal(actual, expected, 'Dancing Font with a horizontal layout of "full".');
 
            test.done();
        });
    },
    dancingFontSync: function(test) {
        test.expect(1);
 
        var expected = grunt.file.read('test/expected/dancingFont');
        var actual = figlet.textSync('pizzapie', {font: 'Dancing Font', horizontalLayout: 'full'});
        test.equal(actual, expected, 'Dancing Font with a horizontal layout of "full".');
 
        test.done();
    },
    printDirection: function(test) {
        test.expect(1);
 
        figlet.text('pizzapie', {
            font: 'Dancing Font',
            horizontalLayout: 'full',
            printDirection: 1
        }, function(err, actual) {
 
            var expected = grunt.file.read('test/expected/dancingFontReverse');
            test.equal(actual, expected, 'Dancing Font with a reversed print direction.');
 
            test.done();
        });
    },
    /*
        This test ensures that all fonts will load without error
    */
    loadAll: function(test) {
        var errCount = 0;
        test.expect(1);
 
        figlet.fonts(function(err, fonts) {
            if (err) {
                errCount++;
                return;
            }
 
            async.eachSeries(fonts, function(font, next) {
                figlet.text('abc ABC ...', {
                    font: font
                }, function(err, data) {
                    if (err) {
                        errCount++;
                    }
                    next();
                });
            }, function(err) {
                test.equal(errCount, 0, 'A problem occurred while testing one of the fonts.');
                test.done();
            });
        });
    }
};