|
1 | 1 | using Test |
2 | 2 | using Classes |
3 | 3 | using Suppressor |
| 4 | +using MacroTools: striplines |
4 | 5 |
|
5 | 6 | @test superclass(Class) === nothing |
6 | | -@test isclass(AbstractClass) == false |
| 7 | + |
| 8 | +@test isclass(AbstractClass) == false # not concrete |
| 9 | +@test isclass(Int) == false # not <: AbstractClass |
7 | 10 |
|
8 | 11 | @class Foo <: Class begin |
9 | 12 | foo::Int |
@@ -140,3 +143,50 @@ xyz = SubTupleHolder(sub, 10, 20, 30, (foo=111, bar=222)) |
140 | 143 | # Test method structure) |
141 | 144 | # "First argument of method whatever must be explicitly typed" |
142 | 145 | @test_throws(LoadError, eval(Meta.parse("@method whatever(i) = i"))) |
| 146 | + |
| 147 | +expr = quote |
| 148 | + abstract type AbstractX <: AbstractClass end |
| 149 | + struct X{} <: AbstractX |
| 150 | + function X() |
| 151 | + #= /Users/rjp/.julia/dev/Classes/src/Classes.jl:136 =# |
| 152 | + new() |
| 153 | + end |
| 154 | + function X(_self::T) where T <: AbstractX |
| 155 | + _self |
| 156 | + end |
| 157 | + end |
| 158 | + Classes.superclass(::Type{X}) = begin |
| 159 | + Class |
| 160 | + end |
| 161 | + X |
| 162 | +end |
| 163 | + |
| 164 | +expected1 = striplines(expr) |
| 165 | +emitted1 = striplines(Classes._defclass(:X, Class, false, nothing, [])) |
| 166 | + |
| 167 | +@test string(expected1) == string(emitted1) |
| 168 | + |
| 169 | +expr = quote |
| 170 | + abstract type AbstractX <: AbstractClass end |
| 171 | + mutable struct X{NT <: NamedTuple} <: AbstractX |
| 172 | + i::Int |
| 173 | + j::Int |
| 174 | + function X{NT}(i::Int, j::Int) where NT <: NamedTuple |
| 175 | + new{NT}(i, j) |
| 176 | + end |
| 177 | + function X(_self::T, i::Int, j::Int) where {T <: AbstractX, NT <: NamedTuple} |
| 178 | + _self.i = i |
| 179 | + _self.j = j |
| 180 | + _self |
| 181 | + end |
| 182 | + end |
| 183 | + Classes.superclass(::Type{X}) = begin |
| 184 | + Class |
| 185 | + end |
| 186 | + X |
| 187 | +end |
| 188 | + |
| 189 | +expected2 = striplines(expr) |
| 190 | +emitted2 = striplines(Classes._defclass(:X, Class, true, [:(NT <: NamedTuple)], [:(i::Int), :(j::Int)])) |
| 191 | + |
| 192 | +@test string(expected2) == string(emitted2) |
0 commit comments