File: buffer-pure-js.js

package info (click to toggle)
node-tap 12.0.1%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 3,916 kB
  • sloc: makefile: 84; sh: 75
file content (43 lines) | stat: -rw-r--r-- 966 bytes parent folder | download | duplicates (2)
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
var tap = require('../../..')
var test = tap.test
var same = require('../..').strict

test('should match empty Buffers', function (t) {
  t.ok(same(Buffer.from([]), Buffer.from([])))
  t.end()
})

test('should match similar Buffers', function (t) {
  var b1 = Buffer.from([0])
  b1.equals = null
  var b2 = Buffer.from([0])
  b2.equals = null
  t.ok(same(b1, b2))

  var b3 = Buffer.from([0, 1, 3])
  b3.equals = null
  var b4 = Buffer.from([0, 1, 3])
  b4.equals = null
  t.ok(same(b3, b4))

  t.end()
})

test('should notice different Buffers', function (t) {
  var b1 = Buffer.from([0, 1, 2])
  b1.equals = null
  var b2 = Buffer.from([0, 1, 23])
  b2.equals = null
  t.notOk(same(b1, b2))

  var shortb = Buffer.from([0, 1])
  shortb.equals = null
  var longb = Buffer.alloc(320)
  longb.equals = null
  for (var i = 0; i < 160; i++) longb.writeUInt16LE(i, i * 2)
  t.notOk(same(
    { x: { y: { z: shortb } } },
    { x: { y: { z: longb } } }
  ))
  t.end()
})