Skip to content

Commit 8d0f836

Browse files
kshyattandyferris
authored andcommitted
More macro error tests (#185)
1 parent 8a7776c commit 8d0f836

File tree

6 files changed

+31
-0
lines changed

6 files changed

+31
-0
lines changed

test/MArray.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,13 @@
4141
@test ((@MArray Float64[i*j*k for i = 1:2, j = 2:3, k =3:4])::MArray{Tuple{2,2,2}}).data === (6.0, 12.0, 9.0, 18.0, 8.0, 16.0, 12.0, 24.0)
4242

4343
@test (ex = macroexpand(:(@MArray [1 2; 3])); isa(ex, Expr) && ex.head == :error)
44+
@test (ex = macroexpand(:(@MArray Float64[1 2; 3])); isa(ex, Expr) && ex.head == :error)
45+
@test (ex = macroexpand(:(@MArray fill)); isa(ex, Expr) && ex.head == :error)
46+
@test (ex = macroexpand(:(@MArray ones)); isa(ex, Expr) && ex.head == :error)
47+
@test (ex = macroexpand(:(@MArray fill(1))); isa(ex, Expr) && ex.head == :error)
48+
@test (ex = macroexpand(:(@MArray eye(5,6,7,8,9))); isa(ex, Expr) && ex.head == :error)
4449

50+
@test ((@MArray fill(3.,2,2,1))::MArray{Tuple{2,2,1}, Float64}).data === (3.0, 3.0, 3.0, 3.0)
4551
@test ((@MArray zeros(2,2,1))::MArray{Tuple{2,2,1}, Float64}).data === (0.0, 0.0, 0.0, 0.0)
4652
@test ((@MArray ones(2,2,1))::MArray{Tuple{2,2,1}, Float64}).data === (1.0, 1.0, 1.0, 1.0)
4753
@test ((@MArray eye(2))::MArray{Tuple{2,2}, Float64}).data === (1.0, 0.0, 0.0, 1.0)

test/MMatrix.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,14 @@
4040
@test ((@MMatrix Float64[i*j for i = 1:2, j=2:3])::MMatrix{2,2}).data === (2.0, 4.0, 3.0, 6.0)
4141

4242
@test (ex = macroexpand(:(@MMatrix [1 2; 3])); isa(ex, Expr) && ex.head == :error)
43+
@test (ex = macroexpand(:(@MMatrix [i*j*k for i = 1:2, j=2:3, k=3:4])); isa(ex, Expr) && ex.head == :error)
44+
@test (ex = macroexpand(:(@MMatrix Float32[i*j*k for i = 1:2, j=2:3, k=3:4])); isa(ex, Expr) && ex.head == :error)
45+
@test (ex = macroexpand(:(@MMatrix fill(2.3, 4, 5, 6))); isa(ex, Expr) && ex.head == :error)
46+
@test (ex = macroexpand(:(@MMatrix ones(4, 5, 6, 7))); isa(ex, Expr) && ex.head == :error)
47+
@test (ex = macroexpand(:(@MMatrix eye(4, 5, 6, 7))); isa(ex, Expr) && ex.head == :error)
4348

4449
@test ((@MMatrix zeros(2,2))::MMatrix{2, 2, Float64}).data === (0.0, 0.0, 0.0, 0.0)
50+
@test ((@MMatrix fill(3.4, 2,2))::MMatrix{2, 2, Float64}).data === (3.4, 3.4, 3.4, 3.4)
4551
@test ((@MMatrix ones(2,2))::MMatrix{2, 2, Float64}).data === (1.0, 1.0, 1.0, 1.0)
4652
@test ((@MMatrix eye(2))::MMatrix{2, 2, Float64}).data === (1.0, 0.0, 0.0, 1.0)
4753
@test ((@MMatrix eye(2,2))::MMatrix{2, 2, Float64}).data === (1.0, 0.0, 0.0, 1.0)

test/MVector.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,18 @@
2424

2525
@test ((@MVector zeros(2))::MVector{2, Float64}).data === (0.0, 0.0)
2626
@test ((@MVector ones(2))::MVector{2, Float64}).data === (1.0, 1.0)
27+
@test ((@MVector fill(2.5, 2))::MVector{2, Float64}).data === (2.5, 2.5)
2728
@test isa(@MVector(rand(2)), MVector{2, Float64})
2829
@test isa(@MVector(randn(2)), MVector{2, Float64})
2930

3031
@test ((@MVector zeros(Float32, 2))::MVector{2,Float32}).data === (0.0f0, 0.0f0)
3132
@test ((@MVector ones(Float32, 2))::MVector{2,Float32}).data === (1.0f0, 1.0f0)
3233
@test isa(@MVector(rand(Float32, 2)), MVector{2, Float32})
3334
@test isa(@MVector(randn(Float32, 2)), MVector{2, Float32})
35+
@test (ex = macroexpand(:(@MVector fill(1.5, 2, 3))); isa(ex, Expr) && ex.head == :error)
36+
@test (ex = macroexpand(:(@MVector ones(2, 3, 4))); isa(ex, Expr) && ex.head == :error)
37+
@test (ex = macroexpand(:(@MVector [i*j for i in 1:2, j in 2:3])); isa(ex, Expr) && ex.head == :error)
38+
@test (ex = macroexpand(:(@MVector Float32[i*j for i in 1:2, j in 2:3])); isa(ex, Expr) && ex.head == :error)
3439
end
3540

3641
@testset "Methods" begin

test/SArray.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,13 @@
3939
@test ((@SArray Float64[i*j*k for i = 1:2, j = 2:3, k =3:4])::SArray{Tuple{2,2,2}}).data === (6.0, 12.0, 9.0, 18.0, 8.0, 16.0, 12.0, 24.0)
4040

4141
@test (ex = macroexpand(:(@SArray [1 2; 3])); isa(ex, Expr) && ex.head == :error)
42+
@test (ex = macroexpand(:(@SArray Float64[1 2; 3])); isa(ex, Expr) && ex.head == :error)
43+
@test (ex = macroexpand(:(@SArray ones)); isa(ex, Expr) && ex.head == :error)
44+
@test (ex = macroexpand(:(@SArray fill)); isa(ex, Expr) && ex.head == :error)
45+
@test (ex = macroexpand(:(@SArray fill(1))); isa(ex, Expr) && ex.head == :error)
46+
@test (ex = macroexpand(:(@SArray eye(5,6,7,8,9))); isa(ex, Expr) && ex.head == :error)
4247

48+
@test ((@SArray fill(3.,2,2,1))::SArray{Tuple{2,2,1}, Float64}).data === (3.0, 3.0, 3.0, 3.0)
4349
@test ((@SArray zeros(2,2,1))::SArray{Tuple{2,2,1}, Float64}).data === (0.0, 0.0, 0.0, 0.0)
4450
@test ((@SArray ones(2,2,1))::SArray{Tuple{2,2,1}, Float64}).data === (1.0, 1.0, 1.0, 1.0)
4551
@test ((@SArray eye(2))::SArray{Tuple{2,2}, Float64}).data === (1.0, 0.0, 0.0, 1.0)

test/SMatrix.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
@test (ex = macroexpand(:(@SMatrix [i*j*k for i = 1:2, j=2:3, k=3:4])); isa(ex, Expr) && ex.head == :error)
4242
@test (ex = macroexpand(:(@SMatrix Float64[i*j*k for i = 1:2, j=2:3, k=3:4])); isa(ex, Expr) && ex.head == :error)
4343
@test (ex = macroexpand(:(@SMatrix fill(1.5, 2, 3, 4))); isa(ex, Expr) && ex.head == :error)
44+
@test (ex = macroexpand(:(@SMatrix ones(2, 3, 4, 5))); isa(ex, Expr) && ex.head == :error)
45+
@test (ex = macroexpand(:(@SMatrix eye(2, 3, 4, 5))); isa(ex, Expr) && ex.head == :error)
4446

4547
@test ((@SMatrix zeros(2,2))::SMatrix{2, 2, Float64}).data === (0.0, 0.0, 0.0, 0.0)
4648
@test ((@SMatrix ones(2,2))::SMatrix{2, 2, Float64}).data === (1.0, 1.0, 1.0, 1.0)

test/SVector.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,19 @@
2727

2828
@test ((@SVector zeros(2))::SVector{2, Float64}).data === (0.0, 0.0)
2929
@test ((@SVector ones(2))::SVector{2, Float64}).data === (1.0, 1.0)
30+
@test ((@SVector fill(2.5, 2))::SVector{2,Float64}).data === (2.5, 2.5)
3031
@test isa(@SVector(rand(2)), SVector{2, Float64})
3132
@test isa(@SVector(randn(2)), SVector{2, Float64})
3233

3334
@test ((@SVector zeros(Float32, 2))::SVector{2,Float32}).data === (0.0f0, 0.0f0)
3435
@test ((@SVector ones(Float32, 2))::SVector{2,Float32}).data === (1.0f0, 1.0f0)
3536
@test isa(@SVector(rand(Float32, 2)), SVector{2, Float32})
3637
@test isa(@SVector(randn(Float32, 2)), SVector{2, Float32})
38+
39+
@test (ex = macroexpand(:(@SVector fill(1.5, 2, 3))); isa(ex, Expr) && ex.head == :error)
40+
@test (ex = macroexpand(:(@SVector ones(2, 3, 4))); isa(ex, Expr) && ex.head == :error)
41+
@test (ex = macroexpand(:(@SVector [i*j for i in 1:2, j in 2:3])); isa(ex, Expr) && ex.head == :error)
42+
@test (ex = macroexpand(:(@SVector Float32[i*j for i in 1:2, j in 2:3])); isa(ex, Expr) && ex.head == :error)
3743
end
3844

3945
@testset "Methods" begin

0 commit comments

Comments
 (0)