indexes.js 599 B

1234567891011121314151617181920212223242526272829
  1. var B = require('../').Buffer
  2. var test = require('tape')
  3. test('indexes from a string', function(t) {
  4. var buf = new B('abc')
  5. t.equal(buf[0], 97)
  6. t.equal(buf[1], 98)
  7. t.equal(buf[2], 99)
  8. t.end()
  9. })
  10. test('indexes from an array', function(t) {
  11. var buf = new B([ 97, 98, 99 ])
  12. t.equal(buf[0], 97)
  13. t.equal(buf[1], 98)
  14. t.equal(buf[2], 99)
  15. t.end()
  16. })
  17. test('set then modify indexes from an array', function(t) {
  18. var buf = new B([ 97, 98, 99 ])
  19. t.equal(buf[2], 99)
  20. t.equal(buf.toString(), 'abc')
  21. buf[2] += 10
  22. t.equal(buf[2], 109)
  23. t.equal(buf.toString(), 'abm')
  24. t.end()
  25. })