|
1 | 1 | using BackendSelection: BackendSelection, @Algorithm_str, @Backend_str, Algorithm, Backend |
2 | 2 | using Test: @test, @testset |
| 3 | +using TestExtras: @constinferred |
3 | 4 |
|
4 | 5 | @testset "BackendSelection" begin |
5 | 6 | for type in (Algorithm, Backend) |
6 | 7 | @testset "$type" begin |
| 8 | + # Note: constructing from a string is not type stable. |
7 | 9 | @test type("backend") isa type{:backend} |
8 | | - @test type(:backend) isa type{:backend} |
9 | | - backend = type("backend"; x=2, y=3) |
| 10 | + @test @constinferred(type(:backend)) isa type{:backend} |
| 11 | + backend = @constinferred type(:backend; x=2, y=3) |
| 12 | + @test backend === type("backend"; x=2, y=3) |
10 | 13 | @test backend isa type{:backend} |
11 | 14 | @test backend.x == 2 |
12 | 15 | @test backend.y == 3 |
13 | | - @test propertynames(backend) == (:x, :y) |
| 16 | + @test @constinferred(getproperty(backend, :x)) == 2 |
| 17 | + @test @constinferred(getproperty(backend, :y)) == 3 |
| 18 | + @test @constinferred(backend[:x]) == 2 |
| 19 | + @test @constinferred(backend[:y]) == 3 |
| 20 | + @test @constinferred(get(backend, :x, "default")) == 2 |
| 21 | + @test @constinferred(get(backend, :y, "default")) == 3 |
| 22 | + @test @constinferred(get(backend, :z, "default")) == "default" |
| 23 | + @test @constinferred(propertynames(backend)) == (:x, :y) |
14 | 24 | (; x, y) = backend |
15 | 25 | @test x == 2 |
16 | 26 | @test y == 3 |
17 | | - @test BackendSelection.parameters(backend) === (; x=2, y=3) |
| 27 | + @test @constinferred(BackendSelection.parameters(backend)) === (; x=2, y=3) |
18 | 28 | end |
19 | 29 | end |
20 | 30 | # Macro syntax. |
21 | | - @test Algorithm"backend"(; x=2, y=3) === Algorithm("backend"; x=2, y=3) |
22 | | - @test Backend"backend"(; x=2, y=3) === Backend("backend"; x=2, y=3) |
| 31 | + @test @constinferred(Algorithm"backend"(; x=2, y=3)) === Algorithm("backend"; x=2, y=3) |
| 32 | + @test @constinferred(Backend"backend"(; x=2, y=3)) === Backend("backend"; x=2, y=3) |
23 | 33 | @test isnothing(show(Algorithm(""))) |
24 | 34 | end |
0 commit comments