Skip to content

Commit dc4028f

Browse files
committed
Update the tests.
1 parent 67d7923 commit dc4028f

File tree

1 file changed

+30
-26
lines changed

1 file changed

+30
-26
lines changed

test/core.jl

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -385,45 +385,51 @@ Context() do ctx
385385

386386
@testset "array constants" begin
387387

388+
# from Julia values
388389
let
389-
typ = LLVM.Int32Type(ctx)
390390
vec = Int32[1,2,3,4]
391-
ca = ConstantArray(typ, vec)
392-
@test convert(Int32, ConstantInt(ca[1]))::Int32 == Int32(1)
393-
@test convert(Vector{Int32}, ca) == vec
391+
ca = ConstantArray(vec, ctx)
392+
@test size(vec) == size(ca)
393+
@test length(vec) == length(ca)
394+
@test ca[1] == ConstantInt(vec[1], ctx)
395+
@test collect(ca) == ConstantInt.(vec, Ref(ctx))
394396
end
395397
let
396-
typ = LLVM.FloatType(ctx)
397398
vec = Float32[1.1f0,2.2f0,3.3f0,4.4f0]
398-
ca = ConstantArray(typ, vec)
399-
@test convert(Float32, ConstantFP(ca[1]))::Float32 == 1.1f0
400-
@test convert(Vector{Float32}, ca) == vec
399+
ca = ConstantArray(vec, ctx)
400+
@test size(vec) == size(ca)
401+
@test length(vec) == length(ca)
402+
@test ca[1] == ConstantFP(vec[1], ctx)
403+
@test collect(ca) == ConstantFP.(vec, Ref(ctx))
401404
end
405+
406+
# multidimensional
402407
let
403-
typ = LLVM.Int64Type(ctx)
404-
vec = fill(5, 3, 4, 5, 6)
405-
ca = ConstantArray(typ, vec)
406-
@test length(ca) == size(vec, 1)
407-
@test llvmtype(ca) == LLVM.ArrayType(LLVM.ArrayType(LLVM.ArrayType(LLVM.ArrayType(LLVM.Int64Type(ctx), 6), 5), 4), 3)
408-
# NOTE: can't test content of the array because the API does not support reading from multidimensional arrays
408+
vec = rand(Int, 2,3,4)
409+
ca = ConstantArray(vec, ctx)
410+
@test size(vec) == size(ca)
411+
@test length(vec) == length(ca)
412+
@test collect(ca) == ConstantInt.(vec, Ref(ctx))
409413
end
410414

411415
end
412416

413417
@testset "struct constants" begin
414-
418+
419+
# from Julia values
415420
let
416421
test_struct = TestStruct(true, -99, 1.5)
417-
constant_struct = ConstantStruct(test_struct, ctx)
422+
constant_struct = ConstantStruct(test_struct, ctx; anonymous=true)
418423
constant_struct_type = llvmtype(constant_struct)
419-
420-
@test typeof(constant_struct_type) == LLVM.StructType
421-
@test context(constant_struct_type) == ctx
424+
425+
@test constant_struct_type isa LLVM.StructType
426+
@test context(constant_struct) == ctx
422427
@test !ispacked(constant_struct_type)
423428
@test !isopaque(constant_struct_type)
424429

425-
@test collect(elements(constant_struct_type)) == [LLVM.Int1Type(ctx), LLVM.Int64Type(ctx), LLVM.HalfType(ctx)]
426-
430+
@test collect(elements(constant_struct_type)) ==
431+
[LLVM.Int1Type(ctx), LLVM.Int64Type(ctx), LLVM.HalfType(ctx)]
432+
427433
expected_operands = [
428434
ConstantInt(LLVM.Int1Type(ctx), Int(true)),
429435
ConstantInt(LLVM.Int64Type(ctx), -99),
@@ -432,13 +438,11 @@ Context() do ctx
432438
@test collect(operands(constant_struct)) == expected_operands
433439
end
434440
let
435-
named_struct_type = LLVM.StructType("named_struct", ctx)
436-
elements!(named_struct_type, [LLVM.Int1Type(ctx), LLVM.Int64Type(ctx), LLVM.HalfType(ctx)], true)
437-
438441
test_struct = TestStruct(false, 52, -2.5)
439-
constant_struct = ConstantStruct(test_struct, named_struct_type)
442+
constant_struct = ConstantStruct(test_struct, ctx; anonymous=false)
443+
constant_struct_type = llvmtype(constant_struct)
440444

441-
@test llvmtype(constant_struct) == named_struct_type
445+
@test constant_struct_type isa LLVM.StructType
442446

443447
expected_operands = [
444448
ConstantInt(LLVM.Int1Type(ctx), Int(false)),

0 commit comments

Comments
 (0)