RxLua/tests/changes.lua

31 lines
1.4 KiB
Lua

describe('changes', function()
describe('with the default comparator', function()
it('produces a value if it is the first value or different from the previous', function()
local observable = Rx.Observable.fromTable({1, 1, 3, 1, 4, 5, 5, 5}, ipairs):changes()
expect(observable).to.produce(1, 3, 1, 4, 5)
end)
it('produces the first value if it is nil', function()
local observable = Rx.Observable.fromValue(nil):changes()
expect(observable).to.produce({{}})
end)
it('produces multiple onNext arguments but only uses the first argument to check for equality', function()
local observable = Rx.Observable.fromTable({1, 1, 3, 1, 4, 5, 5, 5}, ipairs, true):changes()
expect(observable).to.produce({{1, 1}, {3, 3}, {1, 4}, {4, 5}, {5, 6}})
end)
end)
describe('with a custom comparator', function()
it('produces a value if it is the first value or the comparator returns false when passed the previous value and the current value', function()
local observable = Rx.Observable.fromTable({1, 1, 3, 1, 4, 5, 5, 5}, ipairs):changes(function(x, y) return x % 2 == y % 2 end)
expect(observable).to.produce(1, 4, 5)
end)
it('produces the first value if it is nil', function()
local observable = Rx.Observable.fromValue(nil):changes(function(x, y) return true end)
expect(observable).to.produce({{}})
end)
end)
end)