You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

compare.js 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. if (process.env.OBJECT_IMPL) global.TYPED_ARRAY_SUPPORT = false
  2. var B = require('../').Buffer
  3. var test = require('tape')
  4. test('buffer.compare', function (t) {
  5. var b = new B(1).fill('a')
  6. var c = new B(1).fill('c')
  7. var d = new B(2).fill('aa')
  8. t.equal(b.compare(c), -1)
  9. t.equal(c.compare(d), 1)
  10. t.equal(d.compare(b), 1)
  11. t.equal(b.compare(d), -1)
  12. // static method
  13. t.equal(B.compare(b, c), -1)
  14. t.equal(B.compare(c, d), 1)
  15. t.equal(B.compare(d, b), 1)
  16. t.equal(B.compare(b, d), -1)
  17. t.end()
  18. })
  19. test('buffer.compare argument validation', function (t) {
  20. t.throws(function () {
  21. var b = new B(1)
  22. B.compare(b, 'abc')
  23. })
  24. t.throws(function () {
  25. var b = new B(1)
  26. B.compare('abc', b)
  27. })
  28. t.throws(function () {
  29. var b = new B(1)
  30. b.compare('abc')
  31. })
  32. t.end()
  33. })
  34. test('buffer.equals', function (t) {
  35. var b = new B(5).fill('abcdf')
  36. var c = new B(5).fill('abcdf')
  37. var d = new B(5).fill('abcde')
  38. var e = new B(6).fill('abcdef')
  39. t.ok(b.equals(c))
  40. t.ok(!c.equals(d))
  41. t.ok(!d.equals(e))
  42. t.end()
  43. })
  44. test('buffer.equals argument validation', function (t) {
  45. t.throws(function () {
  46. var b = new B(1)
  47. b.equals('abc')
  48. })
  49. t.end()
  50. })