forked from geordanr/xwing-miniatures-font
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
83 lines (65 loc) · 2.69 KB
/
test.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
var request = require('request');
var fontkit = require('fontkit');
var colors = require('colors');
// Returns the JSON font map for the specificed icon set
function getFontMap(name) {
var map = require('./src/json/' + name + '-map.json');
return map[name];
}
// Asserts that all of the characters in the font map have a valid character glyph for the given font
function assertGlyphs(font, mapName, assert) {
var font = fontkit.openSync('dist/' + font + '.ttf')
// Get map of ship icons
var map = getFontMap(mapName);
for (var name in map) {
var character = map[name];
var codePoint = character.charCodeAt();
assert.ok(font.hasGlyphForCodePoint(codePoint), mapName + ": '" + name + "'' checking for valid glyph...")
}
}
exports['test icon glyphs'] = function(assert) {
assertGlyphs('xwing-miniatures', 'icons', assert);
};
exports['test ship glyphs'] = function(assert) {
assertGlyphs('xwing-miniatures-ships', 'ships', assert);
};
const shipAliases = [
'ig2000',
'tieadvancedprototype',
'yt2400freighter',
];
exports['test ship names'] = function(assert, done) {
// Get map of ship icons
var shipMap = getFontMap('ships');
// Get X-Wing database for ships
request('https://github.com/guidokessels/xwing-data/raw/master/data/ships.js', function (error, response, body) {
var allShipData = JSON.parse(body);
// Check that all ships in the database have an icon
allShipData.forEach(function(shipData) {
var name = shipData['xws'];
// Some huge ships are encoded as [name]aft and [name]fore to represent front and back.
// Only check these once.
if (shipData['size'] == 'huge') {
if (name.endsWith('fore')) {
name = name.substring(0, name.length - 4);
} else if (name.endsWith('aft')) {
return;
}
}
// This should only generate a warning
if (shipMap[name] == undefined) {
console.warn((" WARNING: '" + name + "' missing ship icon.").yellow);
}
delete shipMap[name];
});
// Check that all icon names have a ship in the database
// assert.equal(shipMap.length, 0, "The following ships do not exist in the x-wing database: " + Object.keys(shipMap))
for (var name in shipMap) {
if (shipAliases.indexOf(name) === -1) {
assert.ok(false, "'" + name + "' is not in the x-wing ships database. Possible duplicate or typo?");
}
}
done();
});
};
if (module == require.main) require('test').run(exports)