-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy patharraybuffer-loader.js
More file actions
39 lines (30 loc) · 1.18 KB
/
arraybuffer-loader.js
File metadata and controls
39 lines (30 loc) · 1.18 KB
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
'use strict'
var TextDecoder = require('text-encoding').TextDecoder
var expect = require('chai').expect
describe('text files', function () {
it('can bundle ascii text file', function () {
var buffer = require('arraybuffer!./data/ascii.txt')
var array = new Uint8Array(buffer)
var text = new TextDecoder('utf-8').decode(array)
expect(text).to.equal('Hello, World!!\n')
})
it('can bundle multi byte test file', function () {
var buffer = require('arraybuffer!./data/multi-byte.txt')
var array = new Uint8Array(buffer)
var text = new TextDecoder('utf-8').decode(array)
expect(text).to.equal('\uD83D\uDE07\n') // :innocent:
})
})
describe('binary files', function () {
it('can bundle binary file', function () {
var buffer = require('arraybuffer!./data/binary.dat')
var binarray = new Uint8Array(buffer)
var array = Array.prototype.slice.call(binarray) // Array.from
expect(array).to.deep.equal([ 0x01, 0x02, 0x04, 0x00 ])
})
it('can bundle empty file', function () {
var buffer = require('arraybuffer!./data/empty.dat')
var binarray = new Uint8Array(buffer)
expect(binarray.length).to.have.length.equal(0)
})
})