Ohm-Management - Projektarbeit B-ME
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.

test.js 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. var tape = require('tape')
  2. var pager = require('./')
  3. tape('get page', function (t) {
  4. var pages = pager(1024)
  5. var page = pages.get(0)
  6. t.same(page.offset, 0)
  7. t.same(page.buffer, Buffer.alloc(1024))
  8. t.end()
  9. })
  10. tape('get page twice', function (t) {
  11. var pages = pager(1024)
  12. t.same(pages.length, 0)
  13. var page = pages.get(0)
  14. t.same(page.offset, 0)
  15. t.same(page.buffer, Buffer.alloc(1024))
  16. t.same(pages.length, 1)
  17. var other = pages.get(0)
  18. t.same(other, page)
  19. t.end()
  20. })
  21. tape('get no mutable page', function (t) {
  22. var pages = pager(1024)
  23. t.ok(!pages.get(141, true))
  24. t.ok(pages.get(141))
  25. t.ok(pages.get(141, true))
  26. t.end()
  27. })
  28. tape('get far out page', function (t) {
  29. var pages = pager(1024)
  30. var page = pages.get(1000000)
  31. t.same(page.offset, 1000000 * 1024)
  32. t.same(page.buffer, Buffer.alloc(1024))
  33. t.same(pages.length, 1000000 + 1)
  34. var other = pages.get(1)
  35. t.same(other.offset, 1024)
  36. t.same(other.buffer, Buffer.alloc(1024))
  37. t.same(pages.length, 1000000 + 1)
  38. t.ok(other !== page)
  39. t.end()
  40. })
  41. tape('updates', function (t) {
  42. var pages = pager(1024)
  43. t.same(pages.lastUpdate(), null)
  44. var page = pages.get(10)
  45. page.buffer[42] = 1
  46. pages.updated(page)
  47. t.same(pages.lastUpdate(), page)
  48. t.same(pages.lastUpdate(), null)
  49. page.buffer[42] = 2
  50. pages.updated(page)
  51. pages.updated(page)
  52. t.same(pages.lastUpdate(), page)
  53. t.same(pages.lastUpdate(), null)
  54. t.end()
  55. })