This repository was archived by the owner on Apr 5, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest.js
88 lines (70 loc) · 2.33 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
84
85
86
87
88
const test = require('tape')
, rimraf = require('rimraf')
, path = require('path')
, requireSubvert = require('require-subvert')(__dirname)
, pygmentizeOrig = require('pygmentize-bundled')
var pygmentizeCached
, pygmentizeTests
, calls = 0
function pygmentizeProxy () {
calls++
return pygmentizeOrig.apply(this, arguments)
}
requireSubvert.subvert('pygmentize-bundled', pygmentizeProxy)
pygmentizeCached = require('./')
pygmentizeTests = require('pygmentize-bundled/test')
// remove cache so we start from scratch
rimraf.sync(path.resolve(process.env.HOME, '.pygmentize-bundled-cache'))
pygmentizeTests(test, pygmentizeCached)
// should have called pygmentize() because there is no cache
test('test number of calls to pygmentize should be >0', function (t) {
t.ok(calls > 0, 'got ' + calls + ' calls')
calls = 0
t.end()
})
// should all come from cache now
pygmentizeTests(test, pygmentizeCached)
test('test number of calls to pygmentize should be 0', function (t) {
t.equal(calls, 0, 'got zero calls')
t.end()
})
var cachePath = path.resolve(process.cwd(), '.test-cache')
rimraf.sync(cachePath)
function testCustomCachePath (t) {
var lang = 'js'
, format = 'html'
, input = 'var a = "b";'
, output = '<div class="highlight"><pre><span class="kd">var</span> <span class="nx">a</span> '
+ '<span class="o">=</span> <span class="s2">"b"</span><span class="p">;</span></pre></div>'
pygmentizeCached(
{
lang : lang
, format : format
, cachePath : cachePath
}
, input
, function (err, result) {
t.equal(err, null)
t.ok(Buffer.isBuffer(result), 'isBuffer')
result = result.toString().replace(/\n/g, '')
t.equal(result, output)
t.end()
}
)
}
test('test custom cachePath (first)', testCustomCachePath)
// should have called pygmentize() because there is no cache
test('test number of calls to pygmentize should be >0', function (t) {
t.ok(calls > 0, 'got ' + calls + ' calls')
calls = 0
t.end()
})
// should all come from cache now
test('test custom cachePath (second)', testCustomCachePath)
test('test number of calls to pygmentize should be 0', function (t) {
t.equal(calls, 0, 'got zero calls')
t.end()
})
test('cleanup', function (t) {
rimraf(cachePath, t.end)
})