basic.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. var tap = require("tap")
  2. , test = tap.test
  3. , ProtoList = require("../proto-list.js")
  4. tap.plan(1)
  5. tap.test("protoList tests", function (t) {
  6. var p = new ProtoList
  7. p.push({foo:"bar"})
  8. p.push({})
  9. p.set("foo", "baz")
  10. t.equal(p.get("foo"), "baz")
  11. var p = new ProtoList
  12. p.push({foo:"bar"})
  13. p.set("foo", "baz")
  14. t.equal(p.get("foo"), "baz")
  15. t.equal(p.length, 1)
  16. p.pop()
  17. t.equal(p.length, 0)
  18. p.set("foo", "asdf")
  19. t.equal(p.length, 1)
  20. t.equal(p.get("foo"), "asdf")
  21. p.push({bar:"baz"})
  22. t.equal(p.length, 2)
  23. t.equal(p.get("foo"), "asdf")
  24. p.shift()
  25. t.equal(p.length, 1)
  26. t.equal(p.get("foo"), undefined)
  27. p.unshift({foo:"blo", bar:"rab"})
  28. p.unshift({foo:"boo"})
  29. t.equal(p.length, 3)
  30. t.equal(p.get("foo"), "boo")
  31. t.equal(p.get("bar"), "rab")
  32. var ret = p.splice(1, 1, {bar:"bar"})
  33. t.same(ret, [{foo:"blo", bar:"rab"}])
  34. t.equal(p.get("bar"), "bar")
  35. // should not inherit default object properties
  36. t.equal(p.get('hasOwnProperty'), undefined)
  37. // unless we give it those.
  38. p.root = {}
  39. t.equal(p.get('hasOwnProperty'), {}.hasOwnProperty)
  40. p.root = {default:'monkey'}
  41. t.equal(p.get('default'), 'monkey')
  42. p.push({red:'blue'})
  43. p.push({red:'blue'})
  44. p.push({red:'blue'})
  45. while (p.length) {
  46. t.equal(p.get('default'), 'monkey')
  47. p.shift()
  48. }
  49. t.end()
  50. })