-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathruntests.jl
167 lines (127 loc) · 4.78 KB
/
runtests.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
using Test, Interfaces, Tables
abstract type Iterable end
@interface Iterable begin
iterate(::Iterable)
iterate(::Iterable, st)
Base.IteratorSize(::Type{Iterable})::Union{Base.HasLength, Base.HasShape, Base.IsInfinite, Base.SizeUnknown}
if Base.IteratorSize(Iterable) == Base.HasLength()
length(::Iterable)
elseif Base.IteratorSize(Iterable) isa Base.HasShape
length(::Iterable)
size(::Iterable)
end
Base.IteratorEltype(::Type{Iterable})::Union{Base.HasEltype, Base.EltypeUnknown}
if Base.IteratorEltype(Iterable) == Base.HasEltype()
eltype(::Iterable) || eltype(::Type{Iterable})
end
end
@test Interfaces.implements(Int, Iterable, [Base])
abstract type Indexable end
@interface Indexable begin
getindex(::Indexable, i)
setindex!(::Indexable, v, i)
firstindex(::Indexable)
lastindex(::Indexable)
end
@test Interfaces.implements(Array, Indexable, [Base])
@interface AbstractArray T begin
T <: AbstractArray
size(::T)
Base.IndexStyle(::Type{T})::Union{Base.IndexLinear, Base.IndexCartesian}
if Base.IndexStyle(T) == Base.IndexLinear()
getindex(::T, i::Int)
setindex!(::T, v, i::Int)
elseif Base.IndexStyle(T) == Base.IndexCartesian()
getindex(::T, I::Vararg{Int})
setindex!(::T, v, I::Vararg{Int})
end
end
@test Interfaces.implements(Array, AbstractArray, [Base])
struct Foo end
@test_throws InterfaceImplementationError Interfaces.implements(Foo, AbstractArray)
@test_throws InterfaceImplementationError Interfaces.implements(Foo, Iterable)
@interface Tables.AbstractColumns T begin
Tables.getcolumn(::T, ::Int)
Tables.getcolumn(::T, ::Symbol)
Tables.columnnames(::T)
end
@interface Tables.AbstractRow T begin
Tables.getcolumn(::T, ::Int)
Tables.getcolumn(::T, ::Symbol)
Tables.columnnames(::T)
end
abstract type AbstractTable end
@interface AbstractTable begin
Tables.isrowtable(::Type{AbstractTable}) ||
Tables.rowaccess(::Type{AbstractTable}) ||
Tables.columnaccess(::Type{AbstractTable})
if Tables.isrowtable(AbstractTable) || Tables.rowaccess(AbstractTable)
Tables.rows(::AbstractTable)::RT where {RT <: Iterable}
if Base.IteratorEltype(RT) == Base.HasEltype()
eltype(::RT)::Type{Tables.AbstractRow} ||
eltype(::Type{RT})::Type{Tables.AbstractRow}
end
elseif Tables.columnaccess(AbstractTable)
Tables.istable(::Type{AbstractTable})
Tables.columns(::AbstractTable)::Tables.AbstractColumns
end
@optional Tables.schema(::AbstractTable)::Union{Nothing, Tables.Schema}
end
@test Interfaces.implements(Tables.DictRowTable, AbstractTable)
@test Interfaces.implements(Tables.DictColumnTable, AbstractTable)
abstract type Example end
@interface Example T begin
# required subtyping
T <: Example
# required method definition
foo1(arg::Example, arg2::Int)
# method def w/ return type
foo2(arg::Example)::Float64
# method def w/ interface return type
foo3(arg::Example)::Iterable
# one of many required
foo4(arg::Example) || foo5(arg::Example) || foo6(arg::Example)
# conditional
if foo7(T)
foo8(arg::Example)
foo9(arg::Example)::RT where {RT <: Iterable}
foo10(::RT)::Int
elseif foo11(T)
foo12(arg::Example)
else
foo13(arg::Example) || foo14(arg::Example)
end
@optional foo15(arg::Example)
end
@test repr("text/plain", Interfaces.interface(Example)) == """
Interface: Example
* subtyping: `T <: Example`
* method definition: `foo1(arg::Example, arg2::Int)`
* method definition with required return type: `foo2(arg::Example)::Float64`
* method definition with required return type: `foo3(arg::Example)::Iterable`
* one of the following required:
* method definition: `foo4(arg::Example)`
* method definition: `foo5(arg::Example)`
* method definition: `foo6(arg::Example)`
* conditional requirements:
* if foo7(Example)
* method definition: `foo8(arg::Example)`
* method definition with required return type: `foo9(arg::Example)::(RT where RT <: Iterable)`
* method definition with required return type: `foo10(::RT)::Int`
* elseif foo11(Example)
* method definition: `foo12(arg::Example)`
* else
* one of the following required:
* method definition: `foo13(arg::Example)`
* method definition: `foo14(arg::Example)`
* optional interface requirement:
* method definition: `foo15(arg::Example)`"""
abstract type AbstractStridedArray end
@interface AbstractStridedArray A begin
A <: AbstractArray
strides(::A)
Base.unsafe_convert(::Type{<:Ptr}, ::A)
Base.elsize(::Type{<:A})
@optional stride(::A, i::Int)
end
@test Interfaces.implements(Vector{Int}, AbstractStridedArray, [Base])