* Split core lib into multiple files * Refactor data encoding methods * Refactor data masking process * Improve qr code generation process * Increase minimum required node version to 0.10 * Add linter * Add tests and tests coverage * Update travis config to fix compilation issues * Add examples folder * Add missing license tag in package.json * Update build script and add sourcemap support * Publish only strictly needed files on npm * Update readme
36 lines
1.3 KiB
JavaScript
36 lines
1.3 KiB
JavaScript
var test = require('tap').test
|
|
var BitBuffer = require('core/bit-buffer')
|
|
var ByteData = require('core/byte-data')
|
|
var Mode = require('core/mode')
|
|
|
|
test('Byte Data', function (t) {
|
|
var text = '1234'
|
|
var textByte = [49, 50, 51, 52] // 1, 2, 3, 4
|
|
var utf8Text = '\u00bd + \u00bc = \u00be' // 9 char, 12 byte
|
|
|
|
var byteData = new ByteData(text)
|
|
|
|
t.equal(byteData.mode, Mode.BYTE, 'Mode should be BYTE')
|
|
t.equal(byteData.getLength(), text.length, 'Should return correct length')
|
|
|
|
t.ok(ByteData.getCharCountIndicator, 'getCharCountIndicator should be defined')
|
|
|
|
for (var v = 1; v <= 40; v++) {
|
|
t.ok(byteData.getCharCountIndicator(v), 'Should return a positive number')
|
|
}
|
|
|
|
t.throw(function () { byteData.getCharCountIndicator(0) }, 'Should throw if invalid version')
|
|
|
|
var bitBuffer = new BitBuffer()
|
|
byteData.write(bitBuffer)
|
|
t.deepEqual(bitBuffer.buffer, textByte, 'Should write correct data to buffer')
|
|
|
|
byteData.append(text)
|
|
t.equal(byteData.getLength(), text.length * 2, 'Should return correct length')
|
|
t.deepEqual(byteData.data, new Buffer(textByte.concat(textByte)), 'Should correctly append data')
|
|
|
|
var byteDataUtf8 = new ByteData(utf8Text)
|
|
t.equal(byteDataUtf8.getLength(), 12, 'Should return correct length for utf8 chars')
|
|
|
|
t.end()
|
|
})
|