Skip to content

Commit 6a441a7

Browse files
committed
Improved tests
1 parent a0577c6 commit 6a441a7

File tree

1 file changed

+51
-1
lines changed

1 file changed

+51
-1
lines changed

test/test_classes.jl

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
using Test
22
using Classes
33
using Suppressor
4+
using MacroTools: striplines
45

56
@test superclass(Class) === nothing
6-
@test isclass(AbstractClass) == false
7+
8+
@test isclass(AbstractClass) == false # not concrete
9+
@test isclass(Int) == false # not <: AbstractClass
710

811
@class Foo <: Class begin
912
foo::Int
@@ -140,3 +143,50 @@ xyz = SubTupleHolder(sub, 10, 20, 30, (foo=111, bar=222))
140143
# Test method structure)
141144
# "First argument of method whatever must be explicitly typed"
142145
@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

Comments
 (0)