Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for Julia 0.6 #4

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1 +1 @@
julia 0.5-
julia 0.6-
22 changes: 11 additions & 11 deletions src/types.jl
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
# types
abstract AbstractCell
abstract type AbstractCell end

immutable PreCell <: AbstractCell
struct PreCell <: AbstractCell
data::AbstractArray
width::Int
height::Int
end

immutable Vertical <: AbstractCell
struct Vertical <: AbstractCell
data::String
width::Int
height::Int
Vertical(height) = new("|", 1, height)
end

immutable Dash <: AbstractCell
struct Dash <: AbstractCell
data::String
repeat::Int
Dash(dash::String, n::Int) = new(dash, n)
end

immutable Connector <: AbstractCell
struct Connector <: AbstractCell
data::String
Connector() = new("+")
end

type Cell <: AbstractCell
mutable struct Cell <: AbstractCell
data::AbstractArray
width::Int
height::Int
end

type Margin
struct Margin
leftside::Int
rightside::Int
end

type Mill
struct Mill
board::AbstractArray
option::Dict
Mill(board, option::Dict) = new(board, option)
end

typealias Linear{T<:Union{AbstractCell}} AbstractVector{T}
typealias Horizontal{T<:Union{Dash,Connector}} AbstractVector{T}
typealias PlateVector{T<:Union{Linear,Horizontal}} AbstractVector{T}
const Linear{T<:Union{AbstractCell}} = AbstractVector{T}
const Horizontal{T<:Union{Dash,Connector}} = AbstractVector{T}
const PlateVector{T<:Union{Linear,Horizontal}} = AbstractVector{T}
64 changes: 30 additions & 34 deletions test/colored.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Millboard
using Base.Test


macro test_colored(expr)
#println()
#println(expr.args[3])
Expand All @@ -11,32 +10,32 @@ end


cyan = colored(:cyan)
@test_colored "\e[1m\e[36m1\e[0m\e[1m" == 1 |> cyan |> string
@test_colored "\e[1m\e[36mπ = 3.1415926535897...\e[0m\e[1m" == pi |> cyan |> string
@test_colored "\e[36m1\e[39m\e[0m" == 1 |> cyan |> string
@test_colored "\e[36mπ = 3.1415926535897...\e[39m\e[0m" == pi |> cyan |> string


green = colored(:green)
@test_colored "Millboard.Coat(:green,sin)" == sin |> green |> string
@test_colored "Millboard.Coat(:green, sin)" == sin |> green |> string


magenta = colored(:magenta)
@test_colored "\e[1m\e[35mABC\e[0m\e[1m" == "ABC" |> magenta |> string
@test_colored "\e[1m\e[35mABC\e[0m\e[1m" == "ABC" |> magenta(s->s) |> string
@test_colored "\e[1m\e[1m\e[35mABC\e[0m\e[1m\e[1m" == "ABC" |> magenta(s->s[1:end]) |> string
@test_colored "\e[35mABC\e[39m\e[0m" == "ABC" |> magenta |> string
@test_colored "\e[35mABC\e[39m\e[0m" == "ABC" |> magenta(s->s) |> string
@test_colored "\e[0m\e[35mABC\e[39m\e[0m\e[0m" == "ABC" |> magenta(s->s[1:end]) |> string

@test_colored "\e[1m\e[1m\e[35mA\e[0m\e[1m\e[1mBC" == "ABC" |> magenta(s->s[]) |> string
@test_colored "\e[1m\e[1m\e[35mA\e[0m\e[1m\e[1mBC" == "ABC" |> magenta(s->s[1]) |> string
@test_colored "\e[0m\e[35mA\e[39m\e[0m\e[0mBC" == "ABC" |> magenta(s->s[]) |> string
@test_colored "\e[0m\e[35mA\e[39m\e[0m\e[0mBC" == "ABC" |> magenta(s->s[1]) |> string

@test_colored "\e[1mA\e[1m\e[35mB\e[0m\e[1m\e[1mC" == "ABC" |> magenta(s->s[2]) |> string
@test_colored "\e[1mAB\e[1m\e[35mC\e[0m\e[1m\e[1m" == "ABC" |> magenta(s->s[3]) |> string
@test_colored "\e[1mAB\e[1m\e[35mC\e[0m\e[1m\e[1m" == "ABC" |> magenta(s->s[end]) |> string
@test_colored "\e[0mA\e[35mB\e[39m\e[0m\e[0mC" == "ABC" |> magenta(s->s[2]) |> string
@test_colored "\e[0mAB\e[35mC\e[39m\e[0m\e[0m" == "ABC" |> magenta(s->s[3]) |> string
@test_colored "\e[0mAB\e[35mC\e[39m\e[0m\e[0m" == "ABC" |> magenta(s->s[end]) |> string


str = "Lorem ipsum dolor sit amet"
@test_colored "\e[1m\e[33mLorem ipsum dolor sit amet\e[0m\e[1m" == str |> colored(:yellow) |> string
@test_colored "\e[1m\e[33mLorem ipsum dolor sit amet\e[0m\e[1m" == str |> colored(:yellow, s->s) |> string
@test_colored "\e[1m\e[33mLorem ipsum dolor sit amet\e[0m\e[1m" == colored(:yellow, s->s, str) |> string
@test_colored "\e[1mLorem \e[1m\e[33mipsum dol\e[0m\e[1m\e[1mor sit amet" == colored(:yellow, s->s[7:15], str) |> string
@test_colored "\e[33mLorem ipsum dolor sit amet\e[39m\e[0m" == str |> colored(:yellow) |> string
@test_colored "\e[33mLorem ipsum dolor sit amet\e[39m\e[0m" == str |> colored(:yellow, s->s) |> string
@test_colored "\e[33mLorem ipsum dolor sit amet\e[39m\e[0m" == colored(:yellow, s->s, str) |> string
@test_colored "\e[0mLorem \e[33mipsum dol\e[39m\e[0m\e[0mor sit amet" == colored(:yellow, s->s[7:15], str) |> string


# test colored tables
Expand All @@ -45,31 +44,28 @@ colnames = [:blue :green :red :magenta]
board = map(colnames) do name
colored(name, s->s[1:end], string(name))
end
@test_colored "+===+=======+========+======+==========+\n| | :blue | :green | :red | :magenta |\n+===+=======+========+======+==========+\n| 1 | \e[1m\e[1m\e[34mblue\e[0m\e[1m\e[1m | \e[1m\e[1m\e[32mgreen\e[0m\e[1m\e[1m | \e[1m\e[1m\e[31mred\e[0m\e[1m\e[1m | \e[1m\e[1m\e[35mmagenta\e[0m\e[1m\e[1m |\n+---+-------+--------+------+----------+" == table(board, :colnames=>colnames) |> string
@test_colored """
+===+=======+========+======+==========+
| | :blue | :green | :red | :magenta |
+===+=======+========+======+==========+
| 1 | \e[0m\e[34mblue\e[39m\e[0m\e[0m | \e[0m\e[32mgreen\e[39m\e[0m\e[0m | \e[0m\e[31mred\e[39m\e[0m\e[0m | \e[0m\e[35mmagenta\e[39m\e[0m\e[0m |
+---+-------+--------+------+----------+""" == table(board, :colnames=>colnames) |> string

colored_colnames = [colored(:blue, "FIRST")]
@test_colored "+===+=======+=======+=====+=========+\n| | \e[1m\e[34mFIRST\e[0m\e[1m | 2 | 3 | 4 |\n+===+=======+=======+=====+=========+\n| 1 | \e[1m\e[1m\e[34mblue\e[0m\e[1m\e[1m | \e[1m\e[1m\e[32mgreen\e[0m\e[1m\e[1m | \e[1m\e[1m\e[31mred\e[0m\e[1m\e[1m | \e[1m\e[1m\e[35mmagenta\e[0m\e[1m\e[1m |\n+---+-------+-------+-----+---------+" == table(board, :colnames=>colored_colnames) |>string
@test_colored """
+===+=======+=======+=====+=========+
| | \e[34mFIRST\e[39m\e[0m | 2 | 3 | 4 |
+===+=======+=======+=====+=========+
| 1 | \e[0m\e[34mblue\e[39m\e[0m\e[0m | \e[0m\e[32mgreen\e[39m\e[0m\e[0m | \e[0m\e[31mred\e[39m\e[0m\e[0m | \e[0m\e[35mmagenta\e[39m\e[0m\e[0m |
+---+-------+-------+-----+---------+""" == table(board, :colnames=>colored_colnames) |> string


board = [5 6; 7 8]
@test_colored "+===+===+\n| | 1 |\n+===+===+\n| 1 | \e[1m\e[36m5\e[0m\e[1m |\n+---+---+\n| 2 | \e[1m\e[36m7\e[0m\e[1m |\n+---+---+\n| 3 | \e[1m\e[36m6\e[0m\e[1m |\n+---+---+\n| 4 | \e[1m\e[36m8\e[0m\e[1m |\n+---+---+" == board |> cyan(b->b[:]) |> table |> string
@test_colored "+===+===+\n| | 1 |\n+===+===+\n| 1 | \e[1m\e[36m5\e[0m\e[1m |\n+---+---+\n| 2 | \e[1m\e[36m7\e[0m\e[1m |\n+---+---+\n| 3 | \e[1m\e[36m6\e[0m\e[1m |\n+---+---+\n| 4 | \e[1m\e[36m8\e[0m\e[1m |\n+---+---+" == board |> cyan(b->b[:,]) |> table |> string

@test_colored "+===+===+===+\n| | 1 | 2 |\n+===+===+===+\n| 1 | \e[1m\e[36m5\e[0m\e[1m | \e[1m\e[36m6\e[0m\e[1m |\n+---+---+---+\n| 2 | \e[1m\e[36m7\e[0m\e[1m | \e[1m\e[36m8\e[0m\e[1m |\n+---+---+---+" == board |> cyan(b->b[:,:]) |> table |> string
@test_colored "+===+===+===+\n| | 1 | 2 |\n+===+===+===+\n| 1 | \e[1m\e[36m5\e[0m\e[1m | 6 |\n+---+---+---+\n| 2 | \e[1m\e[36m7\e[0m\e[1m | 8 |\n+---+---+---+" == board |> cyan(b->b[1:2]) |> table |> string
@test_colored "+===+===+===+\n| | 1 | 2 |\n+===+===+===+\n| 1 | \e[1m\e[36m5\e[0m\e[1m | \e[1m\e[36m6\e[0m\e[1m |\n+---+---+---+\n| 2 | \e[1m\e[36m7\e[0m\e[1m | \e[1m\e[36m8\e[0m\e[1m |\n+---+---+---+" == board |> cyan(b->b[1:end]) |> table |> string
@test_colored "+===+===+===+\n| | 1 | 2 |\n+===+===+===+\n| 1 | \e[1m\e[36m5\e[0m\e[1m | 6 |\n+---+---+---+\n| 2 | 7 | 8 |\n+---+---+---+" == board |> cyan(b->b[1:1]) |> table |> string
@test_colored "+===+===+===+\n| | 1 | 2 |\n+===+===+===+\n| 1 | 5 | 6 |\n+---+---+---+\n| 2 | 7 | 8 |\n+---+---+---+" == board |> cyan(b->b[2:1]) |> table |> string
@test_colored "+===+===+===+\n| | 1 | 2 |\n+===+===+===+\n| 1 | 5 | 6 |\n+---+---+---+\n| 2 | \e[1m\e[36m7\e[0m\e[1m | 8 |\n+---+---+---+" == board |> cyan(b->b[2,1]) |> table |> string
@test_colored "+===+===+===+\n| | 1 | 2 |\n+===+===+===+\n| 1 | 5 | \e[1m\e[36m6\e[0m\e[1m |\n+---+---+---+\n| 2 | \e[1m\e[36m7\e[0m\e[1m | \e[1m\e[36m8\e[0m\e[1m |\n+---+---+---+" == board |> cyan(b->b[2:end]) |> table |> string
@test_colored "+===+===+===+\n| | 1 | 2 |\n+===+===+===+\n| 1 | 5 | 6 |\n+---+---+---+\n| 2 | \e[1m\e[36m7\e[0m\e[1m | \e[1m\e[36m8\e[0m\e[1m |\n+---+---+---+" == board |> cyan(b->b[2,:]) |> table |> string

@test_colored "+===+===+\n| | 1 |\n+===+===+\n| 1 | \e[36m5\e[39m\e[0m |\n+---+---+\n| 2 | \e[36m7\e[39m\e[0m |\n+---+---+\n| 3 | \e[36m6\e[39m\e[0m |\n+---+---+\n| 4 | \e[36m8\e[39m\e[0m |\n+---+---+" == board |> cyan(b->b[:]) |> table |> string
@test_colored "+===+===+\n| | 1 |\n+===+===+\n| 1 | \e[36m5\e[39m\e[0m |\n+---+---+\n| 2 | \e[36m7\e[39m\e[0m |\n+---+---+\n| 3 | \e[36m6\e[39m\e[0m |\n+---+---+\n| 4 | \e[36m8\e[39m\e[0m |\n+---+---+" == board |> cyan(b->b[:,]) |> table |> string

board = ([1 2], [5 6;7 8], [9 10; 11 12])
@test_colored "+===+=====+=====+=======+\n| | 1 | 2 | 3 |\n+===+=====+=====+=======+\n| | \e[1m\e[36m1 2\e[0m\e[1m |\e[1m\e[36m 5 6\e[0m\e[1m |\e[1m\e[36m 9 10\e[0m\e[1m |\n| 1 | |\e[1m\e[36m 7 8\e[0m\e[1m |\e[1m\e[36m 11 12\e[0m\e[1m |\n+---+-----+-----+-------+" == board |> cyan |> table |> string
@test_colored "+===+=====+=====+=======+\n| | 1 | 2 | 3 |\n+===+=====+=====+=======+\n| | \e[1m\e[36m1 2\e[0m\e[1m |\e[1m\e[36m 5 6\e[0m\e[1m |\e[1m\e[36m 9 10\e[0m\e[1m |\n| 1 | |\e[1m\e[36m 7 8\e[0m\e[1m |\e[1m\e[36m 11 12\e[0m\e[1m |\n+---+-----+-----+-------+" == board |> cyan(b->b) |> table |> string
@test_colored "+===+=====+=====+=======+\n| | 1 | 2 | 3 |\n+===+=====+=====+=======+\n| | \e[1m\e[36m1 2\e[0m\e[1m |\e[1m\e[36m 5 6\e[0m\e[1m |\e[1m\e[36m 9 10\e[0m\e[1m |\n| 1 | |\e[1m\e[36m 7 8\e[0m\e[1m |\e[1m\e[36m 11 12\e[0m\e[1m |\n+---+-----+-----+-------+" == board |> cyan(b->b[:,:]) |> table |> string
@test_colored "+===+=====+=====+=======+\n| | 1 | 2 | 3 |\n+===+=====+=====+=======+\n| | \e[1m\e[36m1 2\e[0m\e[1m | 5 6 | 9 10 |\n| 1 | | 7 8 | 11 12 |\n+---+-----+-----+-------+" == board |> cyan(b->b[]) |> table |> string
@test_colored "+===+=====+=====+=======+\n| | 1 | 2 | 3 |\n+===+=====+=====+=======+\n| | \e[36m1 2\e[39m\e[0m |\e[36m 5 6\e[39m\e[0m |\e[36m 9 10\e[39m\e[0m |\n| 1 | |\e[36m 7 8\e[39m\e[0m |\e[36m 11 12\e[39m\e[0m |\n+---+-----+-----+-------+" == board |> cyan |> table |> string


# coverage
Expand Down
29 changes: 15 additions & 14 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
using Millboard
using Base.Test

include(joinpath(dirname(@__FILE__),"numbers.jl"))
include(joinpath(dirname(@__FILE__),"strings.jl"))
include(joinpath(dirname(@__FILE__),"dicts.jl"))
include(joinpath(dirname(@__FILE__),"enums.jl"))
include(joinpath(dirname(@__FILE__),"functions.jl"))
include(joinpath(dirname(@__FILE__),"tuples.jl"))
include(joinpath(dirname(@__FILE__),"types.jl"))
include(joinpath(dirname(@__FILE__),"unicode.jl"))
include(joinpath(dirname(@__FILE__),"regex.jl"))
all_tests = []
for (root, dirs, files) in walkdir(".")
for filename in files
!endswith(filename, ".jl") && continue
"runtests.jl" == filename && continue
filepath = joinpath(root, filename)[3:end]
!isempty(ARGS) && !any(x->startswith(filepath, x), ARGS) && continue
push!(all_tests, filepath)
end
end

if Base.have_color
include(joinpath(dirname(@__FILE__),"colored.jl"))
for (idx, filepath) in enumerate(all_tests)
numbering = string(idx, /, length(all_tests))
ts = Base.Test.@testset "$numbering $filepath" begin
include(filepath)
end
end
1 change: 1 addition & 0 deletions test/strings.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Millboard
using Base.Test


board = ["Lorem ipsum dolor sit amet"]
@test """
+===+============================+
Expand Down
46 changes: 21 additions & 25 deletions test/tuples.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,30 +36,26 @@ board = [()]


# Julia PR #20288
if VERSION >= v"0.6.0-dev.2505"
@testset "display tuples" begin
board = ((1,2,3),)
@test """
+===+===========+
| | 1 |
+===+===========+
| 1 | (1, 2, 3) |
+---+-----------+""" == table(board) |> string
board = ((1,2,3),)
@test """
+===+===========+
| | 1 |
+===+===========+
| 1 | (1, 2, 3) |
+---+-----------+""" == table(board) |> string

board = [(1,2,3)]
@test """
+===+===========+
| | 1 |
+===+===========+
| 1 | (1, 2, 3) |
+---+-----------+""" == table(board) |> string
board = [(1,2,3)]
@test """
+===+===========+
| | 1 |
+===+===========+
| 1 | (1, 2, 3) |
+---+-----------+""" == table(board) |> string

board = [(1,2,3) (4,5,6)]
@test """
+===+===========+===========+
| | 1 | 2 |
+===+===========+===========+
| 1 | (1, 2, 3) | (4, 5, 6) |
+---+-----------+-----------+""" == table(board) |> string
end
end
board = [(1,2,3) (4,5,6)]
@test """
+===+===========+===========+
| | 1 | 2 |
+===+===========+===========+
| 1 | (1, 2, 3) | (4, 5, 6) |
+---+-----------+-----------+""" == table(board) |> string
1 change: 0 additions & 1 deletion test/unicode.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Millboard
using Base.Test


board = ["한글"]
@test """
+===+======+
Expand Down