Skip to content

Commit

Permalink
add coverage badge
Browse files Browse the repository at this point in the history
  • Loading branch information
starwing committed Aug 17, 2018
1 parent 8805454 commit 8c6556f
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 6 deletions.
8 changes: 5 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,22 @@ before_install:
- pip install --user hererocks
- hererocks env --$LUA -rlatest # Use latest LuaRocks, install into 'env' directory.
- source env/bin/activate # Add directory with all installed binaries to PATH.
- luarocks install luacov
- luarocks install luacov-coveralls --server=https://rocks.moonscript.org/dev
# - luarocks install busted
# - pip install cpp-coveralls
# - luarocks install Lua-cURL --server=https://rocks.moonscript.org/dev
# - luarocks install luacov-coveralls --server=https://rocks.moonscript.org/dev
# - luarocks install lunitx

install:
- luarocks make

script:
- lua test.lua
- lua -lluacov test.lua
# - lunit.sh test.lua

#after_success:
after_success:
- luacov-coveralls -v -i iter.lua -i test.impl.lua
# - coveralls -b .. -r .. --dump c.report.json
# - luacov-coveralls -j c.report.json -v

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Lua Iteration Library
========================
[![Build Status](https://travis-ci.org/starwing/luaiter.svg?branch=master)](https://travis-ci.org/starwing/luaiter)
[![Coverage Status](https://coveralls.io/repos/github/starwing/luaiter/badge.svg?branch=master)](https://coveralls.io/github/starwing/luaiter?branch=master)

luaiter is a rewritten version of [luafun][1]: a high-performance
functional programming library for Lua designed with LuaJIT's trace
Expand Down
2 changes: 1 addition & 1 deletion iter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1056,7 +1056,7 @@ end

setmetatable(Operator, {
__call = function(self, op)
return iter._(assert(self[op], "not such operator"))
return iter._(assert(self[op], "no such operator"))
end
})

Expand Down
78 changes: 76 additions & 2 deletions test.impl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ for _, a in iter(1, 2, 3, 4, 5, 6, 7) do print(a) end
attempt to iterate a number value
--]]

op"--"
--[[ERROR
no such operator
--]]

--! each

Expand Down Expand Up @@ -403,6 +407,24 @@ print(all(_"_1 >= 10, _1 <= 20", take(20, rand(10, 20))))
true
--]]

local f, r = split(5, range(10))
f:each(print)
print '---'
r:each(print)
--[[OUTPUT
1
2
3
4
5
---
6
7
8
9
10
--]]


--iter.array = array
--iter.resolve = resolve
Expand Down Expand Up @@ -644,6 +666,14 @@ iter {1,2,2,3,3,4,5} :groupby(_"_2, _2"):map(_G.unpack or table.unpack)
5
--]]

iter {1,2,2,3,3,4,5} :group(3):map(_G.unpack or table.unpack)
:each(print)
--[[OUTPUT
1,1,2,2,3,2
4,3,5,3,6,4
7,5
--]]

array {1,2,2,3,3,4,5} :packgroupby():flatmap(array):map(_G.unpack or table.unpack)
:each(print)
--[[OUTPUT
Expand Down Expand Up @@ -675,6 +705,14 @@ c,three
d,nil
--]]

zip(array{"a", "b", "c", "d"}, iter{"one", "two", "three"}):each(print)
--[[OUTPUT
a,1,one
b,2,two
c,3,three
d,nil
--]]

zipall(array{"a", "b", "c", "d"}, array{"one", "two", "three"}):each(print)
--[[OUTPUT
a,one
Expand Down Expand Up @@ -819,6 +857,35 @@ filter(_"_1 % 3 == 0", range(10)):each(print)
9
--]]

filterout(_"_1 % 3 == 0", range(10)):each(print)
--[[OUTPUT
1
2
4
5
7
8
10
--]]

local f1,r1 = partition(_"_1 % 3 == 0", range(10))
f1:each(print)
print'---'
r1:each(print)
--[[OUTPUT
3
6
9
---
1
2
4
5
7
8
10
--]]

filter(_"_1 % 3 == 0", range(0)):each(print)
--[[OUTPUT
--]]
Expand Down Expand Up @@ -880,8 +947,6 @@ Emma

--! reducing

eq(_.self(range(10)).reduce(op.add)(), 55)

eq(range(10):map(-_1):reduce(_1+_2), -55)
eq(foldl(_1 + _2, nil, range(5)), 15)
eq(foldl(_1 + _2, 0, range(5)), 15)
Expand Down Expand Up @@ -924,6 +989,15 @@ eq(any(_1, {}), false)

--! operators

eq(_.self(range(10)).reduce(op.add)(), 55)
eq(_(_1.range)(10)(_G):reduce(op.add), 55)
_(_3)(_2, _1.._2, _.dots)("world", "hello", print, "a", "b", "c")
print(_.andor(_.le(_1, _2), _3, _4)(1, 2, "foo", "bar"))
--[[OUTPUT
hello,worldhello,a,b,c
foo
--]]

eq(op, operator) -- an alias

local comparators = { 'le', 'lt', 'eq', 'ne', 'ge', 'gt' }
Expand Down

0 comments on commit 8c6556f

Please sign in to comment.