basic.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. })