Bläddra i källkod

Test Observable.pack; Don't use table.pack;

bjorn 9 år sedan
förälder
incheckning
514f1e484d
3 ändrade filer med 14 tillägg och 1 borttagningar
  1. 1 1
      rx.lua
  2. 1 0
      tests/observable.lua
  3. 12 0
      tests/pack.lua

+ 1 - 1
rx.lua

@@ -1,6 +1,6 @@
 local rx
 
-local pack = table.pack or function(...) return {...} end
+local pack = function(...) return {...} end
 local unpack = table.unpack or unpack
 local function eq(x, y) return x == y end
 local function noop() end

+ 1 - 0
tests/observable.lua

@@ -164,4 +164,5 @@ describe('Observable', function()
   dofile('tests/max.lua')
   dofile('tests/min.lua')
   dofile('tests/merge.lua')
+  dofile('tests/pack.lua')
 end)

+ 12 - 0
tests/pack.lua

@@ -0,0 +1,12 @@
+describe('pack', function()
+  it('produces an error if its parent errors', function()
+    local observable = Rx.Observable.fromValue(''):map(function(x) return x() end)
+    expect(observable.subscribe).to.fail()
+    expect(observable:pack().subscribe).to.fail()
+  end)
+
+  it('wraps elements of the source in tables', function()
+    local observable = Rx.Observable.fromTable({4, 5, 6}, ipairs, true):pack()
+    expect(observable).to.produce({{{4, 1}}, {{5, 2}}, {{6, 3}}})
+  end)
+end)