• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

JuliaLang / julia / #37836

11 Jul 2024 11:31AM UTC coverage: 85.36% (-2.2%) from 87.516%
#37836

push

local

web-flow
fix loading of repeated/concurrent modules (#55066)

More followup to fix issues with require. There was an accidental
variable reuse (build_id) that caused it to be unable to load cache
files in many cases. There was also missing check for a dependency
already being loaded, resulting in trying to load it twice. Finally, the
start_loading code may drop the require_lock, but the surrounding code
was not prepared for that. Now integrate the necessary checks into
start_loading, instead of needing to duplicate them before and
afterwards.

Fixes #53983
Fixes #54940
Closes #55064

74 of 89 new or added lines in 1 file covered. (83.15%)

2133 existing lines in 46 files now uncovered.

73916 of 86593 relevant lines covered (85.36%)

15331627.57 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.96
/stdlib/Markdown/src/GitHub/table.jl
1
# This file is a part of Julia. License is MIT: https://julialang.org/license
2

3
mutable struct Table
4
    rows::Vector{Vector{Any}}
73✔
5
    align::Vector{Symbol}
6
end
7

8
function parserow(stream::IO)
9
    withstream(stream) do
15,682✔
10
        line = readline(stream)
7,925✔
11
        row = split(line, r"(?<!\\)\|")
7,925✔
12
        length(row) == 1 && return
7,925✔
13
        isempty(row[1]) && popfirst!(row)
168✔
14
        map!(x -> strip(replace(x, "\\|" => "|")), row, row)
1,110✔
15
        isempty(row[end]) && pop!(row)
168✔
16
        return row
168✔
17
    end
18
end
19

20
function rowlength!(row, len)
142✔
21
    while length(row) < len push!(row, "") end
142✔
22
    while length(row) > len pop!(row) end
142✔
23
    return row
142✔
24
end
25

26
const default_align = :r
27

28
function parsealign(row)
26✔
29
    align = Symbol[]
26✔
30
    for s in row
26✔
31
        (length(s) ≥ 3 && s ⊆ Set("-:")) || return
59✔
32
        push!(align,
101✔
33
              s[1] == ':' ? (s[end] == ':' ? :c : :l) :
34
              s[end] == ':' ? :r :
35
              default_align)
36
    end
59✔
37
    return align
26✔
38
end
39

40
function github_table(stream::IO, md::MD)
7,757✔
41
    withstream(stream) do
7,757✔
42
        skipblank(stream)
7,757✔
43
        rows = []
7,757✔
UNCOV
44
        cols = 0
×
UNCOV
45
        align = nothing
×
46
        while (row = parserow(stream)) !== nothing
15,682✔
47
            if length(rows) == 0
168✔
48
                cols = length(row)
45✔
49
            end
50
            if align === nothing && length(rows) == 1 # Must have a --- row
168✔
51
                align = parsealign(row)
26✔
52
                (align === nothing || length(align) != cols) && return false
26✔
53
            else
54
                push!(rows, map(x -> parseinline(x, md), rowlength!(row, cols)))
501✔
55
            end
56
        end
168✔
57
        length(rows) <= 1 && return false
7,757✔
58
        push!(md, Table(rows, align))
52✔
59
        return true
26✔
60
    end
61
end
62

63
function html(io::IO, md::Table)
10✔
64
    withtag(io, :table) do
10✔
65
        for (i, row) in enumerate(md.rows)
20✔
66
            withtag(io, :tr) do
21✔
67
                for (j, c) in enumerate(md.rows[i])
21✔
68
                    alignment = md.align[j]
49✔
69
                    alignment = alignment === :l ? "left" : alignment === :r ? "right" : "center"
81✔
70
                     withtag(io, i == 1 ? :th : :td, ("align", alignment)) do
49✔
71
                        htmlinline(io, c)
49✔
72
                    end
73
                end
49✔
74
            end
75
        end
32✔
76
    end
77
end
78

79
mapmap(f, xss) = map(xs->map(f, xs), xss)
174✔
80

81
colwidths(rows; len = length, min = 0) =
30✔
82
    reduce((x,y) -> max.(x,y), [min; convert(Vector{Vector{Int}}, mapmap(len, rows))])
72✔
83

84
padding(width, twidth, a) =
198✔
85
    a === :l ? (0, twidth - width) :
86
    a === :r ? (twidth - width, 0) :
87
    a === :c ? (floor(Int, (twidth-width)/2), ceil(Int, (twidth-width)/2)) :
88
    error("Invalid alignment $a")
89

90
function padcells!(rows, align; len = length, min = 0)
30✔
91
    widths = colwidths(rows, len = len, min = min)
15✔
92
    for i = 1:length(rows), j = axes(rows[1],1)
15✔
93
        cell = rows[i][j]
198✔
94
        lpad, rpad = padding(len(cell), widths[j], align[j])
198✔
95
        rows[i][j] = " "^lpad * cell * " "^rpad
198✔
96
    end
255✔
97
    return rows
15✔
98
end
99

100
_dash(width, align) =
31✔
101
    align === :l ? ":" * "-"^width * " " :
102
    align === :r ? " " * "-"^width * ":" :
103
    align === :c ? ":" * "-"^width * ":" :
104
    throw(ArgumentError("Invalid alignment $align"))
105

106
function plain(io::IO, md::Table)
11✔
107
    cells = mapmap(md.rows) do each
11✔
108
        replace(plaininline(each), "|" => "\\|")
188✔
109
    end
110
    padcells!(cells, md.align, len = length, min = 3)
11✔
111
    for i = axes(cells,1)
11✔
112
        print(io, "| ")
64✔
113
        join(io, cells[i], " | ")
64✔
114
        println(io, " |")
64✔
115
        if i == 1
64✔
116
            print(io, "|")
11✔
117
            join(io, [_dash(length(cells[i][j]), md.align[j]) for j = axes(cells[1],1)], "|")
11✔
118
            println(io, "|")
11✔
119
        end
120
    end
64✔
121
end
122

123
function rst(io::IO, md::Table)
×
124
    cells = mapmap(rstinline, md.rows)
×
125
    padcells!(cells, md.align, len = length, min = 3)
×
126
    single = ["-"^length(c) for c in cells[1]]
×
127
    double = ["="^length(c) for c in cells[1]]
×
128
    function print_row(row, row_sep, col_sep)
×
129
        print(io, col_sep, row_sep)
×
130
        join(io, row, string(row_sep, col_sep, row_sep))
×
131
        println(io, row_sep, col_sep)
×
132
    end
133
    print_row(single, '-', '+')
×
134
    for i = 1:length(cells)
×
135
        print_row(cells[i], ' ', '|')
×
136
        i ≡ 1 ? print_row(double, '=', '+') :
×
137
                print_row(single, '-', '+')
138
    end
×
139
end
140

141
function term(io::IO, md::Table, columns)
4✔
142
    margin_str = " "^margin
4✔
143
    cells = mapmap(x -> annotprint(terminline, x), md.rows)
14✔
144
    padcells!(cells, md.align, len = textwidth)
4✔
145
    for i = 1:length(cells)
4✔
146
        print(io, margin_str)
8✔
147
        join(io, cells[i], " ")
8✔
148
        if i == 1
8✔
149
            println(io)
4✔
150
            print(io, margin_str)
4✔
151
            join(io, ["–"^textwidth(cells[i][j]) for j = 1:length(cells[1])], " ")
4✔
152
        end
153
        i < length(cells) && println(io)
8✔
154
    end
8✔
155
end
156

157
function latex(io::IO, md::Table)
1✔
158
    wrapblock(io, "tabular") do
1✔
159
        align = md.align
1✔
160
        println(io, "{$(join(align, " | "))}")
1✔
161
        for (i, row) in enumerate(md.rows)
2✔
162
            for (j, cell) in enumerate(row)
2✔
163
                j != 1 && print(io, " & ")
4✔
164
                latexinline(io, cell)
4✔
165
            end
6✔
166
            println(io, " \\\\")
2✔
167
            if i == 1
2✔
168
                println(io, "\\hline")
1✔
169
            end
170
        end
2✔
171
    end
172
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc