Package evaluation of CSTParser on Julia 1.13.0-DEV.985 (9c94e7ae32*) started at 2025-08-14T11:17:53.223 ################################################################################ # Set-up # Installing PkgEval dependencies (TestEnv)... Set-up completed after 9.72s ################################################################################ # Installation # Installing CSTParser... Resolving package versions... Updating `~/.julia/environments/v1.13/Project.toml` [00ebfdb7] + CSTParser v3.4.3 Updating `~/.julia/environments/v1.13/Manifest.toml` [00ebfdb7] + CSTParser v3.4.3 [0796e94c] + Tokenize v0.5.29 Installation completed after 0.93s ################################################################################ # Precompilation # Precompiling PkgEval dependencies... Precompiling package dependencies... Precompilation completed after 20.23s ################################################################################ # Testing # Testing CSTParser Status `/tmp/jl_2sKOfF/Project.toml` [00ebfdb7] CSTParser v3.4.3 [f8b46487] TestItemRunner v1.1.0 [0796e94c] Tokenize v0.5.29 [8dfed614] Test v1.11.0 Status `/tmp/jl_2sKOfF/Manifest.toml` [00ebfdb7] CSTParser v3.4.3 [f8b46487] TestItemRunner v1.1.0 [1c621080] TestItems v1.0.0 [0796e94c] Tokenize v0.5.29 [0dad84c5] ArgTools v1.1.2 [56f22d72] Artifacts v1.11.0 [2a0f44e3] Base64 v1.11.0 [ade2ca70] Dates v1.11.0 [f43a241f] Downloads v1.7.0 [7b1f6079] FileWatching v1.11.0 [b77e0a4c] InteractiveUtils v1.11.0 [ac6e5ff7] JuliaSyntaxHighlighting v1.12.0 [b27032c2] LibCURL v0.6.4 [76f85450] LibGit2 v1.11.0 [8f399da3] Libdl v1.11.0 [56ddb016] Logging v1.11.0 [d6f4376e] Markdown v1.11.0 [ca575930] NetworkOptions v1.3.0 [44cfe95a] Pkg v1.13.0 [de0858da] Printf v1.11.0 [9a3f8284] Random v1.11.0 [ea8e919c] SHA v0.7.0 [9e88b42a] Serialization v1.11.0 [f489334b] StyledStrings v1.11.0 [fa267f1f] TOML v1.0.3 [a4e569a6] Tar v1.10.0 [8dfed614] Test v1.11.0 [cf7118a7] UUIDs v1.11.0 [4ec0a83e] Unicode v1.11.0 [e66e0078] CompilerSupportLibraries_jll v1.3.0+1 [deac9b47] LibCURL_jll v8.15.0+1 [e37daf67] LibGit2_jll v1.9.1+0 [29816b5a] LibSSH2_jll v1.11.3+1 [14a3606d] MozillaCACerts_jll v2025.7.15 [458c3c95] OpenSSL_jll v3.5.2+0 [efcefdf7] PCRE2_jll v10.45.0+0 [83775a58] Zlib_jll v1.3.1+2 [3161d3a3] Zstd_jll v1.5.7+1 [8e850ede] nghttp2_jll v1.65.0+0 [3f19e933] p7zip_jll v17.5.0+2 Testing Running tests... Mismatch between flisp and CSTParser when parsing string for outer $ i = 1:3 end ParserState: ParseState at 23 last : INTEGER (1,19-1,19 INTEGER ) (ws) current : END (1,21-1,23 KEYWORD ) (empty) next : ENDMARKER (1,24-1,23 ENDMARKER ) (empty) CSTParser Expr: 1:23 for 1:16 1:2 OP: = 1:10 call 1:2 OP: $ 3:8 outer 9:10 i 11:14 block 11:14 call 11:11 OP: : 12:12 INTEGER: 1 13:14 INTEGER: 3 17:16 block Converted CSTParser Expr: for outer $ i = begin 1:3 end end Base EXPR: for outer $ i = 1:3 end for outer parsing: Test Failed at /home/pkgeval/.julia/packages/CSTParser/0hXvH/test/parser/test_keyword_blocks.jl:154 Expression: "for outer \$ i = 1:3 end" |> test_expr Evaluated: "for outer \$ i = 1:3 end" |> Main.var"##287".test_expr Stacktrace: [1] top-level scope @ ~/.julia/packages/CSTParser/0hXvH/test/parser/test_keyword_blocks.jl:150 [2] macro expansion @ /opt/julia/share/julia/stdlib/v1.13/Test/src/Test.jl:1929 [inlined] [3] macro expansion @ ~/.julia/packages/CSTParser/0hXvH/test/parser/test_keyword_blocks.jl:154 [inlined] [4] macro expansion @ /opt/julia/share/julia/stdlib/v1.13/Test/src/Test.jl:745 [inlined] :kw: Test Failed at /home/pkgeval/.julia/packages/CSTParser/0hXvH/test/shared.jl:37 Expression: to_codeobject(x) == jl_parse(s) Evaluated: f(::typeof(a) = begin 1 end) == f(::typeof(a) = 1) Stacktrace: [1] macro expansion @ /opt/julia/share/julia/stdlib/v1.13/Test/src/Test.jl:745 [inlined] [2] test_expr(s::String, head::Symbol, n::Int64, endswithtrivia::Bool) @ Main.var"##305" ~/.julia/packages/CSTParser/0hXvH/test/shared.jl:37 Mismatch between flisp and CSTParser when parsing string a.{1} ParserState: ParseState at 5 last : INTEGER (1,4-1,4 INTEGER ) (empty) current : RBRACE (1,5-1,5 RBRACE ) (empty) next : ENDMARKER (1,6-1,5 ENDMARKER ) (empty) CSTParser Expr: 1:5 1:1 OP: . 1:1 a 2:4 quote 2:4 braces 2:2 INTEGER: 1 Converted CSTParser Expr: a.:({1}) Base EXPR: a.:({1}) No longer broken things: Test Failed at /home/pkgeval/.julia/packages/CSTParser/0hXvH/test/parser/test_parser.jl:354 Expression: "a.{1}" |> test_expr Evaluated: "a.{1}" |> Main.var"##388".test_expr Stacktrace: [1] top-level scope @ ~/.julia/packages/CSTParser/0hXvH/test/parser/test_parser.jl:533 [2] macro expansion @ /opt/julia/share/julia/stdlib/v1.13/Test/src/Test.jl:745 [inlined] Parsing files in Base: Test Failed at /home/pkgeval/.julia/packages/CSTParser/0hXvH/test/test_check_base.jl:143 Expression: cst_err == meta_err Evaluated: true == false Stacktrace: [1] top-level scope @ ~/.julia/packages/CSTParser/0hXvH/test/test_check_base.jl:143 [2] macro expansion @ /opt/julia/share/julia/stdlib/v1.13/Test/src/Test.jl:745 [inlined] ┌ Error: CSTParser.parse errored, but Meta.parse didn't. │ file = "/opt/julia/bin/../share/julia/base/binaryplatforms.jl" └ @ Main.var"##439" ~/.julia/packages/CSTParser/0hXvH/test/test_check_base.jl:149 ┌ Error: parsing difference │ file = "/opt/julia/bin/../share/julia/base/gmp.jl" └ @ Main.var"##439" ~/.julia/packages/CSTParser/0hXvH/test/test_check_base.jl:157 begin RoundToZero end RoundToZero $(Expr(:kw, :(::typeof(RoundToZero)), quote RoundToZero end)) $(Expr(:kw, :(::typeof(RoundToZero)), :RoundToZero)) divrem(x::BigInt, y::BigInt, ::typeof(RoundToZero) = begin RoundToZero end) divrem(x::BigInt, y::BigInt, ::typeof(RoundToZero) = RoundToZero) divrem(x::BigInt, y::BigInt, ::typeof(RoundToZero) = begin RoundToZero end) = begin MPZ.tdiv_qr(x, y) end divrem(x::BigInt, y::BigInt, ::typeof(RoundToZero) = RoundToZero) = begin MPZ.tdiv_qr(x, y) end begin RoundToZero end RoundToZero $(Expr(:kw, :(::typeof(RoundToZero)), quote RoundToZero end)) $(Expr(:kw, :(::typeof(RoundToZero)), :RoundToZero)) divrem(x::BigInt, y::Integer, ::typeof(RoundToZero) = begin RoundToZero end) divrem(x::BigInt, y::Integer, ::typeof(RoundToZero) = RoundToZero) divrem(x::BigInt, y::Integer, ::typeof(RoundToZero) = begin RoundToZero end) = begin MPZ.tdiv_qr(x, BigInt(y)) end divrem(x::BigInt, y::Integer, ::typeof(RoundToZero) = RoundToZero) = begin MPZ.tdiv_qr(x, BigInt(y)) end begin export BigInt import .Base: *, +, -, /, <, <<, >>, >>>, <=, ==, >, >=, ^, ~, &, |, xor, nand, nor, binomial, cmp, convert, div, divrem, factorial, cld, fld, gcd, gcdx, lcm, mod, ndigits, promote_rule, rem, show, isqrt, string, powermod, sum, prod, trailing_zeros, trailing_ones, count_ones, count_zeros, tryparse_internal, bin, oct, dec, hex, isequal, invmod, _prevpow2, _nextpow2, ndigits0zpb, widen, signed, unsafe_trunc, trunc, iszero, isone, big, flipsign, signbit, sign, isodd, iseven, digits!, hash, hash_integer, top_set_bit, ispositive, isnegative, clamp, unsafe_takestring import Core: Signed, Float16, Float32, Float64 if Clong == Int32 const ClongMax = Union{Int8, Int16, Int32} const CulongMax = Union{UInt8, UInt16, UInt32} else const ClongMax = Union{Int8, Int16, Int32, Int64} const CulongMax = Union{UInt8, UInt16, UInt32, UInt64} end const CdoubleMax = Union{Float16, Float32, Float64} if Sys.iswindows() const libgmp = "libgmp-10.dll" elseif Sys.isapple() const libgmp = "@rpath/libgmp.10.dylib" else const libgmp = "libgmp.so.10" end _version() = begin unsafe_string(unsafe_load(cglobal((:__gmp_version, libgmp), Ptr{Cchar}))) end version() = begin VersionNumber(_version()) end major_version() = begin (_version())[1] end bits_per_limb() = begin Int(unsafe_load(cglobal((:__gmp_bits_per_limb, libgmp), Cint))) end const VERSION = version() const MAJOR_VERSION = major_version() const BITS_PER_LIMB = bits_per_limb() if BITS_PER_LIMB == 32 const Limb = UInt32 const SLimbMax = Union{Int8, Int16, Int32} const ULimbMax = Union{UInt8, UInt16, UInt32} elseif BITS_PER_LIMB == 64 const Limb = UInt64 const SLimbMax = Union{Int8, Int16, Int32, Int64} const ULimbMax = Union{UInt8, UInt16, UInt32, UInt64} else error("GMP: cannot determine the type mp_limb_t (__gmp_bits_per_limb == $(BITS_PER_LIMB))") end Core.@doc " BigInt <: Signed\n\nArbitrary precision integer type.\n" mutable struct BigInt <: Signed alloc::Cint size::Cint d::Ptr{Limb} function BigInt(; nbits::Integer = 0) b = MPZ.init2!(new(), nbits) finalizer(cglobal((:__gmpz_clear, libgmp)), b) return b end end Core.@doc " BigInt(x)\n\nCreate an arbitrary precision integer. `x` may be an `Int` (or anything that can be\nconverted to an `Int`). The usual mathematical operators are defined for this type, and\nresults are promoted to a [`BigInt`](@ref).\n\nInstances can be constructed from strings via [`parse`](@ref), or using the `big`\nstring literal.\n\n# Examples\n```jldoctest\njulia> parse(BigInt, \"42\")\n42\n\njulia> big\"313\"\n313\n\njulia> BigInt(10)^19\n10000000000000000000\n```\n" BigInt(x) Core.@doc " ALLOC_OVERFLOW_FUNCTION\n\nA reference that holds a boolean, if true, indicating julia is linked with a patched GMP that\ndoes not abort on huge allocation and throws OutOfMemoryError instead.\n" const ALLOC_OVERFLOW_FUNCTION = Ref(false) function __init__() try if major_version() != MAJOR_VERSION || bits_per_limb() != BITS_PER_LIMB msg = "The dynamically loaded GMP library (v\"$(version())\" with __gmp_bits_per_limb == $(bits_per_limb()))\ndoes not correspond to the compile time version (v\"$(VERSION)\" with __gmp_bits_per_limb == $(BITS_PER_LIMB)).\nPlease rebuild Julia." if bits_per_limb() != BITS_PER_LIMB @error msg else @warn msg end end ccall((:__gmp_set_memory_functions, libgmp), Cvoid, (Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}), cglobal(:jl_gc_counted_malloc), cglobal(:jl_gc_counted_realloc_with_old_size), cglobal(:jl_gc_counted_free_with_size)) (ZERO.alloc, ZERO.size, ZERO.d) = (0, 0, C_NULL) (ONE.alloc, ONE.size, ONE.d) = (1, 1, pointer(_ONE)) catch ex Base.showerror_nostdio(ex, "WARNING: Error during initialization of module GMP") end try ccall((:__gmp_set_alloc_overflow_function, libgmp), Cvoid, (Ptr{Cvoid},), cglobal(:jl_throw_out_of_memory_error)) ALLOC_OVERFLOW_FUNCTION[] = true catch ex if typeof(ex) != ErrorException rethrow() end end end module MPZ using ..GMP: BigInt, Limb, BITS_PER_LIMB, libgmp const mpz_t = Ref{BigInt} const bitcnt_t = Culong gmpz(op::Symbol) = begin (Symbol(:__gmpz_, op), libgmp) end init!(x::BigInt) = begin ccall((:__gmpz_init, libgmp), Cvoid, (mpz_t,), x) x end init2!(x::BigInt, a) = begin ccall((:__gmpz_init2, libgmp), Cvoid, (mpz_t, bitcnt_t), x, a) x end realloc2!(x, a) = begin ccall((:__gmpz_realloc2, libgmp), Cvoid, (mpz_t, bitcnt_t), x, a) x end realloc2(a) = begin realloc2!(BigInt(), a) end sizeinbase(a::BigInt, b) = begin Int(ccall((:__gmpz_sizeinbase, libgmp), Csize_t, (mpz_t, Cint), a, b)) end for (op, nbits) = (:add => :(BITS_PER_LIMB * (1 + max(abs(a.size), abs(b.size)))), :sub => :(BITS_PER_LIMB * (1 + max(abs(a.size), abs(b.size)))), :mul => 0, :fdiv_q => 0, :tdiv_q => 0, :cdiv_q => 0, :fdiv_r => 0, :tdiv_r => 0, :cdiv_r => 0, :gcd => 0, :lcm => 0, :and => 0, :ior => 0, :xor => 0) op! = Symbol(op, :!) @eval begin ($op!)(x::BigInt, a::BigInt, b::BigInt) = begin ccall($(gmpz(op)), Cvoid, (mpz_t, mpz_t, mpz_t), x, a, b) x end ($op)(a::BigInt, b::BigInt) = begin ($op!)(BigInt(nbits = $nbits), a, b) end ($op!)(x::BigInt, b::BigInt) = begin ($op!)(x, x, b) end end end invert!(x::BigInt, a::BigInt, b::BigInt) = begin ccall((:__gmpz_invert, libgmp), Cint, (mpz_t, mpz_t, mpz_t), x, a, b) end invert!(x::BigInt, b::BigInt) = begin invert!(x, x, b) end invert(a::BigInt, b::BigInt) = begin ret = BigInt() invert!(ret, a, b) ret end for op = (:add_ui, :sub_ui, :mul_ui, :mul_2exp, :fdiv_q_2exp, :pow_ui, :bin_ui) op! = Symbol(op, :!) @eval begin ($op!)(x::BigInt, a::BigInt, b) = begin ccall($(gmpz(op)), Cvoid, (mpz_t, mpz_t, Culong), x, a, b) x end ($op)(a::BigInt, b) = begin ($op!)(BigInt(), a, b) end ($op!)(x::BigInt, b) = begin ($op!)(x, x, b) end end end ui_sub!(x::BigInt, a, b::BigInt) = begin ccall((:__gmpz_ui_sub, libgmp), Cvoid, (mpz_t, Culong, mpz_t), x, a, b) x end ui_sub(a, b::BigInt) = begin ui_sub!(BigInt(), a, b) end for op = (:scan1, :scan0) @eval ($op)(a::BigInt, b) = begin Int(signed(ccall($(gmpz(op)), Culong, (mpz_t, Culong), a, b))) end end mul_si!(x::BigInt, a::BigInt, b) = begin ccall((:__gmpz_mul_si, libgmp), Cvoid, (mpz_t, mpz_t, Clong), x, a, b) x end mul_si(a::BigInt, b) = begin mul_si!(BigInt(), a, b) end mul_si!(x::BigInt, b) = begin mul_si!(x, x, b) end for op = (:neg, :com, :sqrt, :set) op! = Symbol(op, :!) @eval begin ($op!)(x::BigInt, a::BigInt) = begin ccall($(gmpz(op)), Cvoid, (mpz_t, mpz_t), x, a) x end ($op)(a::BigInt) = begin ($op!)(BigInt(), a) end end op === :set && continue @eval ($op!)(x::BigInt) = begin ($op!)(x, x) end end for (op, T) = ((:fac_ui, Culong), (:set_ui, Culong), (:set_si, Clong), (:set_d, Cdouble)) op! = Symbol(op, :!) @eval begin ($op!)(x::BigInt, a) = begin ccall($(gmpz(op)), Cvoid, (mpz_t, $T), x, a) x end ($op)(a) = begin ($op!)(BigInt(), a) end end end popcount(a::BigInt) = begin Int(signed(ccall((:__gmpz_popcount, libgmp), Culong, (mpz_t,), a))) end mpn_popcount(d::Ptr{Limb}, s::Integer) = begin Int(ccall((:__gmpn_popcount, libgmp), Culong, (Ptr{Limb}, Csize_t), d, s)) end mpn_popcount(a::BigInt) = begin mpn_popcount(a.d, abs(a.size)) end function tdiv_qr!(x::BigInt, y::BigInt, a::BigInt, b::BigInt) ccall((:__gmpz_tdiv_qr, libgmp), Cvoid, (mpz_t, mpz_t, mpz_t, mpz_t), x, y, a, b) (x, y) end tdiv_qr(a::BigInt, b::BigInt) = begin tdiv_qr!(BigInt(), BigInt(), a, b) end powm!(x::BigInt, a::BigInt, b::BigInt, c::BigInt) = begin ccall((:__gmpz_powm, libgmp), Cvoid, (mpz_t, mpz_t, mpz_t, mpz_t), x, a, b, c) x end powm(a::BigInt, b::BigInt, c::BigInt) = begin powm!(BigInt(), a, b, c) end powm!(x::BigInt, b::BigInt, c::BigInt) = begin powm!(x, x, b, c) end function gcdext!(x::BigInt, y::BigInt, z::BigInt, a::BigInt, b::BigInt) ccall((:__gmpz_gcdext, libgmp), Cvoid, (mpz_t, mpz_t, mpz_t, mpz_t, mpz_t), x, y, z, a, b) (x, y, z) end gcdext(a::BigInt, b::BigInt) = begin gcdext!(BigInt(), BigInt(), BigInt(), a, b) end cmp(a::BigInt, b::BigInt) = begin Int(ccall((:__gmpz_cmp, libgmp), Cint, (mpz_t, mpz_t), a, b)) end cmp_si(a::BigInt, b) = begin Int(ccall((:__gmpz_cmp_si, libgmp), Cint, (mpz_t, Clong), a, b)) end cmp_ui(a::BigInt, b) = begin Int(ccall((:__gmpz_cmp_ui, libgmp), Cint, (mpz_t, Culong), a, b)) end cmp_d(a::BigInt, b) = begin Int(ccall((:__gmpz_cmp_d, libgmp), Cint, (mpz_t, Cdouble), a, b)) end mpn_cmp(a::Ptr{Limb}, b::Ptr{Limb}, c) = begin ccall((:__gmpn_cmp, libgmp), Cint, (Ptr{Limb}, Ptr{Limb}, Clong), a, b, c) end mpn_cmp(a::BigInt, b::BigInt, c) = begin mpn_cmp(a.d, b.d, c) end get_str!(x, a, b::BigInt) = begin ccall((:__gmpz_get_str, libgmp), Ptr{Cchar}, (Ptr{Cchar}, Cint, mpz_t), x, a, b) x end set_str!(x::BigInt, a, b) = begin Int(ccall((:__gmpz_set_str, libgmp), Cint, (mpz_t, Ptr{UInt8}, Cint), x, a, b)) end get_d(a::BigInt) = begin ccall((:__gmpz_get_d, libgmp), Cdouble, (mpz_t,), a) end function export!(a::AbstractVector{T}, n::BigInt; order::Integer = -1, nails::Integer = 0, endian::Integer = 0) where T <: Base.BitInteger stride(a, 1) == 1 || throw(ArgumentError("a must have stride 1")) ndigits = cld(sizeinbase(n, 2), 8 * sizeof(T) - nails) length(a) < ndigits && resize!(a, ndigits) fill!(a, zero(T)) count = Ref{Csize_t}() ccall((:__gmpz_export, libgmp), Ptr{T}, (Ptr{T}, Ref{Csize_t}, Cint, Csize_t, Cint, Csize_t, mpz_t), a, count, order, sizeof(T), endian, nails, n) @assert count[] ≤ length(a) return (a, Int(count[])) end limbs_write!(x::BigInt, a) = begin ccall((:__gmpz_limbs_write, libgmp), Ptr{Limb}, (mpz_t, Clong), x, a) end limbs_finish!(x::BigInt, a) = begin ccall((:__gmpz_limbs_finish, libgmp), Cvoid, (mpz_t, Clong), x, a) end setbit!(x, a) = begin ccall((:__gmpz_setbit, libgmp), Cvoid, (mpz_t, bitcnt_t), x, a) x end tstbit(a::BigInt, b) = begin ccall((:__gmpz_tstbit, libgmp), Cint, (mpz_t, bitcnt_t), a, b) % Bool end end const ZERO = BigInt() const ONE = BigInt() const _ONE = Limb[1] widen(::Type{Int128}) = begin BigInt end widen(::Type{UInt128}) = begin BigInt end widen(::Type{BigInt}) = begin BigInt end signed(x::BigInt) = begin x end BigInt(x::BigInt) = begin x end Signed(x::BigInt) = begin x end function tryparse_internal(::Type{BigInt}, s::AbstractString, startpos::Int, endpos::Int, base_::Integer, raise::Bool) bstr = if startpos == firstindex(s) && endpos == lastindex(s) String(s) else String(SubString(s, startpos, endpos)) end (sgn, base, i) = Base.parseint_preamble(true, Int(base_), bstr, firstindex(bstr), lastindex(bstr)) if !(2 <= base <= 62) raise && throw(ArgumentError("invalid base: base must be 2 ≤ base ≤ 62, got $(base)")) return nothing end if i == 0 raise && throw(ArgumentError("premature end of integer: $(repr(bstr))")) return nothing end z = BigInt() if Base.containsnul(bstr) err = -1 else err = GC.@preserve(bstr, MPZ.set_str!(z, pointer(bstr) + (i - firstindex(bstr)), base)) end if err != 0 raise && throw(ArgumentError("invalid BigInt: $(repr(bstr))")) return nothing end flipsign!(z, sgn) end BigInt(x::Union{Clong, Int32}) = begin MPZ.set_si(x) end BigInt(x::Union{Culong, UInt32}) = begin MPZ.set_ui(x) end BigInt(x::Bool) = begin BigInt(UInt(x)) end unsafe_trunc(::Type{BigInt}, x::Union{Float16, Float32, Float64}) = begin MPZ.set_d(x) end function BigInt(x::Float64) isinteger(x) || throw(InexactError(:BigInt, BigInt, x)) unsafe_trunc(BigInt, x) end BigInt(x::Float16) = begin BigInt(Float64(x)) end BigInt(x::Float32) = begin BigInt(Float64(x)) end function BigInt(x::Integer) isbits(x) && (typemin(Clong) <= x <= typemax(Clong) && return BigInt((x % Clong)::Clong)) nd = ndigits(x, base = 2) z = MPZ.realloc2(nd) ux = unsigned(if x < 0 -x else x end) size = 0 limbnbits = sizeof(Limb) << 3 while nd > 0 size += 1 unsafe_store!(z.d, ux % Limb, size) ux >>= limbnbits nd -= limbnbits end z.size = if x < 0 -size else size end z end rem(x::BigInt, ::Type{Bool}) = begin (!(iszero(x)) & unsafe_load(x.d)) % Bool end (rem(x::BigInt, ::Type{T}) where T <: Union{SLimbMax, ULimbMax}) = begin if iszero(x) zero(T) else flipsign(unsafe_load(x.d) % T, x.size) end end function rem(x::BigInt, ::Type{T}) where T <: Union{Base.BitUnsigned, Base.BitSigned} u = zero(T) for l = 1:min(abs(x.size), cld(sizeof(T), sizeof(Limb))) u += (unsafe_load(x.d, l) % T) << (sizeof(Limb) << 3 * (l - 1)) end flipsign(u, x.size) end rem(x::Integer, ::Type{BigInt}) = begin BigInt(x) end clamp(x, ::Type{BigInt}) = begin convert(BigInt, x) end isodd(x::BigInt) = begin MPZ.tstbit(x, 0) end iseven(x::BigInt) = begin !(isodd(x)) end function (::Type{T})(x::BigInt) where T <: Base.BitUnsigned if sizeof(T) < sizeof(Limb) convert(T, convert(Limb, x)) else 0 <= x.size <= cld(sizeof(T), sizeof(Limb)) || throw(InexactError(nameof(T), T, x)) x % T end end function (::Type{T})(x::BigInt) where T <: Base.BitSigned n = abs(x.size) if sizeof(T) < sizeof(Limb) SLimb = typeof(Signed(one(Limb))) convert(T, convert(SLimb, x)) else 0 <= n <= cld(sizeof(T), sizeof(Limb)) || throw(InexactError(nameof(T), T, x)) y = x % T ispositive(x) ⊻ (y > 0) && throw(InexactError(nameof(T), T, x)) y end end Float64(n::BigInt, ::RoundingMode{:ToZero}) = begin MPZ.get_d(n) end function (::Type{T})(n::BigInt, ::RoundingMode{:ToZero}) where T <: Union{Float16, Float32} T(Float64(n, RoundToZero), RoundToZero) end function (::Type{T})(n::BigInt, ::RoundingMode{:Down}) where T <: CdoubleMax x = T(n, RoundToZero) if x > n prevfloat(x) else x end end function (::Type{T})(n::BigInt, ::RoundingMode{:Up}) where T <: CdoubleMax x = T(n, RoundToZero) if x < n nextfloat(x) else x end end function Float64(x::BigInt, ::RoundingMode{:Nearest}) x == 0 && return 0.0 xsize = abs(x.size) if xsize * BITS_PER_LIMB > 1024 z = Inf64 elseif xsize == 1 z = Float64(unsafe_load(x.d)) elseif Limb == UInt32 && xsize == 2 z = Float64((unsafe_load(x.d, 2) % UInt64) << BITS_PER_LIMB + unsafe_load(x.d)) else y1 = unsafe_load(x.d, xsize) % UInt64 n = top_set_bit(y1) y = y1 >> (n - (precision(Float64) + 1)) if Limb == UInt64 y += if n > precision(Float64) 0 else unsafe_load(x.d, xsize - 1) >> (10 + n) end else y += (unsafe_load(x.d, xsize - 1) % UInt64) >> (n - 22) y += if n > precision(Float64) - 32 0 else unsafe_load(x.d, xsize - 2) >> (10 + n) end end y = (y + 1) >> 1 y &= ~(UInt64(trailing_zeros(x) == (n - 54) + (xsize - 1) * BITS_PER_LIMB)) d = ((n + 1021) % UInt64) << 52 z = reinterpret(Float64, d + y) z = ldexp(z, (xsize - 1) * BITS_PER_LIMB) end return flipsign(z, x.size) end function Float32(x::BigInt, ::RoundingMode{:Nearest}) x == 0 && return 0.0f0 xsize = abs(x.size) if xsize * BITS_PER_LIMB > 128 z = Inf32 elseif xsize == 1 z = Float32(unsafe_load(x.d)) else y1 = unsafe_load(x.d, xsize) n = BITS_PER_LIMB - leading_zeros(y1) y = y1 >> (n - (precision(Float32) + 1)) % UInt32 y += if n > precision(Float32) 0 else unsafe_load(x.d, xsize - 1) >> (BITS_PER_LIMB - -25) end % UInt32 y = (y + one(UInt32)) >> 1 y &= ~(UInt32(trailing_zeros(x) == (n - 25) + (xsize - 1) * BITS_PER_LIMB)) d = ((n + 125) % UInt32) << 23 z = reinterpret(Float32, d + y) z = ldexp(z, (xsize - 1) * BITS_PER_LIMB) end return flipsign(z, x.size) end function Float16(x::BigInt, ::RoundingMode{:Nearest}) x == 0 && return Float16(0.0) y1 = unsafe_load(x.d) n = BITS_PER_LIMB - leading_zeros(y1) if n > 16 || abs(x.size) > 1 z = Inf16 else y = y1 >> (n - (precision(Float16) + 1)) % UInt16 y = (y + one(UInt16)) >> 1 y &= ~(UInt16(trailing_zeros(x) == n - 12)) d = ((n + 13) % UInt16) << 10 z = reinterpret(Float16, d + y) end return flipsign(z, x.size) end Float64(n::BigInt) = begin Float64(n, RoundNearest) end Float32(n::BigInt) = begin Float32(n, RoundNearest) end Float16(n::BigInt) = begin Float16(n, RoundNearest) end promote_rule(::Type{BigInt}, ::Type{<:Integer}) = begin BigInt end Core.@doc " big(x)\n\nConvert a number to a maximum precision representation (typically [`BigInt`](@ref) or\n`BigFloat`). See [`BigFloat`](@ref BigFloat(::Any, rounding::RoundingMode)) for\ninformation about some pitfalls with floating-point numbers.\n" function big end big(::Type{<:Integer}) = begin BigInt end big(::Type{<:Rational}) = begin Rational{BigInt} end big(n::Integer) = begin convert(BigInt, n) end for (fJ, fC) = ((:+, :add), (:-, :sub), (:*, :mul), (:mod, :fdiv_r), (:rem, :tdiv_r), (:gcd, :gcd), (:lcm, :lcm), (:&, :and), (:|, :ior), (:xor, :xor)) @eval begin ($fJ)(x::BigInt, y::BigInt) = begin MPZ.:($fC)(x, y) end end end for (r, f) = ((RoundToZero, :tdiv_q), (RoundDown, :fdiv_q), (RoundUp, :cdiv_q)) @eval div(x::BigInt, y::BigInt, ::typeof($r)) = begin MPZ.:($f)(x, y) end end div(x::BigInt, y::BigInt) = begin div(x, y, RoundToZero) end fld(x::BigInt, y::BigInt) = begin div(x, y, RoundDown) end cld(x::BigInt, y::BigInt) = begin div(x, y, RoundUp) end x::BigInt / y::BigInt = begin float(x) / float(y) end function invmod(x::BigInt, y::BigInt) z = zero(BigInt) ya = abs(y) if ya == 1 return z end if y == 0 || MPZ.invert!(z, x, ya) == 0 throw(DomainError(y)) end if y < 0 MPZ.add!(z, y) end return z end for (fJ, fC) = ((:+, :add), (:*, :mul), (:&, :and), (:|, :ior), (:xor, :xor)) fC! = Symbol(fC, :!) @eval begin ($fJ)(a::BigInt, b::BigInt, c::BigInt) = begin MPZ.:($fC!)(MPZ.:($fC)(a, b), c) end ($fJ)(a::BigInt, b::BigInt, c::BigInt, d::BigInt) = begin MPZ.:($fC!)(MPZ.:($fC!)(MPZ.:($fC)(a, b), c), d) end ($fJ)(a::BigInt, b::BigInt, c::BigInt, d::BigInt, e::BigInt) = begin MPZ.:($fC!)(MPZ.:($fC!)(MPZ.:($fC!)(MPZ.:($fC)(a, b), c), d), e) end end end x::BigInt + c::CulongMax = begin MPZ.add_ui(x, c) end c::CulongMax + x::BigInt = begin x + c end x::BigInt - c::CulongMax = begin MPZ.sub_ui(x, c) end c::CulongMax - x::BigInt = begin MPZ.ui_sub(c, x) end x::BigInt + c::ClongMax = begin if c < 0 x - -(c % Culong) else x + convert(Culong, c) end end c::ClongMax + x::BigInt = begin if c < 0 x - -(c % Culong) else x + convert(Culong, c) end end x::BigInt - c::ClongMax = begin if c < 0 x + -(c % Culong) else x - convert(Culong, c) end end c::ClongMax - x::BigInt = begin if c < 0 -((x + -(c % Culong))) else convert(Culong, c) - x end end x::BigInt * c::CulongMax = begin MPZ.mul_ui(x, c) end c::CulongMax * x::BigInt = begin x * c end x::BigInt * c::ClongMax = begin MPZ.mul_si(x, c) end c::ClongMax * x::BigInt = begin x * c end x::BigInt / y::Union{ClongMax, CulongMax} = begin float(x) / y end x::Union{ClongMax, CulongMax} / y::BigInt = begin x / float(y) end -(x::BigInt) = begin MPZ.neg(x) end ~(x::BigInt) = begin MPZ.com(x) end x::BigInt << c::UInt = begin if c == 0 x else MPZ.mul_2exp(x, c) end end x::BigInt >> c::UInt = begin if c == 0 x else MPZ.fdiv_q_2exp(x, c) end end x::BigInt >>> c::UInt = begin x >> c end function trailing_zeros(x::BigInt) c = MPZ.scan1(x, 0) c == -1 && throw(DomainError(x, "`x` must be non-zero")) c end function trailing_ones(x::BigInt) c = MPZ.scan0(x, 0) c == -1 && throw(DomainError(x, "`x` must not be equal to -1")) c end function count_ones(x::BigInt) c = MPZ.popcount(x) c == -1 && throw(DomainError(x, "`x` cannot be negative")) c end function count_zeros(x::BigInt) c = MPZ.popcount(~x) c == -1 && throw(DomainError(x, "`x` must be negative")) c end Core.@doc " count_ones_abs(x::BigInt)\n\nNumber of ones in the binary representation of abs(x).\n" count_ones_abs(x::BigInt) = begin if iszero(x) 0 else MPZ.mpn_popcount(x) end end function top_set_bit(x::BigInt) isnegative(x) && throw(DomainError(x, "top_set_bit only supports negative arguments when they have type BitSigned.")) iszero(x) && return 0 x.size * sizeof(Limb) << 3 - leading_zeros(GC.@preserve(x, unsafe_load(x.d, x.size))) end divrem(x::BigInt, y::BigInt, ::typeof(RoundToZero) = begin RoundToZero end) = begin MPZ.tdiv_qr(x, y) end divrem(x::BigInt, y::Integer, ::typeof(RoundToZero) = begin RoundToZero end) = begin MPZ.tdiv_qr(x, BigInt(y)) end cmp(x::BigInt, y::BigInt) = begin sign(MPZ.cmp(x, y)) end cmp(x::BigInt, y::ClongMax) = begin sign(MPZ.cmp_si(x, y)) end cmp(x::BigInt, y::CulongMax) = begin sign(MPZ.cmp_ui(x, y)) end cmp(x::BigInt, y::Integer) = begin cmp(x, big(y)) end cmp(x::Integer, y::BigInt) = begin -(cmp(y, x)) end cmp(x::BigInt, y::CdoubleMax) = begin if isnan(y) -1 else sign(MPZ.cmp_d(x, y)) end end cmp(x::CdoubleMax, y::BigInt) = begin -(cmp(y, x)) end isqrt(x::BigInt) = begin MPZ.sqrt(x) end x::BigInt ^ y::Culong = begin MPZ.pow_ui(x, y) end function bigint_pow(x::BigInt, y::Integer) x == 1 && return x x == -1 && return if isodd(y) x else -x end if y < 0 throw(DomainError(y, "`y` cannot be negative.")) end @noinline throw1(y) = begin throw(OverflowError("exponent $(y) is too large and computation will overflow")) end if y > typemax(Culong) x == 0 && return x throw1(y) end return x ^ convert(Culong, y) end x::BigInt ^ y::BigInt = begin bigint_pow(x, y) end x::BigInt ^ y::Bool = begin if y x else one(x) end end x::BigInt ^ y::Integer = begin bigint_pow(x, y) end x::Integer ^ y::BigInt = begin bigint_pow(BigInt(x), y) end x::Bool ^ y::BigInt = begin Base.power_by_squaring(x, y) end function powermod(x::BigInt, p::BigInt, m::BigInt) r = MPZ.powm(x, p, m) return if m < 0 && r > 0 MPZ.add!(r, m) else r end end powermod(x::Integer, p::Integer, m::BigInt) = begin powermod(big(x), big(p), m) end function gcdx(a::BigInt, b::BigInt) (g, s, t) = MPZ.gcdext(a, b) if t == 0 if a == b return (g, t, s) elseif abs(a) == abs(b) return (g, t, -s) end end (g, s, t) end +(x::BigInt, y::BigInt, rest::BigInt...) = begin sum(tuple(x, y, rest...)) end sum(arr::Union{AbstractArray{BigInt}, Tuple{BigInt, Vararg{BigInt}}}) = begin foldl(MPZ.add!, arr; init = BigInt(0)) end function prod(arr::AbstractArray{BigInt}) nbits = BITS_PER_LIMB for x = arr iszero(x) && return zero(BigInt) xsize = abs(x.size) lz = GC.@preserve(x, leading_zeros(unsafe_load(x.d, xsize))) nbits += xsize * BITS_PER_LIMB - lz end init = BigInt(; nbits) MPZ.set_si!(init, 1) foldl(MPZ.mul!, arr; init) end factorial(n::BigInt) = begin if !(isnegative(n)) MPZ.fac_ui(n) else throw(DomainError(n, "`n` must not be negative.")) end end function binomial(n::BigInt, k::Integer) k < 0 && return BigInt(0) k <= typemax(Culong) && return binomial(n, Culong(k)) n < 0 && return if isodd(k) -(binomial((k - n) - 1, k)) else binomial((k - n) - 1, k) end κ = n - k κ < 0 && return BigInt(0) κ <= typemax(Culong) && return binomial(n, Culong(κ)) throw(OverflowError("Computation would exceed memory")) end binomial(n::BigInt, k::Culong) = begin MPZ.bin_ui(n, k) end x::BigInt == y::BigInt = begin cmp(x, y) == 0 end x::BigInt == i::Integer = begin cmp(x, i) == 0 end i::Integer == x::BigInt = begin cmp(x, i) == 0 end x::BigInt == f::CdoubleMax = begin if isnan(f) false else cmp(x, f) == 0 end end f::CdoubleMax == x::BigInt = begin if isnan(f) false else cmp(x, f) == 0 end end iszero(x::BigInt) = begin x.size == 0 end isone(x::BigInt) = begin x == Culong(1) end x::BigInt <= y::BigInt = begin cmp(x, y) <= 0 end x::BigInt <= i::Integer = begin cmp(x, i) <= 0 end i::Integer <= x::BigInt = begin cmp(x, i) >= 0 end x::BigInt <= f::CdoubleMax = begin if isnan(f) false else cmp(x, f) <= 0 end end f::CdoubleMax <= x::BigInt = begin if isnan(f) false else cmp(x, f) >= 0 end end x::BigInt < y::BigInt = begin cmp(x, y) < 0 end x::BigInt < i::Integer = begin cmp(x, i) < 0 end i::Integer < x::BigInt = begin cmp(x, i) > 0 end x::BigInt < f::CdoubleMax = begin if isnan(f) false else cmp(x, f) < 0 end end f::CdoubleMax < x::BigInt = begin if isnan(f) false else cmp(x, f) > 0 end end isnegative(x::BigInt) = begin x.size < 0 end ispositive(x::BigInt) = begin x.size > 0 end signbit(x::BigInt) = begin isnegative(x) end flipsign!(x::BigInt, y::Integer) = begin signbit(y) && (x.size = -(x.size)) x end flipsign(x::BigInt, y::Integer) = begin if signbit(y) -x else x end end flipsign(x::BigInt, y::BigInt) = begin if signbit(y) -x else x end end function sign(x::BigInt) isnegative(x) && return -(one(x)) ispositive(x) && return one(x) return x end show(io::IO, x::BigInt) = begin print(io, string(x)) end function string(n::BigInt; base::Integer = 10, pad::Integer = 1) base < 0 && return Base._base(Int(base), n, pad, (base > 0) & (n.size < 0)) 2 <= base <= 62 || throw(ArgumentError("base must be 2 ≤ base ≤ 62, got $(base)")) iszero(n) && (pad < 1 && return "") nd1 = ndigits(n, base = base) nd = max(nd1, pad) sv = Base.StringMemory(nd + isnegative(n)) GC.@preserve sv MPZ.get_str!((pointer(sv) + nd) - nd1, base, n) @inbounds for i = (1:nd - nd1) .+ isnegative(n) sv[i] = '0' % UInt8 end isnegative(n) && (sv[1] = '-' % UInt8) unsafe_takestring(sv) end function digits!(a::AbstractVector{T}, n::BigInt; base::Integer = 10) where T <: Integer if base ≥ 2 if base ≤ 62 s = codeunits(string(n; base)) (i, j) = (firstindex(a) - 1, length(s) + 1) lasti = min(lastindex(a), ((firstindex(a) + length(s)) - 1) - isnegative(n)) while i < lasti x = s[j -= 1] a[i += 1] = if base ≤ 36 if x > 0x39 x - 0x57 else x - 0x30 end else if x > 0x39 if x > 0x60 x - 0x3d else x - 0x37 end else x - 0x30 end end end lasti = lastindex(a) while i < lasti a[i += 1] = zero(T) end return if isnegative(n) map!(-, a, a) else a end elseif a isa StridedVector{<:Base.BitInteger} && (stride(a, 1) == 1 && (ispow2(base) && base - 1 ≤ typemax(T))) origlen = length(a) (_, writelen) = MPZ.export!(a, n; nails = 8 * sizeof(T) - trailing_zeros(base)) length(a) != origlen && resize!(a, origlen) a[var"begin" + writelen:var"end"] .= zero(T) return if isnegative(n) map!(-, a, a) else a end end end return invoke(digits!, Tuple{typeof(a), Integer}, a, n; base) end function ndigits0zpb(x::BigInt, b::Integer) b < 2 && throw(DomainError(b, "`b` cannot be less than 2.")) x.size == 0 && return 0 if ispow2(b) && 2 <= b <= 62 MPZ.sizeinbase(x, b) else n = MPZ.sizeinbase(x, 2) lb = log2(b) (q, r) = divrem(n, lb) iq = Int(q) maxerr = q * eps(lb) if r - 1.0 < maxerr if abs(x) >= big(b) ^ iq iq + 1 else iq end elseif lb - r < maxerr if abs(x) >= big(b) ^ (iq + 1) iq + 2 else iq + 1 end else iq + 1 end end end _prevpow2(x::BigInt) = begin if -2 <= x <= 2 x else flipsign!(ONE << (ndigits(x, base = 2) - 1), x) end end _nextpow2(x::BigInt) = begin if count_ones_abs(x) <= 1 x else flipsign!(ONE << ndigits(x, base = 2), x) end end Base.checked_abs(x::BigInt) = begin abs(x) end Base.checked_neg(x::BigInt) = begin -x end Base.checked_add(a::BigInt, b::BigInt) = begin a + b end Base.checked_sub(a::BigInt, b::BigInt) = begin a - b end Base.checked_mul(a::BigInt, b::BigInt) = begin a * b end Base.checked_div(a::BigInt, b::BigInt) = begin div(a, b) end Base.checked_rem(a::BigInt, b::BigInt) = begin rem(a, b) end Base.checked_fld(a::BigInt, b::BigInt) = begin fld(a, b) end Base.checked_mod(a::BigInt, b::BigInt) = begin mod(a, b) end Base.checked_cld(a::BigInt, b::BigInt) = begin cld(a, b) end Base.add_with_overflow(a::BigInt, b::BigInt) = begin (a + b, false) end Base.sub_with_overflow(a::BigInt, b::BigInt) = begin (a - b, false) end Base.mul_with_overflow(a::BigInt, b::BigInt) = begin (a * b, false) end Base.checked_pow(x::BigInt, p::Integer) = begin x ^ p end Base.checked_pow(x::Integer, p::BigInt) = begin x ^ p end Base.checked_pow(x::BigInt, p::BigInt) = begin x ^ p end Base.deepcopy_internal(x::BigInt, stackdict::IdDict) = begin get!((()->begin MPZ.set(x) end), stackdict, x)::BigInt end Base._hash_shl!(x::BigInt, n) = begin MPZ.mul_2exp!(x, n) end if Limb === UInt64 === UInt using .Base: HASH_SECRET, hash_bytes, hash_finalizer function hash_integer(n::BigInt, h::UInt) iszero(n) && return hash_integer(0, h) GC.@preserve n begin s = n.size h ⊻= s < 0 us = abs(s) leading_zero_bytes = div(leading_zeros(unsafe_load(n.d, us)), 8) hash_bytes(Ptr{UInt8}(n.d), 8us - leading_zero_bytes, h, HASH_SECRET) end end function hash(x::BigInt, h::UInt) GC.@preserve x begin sz = x.size sz == 0 && return hash(0, h) ptr = Ptr{UInt64}(x.d) if sz == 1 return hash(unsafe_load(ptr), h) elseif sz == -1 limb = unsafe_load(ptr) limb <= typemin(Int) % UInt && return hash(-(limb % Int), h) end pow = trailing_zeros(x) nd = Base.ndigits0z(x, 2) idx = pow >>> 6 + 1 shift = (pow & 63) % UInt upshift = BITS_PER_LIMB - shift asz = abs(sz) if shift == 0 limb = unsafe_load(ptr, idx) else limb1 = unsafe_load(ptr, idx) limb2 = if idx < asz unsafe_load(ptr, idx + 1) else UInt(0) end limb = limb2 << upshift | limb1 >> shift end if nd <= 1024 && nd - pow <= 53 return hash(ldexp(flipsign(Float64(limb), sz), pow), h) end h = hash_integer(pow, h) h ⊻= sz < 0 leading_zero_bytes = div(leading_zeros(unsafe_load(x.d, asz)), 8) trailing_zero_bytes = div(pow, 8) return hash_bytes(Ptr{UInt8}(x.d) + trailing_zero_bytes, 8asz - (leading_zero_bytes + trailing_zero_bytes), h, HASH_SECRET) end end end module MPQ import .Base: unsafe_rational, __throw_rational_argerror_zero import ..GMP: BigInt, MPZ, Limb, libgmp gmpq(op::Symbol) = begin (Symbol(:__gmpq_, op), libgmp) end mutable struct _MPQ num_alloc::Cint num_size::Cint num_d::Ptr{Limb} den_alloc::Cint den_size::Cint den_d::Ptr{Limb} rat::Rational{BigInt} end const mpq_t = Ref{_MPQ} _MPQ(x::BigInt, y::BigInt) = begin _MPQ(x.alloc, x.size, x.d, y.alloc, y.size, y.d, unsafe_rational(BigInt, x, y)) end _MPQ() = begin _MPQ(BigInt(), BigInt()) end _MPQ(x::Rational{BigInt}) = begin _MPQ(x.num, x.den) end function sync_rational!(xq::_MPQ) xq.rat.num.alloc = xq.num_alloc xq.rat.num.size = xq.num_size xq.rat.num.d = xq.num_d xq.rat.den.alloc = xq.den_alloc xq.rat.den.size = xq.den_size xq.rat.den.d = xq.den_d return xq.rat end function Rational{BigInt}(num::BigInt, den::BigInt) if iszero(den) iszero(num) && __throw_rational_argerror_zero(BigInt) return set_si(flipsign(1, num), 0) end xq = _MPQ(MPZ.set(num), MPZ.set(den)) ccall((:__gmpq_canonicalize, libgmp), Cvoid, (mpq_t,), xq) return sync_rational!(xq) end function set!(z::Rational{BigInt}, x::Rational{BigInt}) zq = _MPQ(z) ccall((:__gmpq_set, libgmp), Cvoid, (mpq_t, mpq_t), zq, _MPQ(x)) return sync_rational!(zq) end function set_z!(z::Rational{BigInt}, x::BigInt) zq = _MPQ(z) ccall((:__gmpq_set_z, libgmp), Cvoid, (mpq_t, MPZ.mpz_t), zq, x) return sync_rational!(zq) end for (op, T) = ((:set, Rational{BigInt}), (:set_z, BigInt)) op! = Symbol(op, :!) @eval ($op)(a::$T) = begin ($op!)(unsafe_rational(BigInt(), BigInt()), a) end end for (op, T1, T2) = ((:set_ui, Culong, Culong), (:set_si, Clong, Culong)) op! = Symbol(op, :!) @eval begin function ($op!)(z::Rational{BigInt}, a, b) zq = _MPQ(z) ccall($(gmpq(op)), Cvoid, (mpq_t, $T1, $T2), zq, a, b) return sync_rational!(zq) end ($op)(a, b) = begin ($op!)(unsafe_rational(BigInt(), BigInt()), a, b) end end end function add!(z::Rational{BigInt}, x::Rational{BigInt}, y::Rational{BigInt}) if iszero(x.den) || iszero(y.den) if iszero(x.den) && (iszero(y.den) && isnegative(x.num) != isnegative(y.num)) throw(DivideError()) end return set!(z, if iszero(x.den) x else y end) end zq = _MPQ(z) ccall((:__gmpq_add, libgmp), Cvoid, (mpq_t, mpq_t, mpq_t), zq, _MPQ(x), _MPQ(y)) return sync_rational!(zq) end function sub!(z::Rational{BigInt}, x::Rational{BigInt}, y::Rational{BigInt}) if iszero(x.den) || iszero(y.den) if iszero(x.den) && (iszero(y.den) && isnegative(x.num) == isnegative(y.num)) throw(DivideError()) end iszero(x.den) && return set!(z, x) return set_si!(z, flipsign(-1, y.num), 0) end zq = _MPQ(z) ccall((:__gmpq_sub, libgmp), Cvoid, (mpq_t, mpq_t, mpq_t), zq, _MPQ(x), _MPQ(y)) return sync_rational!(zq) end function mul!(z::Rational{BigInt}, x::Rational{BigInt}, y::Rational{BigInt}) if iszero(x.den) || iszero(y.den) if iszero(x.num) || iszero(y.num) throw(DivideError()) end return set_si!(z, ifelse(xor(isnegative(x.num), isnegative(y.num)), -1, 1), 0) end zq = _MPQ(z) ccall((:__gmpq_mul, libgmp), Cvoid, (mpq_t, mpq_t, mpq_t), zq, _MPQ(x), _MPQ(y)) return sync_rational!(zq) end function div!(z::Rational{BigInt}, x::Rational{BigInt}, y::Rational{BigInt}) if iszero(x.den) if iszero(y.den) throw(DivideError()) end isnegative(y.num) || return set!(z, x) return set_si!(z, flipsign(-1, x.num), 0) elseif iszero(y.den) return set_si!(z, 0, 1) elseif iszero(y.num) if iszero(x.num) throw(DivideError()) end return set_si!(z, flipsign(1, x.num), 0) end zq = _MPQ(z) ccall((:__gmpq_div, libgmp), Cvoid, (mpq_t, mpq_t, mpq_t), zq, _MPQ(x), _MPQ(y)) return sync_rational!(zq) end for (fJ, fC) = ((:+, :add), (:-, :sub), (:*, :mul), (://, :div)) fC! = Symbol(fC, :!) @eval begin ($fC!)(x::Rational{BigInt}, y::Rational{BigInt}) = begin ($fC!)(x, x, y) end Base.:($fJ)(x::Rational{BigInt}, y::Rational{BigInt}) = begin ($fC!)(unsafe_rational(BigInt(), BigInt()), x, y) end end end function Base.cmp(x::Rational{BigInt}, y::Rational{BigInt}) Int(ccall((:__gmpq_cmp, libgmp), Cint, (mpq_t, mpq_t), _MPQ(x), _MPQ(y))) end end end begin export BigInt import .Base: *, +, -, /, <, <<, >>, >>>, <=, ==, >, >=, ^, ~, &, |, xor, nand, nor, binomial, cmp, convert, div, divrem, factorial, cld, fld, gcd, gcdx, lcm, mod, ndigits, promote_rule, rem, show, isqrt, string, powermod, sum, prod, trailing_zeros, trailing_ones, count_ones, count_zeros, tryparse_internal, bin, oct, dec, hex, isequal, invmod, _prevpow2, _nextpow2, ndigits0zpb, widen, signed, unsafe_trunc, trunc, iszero, isone, big, flipsign, signbit, sign, isodd, iseven, digits!, hash, hash_integer, top_set_bit, ispositive, isnegative, clamp, unsafe_takestring import Core: Signed, Float16, Float32, Float64 if Clong == Int32 const ClongMax = Union{Int8, Int16, Int32} const CulongMax = Union{UInt8, UInt16, UInt32} else const ClongMax = Union{Int8, Int16, Int32, Int64} const CulongMax = Union{UInt8, UInt16, UInt32, UInt64} end const CdoubleMax = Union{Float16, Float32, Float64} if Sys.iswindows() const libgmp = "libgmp-10.dll" elseif Sys.isapple() const libgmp = "@rpath/libgmp.10.dylib" else const libgmp = "libgmp.so.10" end _version() = begin unsafe_string(unsafe_load(cglobal((:__gmp_version, libgmp), Ptr{Cchar}))) end version() = begin VersionNumber(_version()) end major_version() = begin (_version())[1] end bits_per_limb() = begin Int(unsafe_load(cglobal((:__gmp_bits_per_limb, libgmp), Cint))) end const VERSION = version() const MAJOR_VERSION = major_version() const BITS_PER_LIMB = bits_per_limb() if BITS_PER_LIMB == 32 const Limb = UInt32 const SLimbMax = Union{Int8, Int16, Int32} const ULimbMax = Union{UInt8, UInt16, UInt32} elseif BITS_PER_LIMB == 64 const Limb = UInt64 const SLimbMax = Union{Int8, Int16, Int32, Int64} const ULimbMax = Union{UInt8, UInt16, UInt32, UInt64} else error("GMP: cannot determine the type mp_limb_t (__gmp_bits_per_limb == $(BITS_PER_LIMB))") end Core.@doc " BigInt <: Signed\n\nArbitrary precision integer type.\n" mutable struct BigInt <: Signed alloc::Cint size::Cint d::Ptr{Limb} function BigInt(; nbits::Integer = 0) b = MPZ.init2!(new(), nbits) finalizer(cglobal((:__gmpz_clear, libgmp)), b) return b end end Core.@doc " BigInt(x)\n\nCreate an arbitrary precision integer. `x` may be an `Int` (or anything that can be\nconverted to an `Int`). The usual mathematical operators are defined for this type, and\nresults are promoted to a [`BigInt`](@ref).\n\nInstances can be constructed from strings via [`parse`](@ref), or using the `big`\nstring literal.\n\n# Examples\n```jldoctest\njulia> parse(BigInt, \"42\")\n42\n\njulia> big\"313\"\n313\n\njulia> BigInt(10)^19\n10000000000000000000\n```\n" BigInt(x) Core.@doc " ALLOC_OVERFLOW_FUNCTION\n\nA reference that holds a boolean, if true, indicating julia is linked with a patched GMP that\ndoes not abort on huge allocation and throws OutOfMemoryError instead.\n" const ALLOC_OVERFLOW_FUNCTION = Ref(false) function __init__() try if major_version() != MAJOR_VERSION || bits_per_limb() != BITS_PER_LIMB msg = "The dynamically loaded GMP library (v\"$(version())\" with __gmp_bits_per_limb == $(bits_per_limb()))\ndoes not correspond to the compile time version (v\"$(VERSION)\" with __gmp_bits_per_limb == $(BITS_PER_LIMB)).\nPlease rebuild Julia." if bits_per_limb() != BITS_PER_LIMB @error msg else @warn msg end end ccall((:__gmp_set_memory_functions, libgmp), Cvoid, (Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}), cglobal(:jl_gc_counted_malloc), cglobal(:jl_gc_counted_realloc_with_old_size), cglobal(:jl_gc_counted_free_with_size)) (ZERO.alloc, ZERO.size, ZERO.d) = (0, 0, C_NULL) (ONE.alloc, ONE.size, ONE.d) = (1, 1, pointer(_ONE)) catch ex Base.showerror_nostdio(ex, "WARNING: Error during initialization of module GMP") end try ccall((:__gmp_set_alloc_overflow_function, libgmp), Cvoid, (Ptr{Cvoid},), cglobal(:jl_throw_out_of_memory_error)) ALLOC_OVERFLOW_FUNCTION[] = true catch ex if typeof(ex) != ErrorException rethrow() end end end module MPZ using ..GMP: BigInt, Limb, BITS_PER_LIMB, libgmp const mpz_t = Ref{BigInt} const bitcnt_t = Culong gmpz(op::Symbol) = begin (Symbol(:__gmpz_, op), libgmp) end init!(x::BigInt) = begin ccall((:__gmpz_init, libgmp), Cvoid, (mpz_t,), x) x end init2!(x::BigInt, a) = begin ccall((:__gmpz_init2, libgmp), Cvoid, (mpz_t, bitcnt_t), x, a) x end realloc2!(x, a) = begin ccall((:__gmpz_realloc2, libgmp), Cvoid, (mpz_t, bitcnt_t), x, a) x end realloc2(a) = begin realloc2!(BigInt(), a) end sizeinbase(a::BigInt, b) = begin Int(ccall((:__gmpz_sizeinbase, libgmp), Csize_t, (mpz_t, Cint), a, b)) end for (op, nbits) = (:add => :(BITS_PER_LIMB * (1 + max(abs(a.size), abs(b.size)))), :sub => :(BITS_PER_LIMB * (1 + max(abs(a.size), abs(b.size)))), :mul => 0, :fdiv_q => 0, :tdiv_q => 0, :cdiv_q => 0, :fdiv_r => 0, :tdiv_r => 0, :cdiv_r => 0, :gcd => 0, :lcm => 0, :and => 0, :ior => 0, :xor => 0) op! = Symbol(op, :!) @eval begin ($op!)(x::BigInt, a::BigInt, b::BigInt) = begin ccall($(gmpz(op)), Cvoid, (mpz_t, mpz_t, mpz_t), x, a, b) x end ($op)(a::BigInt, b::BigInt) = begin ($op!)(BigInt(nbits = $nbits), a, b) end ($op!)(x::BigInt, b::BigInt) = begin ($op!)(x, x, b) end end end invert!(x::BigInt, a::BigInt, b::BigInt) = begin ccall((:__gmpz_invert, libgmp), Cint, (mpz_t, mpz_t, mpz_t), x, a, b) end invert!(x::BigInt, b::BigInt) = begin invert!(x, x, b) end invert(a::BigInt, b::BigInt) = begin ret = BigInt() invert!(ret, a, b) ret end for op = (:add_ui, :sub_ui, :mul_ui, :mul_2exp, :fdiv_q_2exp, :pow_ui, :bin_ui) op! = Symbol(op, :!) @eval begin ($op!)(x::BigInt, a::BigInt, b) = begin ccall($(gmpz(op)), Cvoid, (mpz_t, mpz_t, Culong), x, a, b) x end ($op)(a::BigInt, b) = begin ($op!)(BigInt(), a, b) end ($op!)(x::BigInt, b) = begin ($op!)(x, x, b) end end end ui_sub!(x::BigInt, a, b::BigInt) = begin ccall((:__gmpz_ui_sub, libgmp), Cvoid, (mpz_t, Culong, mpz_t), x, a, b) x end ui_sub(a, b::BigInt) = begin ui_sub!(BigInt(), a, b) end for op = (:scan1, :scan0) @eval ($op)(a::BigInt, b) = begin Int(signed(ccall($(gmpz(op)), Culong, (mpz_t, Culong), a, b))) end end mul_si!(x::BigInt, a::BigInt, b) = begin ccall((:__gmpz_mul_si, libgmp), Cvoid, (mpz_t, mpz_t, Clong), x, a, b) x end mul_si(a::BigInt, b) = begin mul_si!(BigInt(), a, b) end mul_si!(x::BigInt, b) = begin mul_si!(x, x, b) end for op = (:neg, :com, :sqrt, :set) op! = Symbol(op, :!) @eval begin ($op!)(x::BigInt, a::BigInt) = begin ccall($(gmpz(op)), Cvoid, (mpz_t, mpz_t), x, a) x end ($op)(a::BigInt) = begin ($op!)(BigInt(), a) end end op === :set && continue @eval ($op!)(x::BigInt) = begin ($op!)(x, x) end end for (op, T) = ((:fac_ui, Culong), (:set_ui, Culong), (:set_si, Clong), (:set_d, Cdouble)) op! = Symbol(op, :!) @eval begin ($op!)(x::BigInt, a) = begin ccall($(gmpz(op)), Cvoid, (mpz_t, $T), x, a) x end ($op)(a) = begin ($op!)(BigInt(), a) end end end popcount(a::BigInt) = begin Int(signed(ccall((:__gmpz_popcount, libgmp), Culong, (mpz_t,), a))) end mpn_popcount(d::Ptr{Limb}, s::Integer) = begin Int(ccall((:__gmpn_popcount, libgmp), Culong, (Ptr{Limb}, Csize_t), d, s)) end mpn_popcount(a::BigInt) = begin mpn_popcount(a.d, abs(a.size)) end function tdiv_qr!(x::BigInt, y::BigInt, a::BigInt, b::BigInt) ccall((:__gmpz_tdiv_qr, libgmp), Cvoid, (mpz_t, mpz_t, mpz_t, mpz_t), x, y, a, b) (x, y) end tdiv_qr(a::BigInt, b::BigInt) = begin tdiv_qr!(BigInt(), BigInt(), a, b) end powm!(x::BigInt, a::BigInt, b::BigInt, c::BigInt) = begin ccall((:__gmpz_powm, libgmp), Cvoid, (mpz_t, mpz_t, mpz_t, mpz_t), x, a, b, c) x end powm(a::BigInt, b::BigInt, c::BigInt) = begin powm!(BigInt(), a, b, c) end powm!(x::BigInt, b::BigInt, c::BigInt) = begin powm!(x, x, b, c) end function gcdext!(x::BigInt, y::BigInt, z::BigInt, a::BigInt, b::BigInt) ccall((:__gmpz_gcdext, libgmp), Cvoid, (mpz_t, mpz_t, mpz_t, mpz_t, mpz_t), x, y, z, a, b) (x, y, z) end gcdext(a::BigInt, b::BigInt) = begin gcdext!(BigInt(), BigInt(), BigInt(), a, b) end cmp(a::BigInt, b::BigInt) = begin Int(ccall((:__gmpz_cmp, libgmp), Cint, (mpz_t, mpz_t), a, b)) end cmp_si(a::BigInt, b) = begin Int(ccall((:__gmpz_cmp_si, libgmp), Cint, (mpz_t, Clong), a, b)) end cmp_ui(a::BigInt, b) = begin Int(ccall((:__gmpz_cmp_ui, libgmp), Cint, (mpz_t, Culong), a, b)) end cmp_d(a::BigInt, b) = begin Int(ccall((:__gmpz_cmp_d, libgmp), Cint, (mpz_t, Cdouble), a, b)) end mpn_cmp(a::Ptr{Limb}, b::Ptr{Limb}, c) = begin ccall((:__gmpn_cmp, libgmp), Cint, (Ptr{Limb}, Ptr{Limb}, Clong), a, b, c) end mpn_cmp(a::BigInt, b::BigInt, c) = begin mpn_cmp(a.d, b.d, c) end get_str!(x, a, b::BigInt) = begin ccall((:__gmpz_get_str, libgmp), Ptr{Cchar}, (Ptr{Cchar}, Cint, mpz_t), x, a, b) x end set_str!(x::BigInt, a, b) = begin Int(ccall((:__gmpz_set_str, libgmp), Cint, (mpz_t, Ptr{UInt8}, Cint), x, a, b)) end get_d(a::BigInt) = begin ccall((:__gmpz_get_d, libgmp), Cdouble, (mpz_t,), a) end function export!(a::AbstractVector{T}, n::BigInt; order::Integer = -1, nails::Integer = 0, endian::Integer = 0) where T <: Base.BitInteger stride(a, 1) == 1 || throw(ArgumentError("a must have stride 1")) ndigits = cld(sizeinbase(n, 2), 8 * sizeof(T) - nails) length(a) < ndigits && resize!(a, ndigits) fill!(a, zero(T)) count = Ref{Csize_t}() ccall((:__gmpz_export, libgmp), Ptr{T}, (Ptr{T}, Ref{Csize_t}, Cint, Csize_t, Cint, Csize_t, mpz_t), a, count, order, sizeof(T), endian, nails, n) @assert count[] ≤ length(a) return (a, Int(count[])) end limbs_write!(x::BigInt, a) = begin ccall((:__gmpz_limbs_write, libgmp), Ptr{Limb}, (mpz_t, Clong), x, a) end limbs_finish!(x::BigInt, a) = begin ccall((:__gmpz_limbs_finish, libgmp), Cvoid, (mpz_t, Clong), x, a) end setbit!(x, a) = begin ccall((:__gmpz_setbit, libgmp), Cvoid, (mpz_t, bitcnt_t), x, a) x end tstbit(a::BigInt, b) = begin ccall((:__gmpz_tstbit, libgmp), Cint, (mpz_t, bitcnt_t), a, b) % Bool end end const ZERO = BigInt() const ONE = BigInt() const _ONE = Limb[1] widen(::Type{Int128}) = begin BigInt end widen(::Type{UInt128}) = begin BigInt end widen(::Type{BigInt}) = begin BigInt end signed(x::BigInt) = begin x end BigInt(x::BigInt) = begin x end Signed(x::BigInt) = begin x end function tryparse_internal(::Type{BigInt}, s::AbstractString, startpos::Int, endpos::Int, base_::Integer, raise::Bool) bstr = if startpos == firstindex(s) && endpos == lastindex(s) String(s) else String(SubString(s, startpos, endpos)) end (sgn, base, i) = Base.parseint_preamble(true, Int(base_), bstr, firstindex(bstr), lastindex(bstr)) if !(2 <= base <= 62) raise && throw(ArgumentError("invalid base: base must be 2 ≤ base ≤ 62, got $(base)")) return nothing end if i == 0 raise && throw(ArgumentError("premature end of integer: $(repr(bstr))")) return nothing end z = BigInt() if Base.containsnul(bstr) err = -1 else err = GC.@preserve(bstr, MPZ.set_str!(z, pointer(bstr) + (i - firstindex(bstr)), base)) end if err != 0 raise && throw(ArgumentError("invalid BigInt: $(repr(bstr))")) return nothing end flipsign!(z, sgn) end BigInt(x::Union{Clong, Int32}) = begin MPZ.set_si(x) end BigInt(x::Union{Culong, UInt32}) = begin MPZ.set_ui(x) end BigInt(x::Bool) = begin BigInt(UInt(x)) end unsafe_trunc(::Type{BigInt}, x::Union{Float16, Float32, Float64}) = begin MPZ.set_d(x) end function BigInt(x::Float64) isinteger(x) || throw(InexactError(:BigInt, BigInt, x)) unsafe_trunc(BigInt, x) end BigInt(x::Float16) = begin BigInt(Float64(x)) end BigInt(x::Float32) = begin BigInt(Float64(x)) end function BigInt(x::Integer) isbits(x) && (typemin(Clong) <= x <= typemax(Clong) && return BigInt((x % Clong)::Clong)) nd = ndigits(x, base = 2) z = MPZ.realloc2(nd) ux = unsigned(if x < 0 -x else x end) size = 0 limbnbits = sizeof(Limb) << 3 while nd > 0 size += 1 unsafe_store!(z.d, ux % Limb, size) ux >>= limbnbits nd -= limbnbits end z.size = if x < 0 -size else size end z end rem(x::BigInt, ::Type{Bool}) = begin (!(iszero(x)) & unsafe_load(x.d)) % Bool end (rem(x::BigInt, ::Type{T}) where T <: Union{SLimbMax, ULimbMax}) = begin if iszero(x) zero(T) else flipsign(unsafe_load(x.d) % T, x.size) end end function rem(x::BigInt, ::Type{T}) where T <: Union{Base.BitUnsigned, Base.BitSigned} u = zero(T) for l = 1:min(abs(x.size), cld(sizeof(T), sizeof(Limb))) u += (unsafe_load(x.d, l) % T) << (sizeof(Limb) << 3 * (l - 1)) end flipsign(u, x.size) end rem(x::Integer, ::Type{BigInt}) = begin BigInt(x) end clamp(x, ::Type{BigInt}) = begin convert(BigInt, x) end isodd(x::BigInt) = begin MPZ.tstbit(x, 0) end iseven(x::BigInt) = begin !(isodd(x)) end function (::Type{T})(x::BigInt) where T <: Base.BitUnsigned if sizeof(T) < sizeof(Limb) convert(T, convert(Limb, x)) else 0 <= x.size <= cld(sizeof(T), sizeof(Limb)) || throw(InexactError(nameof(T), T, x)) x % T end end function (::Type{T})(x::BigInt) where T <: Base.BitSigned n = abs(x.size) if sizeof(T) < sizeof(Limb) SLimb = typeof(Signed(one(Limb))) convert(T, convert(SLimb, x)) else 0 <= n <= cld(sizeof(T), sizeof(Limb)) || throw(InexactError(nameof(T), T, x)) y = x % T ispositive(x) ⊻ (y > 0) && throw(InexactError(nameof(T), T, x)) y end end Float64(n::BigInt, ::RoundingMode{:ToZero}) = begin MPZ.get_d(n) end function (::Type{T})(n::BigInt, ::RoundingMode{:ToZero}) where T <: Union{Float16, Float32} T(Float64(n, RoundToZero), RoundToZero) end function (::Type{T})(n::BigInt, ::RoundingMode{:Down}) where T <: CdoubleMax x = T(n, RoundToZero) if x > n prevfloat(x) else x end end function (::Type{T})(n::BigInt, ::RoundingMode{:Up}) where T <: CdoubleMax x = T(n, RoundToZero) if x < n nextfloat(x) else x end end function Float64(x::BigInt, ::RoundingMode{:Nearest}) x == 0 && return 0.0 xsize = abs(x.size) if xsize * BITS_PER_LIMB > 1024 z = Inf64 elseif xsize == 1 z = Float64(unsafe_load(x.d)) elseif Limb == UInt32 && xsize == 2 z = Float64((unsafe_load(x.d, 2) % UInt64) << BITS_PER_LIMB + unsafe_load(x.d)) else y1 = unsafe_load(x.d, xsize) % UInt64 n = top_set_bit(y1) y = y1 >> (n - (precision(Float64) + 1)) if Limb == UInt64 y += if n > precision(Float64) 0 else unsafe_load(x.d, xsize - 1) >> (10 + n) end else y += (unsafe_load(x.d, xsize - 1) % UInt64) >> (n - 22) y += if n > precision(Float64) - 32 0 else unsafe_load(x.d, xsize - 2) >> (10 + n) end end y = (y + 1) >> 1 y &= ~(UInt64(trailing_zeros(x) == (n - 54) + (xsize - 1) * BITS_PER_LIMB)) d = ((n + 1021) % UInt64) << 52 z = reinterpret(Float64, d + y) z = ldexp(z, (xsize - 1) * BITS_PER_LIMB) end return flipsign(z, x.size) end function Float32(x::BigInt, ::RoundingMode{:Nearest}) x == 0 && return 0.0f0 xsize = abs(x.size) if xsize * BITS_PER_LIMB > 128 z = Inf32 elseif xsize == 1 z = Float32(unsafe_load(x.d)) else y1 = unsafe_load(x.d, xsize) n = BITS_PER_LIMB - leading_zeros(y1) y = y1 >> (n - (precision(Float32) + 1)) % UInt32 y += if n > precision(Float32) 0 else unsafe_load(x.d, xsize - 1) >> (BITS_PER_LIMB - -25) end % UInt32 y = (y + one(UInt32)) >> 1 y &= ~(UInt32(trailing_zeros(x) == (n - 25) + (xsize - 1) * BITS_PER_LIMB)) d = ((n + 125) % UInt32) << 23 z = reinterpret(Float32, d + y) z = ldexp(z, (xsize - 1) * BITS_PER_LIMB) end return flipsign(z, x.size) end function Float16(x::BigInt, ::RoundingMode{:Nearest}) x == 0 && return Float16(0.0) y1 = unsafe_load(x.d) n = BITS_PER_LIMB - leading_zeros(y1) if n > 16 || abs(x.size) > 1 z = Inf16 else y = y1 >> (n - (precision(Float16) + 1)) % UInt16 y = (y + one(UInt16)) >> 1 y &= ~(UInt16(trailing_zeros(x) == n - 12)) d = ((n + 13) % UInt16) << 10 z = reinterpret(Float16, d + y) end return flipsign(z, x.size) end Float64(n::BigInt) = begin Float64(n, RoundNearest) end Float32(n::BigInt) = begin Float32(n, RoundNearest) end Float16(n::BigInt) = begin Float16(n, RoundNearest) end promote_rule(::Type{BigInt}, ::Type{<:Integer}) = begin BigInt end Core.@doc " big(x)\n\nConvert a number to a maximum precision representation (typically [`BigInt`](@ref) or\n`BigFloat`). See [`BigFloat`](@ref BigFloat(::Any, rounding::RoundingMode)) for\ninformation about some pitfalls with floating-point numbers.\n" function big end big(::Type{<:Integer}) = begin BigInt end big(::Type{<:Rational}) = begin Rational{BigInt} end big(n::Integer) = begin convert(BigInt, n) end for (fJ, fC) = ((:+, :add), (:-, :sub), (:*, :mul), (:mod, :fdiv_r), (:rem, :tdiv_r), (:gcd, :gcd), (:lcm, :lcm), (:&, :and), (:|, :ior), (:xor, :xor)) @eval begin ($fJ)(x::BigInt, y::BigInt) = begin MPZ.:($fC)(x, y) end end end for (r, f) = ((RoundToZero, :tdiv_q), (RoundDown, :fdiv_q), (RoundUp, :cdiv_q)) @eval div(x::BigInt, y::BigInt, ::typeof($r)) = begin MPZ.:($f)(x, y) end end div(x::BigInt, y::BigInt) = begin div(x, y, RoundToZero) end fld(x::BigInt, y::BigInt) = begin div(x, y, RoundDown) end cld(x::BigInt, y::BigInt) = begin div(x, y, RoundUp) end x::BigInt / y::BigInt = begin float(x) / float(y) end function invmod(x::BigInt, y::BigInt) z = zero(BigInt) ya = abs(y) if ya == 1 return z end if y == 0 || MPZ.invert!(z, x, ya) == 0 throw(DomainError(y)) end if y < 0 MPZ.add!(z, y) end return z end for (fJ, fC) = ((:+, :add), (:*, :mul), (:&, :and), (:|, :ior), (:xor, :xor)) fC! = Symbol(fC, :!) @eval begin ($fJ)(a::BigInt, b::BigInt, c::BigInt) = begin MPZ.:($fC!)(MPZ.:($fC)(a, b), c) end ($fJ)(a::BigInt, b::BigInt, c::BigInt, d::BigInt) = begin MPZ.:($fC!)(MPZ.:($fC!)(MPZ.:($fC)(a, b), c), d) end ($fJ)(a::BigInt, b::BigInt, c::BigInt, d::BigInt, e::BigInt) = begin MPZ.:($fC!)(MPZ.:($fC!)(MPZ.:($fC!)(MPZ.:($fC)(a, b), c), d), e) end end end x::BigInt + c::CulongMax = begin MPZ.add_ui(x, c) end c::CulongMax + x::BigInt = begin x + c end x::BigInt - c::CulongMax = begin MPZ.sub_ui(x, c) end c::CulongMax - x::BigInt = begin MPZ.ui_sub(c, x) end x::BigInt + c::ClongMax = begin if c < 0 x - -(c % Culong) else x + convert(Culong, c) end end c::ClongMax + x::BigInt = begin if c < 0 x - -(c % Culong) else x + convert(Culong, c) end end x::BigInt - c::ClongMax = begin if c < 0 x + -(c % Culong) else x - convert(Culong, c) end end c::ClongMax - x::BigInt = begin if c < 0 -((x + -(c % Culong))) else convert(Culong, c) - x end end x::BigInt * c::CulongMax = begin MPZ.mul_ui(x, c) end c::CulongMax * x::BigInt = begin x * c end x::BigInt * c::ClongMax = begin MPZ.mul_si(x, c) end c::ClongMax * x::BigInt = begin x * c end x::BigInt / y::Union{ClongMax, CulongMax} = begin float(x) / y end x::Union{ClongMax, CulongMax} / y::BigInt = begin x / float(y) end -(x::BigInt) = begin MPZ.neg(x) end ~(x::BigInt) = begin MPZ.com(x) end x::BigInt << c::UInt = begin if c == 0 x else MPZ.mul_2exp(x, c) end end x::BigInt >> c::UInt = begin if c == 0 x else MPZ.fdiv_q_2exp(x, c) end end x::BigInt >>> c::UInt = begin x >> c end function trailing_zeros(x::BigInt) c = MPZ.scan1(x, 0) c == -1 && throw(DomainError(x, "`x` must be non-zero")) c end function trailing_ones(x::BigInt) c = MPZ.scan0(x, 0) c == -1 && throw(DomainError(x, "`x` must not be equal to -1")) c end function count_ones(x::BigInt) c = MPZ.popcount(x) c == -1 && throw(DomainError(x, "`x` cannot be negative")) c end function count_zeros(x::BigInt) c = MPZ.popcount(~x) c == -1 && throw(DomainError(x, "`x` must be negative")) c end Core.@doc " count_ones_abs(x::BigInt)\n\nNumber of ones in the binary representation of abs(x).\n" count_ones_abs(x::BigInt) = begin if iszero(x) 0 else MPZ.mpn_popcount(x) end end function top_set_bit(x::BigInt) isnegative(x) && throw(DomainError(x, "top_set_bit only supports negative arguments when they have type BitSigned.")) iszero(x) && return 0 x.size * sizeof(Limb) << 3 - leading_zeros(GC.@preserve(x, unsafe_load(x.d, x.size))) end divrem(x::BigInt, y::BigInt, ::typeof(RoundToZero) = RoundToZero) = begin MPZ.tdiv_qr(x, y) end divrem(x::BigInt, y::Integer, ::typeof(RoundToZero) = RoundToZero) = begin MPZ.tdiv_qr(x, BigInt(y)) end cmp(x::BigInt, y::BigInt) = begin sign(MPZ.cmp(x, y)) end cmp(x::BigInt, y::ClongMax) = begin sign(MPZ.cmp_si(x, y)) end cmp(x::BigInt, y::CulongMax) = begin sign(MPZ.cmp_ui(x, y)) end cmp(x::BigInt, y::Integer) = begin cmp(x, big(y)) end cmp(x::Integer, y::BigInt) = begin -(cmp(y, x)) end cmp(x::BigInt, y::CdoubleMax) = begin if isnan(y) -1 else sign(MPZ.cmp_d(x, y)) end end cmp(x::CdoubleMax, y::BigInt) = begin -(cmp(y, x)) end isqrt(x::BigInt) = begin MPZ.sqrt(x) end x::BigInt ^ y::Culong = begin MPZ.pow_ui(x, y) end function bigint_pow(x::BigInt, y::Integer) x == 1 && return x x == -1 && return if isodd(y) x else -x end if y < 0 throw(DomainError(y, "`y` cannot be negative.")) end @noinline throw1(y) = begin throw(OverflowError("exponent $(y) is too large and computation will overflow")) end if y > typemax(Culong) x == 0 && return x throw1(y) end return x ^ convert(Culong, y) end x::BigInt ^ y::BigInt = begin bigint_pow(x, y) end x::BigInt ^ y::Bool = begin if y x else one(x) end end x::BigInt ^ y::Integer = begin bigint_pow(x, y) end x::Integer ^ y::BigInt = begin bigint_pow(BigInt(x), y) end x::Bool ^ y::BigInt = begin Base.power_by_squaring(x, y) end function powermod(x::BigInt, p::BigInt, m::BigInt) r = MPZ.powm(x, p, m) return if m < 0 && r > 0 MPZ.add!(r, m) else r end end powermod(x::Integer, p::Integer, m::BigInt) = begin powermod(big(x), big(p), m) end function gcdx(a::BigInt, b::BigInt) (g, s, t) = MPZ.gcdext(a, b) if t == 0 if a == b return (g, t, s) elseif abs(a) == abs(b) return (g, t, -s) end end (g, s, t) end +(x::BigInt, y::BigInt, rest::BigInt...) = begin sum(tuple(x, y, rest...)) end sum(arr::Union{AbstractArray{BigInt}, Tuple{BigInt, Vararg{BigInt}}}) = begin foldl(MPZ.add!, arr; init = BigInt(0)) end function prod(arr::AbstractArray{BigInt}) nbits = BITS_PER_LIMB for x = arr iszero(x) && return zero(BigInt) xsize = abs(x.size) lz = GC.@preserve(x, leading_zeros(unsafe_load(x.d, xsize))) nbits += xsize * BITS_PER_LIMB - lz end init = BigInt(; nbits) MPZ.set_si!(init, 1) foldl(MPZ.mul!, arr; init) end factorial(n::BigInt) = begin if !(isnegative(n)) MPZ.fac_ui(n) else throw(DomainError(n, "`n` must not be negative.")) end end function binomial(n::BigInt, k::Integer) k < 0 && return BigInt(0) k <= typemax(Culong) && return binomial(n, Culong(k)) n < 0 && return if isodd(k) -(binomial((k - n) - 1, k)) else binomial((k - n) - 1, k) end κ = n - k κ < 0 && return BigInt(0) κ <= typemax(Culong) && return binomial(n, Culong(κ)) throw(OverflowError("Computation would exceed memory")) end binomial(n::BigInt, k::Culong) = begin MPZ.bin_ui(n, k) end x::BigInt == y::BigInt = begin cmp(x, y) == 0 end x::BigInt == i::Integer = begin cmp(x, i) == 0 end i::Integer == x::BigInt = begin cmp(x, i) == 0 end x::BigInt == f::CdoubleMax = begin if isnan(f) false else cmp(x, f) == 0 end end f::CdoubleMax == x::BigInt = begin if isnan(f) false else cmp(x, f) == 0 end end iszero(x::BigInt) = begin x.size == 0 end isone(x::BigInt) = begin x == Culong(1) end x::BigInt <= y::BigInt = begin cmp(x, y) <= 0 end x::BigInt <= i::Integer = begin cmp(x, i) <= 0 end i::Integer <= x::BigInt = begin cmp(x, i) >= 0 end x::BigInt <= f::CdoubleMax = begin if isnan(f) false else cmp(x, f) <= 0 end end f::CdoubleMax <= x::BigInt = begin if isnan(f) false else cmp(x, f) >= 0 end end x::BigInt < y::BigInt = begin cmp(x, y) < 0 end x::BigInt < i::Integer = begin cmp(x, i) < 0 end i::Integer < x::BigInt = begin cmp(x, i) > 0 end x::BigInt < f::CdoubleMax = begin if isnan(f) false else cmp(x, f) < 0 end end f::CdoubleMax < x::BigInt = begin if isnan(f) false else cmp(x, f) > 0 end end isnegative(x::BigInt) = begin x.size < 0 end ispositive(x::BigInt) = begin x.size > 0 end signbit(x::BigInt) = begin isnegative(x) end flipsign!(x::BigInt, y::Integer) = begin signbit(y) && (x.size = -(x.size)) x end flipsign(x::BigInt, y::Integer) = begin if signbit(y) -x else x end end flipsign(x::BigInt, y::BigInt) = begin if signbit(y) -x else x end end function sign(x::BigInt) isnegative(x) && return -(one(x)) ispositive(x) && return one(x) return x end show(io::IO, x::BigInt) = begin print(io, string(x)) end function string(n::BigInt; base::Integer = 10, pad::Integer = 1) base < 0 && return Base._base(Int(base), n, pad, (base > 0) & (n.size < 0)) 2 <= base <= 62 || throw(ArgumentError("base must be 2 ≤ base ≤ 62, got $(base)")) iszero(n) && (pad < 1 && return "") nd1 = ndigits(n, base = base) nd = max(nd1, pad) sv = Base.StringMemory(nd + isnegative(n)) GC.@preserve sv MPZ.get_str!((pointer(sv) + nd) - nd1, base, n) @inbounds for i = (1:nd - nd1) .+ isnegative(n) sv[i] = '0' % UInt8 end isnegative(n) && (sv[1] = '-' % UInt8) unsafe_takestring(sv) end function digits!(a::AbstractVector{T}, n::BigInt; base::Integer = 10) where T <: Integer if base ≥ 2 if base ≤ 62 s = codeunits(string(n; base)) (i, j) = (firstindex(a) - 1, length(s) + 1) lasti = min(lastindex(a), ((firstindex(a) + length(s)) - 1) - isnegative(n)) while i < lasti x = s[j -= 1] a[i += 1] = if base ≤ 36 if x > 0x39 x - 0x57 else x - 0x30 end else if x > 0x39 if x > 0x60 x - 0x3d else x - 0x37 end else x - 0x30 end end end lasti = lastindex(a) while i < lasti a[i += 1] = zero(T) end return if isnegative(n) map!(-, a, a) else a end elseif a isa StridedVector{<:Base.BitInteger} && (stride(a, 1) == 1 && (ispow2(base) && base - 1 ≤ typemax(T))) origlen = length(a) (_, writelen) = MPZ.export!(a, n; nails = 8 * sizeof(T) - trailing_zeros(base)) length(a) != origlen && resize!(a, origlen) a[var"begin" + writelen:var"end"] .= zero(T) return if isnegative(n) map!(-, a, a) else a end end end return invoke(digits!, Tuple{typeof(a), Integer}, a, n; base) end function ndigits0zpb(x::BigInt, b::Integer) b < 2 && throw(DomainError(b, "`b` cannot be less than 2.")) x.size == 0 && return 0 if ispow2(b) && 2 <= b <= 62 MPZ.sizeinbase(x, b) else n = MPZ.sizeinbase(x, 2) lb = log2(b) (q, r) = divrem(n, lb) iq = Int(q) maxerr = q * eps(lb) if r - 1.0 < maxerr if abs(x) >= big(b) ^ iq iq + 1 else iq end elseif lb - r < maxerr if abs(x) >= big(b) ^ (iq + 1) iq + 2 else iq + 1 end else iq + 1 end end end _prevpow2(x::BigInt) = begin if -2 <= x <= 2 x else flipsign!(ONE << (ndigits(x, base = 2) - 1), x) end end _nextpow2(x::BigInt) = begin if count_ones_abs(x) <= 1 x else flipsign!(ONE << ndigits(x, base = 2), x) end end Base.checked_abs(x::BigInt) = begin abs(x) end Base.checked_neg(x::BigInt) = begin -x end Base.checked_add(a::BigInt, b::BigInt) = begin a + b end Base.checked_sub(a::BigInt, b::BigInt) = begin a - b end Base.checked_mul(a::BigInt, b::BigInt) = begin a * b end Base.checked_div(a::BigInt, b::BigInt) = begin div(a, b) end Base.checked_rem(a::BigInt, b::BigInt) = begin rem(a, b) end Base.checked_fld(a::BigInt, b::BigInt) = begin fld(a, b) end Base.checked_mod(a::BigInt, b::BigInt) = begin mod(a, b) end Base.checked_cld(a::BigInt, b::BigInt) = begin cld(a, b) end Base.add_with_overflow(a::BigInt, b::BigInt) = begin (a + b, false) end Base.sub_with_overflow(a::BigInt, b::BigInt) = begin (a - b, false) end Base.mul_with_overflow(a::BigInt, b::BigInt) = begin (a * b, false) end Base.checked_pow(x::BigInt, p::Integer) = begin x ^ p end Base.checked_pow(x::Integer, p::BigInt) = begin x ^ p end Base.checked_pow(x::BigInt, p::BigInt) = begin x ^ p end Base.deepcopy_internal(x::BigInt, stackdict::IdDict) = begin get!((()->begin MPZ.set(x) end), stackdict, x)::BigInt end Base._hash_shl!(x::BigInt, n) = begin MPZ.mul_2exp!(x, n) end if Limb === UInt64 === UInt using .Base: HASH_SECRET, hash_bytes, hash_finalizer function hash_integer(n::BigInt, h::UInt) iszero(n) && return hash_integer(0, h) GC.@preserve n begin s = n.size h ⊻= s < 0 us = abs(s) leading_zero_bytes = div(leading_zeros(unsafe_load(n.d, us)), 8) hash_bytes(Ptr{UInt8}(n.d), 8us - leading_zero_bytes, h, HASH_SECRET) end end function hash(x::BigInt, h::UInt) GC.@preserve x begin sz = x.size sz == 0 && return hash(0, h) ptr = Ptr{UInt64}(x.d) if sz == 1 return hash(unsafe_load(ptr), h) elseif sz == -1 limb = unsafe_load(ptr) limb <= typemin(Int) % UInt && return hash(-(limb % Int), h) end pow = trailing_zeros(x) nd = Base.ndigits0z(x, 2) idx = pow >>> 6 + 1 shift = (pow & 63) % UInt upshift = BITS_PER_LIMB - shift asz = abs(sz) if shift == 0 limb = unsafe_load(ptr, idx) else limb1 = unsafe_load(ptr, idx) limb2 = if idx < asz unsafe_load(ptr, idx + 1) else UInt(0) end limb = limb2 << upshift | limb1 >> shift end if nd <= 1024 && nd - pow <= 53 return hash(ldexp(flipsign(Float64(limb), sz), pow), h) end h = hash_integer(pow, h) h ⊻= sz < 0 leading_zero_bytes = div(leading_zeros(unsafe_load(x.d, asz)), 8) trailing_zero_bytes = div(pow, 8) return hash_bytes(Ptr{UInt8}(x.d) + trailing_zero_bytes, 8asz - (leading_zero_bytes + trailing_zero_bytes), h, HASH_SECRET) end end end module MPQ import .Base: unsafe_rational, __throw_rational_argerror_zero import ..GMP: BigInt, MPZ, Limb, libgmp gmpq(op::Symbol) = begin (Symbol(:__gmpq_, op), libgmp) end mutable struct _MPQ num_alloc::Cint num_size::Cint num_d::Ptr{Limb} den_alloc::Cint den_size::Cint den_d::Ptr{Limb} rat::Rational{BigInt} end const mpq_t = Ref{_MPQ} _MPQ(x::BigInt, y::BigInt) = begin _MPQ(x.alloc, x.size, x.d, y.alloc, y.size, y.d, unsafe_rational(BigInt, x, y)) end _MPQ() = begin _MPQ(BigInt(), BigInt()) end _MPQ(x::Rational{BigInt}) = begin _MPQ(x.num, x.den) end function sync_rational!(xq::_MPQ) xq.rat.num.alloc = xq.num_alloc xq.rat.num.size = xq.num_size xq.rat.num.d = xq.num_d xq.rat.den.alloc = xq.den_alloc xq.rat.den.size = xq.den_size xq.rat.den.d = xq.den_d return xq.rat end function Rational{BigInt}(num::BigInt, den::BigInt) if iszero(den) iszero(num) && __throw_rational_argerror_zero(BigInt) return set_si(flipsign(1, num), 0) end xq = _MPQ(MPZ.set(num), MPZ.set(den)) ccall((:__gmpq_canonicalize, libgmp), Cvoid, (mpq_t,), xq) return sync_rational!(xq) end function set!(z::Rational{BigInt}, x::Rational{BigInt}) zq = _MPQ(z) ccall((:__gmpq_set, libgmp), Cvoid, (mpq_t, mpq_t), zq, _MPQ(x)) return sync_rational!(zq) end function set_z!(z::Rational{BigInt}, x::BigInt) zq = _MPQ(z) ccall((:__gmpq_set_z, libgmp), Cvoid, (mpq_t, MPZ.mpz_t), zq, x) return sync_rational!(zq) end for (op, T) = ((:set, Rational{BigInt}), (:set_z, BigInt)) op! = Symbol(op, :!) @eval ($op)(a::$T) = begin ($op!)(unsafe_rational(BigInt(), BigInt()), a) end end for (op, T1, T2) = ((:set_ui, Culong, Culong), (:set_si, Clong, Culong)) op! = Symbol(op, :!) @eval begin function ($op!)(z::Rational{BigInt}, a, b) zq = _MPQ(z) ccall($(gmpq(op)), Cvoid, (mpq_t, $T1, $T2), zq, a, b) return sync_rational!(zq) end ($op)(a, b) = begin ($op!)(unsafe_rational(BigInt(), BigInt()), a, b) end end end function add!(z::Rational{BigInt}, x::Rational{BigInt}, y::Rational{BigInt}) if iszero(x.den) || iszero(y.den) if iszero(x.den) && (iszero(y.den) && isnegative(x.num) != isnegative(y.num)) throw(DivideError()) end return set!(z, if iszero(x.den) x else y end) end zq = _MPQ(z) ccall((:__gmpq_add, libgmp), Cvoid, (mpq_t, mpq_t, mpq_t), zq, _MPQ(x), _MPQ(y)) return sync_rational!(zq) end function sub!(z::Rational{BigInt}, x::Rational{BigInt}, y::Rational{BigInt}) if iszero(x.den) || iszero(y.den) if iszero(x.den) && (iszero(y.den) && isnegative(x.num) == isnegative(y.num)) throw(DivideError()) end iszero(x.den) && return set!(z, x) return set_si!(z, flipsign(-1, y.num), 0) end zq = _MPQ(z) ccall((:__gmpq_sub, libgmp), Cvoid, (mpq_t, mpq_t, mpq_t), zq, _MPQ(x), _MPQ(y)) return sync_rational!(zq) end function mul!(z::Rational{BigInt}, x::Rational{BigInt}, y::Rational{BigInt}) if iszero(x.den) || iszero(y.den) if iszero(x.num) || iszero(y.num) throw(DivideError()) end return set_si!(z, ifelse(xor(isnegative(x.num), isnegative(y.num)), -1, 1), 0) end zq = _MPQ(z) ccall((:__gmpq_mul, libgmp), Cvoid, (mpq_t, mpq_t, mpq_t), zq, _MPQ(x), _MPQ(y)) return sync_rational!(zq) end function div!(z::Rational{BigInt}, x::Rational{BigInt}, y::Rational{BigInt}) if iszero(x.den) if iszero(y.den) throw(DivideError()) end isnegative(y.num) || return set!(z, x) return set_si!(z, flipsign(-1, x.num), 0) elseif iszero(y.den) return set_si!(z, 0, 1) elseif iszero(y.num) if iszero(x.num) throw(DivideError()) end return set_si!(z, flipsign(1, x.num), 0) end zq = _MPQ(z) ccall((:__gmpq_div, libgmp), Cvoid, (mpq_t, mpq_t, mpq_t), zq, _MPQ(x), _MPQ(y)) return sync_rational!(zq) end for (fJ, fC) = ((:+, :add), (:-, :sub), (:*, :mul), (://, :div)) fC! = Symbol(fC, :!) @eval begin ($fC!)(x::Rational{BigInt}, y::Rational{BigInt}) = begin ($fC!)(x, x, y) end Base.:($fJ)(x::Rational{BigInt}, y::Rational{BigInt}) = begin ($fC!)(unsafe_rational(BigInt(), BigInt()), x, y) end end end function Base.cmp(x::Rational{BigInt}, y::Rational{BigInt}) Int(ccall((:__gmpq_cmp, libgmp), Cint, (mpq_t, mpq_t), _MPQ(x), _MPQ(y))) end end end module GMP export BigInt import .Base: *, +, -, /, <, <<, >>, >>>, <=, ==, >, >=, ^, ~, &, |, xor, nand, nor, binomial, cmp, convert, div, divrem, factorial, cld, fld, gcd, gcdx, lcm, mod, ndigits, promote_rule, rem, show, isqrt, string, powermod, sum, prod, trailing_zeros, trailing_ones, count_ones, count_zeros, tryparse_internal, bin, oct, dec, hex, isequal, invmod, _prevpow2, _nextpow2, ndigits0zpb, widen, signed, unsafe_trunc, trunc, iszero, isone, big, flipsign, signbit, sign, isodd, iseven, digits!, hash, hash_integer, top_set_bit, ispositive, isnegative, clamp, unsafe_takestring import Core: Signed, Float16, Float32, Float64 if Clong == Int32 const ClongMax = Union{Int8, Int16, Int32} const CulongMax = Union{UInt8, UInt16, UInt32} else const ClongMax = Union{Int8, Int16, Int32, Int64} const CulongMax = Union{UInt8, UInt16, UInt32, UInt64} end const CdoubleMax = Union{Float16, Float32, Float64} if Sys.iswindows() const libgmp = "libgmp-10.dll" elseif Sys.isapple() const libgmp = "@rpath/libgmp.10.dylib" else const libgmp = "libgmp.so.10" end _version() = begin unsafe_string(unsafe_load(cglobal((:__gmp_version, libgmp), Ptr{Cchar}))) end version() = begin VersionNumber(_version()) end major_version() = begin (_version())[1] end bits_per_limb() = begin Int(unsafe_load(cglobal((:__gmp_bits_per_limb, libgmp), Cint))) end const VERSION = version() const MAJOR_VERSION = major_version() const BITS_PER_LIMB = bits_per_limb() if BITS_PER_LIMB == 32 const Limb = UInt32 const SLimbMax = Union{Int8, Int16, Int32} const ULimbMax = Union{UInt8, UInt16, UInt32} elseif BITS_PER_LIMB == 64 const Limb = UInt64 const SLimbMax = Union{Int8, Int16, Int32, Int64} const ULimbMax = Union{UInt8, UInt16, UInt32, UInt64} else error("GMP: cannot determine the type mp_limb_t (__gmp_bits_per_limb == $(BITS_PER_LIMB))") end Core.@doc " BigInt <: Signed\n\nArbitrary precision integer type.\n" mutable struct BigInt <: Signed alloc::Cint size::Cint d::Ptr{Limb} function BigInt(; nbits::Integer = 0) b = MPZ.init2!(new(), nbits) finalizer(cglobal((:__gmpz_clear, libgmp)), b) return b end end Core.@doc " BigInt(x)\n\nCreate an arbitrary precision integer. `x` may be an `Int` (or anything that can be\nconverted to an `Int`). The usual mathematical operators are defined for this type, and\nresults are promoted to a [`BigInt`](@ref).\n\nInstances can be constructed from strings via [`parse`](@ref), or using the `big`\nstring literal.\n\n# Examples\n```jldoctest\njulia> parse(BigInt, \"42\")\n42\n\njulia> big\"313\"\n313\n\njulia> BigInt(10)^19\n10000000000000000000\n```\n" BigInt(x) Core.@doc " ALLOC_OVERFLOW_FUNCTION\n\nA reference that holds a boolean, if true, indicating julia is linked with a patched GMP that\ndoes not abort on huge allocation and throws OutOfMemoryError instead.\n" const ALLOC_OVERFLOW_FUNCTION = Ref(false) function __init__() try if major_version() != MAJOR_VERSION || bits_per_limb() != BITS_PER_LIMB msg = "The dynamically loaded GMP library (v\"$(version())\" with __gmp_bits_per_limb == $(bits_per_limb()))\ndoes not correspond to the compile time version (v\"$(VERSION)\" with __gmp_bits_per_limb == $(BITS_PER_LIMB)).\nPlease rebuild Julia." if bits_per_limb() != BITS_PER_LIMB @error msg else @warn msg end end ccall((:__gmp_set_memory_functions, libgmp), Cvoid, (Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}), cglobal(:jl_gc_counted_malloc), cglobal(:jl_gc_counted_realloc_with_old_size), cglobal(:jl_gc_counted_free_with_size)) (ZERO.alloc, ZERO.size, ZERO.d) = (0, 0, C_NULL) (ONE.alloc, ONE.size, ONE.d) = (1, 1, pointer(_ONE)) catch ex Base.showerror_nostdio(ex, "WARNING: Error during initialization of module GMP") end try ccall((:__gmp_set_alloc_overflow_function, libgmp), Cvoid, (Ptr{Cvoid},), cglobal(:jl_throw_out_of_memory_error)) ALLOC_OVERFLOW_FUNCTION[] = true catch ex if typeof(ex) != ErrorException rethrow() end end end module MPZ using ..GMP: BigInt, Limb, BITS_PER_LIMB, libgmp const mpz_t = Ref{BigInt} const bitcnt_t = Culong gmpz(op::Symbol) = begin (Symbol(:__gmpz_, op), libgmp) end init!(x::BigInt) = begin ccall((:__gmpz_init, libgmp), Cvoid, (mpz_t,), x) x end init2!(x::BigInt, a) = begin ccall((:__gmpz_init2, libgmp), Cvoid, (mpz_t, bitcnt_t), x, a) x end realloc2!(x, a) = begin ccall((:__gmpz_realloc2, libgmp), Cvoid, (mpz_t, bitcnt_t), x, a) x end realloc2(a) = begin realloc2!(BigInt(), a) end sizeinbase(a::BigInt, b) = begin Int(ccall((:__gmpz_sizeinbase, libgmp), Csize_t, (mpz_t, Cint), a, b)) end for (op, nbits) = (:add => :(BITS_PER_LIMB * (1 + max(abs(a.size), abs(b.size)))), :sub => :(BITS_PER_LIMB * (1 + max(abs(a.size), abs(b.size)))), :mul => 0, :fdiv_q => 0, :tdiv_q => 0, :cdiv_q => 0, :fdiv_r => 0, :tdiv_r => 0, :cdiv_r => 0, :gcd => 0, :lcm => 0, :and => 0, :ior => 0, :xor => 0) op! = Symbol(op, :!) @eval begin ($op!)(x::BigInt, a::BigInt, b::BigInt) = begin ccall($(gmpz(op)), Cvoid, (mpz_t, mpz_t, mpz_t), x, a, b) x end ($op)(a::BigInt, b::BigInt) = begin ($op!)(BigInt(nbits = $nbits), a, b) end ($op!)(x::BigInt, b::BigInt) = begin ($op!)(x, x, b) end end end invert!(x::BigInt, a::BigInt, b::BigInt) = begin ccall((:__gmpz_invert, libgmp), Cint, (mpz_t, mpz_t, mpz_t), x, a, b) end invert!(x::BigInt, b::BigInt) = begin invert!(x, x, b) end invert(a::BigInt, b::BigInt) = begin ret = BigInt() invert!(ret, a, b) ret end for op = (:add_ui, :sub_ui, :mul_ui, :mul_2exp, :fdiv_q_2exp, :pow_ui, :bin_ui) op! = Symbol(op, :!) @eval begin ($op!)(x::BigInt, a::BigInt, b) = begin ccall($(gmpz(op)), Cvoid, (mpz_t, mpz_t, Culong), x, a, b) x end ($op)(a::BigInt, b) = begin ($op!)(BigInt(), a, b) end ($op!)(x::BigInt, b) = begin ($op!)(x, x, b) end end end ui_sub!(x::BigInt, a, b::BigInt) = begin ccall((:__gmpz_ui_sub, libgmp), Cvoid, (mpz_t, Culong, mpz_t), x, a, b) x end ui_sub(a, b::BigInt) = begin ui_sub!(BigInt(), a, b) end for op = (:scan1, :scan0) @eval ($op)(a::BigInt, b) = begin Int(signed(ccall($(gmpz(op)), Culong, (mpz_t, Culong), a, b))) end end mul_si!(x::BigInt, a::BigInt, b) = begin ccall((:__gmpz_mul_si, libgmp), Cvoid, (mpz_t, mpz_t, Clong), x, a, b) x end mul_si(a::BigInt, b) = begin mul_si!(BigInt(), a, b) end mul_si!(x::BigInt, b) = begin mul_si!(x, x, b) end for op = (:neg, :com, :sqrt, :set) op! = Symbol(op, :!) @eval begin ($op!)(x::BigInt, a::BigInt) = begin ccall($(gmpz(op)), Cvoid, (mpz_t, mpz_t), x, a) x end ($op)(a::BigInt) = begin ($op!)(BigInt(), a) end end op === :set && continue @eval ($op!)(x::BigInt) = begin ($op!)(x, x) end end for (op, T) = ((:fac_ui, Culong), (:set_ui, Culong), (:set_si, Clong), (:set_d, Cdouble)) op! = Symbol(op, :!) @eval begin ($op!)(x::BigInt, a) = begin ccall($(gmpz(op)), Cvoid, (mpz_t, $T), x, a) x end ($op)(a) = begin ($op!)(BigInt(), a) end end end popcount(a::BigInt) = begin Int(signed(ccall((:__gmpz_popcount, libgmp), Culong, (mpz_t,), a))) end mpn_popcount(d::Ptr{Limb}, s::Integer) = begin Int(ccall((:__gmpn_popcount, libgmp), Culong, (Ptr{Limb}, Csize_t), d, s)) end mpn_popcount(a::BigInt) = begin mpn_popcount(a.d, abs(a.size)) end function tdiv_qr!(x::BigInt, y::BigInt, a::BigInt, b::BigInt) ccall((:__gmpz_tdiv_qr, libgmp), Cvoid, (mpz_t, mpz_t, mpz_t, mpz_t), x, y, a, b) (x, y) end tdiv_qr(a::BigInt, b::BigInt) = begin tdiv_qr!(BigInt(), BigInt(), a, b) end powm!(x::BigInt, a::BigInt, b::BigInt, c::BigInt) = begin ccall((:__gmpz_powm, libgmp), Cvoid, (mpz_t, mpz_t, mpz_t, mpz_t), x, a, b, c) x end powm(a::BigInt, b::BigInt, c::BigInt) = begin powm!(BigInt(), a, b, c) end powm!(x::BigInt, b::BigInt, c::BigInt) = begin powm!(x, x, b, c) end function gcdext!(x::BigInt, y::BigInt, z::BigInt, a::BigInt, b::BigInt) ccall((:__gmpz_gcdext, libgmp), Cvoid, (mpz_t, mpz_t, mpz_t, mpz_t, mpz_t), x, y, z, a, b) (x, y, z) end gcdext(a::BigInt, b::BigInt) = begin gcdext!(BigInt(), BigInt(), BigInt(), a, b) end cmp(a::BigInt, b::BigInt) = begin Int(ccall((:__gmpz_cmp, libgmp), Cint, (mpz_t, mpz_t), a, b)) end cmp_si(a::BigInt, b) = begin Int(ccall((:__gmpz_cmp_si, libgmp), Cint, (mpz_t, Clong), a, b)) end cmp_ui(a::BigInt, b) = begin Int(ccall((:__gmpz_cmp_ui, libgmp), Cint, (mpz_t, Culong), a, b)) end cmp_d(a::BigInt, b) = begin Int(ccall((:__gmpz_cmp_d, libgmp), Cint, (mpz_t, Cdouble), a, b)) end mpn_cmp(a::Ptr{Limb}, b::Ptr{Limb}, c) = begin ccall((:__gmpn_cmp, libgmp), Cint, (Ptr{Limb}, Ptr{Limb}, Clong), a, b, c) end mpn_cmp(a::BigInt, b::BigInt, c) = begin mpn_cmp(a.d, b.d, c) end get_str!(x, a, b::BigInt) = begin ccall((:__gmpz_get_str, libgmp), Ptr{Cchar}, (Ptr{Cchar}, Cint, mpz_t), x, a, b) x end set_str!(x::BigInt, a, b) = begin Int(ccall((:__gmpz_set_str, libgmp), Cint, (mpz_t, Ptr{UInt8}, Cint), x, a, b)) end get_d(a::BigInt) = begin ccall((:__gmpz_get_d, libgmp), Cdouble, (mpz_t,), a) end function export!(a::AbstractVector{T}, n::BigInt; order::Integer = -1, nails::Integer = 0, endian::Integer = 0) where T <: Base.BitInteger stride(a, 1) == 1 || throw(ArgumentError("a must have stride 1")) ndigits = cld(sizeinbase(n, 2), 8 * sizeof(T) - nails) length(a) < ndigits && resize!(a, ndigits) fill!(a, zero(T)) count = Ref{Csize_t}() ccall((:__gmpz_export, libgmp), Ptr{T}, (Ptr{T}, Ref{Csize_t}, Cint, Csize_t, Cint, Csize_t, mpz_t), a, count, order, sizeof(T), endian, nails, n) @assert count[] ≤ length(a) return (a, Int(count[])) end limbs_write!(x::BigInt, a) = begin ccall((:__gmpz_limbs_write, libgmp), Ptr{Limb}, (mpz_t, Clong), x, a) end limbs_finish!(x::BigInt, a) = begin ccall((:__gmpz_limbs_finish, libgmp), Cvoid, (mpz_t, Clong), x, a) end setbit!(x, a) = begin ccall((:__gmpz_setbit, libgmp), Cvoid, (mpz_t, bitcnt_t), x, a) x end tstbit(a::BigInt, b) = begin ccall((:__gmpz_tstbit, libgmp), Cint, (mpz_t, bitcnt_t), a, b) % Bool end end const ZERO = BigInt() const ONE = BigInt() const _ONE = Limb[1] widen(::Type{Int128}) = begin BigInt end widen(::Type{UInt128}) = begin BigInt end widen(::Type{BigInt}) = begin BigInt end signed(x::BigInt) = begin x end BigInt(x::BigInt) = begin x end Signed(x::BigInt) = begin x end function tryparse_internal(::Type{BigInt}, s::AbstractString, startpos::Int, endpos::Int, base_::Integer, raise::Bool) bstr = if startpos == firstindex(s) && endpos == lastindex(s) String(s) else String(SubString(s, startpos, endpos)) end (sgn, base, i) = Base.parseint_preamble(true, Int(base_), bstr, firstindex(bstr), lastindex(bstr)) if !(2 <= base <= 62) raise && throw(ArgumentError("invalid base: base must be 2 ≤ base ≤ 62, got $(base)")) return nothing end if i == 0 raise && throw(ArgumentError("premature end of integer: $(repr(bstr))")) return nothing end z = BigInt() if Base.containsnul(bstr) err = -1 else err = GC.@preserve(bstr, MPZ.set_str!(z, pointer(bstr) + (i - firstindex(bstr)), base)) end if err != 0 raise && throw(ArgumentError("invalid BigInt: $(repr(bstr))")) return nothing end flipsign!(z, sgn) end BigInt(x::Union{Clong, Int32}) = begin MPZ.set_si(x) end BigInt(x::Union{Culong, UInt32}) = begin MPZ.set_ui(x) end BigInt(x::Bool) = begin BigInt(UInt(x)) end unsafe_trunc(::Type{BigInt}, x::Union{Float16, Float32, Float64}) = begin MPZ.set_d(x) end function BigInt(x::Float64) isinteger(x) || throw(InexactError(:BigInt, BigInt, x)) unsafe_trunc(BigInt, x) end BigInt(x::Float16) = begin BigInt(Float64(x)) end BigInt(x::Float32) = begin BigInt(Float64(x)) end function BigInt(x::Integer) isbits(x) && (typemin(Clong) <= x <= typemax(Clong) && return BigInt((x % Clong)::Clong)) nd = ndigits(x, base = 2) z = MPZ.realloc2(nd) ux = unsigned(if x < 0 -x else x end) size = 0 limbnbits = sizeof(Limb) << 3 while nd > 0 size += 1 unsafe_store!(z.d, ux % Limb, size) ux >>= limbnbits nd -= limbnbits end z.size = if x < 0 -size else size end z end rem(x::BigInt, ::Type{Bool}) = begin (!(iszero(x)) & unsafe_load(x.d)) % Bool end (rem(x::BigInt, ::Type{T}) where T <: Union{SLimbMax, ULimbMax}) = begin if iszero(x) zero(T) else flipsign(unsafe_load(x.d) % T, x.size) end end function rem(x::BigInt, ::Type{T}) where T <: Union{Base.BitUnsigned, Base.BitSigned} u = zero(T) for l = 1:min(abs(x.size), cld(sizeof(T), sizeof(Limb))) u += (unsafe_load(x.d, l) % T) << (sizeof(Limb) << 3 * (l - 1)) end flipsign(u, x.size) end rem(x::Integer, ::Type{BigInt}) = begin BigInt(x) end clamp(x, ::Type{BigInt}) = begin convert(BigInt, x) end isodd(x::BigInt) = begin MPZ.tstbit(x, 0) end iseven(x::BigInt) = begin !(isodd(x)) end function (::Type{T})(x::BigInt) where T <: Base.BitUnsigned if sizeof(T) < sizeof(Limb) convert(T, convert(Limb, x)) else 0 <= x.size <= cld(sizeof(T), sizeof(Limb)) || throw(InexactError(nameof(T), T, x)) x % T end end function (::Type{T})(x::BigInt) where T <: Base.BitSigned n = abs(x.size) if sizeof(T) < sizeof(Limb) SLimb = typeof(Signed(one(Limb))) convert(T, convert(SLimb, x)) else 0 <= n <= cld(sizeof(T), sizeof(Limb)) || throw(InexactError(nameof(T), T, x)) y = x % T ispositive(x) ⊻ (y > 0) && throw(InexactError(nameof(T), T, x)) y end end Float64(n::BigInt, ::RoundingMode{:ToZero}) = begin MPZ.get_d(n) end function (::Type{T})(n::BigInt, ::RoundingMode{:ToZero}) where T <: Union{Float16, Float32} T(Float64(n, RoundToZero), RoundToZero) end function (::Type{T})(n::BigInt, ::RoundingMode{:Down}) where T <: CdoubleMax x = T(n, RoundToZero) if x > n prevfloat(x) else x end end function (::Type{T})(n::BigInt, ::RoundingMode{:Up}) where T <: CdoubleMax x = T(n, RoundToZero) if x < n nextfloat(x) else x end end function Float64(x::BigInt, ::RoundingMode{:Nearest}) x == 0 && return 0.0 xsize = abs(x.size) if xsize * BITS_PER_LIMB > 1024 z = Inf64 elseif xsize == 1 z = Float64(unsafe_load(x.d)) elseif Limb == UInt32 && xsize == 2 z = Float64((unsafe_load(x.d, 2) % UInt64) << BITS_PER_LIMB + unsafe_load(x.d)) else y1 = unsafe_load(x.d, xsize) % UInt64 n = top_set_bit(y1) y = y1 >> (n - (precision(Float64) + 1)) if Limb == UInt64 y += if n > precision(Float64) 0 else unsafe_load(x.d, xsize - 1) >> (10 + n) end else y += (unsafe_load(x.d, xsize - 1) % UInt64) >> (n - 22) y += if n > precision(Float64) - 32 0 else unsafe_load(x.d, xsize - 2) >> (10 + n) end end y = (y + 1) >> 1 y &= ~(UInt64(trailing_zeros(x) == (n - 54) + (xsize - 1) * BITS_PER_LIMB)) d = ((n + 1021) % UInt64) << 52 z = reinterpret(Float64, d + y) z = ldexp(z, (xsize - 1) * BITS_PER_LIMB) end return flipsign(z, x.size) end function Float32(x::BigInt, ::RoundingMode{:Nearest}) x == 0 && return 0.0f0 xsize = abs(x.size) if xsize * BITS_PER_LIMB > 128 z = Inf32 elseif xsize == 1 z = Float32(unsafe_load(x.d)) else y1 = unsafe_load(x.d, xsize) n = BITS_PER_LIMB - leading_zeros(y1) y = y1 >> (n - (precision(Float32) + 1)) % UInt32 y += if n > precision(Float32) 0 else unsafe_load(x.d, xsize - 1) >> (BITS_PER_LIMB - -25) end % UInt32 y = (y + one(UInt32)) >> 1 y &= ~(UInt32(trailing_zeros(x) == (n - 25) + (xsize - 1) * BITS_PER_LIMB)) d = ((n + 125) % UInt32) << 23 z = reinterpret(Float32, d + y) z = ldexp(z, (xsize - 1) * BITS_PER_LIMB) end return flipsign(z, x.size) end function Float16(x::BigInt, ::RoundingMode{:Nearest}) x == 0 && return Float16(0.0) y1 = unsafe_load(x.d) n = BITS_PER_LIMB - leading_zeros(y1) if n > 16 || abs(x.size) > 1 z = Inf16 else y = y1 >> (n - (precision(Float16) + 1)) % UInt16 y = (y + one(UInt16)) >> 1 y &= ~(UInt16(trailing_zeros(x) == n - 12)) d = ((n + 13) % UInt16) << 10 z = reinterpret(Float16, d + y) end return flipsign(z, x.size) end Float64(n::BigInt) = begin Float64(n, RoundNearest) end Float32(n::BigInt) = begin Float32(n, RoundNearest) end Float16(n::BigInt) = begin Float16(n, RoundNearest) end promote_rule(::Type{BigInt}, ::Type{<:Integer}) = begin BigInt end Core.@doc " big(x)\n\nConvert a number to a maximum precision representation (typically [`BigInt`](@ref) or\n`BigFloat`). See [`BigFloat`](@ref BigFloat(::Any, rounding::RoundingMode)) for\ninformation about some pitfalls with floating-point numbers.\n" function big end big(::Type{<:Integer}) = begin BigInt end big(::Type{<:Rational}) = begin Rational{BigInt} end big(n::Integer) = begin convert(BigInt, n) end for (fJ, fC) = ((:+, :add), (:-, :sub), (:*, :mul), (:mod, :fdiv_r), (:rem, :tdiv_r), (:gcd, :gcd), (:lcm, :lcm), (:&, :and), (:|, :ior), (:xor, :xor)) @eval begin ($fJ)(x::BigInt, y::BigInt) = begin MPZ.:($fC)(x, y) end end end for (r, f) = ((RoundToZero, :tdiv_q), (RoundDown, :fdiv_q), (RoundUp, :cdiv_q)) @eval div(x::BigInt, y::BigInt, ::typeof($r)) = begin MPZ.:($f)(x, y) end end div(x::BigInt, y::BigInt) = begin div(x, y, RoundToZero) end fld(x::BigInt, y::BigInt) = begin div(x, y, RoundDown) end cld(x::BigInt, y::BigInt) = begin div(x, y, RoundUp) end x::BigInt / y::BigInt = begin float(x) / float(y) end function invmod(x::BigInt, y::BigInt) z = zero(BigInt) ya = abs(y) if ya == 1 return z end if y == 0 || MPZ.invert!(z, x, ya) == 0 throw(DomainError(y)) end if y < 0 MPZ.add!(z, y) end return z end for (fJ, fC) = ((:+, :add), (:*, :mul), (:&, :and), (:|, :ior), (:xor, :xor)) fC! = Symbol(fC, :!) @eval begin ($fJ)(a::BigInt, b::BigInt, c::BigInt) = begin MPZ.:($fC!)(MPZ.:($fC)(a, b), c) end ($fJ)(a::BigInt, b::BigInt, c::BigInt, d::BigInt) = begin MPZ.:($fC!)(MPZ.:($fC!)(MPZ.:($fC)(a, b), c), d) end ($fJ)(a::BigInt, b::BigInt, c::BigInt, d::BigInt, e::BigInt) = begin MPZ.:($fC!)(MPZ.:($fC!)(MPZ.:($fC!)(MPZ.:($fC)(a, b), c), d), e) end end end x::BigInt + c::CulongMax = begin MPZ.add_ui(x, c) end c::CulongMax + x::BigInt = begin x + c end x::BigInt - c::CulongMax = begin MPZ.sub_ui(x, c) end c::CulongMax - x::BigInt = begin MPZ.ui_sub(c, x) end x::BigInt + c::ClongMax = begin if c < 0 x - -(c % Culong) else x + convert(Culong, c) end end c::ClongMax + x::BigInt = begin if c < 0 x - -(c % Culong) else x + convert(Culong, c) end end x::BigInt - c::ClongMax = begin if c < 0 x + -(c % Culong) else x - convert(Culong, c) end end c::ClongMax - x::BigInt = begin if c < 0 -((x + -(c % Culong))) else convert(Culong, c) - x end end x::BigInt * c::CulongMax = begin MPZ.mul_ui(x, c) end c::CulongMax * x::BigInt = begin x * c end x::BigInt * c::ClongMax = begin MPZ.mul_si(x, c) end c::ClongMax * x::BigInt = begin x * c end x::BigInt / y::Union{ClongMax, CulongMax} = begin float(x) / y end x::Union{ClongMax, CulongMax} / y::BigInt = begin x / float(y) end -(x::BigInt) = begin MPZ.neg(x) end ~(x::BigInt) = begin MPZ.com(x) end x::BigInt << c::UInt = begin if c == 0 x else MPZ.mul_2exp(x, c) end end x::BigInt >> c::UInt = begin if c == 0 x else MPZ.fdiv_q_2exp(x, c) end end x::BigInt >>> c::UInt = begin x >> c end function trailing_zeros(x::BigInt) c = MPZ.scan1(x, 0) c == -1 && throw(DomainError(x, "`x` must be non-zero")) c end function trailing_ones(x::BigInt) c = MPZ.scan0(x, 0) c == -1 && throw(DomainError(x, "`x` must not be equal to -1")) c end function count_ones(x::BigInt) c = MPZ.popcount(x) c == -1 && throw(DomainError(x, "`x` cannot be negative")) c end function count_zeros(x::BigInt) c = MPZ.popcount(~x) c == -1 && throw(DomainError(x, "`x` must be negative")) c end Core.@doc " count_ones_abs(x::BigInt)\n\nNumber of ones in the binary representation of abs(x).\n" count_ones_abs(x::BigInt) = begin if iszero(x) 0 else MPZ.mpn_popcount(x) end end function top_set_bit(x::BigInt) isnegative(x) && throw(DomainError(x, "top_set_bit only supports negative arguments when they have type BitSigned.")) iszero(x) && return 0 x.size * sizeof(Limb) << 3 - leading_zeros(GC.@preserve(x, unsafe_load(x.d, x.size))) end divrem(x::BigInt, y::BigInt, ::typeof(RoundToZero) = begin RoundToZero end) = begin MPZ.tdiv_qr(x, y) end divrem(x::BigInt, y::Integer, ::typeof(RoundToZero) = begin RoundToZero end) = begin MPZ.tdiv_qr(x, BigInt(y)) end cmp(x::BigInt, y::BigInt) = begin sign(MPZ.cmp(x, y)) end cmp(x::BigInt, y::ClongMax) = begin sign(MPZ.cmp_si(x, y)) end cmp(x::BigInt, y::CulongMax) = begin sign(MPZ.cmp_ui(x, y)) end cmp(x::BigInt, y::Integer) = begin cmp(x, big(y)) end cmp(x::Integer, y::BigInt) = begin -(cmp(y, x)) end cmp(x::BigInt, y::CdoubleMax) = begin if isnan(y) -1 else sign(MPZ.cmp_d(x, y)) end end cmp(x::CdoubleMax, y::BigInt) = begin -(cmp(y, x)) end isqrt(x::BigInt) = begin MPZ.sqrt(x) end x::BigInt ^ y::Culong = begin MPZ.pow_ui(x, y) end function bigint_pow(x::BigInt, y::Integer) x == 1 && return x x == -1 && return if isodd(y) x else -x end if y < 0 throw(DomainError(y, "`y` cannot be negative.")) end @noinline throw1(y) = begin throw(OverflowError("exponent $(y) is too large and computation will overflow")) end if y > typemax(Culong) x == 0 && return x throw1(y) end return x ^ convert(Culong, y) end x::BigInt ^ y::BigInt = begin bigint_pow(x, y) end x::BigInt ^ y::Bool = begin if y x else one(x) end end x::BigInt ^ y::Integer = begin bigint_pow(x, y) end x::Integer ^ y::BigInt = begin bigint_pow(BigInt(x), y) end x::Bool ^ y::BigInt = begin Base.power_by_squaring(x, y) end function powermod(x::BigInt, p::BigInt, m::BigInt) r = MPZ.powm(x, p, m) return if m < 0 && r > 0 MPZ.add!(r, m) else r end end powermod(x::Integer, p::Integer, m::BigInt) = begin powermod(big(x), big(p), m) end function gcdx(a::BigInt, b::BigInt) (g, s, t) = MPZ.gcdext(a, b) if t == 0 if a == b return (g, t, s) elseif abs(a) == abs(b) return (g, t, -s) end end (g, s, t) end +(x::BigInt, y::BigInt, rest::BigInt...) = begin sum(tuple(x, y, rest...)) end sum(arr::Union{AbstractArray{BigInt}, Tuple{BigInt, Vararg{BigInt}}}) = begin foldl(MPZ.add!, arr; init = BigInt(0)) end function prod(arr::AbstractArray{BigInt}) nbits = BITS_PER_LIMB for x = arr iszero(x) && return zero(BigInt) xsize = abs(x.size) lz = GC.@preserve(x, leading_zeros(unsafe_load(x.d, xsize))) nbits += xsize * BITS_PER_LIMB - lz end init = BigInt(; nbits) MPZ.set_si!(init, 1) foldl(MPZ.mul!, arr; init) end factorial(n::BigInt) = begin if !(isnegative(n)) MPZ.fac_ui(n) else throw(DomainError(n, "`n` must not be negative.")) end end function binomial(n::BigInt, k::Integer) k < 0 && return BigInt(0) k <= typemax(Culong) && return binomial(n, Culong(k)) n < 0 && return if isodd(k) -(binomial((k - n) - 1, k)) else binomial((k - n) - 1, k) end κ = n - k κ < 0 && return BigInt(0) κ <= typemax(Culong) && return binomial(n, Culong(κ)) throw(OverflowError("Computation would exceed memory")) end binomial(n::BigInt, k::Culong) = begin MPZ.bin_ui(n, k) end x::BigInt == y::BigInt = begin cmp(x, y) == 0 end x::BigInt == i::Integer = begin cmp(x, i) == 0 end i::Integer == x::BigInt = begin cmp(x, i) == 0 end x::BigInt == f::CdoubleMax = begin if isnan(f) false else cmp(x, f) == 0 end end f::CdoubleMax == x::BigInt = begin if isnan(f) false else cmp(x, f) == 0 end end iszero(x::BigInt) = begin x.size == 0 end isone(x::BigInt) = begin x == Culong(1) end x::BigInt <= y::BigInt = begin cmp(x, y) <= 0 end x::BigInt <= i::Integer = begin cmp(x, i) <= 0 end i::Integer <= x::BigInt = begin cmp(x, i) >= 0 end x::BigInt <= f::CdoubleMax = begin if isnan(f) false else cmp(x, f) <= 0 end end f::CdoubleMax <= x::BigInt = begin if isnan(f) false else cmp(x, f) >= 0 end end x::BigInt < y::BigInt = begin cmp(x, y) < 0 end x::BigInt < i::Integer = begin cmp(x, i) < 0 end i::Integer < x::BigInt = begin cmp(x, i) > 0 end x::BigInt < f::CdoubleMax = begin if isnan(f) false else cmp(x, f) < 0 end end f::CdoubleMax < x::BigInt = begin if isnan(f) false else cmp(x, f) > 0 end end isnegative(x::BigInt) = begin x.size < 0 end ispositive(x::BigInt) = begin x.size > 0 end signbit(x::BigInt) = begin isnegative(x) end flipsign!(x::BigInt, y::Integer) = begin signbit(y) && (x.size = -(x.size)) x end flipsign(x::BigInt, y::Integer) = begin if signbit(y) -x else x end end flipsign(x::BigInt, y::BigInt) = begin if signbit(y) -x else x end end function sign(x::BigInt) isnegative(x) && return -(one(x)) ispositive(x) && return one(x) return x end show(io::IO, x::BigInt) = begin print(io, string(x)) end function string(n::BigInt; base::Integer = 10, pad::Integer = 1) base < 0 && return Base._base(Int(base), n, pad, (base > 0) & (n.size < 0)) 2 <= base <= 62 || throw(ArgumentError("base must be 2 ≤ base ≤ 62, got $(base)")) iszero(n) && (pad < 1 && return "") nd1 = ndigits(n, base = base) nd = max(nd1, pad) sv = Base.StringMemory(nd + isnegative(n)) GC.@preserve sv MPZ.get_str!((pointer(sv) + nd) - nd1, base, n) @inbounds for i = (1:nd - nd1) .+ isnegative(n) sv[i] = '0' % UInt8 end isnegative(n) && (sv[1] = '-' % UInt8) unsafe_takestring(sv) end function digits!(a::AbstractVector{T}, n::BigInt; base::Integer = 10) where T <: Integer if base ≥ 2 if base ≤ 62 s = codeunits(string(n; base)) (i, j) = (firstindex(a) - 1, length(s) + 1) lasti = min(lastindex(a), ((firstindex(a) + length(s)) - 1) - isnegative(n)) while i < lasti x = s[j -= 1] a[i += 1] = if base ≤ 36 if x > 0x39 x - 0x57 else x - 0x30 end else if x > 0x39 if x > 0x60 x - 0x3d else x - 0x37 end else x - 0x30 end end end lasti = lastindex(a) while i < lasti a[i += 1] = zero(T) end return if isnegative(n) map!(-, a, a) else a end elseif a isa StridedVector{<:Base.BitInteger} && (stride(a, 1) == 1 && (ispow2(base) && base - 1 ≤ typemax(T))) origlen = length(a) (_, writelen) = MPZ.export!(a, n; nails = 8 * sizeof(T) - trailing_zeros(base)) length(a) != origlen && resize!(a, origlen) a[var"begin" + writelen:var"end"] .= zero(T) return if isnegative(n) map!(-, a, a) else a end end end return invoke(digits!, Tuple{typeof(a), Integer}, a, n; base) end function ndigits0zpb(x::BigInt, b::Integer) b < 2 && throw(DomainError(b, "`b` cannot be less than 2.")) x.size == 0 && return 0 if ispow2(b) && 2 <= b <= 62 MPZ.sizeinbase(x, b) else n = MPZ.sizeinbase(x, 2) lb = log2(b) (q, r) = divrem(n, lb) iq = Int(q) maxerr = q * eps(lb) if r - 1.0 < maxerr if abs(x) >= big(b) ^ iq iq + 1 else iq end elseif lb - r < maxerr if abs(x) >= big(b) ^ (iq + 1) iq + 2 else iq + 1 end else iq + 1 end end end _prevpow2(x::BigInt) = begin if -2 <= x <= 2 x else flipsign!(ONE << (ndigits(x, base = 2) - 1), x) end end _nextpow2(x::BigInt) = begin if count_ones_abs(x) <= 1 x else flipsign!(ONE << ndigits(x, base = 2), x) end end Base.checked_abs(x::BigInt) = begin abs(x) end Base.checked_neg(x::BigInt) = begin -x end Base.checked_add(a::BigInt, b::BigInt) = begin a + b end Base.checked_sub(a::BigInt, b::BigInt) = begin a - b end Base.checked_mul(a::BigInt, b::BigInt) = begin a * b end Base.checked_div(a::BigInt, b::BigInt) = begin div(a, b) end Base.checked_rem(a::BigInt, b::BigInt) = begin rem(a, b) end Base.checked_fld(a::BigInt, b::BigInt) = begin fld(a, b) end Base.checked_mod(a::BigInt, b::BigInt) = begin mod(a, b) end Base.checked_cld(a::BigInt, b::BigInt) = begin cld(a, b) end Base.add_with_overflow(a::BigInt, b::BigInt) = begin (a + b, false) end Base.sub_with_overflow(a::BigInt, b::BigInt) = begin (a - b, false) end Base.mul_with_overflow(a::BigInt, b::BigInt) = begin (a * b, false) end Base.checked_pow(x::BigInt, p::Integer) = begin x ^ p end Base.checked_pow(x::Integer, p::BigInt) = begin x ^ p end Base.checked_pow(x::BigInt, p::BigInt) = begin x ^ p end Base.deepcopy_internal(x::BigInt, stackdict::IdDict) = begin get!((()->begin MPZ.set(x) end), stackdict, x)::BigInt end Base._hash_shl!(x::BigInt, n) = begin MPZ.mul_2exp!(x, n) end if Limb === UInt64 === UInt using .Base: HASH_SECRET, hash_bytes, hash_finalizer function hash_integer(n::BigInt, h::UInt) iszero(n) && return hash_integer(0, h) GC.@preserve n begin s = n.size h ⊻= s < 0 us = abs(s) leading_zero_bytes = div(leading_zeros(unsafe_load(n.d, us)), 8) hash_bytes(Ptr{UInt8}(n.d), 8us - leading_zero_bytes, h, HASH_SECRET) end end function hash(x::BigInt, h::UInt) GC.@preserve x begin sz = x.size sz == 0 && return hash(0, h) ptr = Ptr{UInt64}(x.d) if sz == 1 return hash(unsafe_load(ptr), h) elseif sz == -1 limb = unsafe_load(ptr) limb <= typemin(Int) % UInt && return hash(-(limb % Int), h) end pow = trailing_zeros(x) nd = Base.ndigits0z(x, 2) idx = pow >>> 6 + 1 shift = (pow & 63) % UInt upshift = BITS_PER_LIMB - shift asz = abs(sz) if shift == 0 limb = unsafe_load(ptr, idx) else limb1 = unsafe_load(ptr, idx) limb2 = if idx < asz unsafe_load(ptr, idx + 1) else UInt(0) end limb = limb2 << upshift | limb1 >> shift end if nd <= 1024 && nd - pow <= 53 return hash(ldexp(flipsign(Float64(limb), sz), pow), h) end h = hash_integer(pow, h) h ⊻= sz < 0 leading_zero_bytes = div(leading_zeros(unsafe_load(x.d, asz)), 8) trailing_zero_bytes = div(pow, 8) return hash_bytes(Ptr{UInt8}(x.d) + trailing_zero_bytes, 8asz - (leading_zero_bytes + trailing_zero_bytes), h, HASH_SECRET) end end end module MPQ import .Base: unsafe_rational, __throw_rational_argerror_zero import ..GMP: BigInt, MPZ, Limb, libgmp gmpq(op::Symbol) = begin (Symbol(:__gmpq_, op), libgmp) end mutable struct _MPQ num_alloc::Cint num_size::Cint num_d::Ptr{Limb} den_alloc::Cint den_size::Cint den_d::Ptr{Limb} rat::Rational{BigInt} end const mpq_t = Ref{_MPQ} _MPQ(x::BigInt, y::BigInt) = begin _MPQ(x.alloc, x.size, x.d, y.alloc, y.size, y.d, unsafe_rational(BigInt, x, y)) end _MPQ() = begin _MPQ(BigInt(), BigInt()) end _MPQ(x::Rational{BigInt}) = begin _MPQ(x.num, x.den) end function sync_rational!(xq::_MPQ) xq.rat.num.alloc = xq.num_alloc xq.rat.num.size = xq.num_size xq.rat.num.d = xq.num_d xq.rat.den.alloc = xq.den_alloc xq.rat.den.size = xq.den_size xq.rat.den.d = xq.den_d return xq.rat end function Rational{BigInt}(num::BigInt, den::BigInt) if iszero(den) iszero(num) && __throw_rational_argerror_zero(BigInt) return set_si(flipsign(1, num), 0) end xq = _MPQ(MPZ.set(num), MPZ.set(den)) ccall((:__gmpq_canonicalize, libgmp), Cvoid, (mpq_t,), xq) return sync_rational!(xq) end function set!(z::Rational{BigInt}, x::Rational{BigInt}) zq = _MPQ(z) ccall((:__gmpq_set, libgmp), Cvoid, (mpq_t, mpq_t), zq, _MPQ(x)) return sync_rational!(zq) end function set_z!(z::Rational{BigInt}, x::BigInt) zq = _MPQ(z) ccall((:__gmpq_set_z, libgmp), Cvoid, (mpq_t, MPZ.mpz_t), zq, x) return sync_rational!(zq) end for (op, T) = ((:set, Rational{BigInt}), (:set_z, BigInt)) op! = Symbol(op, :!) @eval ($op)(a::$T) = begin ($op!)(unsafe_rational(BigInt(), BigInt()), a) end end for (op, T1, T2) = ((:set_ui, Culong, Culong), (:set_si, Clong, Culong)) op! = Symbol(op, :!) @eval begin function ($op!)(z::Rational{BigInt}, a, b) zq = _MPQ(z) ccall($(gmpq(op)), Cvoid, (mpq_t, $T1, $T2), zq, a, b) return sync_rational!(zq) end ($op)(a, b) = begin ($op!)(unsafe_rational(BigInt(), BigInt()), a, b) end end end function add!(z::Rational{BigInt}, x::Rational{BigInt}, y::Rational{BigInt}) if iszero(x.den) || iszero(y.den) if iszero(x.den) && (iszero(y.den) && isnegative(x.num) != isnegative(y.num)) throw(DivideError()) end return set!(z, if iszero(x.den) x else y end) end zq = _MPQ(z) ccall((:__gmpq_add, libgmp), Cvoid, (mpq_t, mpq_t, mpq_t), zq, _MPQ(x), _MPQ(y)) return sync_rational!(zq) end function sub!(z::Rational{BigInt}, x::Rational{BigInt}, y::Rational{BigInt}) if iszero(x.den) || iszero(y.den) if iszero(x.den) && (iszero(y.den) && isnegative(x.num) == isnegative(y.num)) throw(DivideError()) end iszero(x.den) && return set!(z, x) return set_si!(z, flipsign(-1, y.num), 0) end zq = _MPQ(z) ccall((:__gmpq_sub, libgmp), Cvoid, (mpq_t, mpq_t, mpq_t), zq, _MPQ(x), _MPQ(y)) return sync_rational!(zq) end function mul!(z::Rational{BigInt}, x::Rational{BigInt}, y::Rational{BigInt}) if iszero(x.den) || iszero(y.den) if iszero(x.num) || iszero(y.num) throw(DivideError()) end return set_si!(z, ifelse(xor(isnegative(x.num), isnegative(y.num)), -1, 1), 0) end zq = _MPQ(z) ccall((:__gmpq_mul, libgmp), Cvoid, (mpq_t, mpq_t, mpq_t), zq, _MPQ(x), _MPQ(y)) return sync_rational!(zq) end function div!(z::Rational{BigInt}, x::Rational{BigInt}, y::Rational{BigInt}) if iszero(x.den) if iszero(y.den) throw(DivideError()) end isnegative(y.num) || return set!(z, x) return set_si!(z, flipsign(-1, x.num), 0) elseif iszero(y.den) return set_si!(z, 0, 1) elseif iszero(y.num) if iszero(x.num) throw(DivideError()) end return set_si!(z, flipsign(1, x.num), 0) end zq = _MPQ(z) ccall((:__gmpq_div, libgmp), Cvoid, (mpq_t, mpq_t, mpq_t), zq, _MPQ(x), _MPQ(y)) return sync_rational!(zq) end for (fJ, fC) = ((:+, :add), (:-, :sub), (:*, :mul), (://, :div)) fC! = Symbol(fC, :!) @eval begin ($fC!)(x::Rational{BigInt}, y::Rational{BigInt}) = begin ($fC!)(x, x, y) end Base.:($fJ)(x::Rational{BigInt}, y::Rational{BigInt}) = begin ($fC!)(unsafe_rational(BigInt(), BigInt()), x, y) end end end function Base.cmp(x::Rational{BigInt}, y::Rational{BigInt}) Int(ccall((:__gmpq_cmp, libgmp), Cint, (mpq_t, mpq_t), _MPQ(x), _MPQ(y))) end end end module GMP export BigInt import .Base: *, +, -, /, <, <<, >>, >>>, <=, ==, >, >=, ^, ~, &, |, xor, nand, nor, binomial, cmp, convert, div, divrem, factorial, cld, fld, gcd, gcdx, lcm, mod, ndigits, promote_rule, rem, show, isqrt, string, powermod, sum, prod, trailing_zeros, trailing_ones, count_ones, count_zeros, tryparse_internal, bin, oct, dec, hex, isequal, invmod, _prevpow2, _nextpow2, ndigits0zpb, widen, signed, unsafe_trunc, trunc, iszero, isone, big, flipsign, signbit, sign, isodd, iseven, digits!, hash, hash_integer, top_set_bit, ispositive, isnegative, clamp, unsafe_takestring import Core: Signed, Float16, Float32, Float64 if Clong == Int32 const ClongMax = Union{Int8, Int16, Int32} const CulongMax = Union{UInt8, UInt16, UInt32} else const ClongMax = Union{Int8, Int16, Int32, Int64} const CulongMax = Union{UInt8, UInt16, UInt32, UInt64} end const CdoubleMax = Union{Float16, Float32, Float64} if Sys.iswindows() const libgmp = "libgmp-10.dll" elseif Sys.isapple() const libgmp = "@rpath/libgmp.10.dylib" else const libgmp = "libgmp.so.10" end _version() = begin unsafe_string(unsafe_load(cglobal((:__gmp_version, libgmp), Ptr{Cchar}))) end version() = begin VersionNumber(_version()) end major_version() = begin (_version())[1] end bits_per_limb() = begin Int(unsafe_load(cglobal((:__gmp_bits_per_limb, libgmp), Cint))) end const VERSION = version() const MAJOR_VERSION = major_version() const BITS_PER_LIMB = bits_per_limb() if BITS_PER_LIMB == 32 const Limb = UInt32 const SLimbMax = Union{Int8, Int16, Int32} const ULimbMax = Union{UInt8, UInt16, UInt32} elseif BITS_PER_LIMB == 64 const Limb = UInt64 const SLimbMax = Union{Int8, Int16, Int32, Int64} const ULimbMax = Union{UInt8, UInt16, UInt32, UInt64} else error("GMP: cannot determine the type mp_limb_t (__gmp_bits_per_limb == $(BITS_PER_LIMB))") end Core.@doc " BigInt <: Signed\n\nArbitrary precision integer type.\n" mutable struct BigInt <: Signed alloc::Cint size::Cint d::Ptr{Limb} function BigInt(; nbits::Integer = 0) b = MPZ.init2!(new(), nbits) finalizer(cglobal((:__gmpz_clear, libgmp)), b) return b end end Core.@doc " BigInt(x)\n\nCreate an arbitrary precision integer. `x` may be an `Int` (or anything that can be\nconverted to an `Int`). The usual mathematical operators are defined for this type, and\nresults are promoted to a [`BigInt`](@ref).\n\nInstances can be constructed from strings via [`parse`](@ref), or using the `big`\nstring literal.\n\n# Examples\n```jldoctest\njulia> parse(BigInt, \"42\")\n42\n\njulia> big\"313\"\n313\n\njulia> BigInt(10)^19\n10000000000000000000\n```\n" BigInt(x) Core.@doc " ALLOC_OVERFLOW_FUNCTION\n\nA reference that holds a boolean, if true, indicating julia is linked with a patched GMP that\ndoes not abort on huge allocation and throws OutOfMemoryError instead.\n" const ALLOC_OVERFLOW_FUNCTION = Ref(false) function __init__() try if major_version() != MAJOR_VERSION || bits_per_limb() != BITS_PER_LIMB msg = "The dynamically loaded GMP library (v\"$(version())\" with __gmp_bits_per_limb == $(bits_per_limb()))\ndoes not correspond to the compile time version (v\"$(VERSION)\" with __gmp_bits_per_limb == $(BITS_PER_LIMB)).\nPlease rebuild Julia." if bits_per_limb() != BITS_PER_LIMB @error msg else @warn msg end end ccall((:__gmp_set_memory_functions, libgmp), Cvoid, (Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}), cglobal(:jl_gc_counted_malloc), cglobal(:jl_gc_counted_realloc_with_old_size), cglobal(:jl_gc_counted_free_with_size)) (ZERO.alloc, ZERO.size, ZERO.d) = (0, 0, C_NULL) (ONE.alloc, ONE.size, ONE.d) = (1, 1, pointer(_ONE)) catch ex Base.showerror_nostdio(ex, "WARNING: Error during initialization of module GMP") end try ccall((:__gmp_set_alloc_overflow_function, libgmp), Cvoid, (Ptr{Cvoid},), cglobal(:jl_throw_out_of_memory_error)) ALLOC_OVERFLOW_FUNCTION[] = true catch ex if typeof(ex) != ErrorException rethrow() end end end module MPZ using ..GMP: BigInt, Limb, BITS_PER_LIMB, libgmp const mpz_t = Ref{BigInt} const bitcnt_t = Culong gmpz(op::Symbol) = begin (Symbol(:__gmpz_, op), libgmp) end init!(x::BigInt) = begin ccall((:__gmpz_init, libgmp), Cvoid, (mpz_t,), x) x end init2!(x::BigInt, a) = begin ccall((:__gmpz_init2, libgmp), Cvoid, (mpz_t, bitcnt_t), x, a) x end realloc2!(x, a) = begin ccall((:__gmpz_realloc2, libgmp), Cvoid, (mpz_t, bitcnt_t), x, a) x end realloc2(a) = begin realloc2!(BigInt(), a) end sizeinbase(a::BigInt, b) = begin Int(ccall((:__gmpz_sizeinbase, libgmp), Csize_t, (mpz_t, Cint), a, b)) end for (op, nbits) = (:add => :(BITS_PER_LIMB * (1 + max(abs(a.size), abs(b.size)))), :sub => :(BITS_PER_LIMB * (1 + max(abs(a.size), abs(b.size)))), :mul => 0, :fdiv_q => 0, :tdiv_q => 0, :cdiv_q => 0, :fdiv_r => 0, :tdiv_r => 0, :cdiv_r => 0, :gcd => 0, :lcm => 0, :and => 0, :ior => 0, :xor => 0) op! = Symbol(op, :!) @eval begin ($op!)(x::BigInt, a::BigInt, b::BigInt) = begin ccall($(gmpz(op)), Cvoid, (mpz_t, mpz_t, mpz_t), x, a, b) x end ($op)(a::BigInt, b::BigInt) = begin ($op!)(BigInt(nbits = $nbits), a, b) end ($op!)(x::BigInt, b::BigInt) = begin ($op!)(x, x, b) end end end invert!(x::BigInt, a::BigInt, b::BigInt) = begin ccall((:__gmpz_invert, libgmp), Cint, (mpz_t, mpz_t, mpz_t), x, a, b) end invert!(x::BigInt, b::BigInt) = begin invert!(x, x, b) end invert(a::BigInt, b::BigInt) = begin ret = BigInt() invert!(ret, a, b) ret end for op = (:add_ui, :sub_ui, :mul_ui, :mul_2exp, :fdiv_q_2exp, :pow_ui, :bin_ui) op! = Symbol(op, :!) @eval begin ($op!)(x::BigInt, a::BigInt, b) = begin ccall($(gmpz(op)), Cvoid, (mpz_t, mpz_t, Culong), x, a, b) x end ($op)(a::BigInt, b) = begin ($op!)(BigInt(), a, b) end ($op!)(x::BigInt, b) = begin ($op!)(x, x, b) end end end ui_sub!(x::BigInt, a, b::BigInt) = begin ccall((:__gmpz_ui_sub, libgmp), Cvoid, (mpz_t, Culong, mpz_t), x, a, b) x end ui_sub(a, b::BigInt) = begin ui_sub!(BigInt(), a, b) end for op = (:scan1, :scan0) @eval ($op)(a::BigInt, b) = begin Int(signed(ccall($(gmpz(op)), Culong, (mpz_t, Culong), a, b))) end end mul_si!(x::BigInt, a::BigInt, b) = begin ccall((:__gmpz_mul_si, libgmp), Cvoid, (mpz_t, mpz_t, Clong), x, a, b) x end mul_si(a::BigInt, b) = begin mul_si!(BigInt(), a, b) end mul_si!(x::BigInt, b) = begin mul_si!(x, x, b) end for op = (:neg, :com, :sqrt, :set) op! = Symbol(op, :!) @eval begin ($op!)(x::BigInt, a::BigInt) = begin ccall($(gmpz(op)), Cvoid, (mpz_t, mpz_t), x, a) x end ($op)(a::BigInt) = begin ($op!)(BigInt(), a) end end op === :set && continue @eval ($op!)(x::BigInt) = begin ($op!)(x, x) end end for (op, T) = ((:fac_ui, Culong), (:set_ui, Culong), (:set_si, Clong), (:set_d, Cdouble)) op! = Symbol(op, :!) @eval begin ($op!)(x::BigInt, a) = begin ccall($(gmpz(op)), Cvoid, (mpz_t, $T), x, a) x end ($op)(a) = begin ($op!)(BigInt(), a) end end end popcount(a::BigInt) = begin Int(signed(ccall((:__gmpz_popcount, libgmp), Culong, (mpz_t,), a))) end mpn_popcount(d::Ptr{Limb}, s::Integer) = begin Int(ccall((:__gmpn_popcount, libgmp), Culong, (Ptr{Limb}, Csize_t), d, s)) end mpn_popcount(a::BigInt) = begin mpn_popcount(a.d, abs(a.size)) end function tdiv_qr!(x::BigInt, y::BigInt, a::BigInt, b::BigInt) ccall((:__gmpz_tdiv_qr, libgmp), Cvoid, (mpz_t, mpz_t, mpz_t, mpz_t), x, y, a, b) (x, y) end tdiv_qr(a::BigInt, b::BigInt) = begin tdiv_qr!(BigInt(), BigInt(), a, b) end powm!(x::BigInt, a::BigInt, b::BigInt, c::BigInt) = begin ccall((:__gmpz_powm, libgmp), Cvoid, (mpz_t, mpz_t, mpz_t, mpz_t), x, a, b, c) x end powm(a::BigInt, b::BigInt, c::BigInt) = begin powm!(BigInt(), a, b, c) end powm!(x::BigInt, b::BigInt, c::BigInt) = begin powm!(x, x, b, c) end function gcdext!(x::BigInt, y::BigInt, z::BigInt, a::BigInt, b::BigInt) ccall((:__gmpz_gcdext, libgmp), Cvoid, (mpz_t, mpz_t, mpz_t, mpz_t, mpz_t), x, y, z, a, b) (x, y, z) end gcdext(a::BigInt, b::BigInt) = begin gcdext!(BigInt(), BigInt(), BigInt(), a, b) end cmp(a::BigInt, b::BigInt) = begin Int(ccall((:__gmpz_cmp, libgmp), Cint, (mpz_t, mpz_t), a, b)) end cmp_si(a::BigInt, b) = begin Int(ccall((:__gmpz_cmp_si, libgmp), Cint, (mpz_t, Clong), a, b)) end cmp_ui(a::BigInt, b) = begin Int(ccall((:__gmpz_cmp_ui, libgmp), Cint, (mpz_t, Culong), a, b)) end cmp_d(a::BigInt, b) = begin Int(ccall((:__gmpz_cmp_d, libgmp), Cint, (mpz_t, Cdouble), a, b)) end mpn_cmp(a::Ptr{Limb}, b::Ptr{Limb}, c) = begin ccall((:__gmpn_cmp, libgmp), Cint, (Ptr{Limb}, Ptr{Limb}, Clong), a, b, c) end mpn_cmp(a::BigInt, b::BigInt, c) = begin mpn_cmp(a.d, b.d, c) end get_str!(x, a, b::BigInt) = begin ccall((:__gmpz_get_str, libgmp), Ptr{Cchar}, (Ptr{Cchar}, Cint, mpz_t), x, a, b) x end set_str!(x::BigInt, a, b) = begin Int(ccall((:__gmpz_set_str, libgmp), Cint, (mpz_t, Ptr{UInt8}, Cint), x, a, b)) end get_d(a::BigInt) = begin ccall((:__gmpz_get_d, libgmp), Cdouble, (mpz_t,), a) end function export!(a::AbstractVector{T}, n::BigInt; order::Integer = -1, nails::Integer = 0, endian::Integer = 0) where T <: Base.BitInteger stride(a, 1) == 1 || throw(ArgumentError("a must have stride 1")) ndigits = cld(sizeinbase(n, 2), 8 * sizeof(T) - nails) length(a) < ndigits && resize!(a, ndigits) fill!(a, zero(T)) count = Ref{Csize_t}() ccall((:__gmpz_export, libgmp), Ptr{T}, (Ptr{T}, Ref{Csize_t}, Cint, Csize_t, Cint, Csize_t, mpz_t), a, count, order, sizeof(T), endian, nails, n) @assert count[] ≤ length(a) return (a, Int(count[])) end limbs_write!(x::BigInt, a) = begin ccall((:__gmpz_limbs_write, libgmp), Ptr{Limb}, (mpz_t, Clong), x, a) end limbs_finish!(x::BigInt, a) = begin ccall((:__gmpz_limbs_finish, libgmp), Cvoid, (mpz_t, Clong), x, a) end setbit!(x, a) = begin ccall((:__gmpz_setbit, libgmp), Cvoid, (mpz_t, bitcnt_t), x, a) x end tstbit(a::BigInt, b) = begin ccall((:__gmpz_tstbit, libgmp), Cint, (mpz_t, bitcnt_t), a, b) % Bool end end const ZERO = BigInt() const ONE = BigInt() const _ONE = Limb[1] widen(::Type{Int128}) = begin BigInt end widen(::Type{UInt128}) = begin BigInt end widen(::Type{BigInt}) = begin BigInt end signed(x::BigInt) = begin x end BigInt(x::BigInt) = begin x end Signed(x::BigInt) = begin x end function tryparse_internal(::Type{BigInt}, s::AbstractString, startpos::Int, endpos::Int, base_::Integer, raise::Bool) bstr = if startpos == firstindex(s) && endpos == lastindex(s) String(s) else String(SubString(s, startpos, endpos)) end (sgn, base, i) = Base.parseint_preamble(true, Int(base_), bstr, firstindex(bstr), lastindex(bstr)) if !(2 <= base <= 62) raise && throw(ArgumentError("invalid base: base must be 2 ≤ base ≤ 62, got $(base)")) return nothing end if i == 0 raise && throw(ArgumentError("premature end of integer: $(repr(bstr))")) return nothing end z = BigInt() if Base.containsnul(bstr) err = -1 else err = GC.@preserve(bstr, MPZ.set_str!(z, pointer(bstr) + (i - firstindex(bstr)), base)) end if err != 0 raise && throw(ArgumentError("invalid BigInt: $(repr(bstr))")) return nothing end flipsign!(z, sgn) end BigInt(x::Union{Clong, Int32}) = begin MPZ.set_si(x) end BigInt(x::Union{Culong, UInt32}) = begin MPZ.set_ui(x) end BigInt(x::Bool) = begin BigInt(UInt(x)) end unsafe_trunc(::Type{BigInt}, x::Union{Float16, Float32, Float64}) = begin MPZ.set_d(x) end function BigInt(x::Float64) isinteger(x) || throw(InexactError(:BigInt, BigInt, x)) unsafe_trunc(BigInt, x) end BigInt(x::Float16) = begin BigInt(Float64(x)) end BigInt(x::Float32) = begin BigInt(Float64(x)) end function BigInt(x::Integer) isbits(x) && (typemin(Clong) <= x <= typemax(Clong) && return BigInt((x % Clong)::Clong)) nd = ndigits(x, base = 2) z = MPZ.realloc2(nd) ux = unsigned(if x < 0 -x else x end) size = 0 limbnbits = sizeof(Limb) << 3 while nd > 0 size += 1 unsafe_store!(z.d, ux % Limb, size) ux >>= limbnbits nd -= limbnbits end z.size = if x < 0 -size else size end z end rem(x::BigInt, ::Type{Bool}) = begin (!(iszero(x)) & unsafe_load(x.d)) % Bool end (rem(x::BigInt, ::Type{T}) where T <: Union{SLimbMax, ULimbMax}) = begin if iszero(x) zero(T) else flipsign(unsafe_load(x.d) % T, x.size) end end function rem(x::BigInt, ::Type{T}) where T <: Union{Base.BitUnsigned, Base.BitSigned} u = zero(T) for l = 1:min(abs(x.size), cld(sizeof(T), sizeof(Limb))) u += (unsafe_load(x.d, l) % T) << (sizeof(Limb) << 3 * (l - 1)) end flipsign(u, x.size) end rem(x::Integer, ::Type{BigInt}) = begin BigInt(x) end clamp(x, ::Type{BigInt}) = begin convert(BigInt, x) end isodd(x::BigInt) = begin MPZ.tstbit(x, 0) end iseven(x::BigInt) = begin !(isodd(x)) end function (::Type{T})(x::BigInt) where T <: Base.BitUnsigned if sizeof(T) < sizeof(Limb) convert(T, convert(Limb, x)) else 0 <= x.size <= cld(sizeof(T), sizeof(Limb)) || throw(InexactError(nameof(T), T, x)) x % T end end function (::Type{T})(x::BigInt) where T <: Base.BitSigned n = abs(x.size) if sizeof(T) < sizeof(Limb) SLimb = typeof(Signed(one(Limb))) convert(T, convert(SLimb, x)) else 0 <= n <= cld(sizeof(T), sizeof(Limb)) || throw(InexactError(nameof(T), T, x)) y = x % T ispositive(x) ⊻ (y > 0) && throw(InexactError(nameof(T), T, x)) y end end Float64(n::BigInt, ::RoundingMode{:ToZero}) = begin MPZ.get_d(n) end function (::Type{T})(n::BigInt, ::RoundingMode{:ToZero}) where T <: Union{Float16, Float32} T(Float64(n, RoundToZero), RoundToZero) end function (::Type{T})(n::BigInt, ::RoundingMode{:Down}) where T <: CdoubleMax x = T(n, RoundToZero) if x > n prevfloat(x) else x end end function (::Type{T})(n::BigInt, ::RoundingMode{:Up}) where T <: CdoubleMax x = T(n, RoundToZero) if x < n nextfloat(x) else x end end function Float64(x::BigInt, ::RoundingMode{:Nearest}) x == 0 && return 0.0 xsize = abs(x.size) if xsize * BITS_PER_LIMB > 1024 z = Inf64 elseif xsize == 1 z = Float64(unsafe_load(x.d)) elseif Limb == UInt32 && xsize == 2 z = Float64((unsafe_load(x.d, 2) % UInt64) << BITS_PER_LIMB + unsafe_load(x.d)) else y1 = unsafe_load(x.d, xsize) % UInt64 n = top_set_bit(y1) y = y1 >> (n - (precision(Float64) + 1)) if Limb == UInt64 y += if n > precision(Float64) 0 else unsafe_load(x.d, xsize - 1) >> (10 + n) end else y += (unsafe_load(x.d, xsize - 1) % UInt64) >> (n - 22) y += if n > precision(Float64) - 32 0 else unsafe_load(x.d, xsize - 2) >> (10 + n) end end y = (y + 1) >> 1 y &= ~(UInt64(trailing_zeros(x) == (n - 54) + (xsize - 1) * BITS_PER_LIMB)) d = ((n + 1021) % UInt64) << 52 z = reinterpret(Float64, d + y) z = ldexp(z, (xsize - 1) * BITS_PER_LIMB) end return flipsign(z, x.size) end function Float32(x::BigInt, ::RoundingMode{:Nearest}) x == 0 && return 0.0f0 xsize = abs(x.size) if xsize * BITS_PER_LIMB > 128 z = Inf32 elseif xsize == 1 z = Float32(unsafe_load(x.d)) else y1 = unsafe_load(x.d, xsize) n = BITS_PER_LIMB - leading_zeros(y1) y = y1 >> (n - (precision(Float32) + 1)) % UInt32 y += if n > precision(Float32) 0 else unsafe_load(x.d, xsize - 1) >> (BITS_PER_LIMB - -25) end % UInt32 y = (y + one(UInt32)) >> 1 y &= ~(UInt32(trailing_zeros(x) == (n - 25) + (xsize - 1) * BITS_PER_LIMB)) d = ((n + 125) % UInt32) << 23 z = reinterpret(Float32, d + y) z = ldexp(z, (xsize - 1) * BITS_PER_LIMB) end return flipsign(z, x.size) end function Float16(x::BigInt, ::RoundingMode{:Nearest}) x == 0 && return Float16(0.0) y1 = unsafe_load(x.d) n = BITS_PER_LIMB - leading_zeros(y1) if n > 16 || abs(x.size) > 1 z = Inf16 else y = y1 >> (n - (precision(Float16) + 1)) % UInt16 y = (y + one(UInt16)) >> 1 y &= ~(UInt16(trailing_zeros(x) == n - 12)) d = ((n + 13) % UInt16) << 10 z = reinterpret(Float16, d + y) end return flipsign(z, x.size) end Float64(n::BigInt) = begin Float64(n, RoundNearest) end Float32(n::BigInt) = begin Float32(n, RoundNearest) end Float16(n::BigInt) = begin Float16(n, RoundNearest) end promote_rule(::Type{BigInt}, ::Type{<:Integer}) = begin BigInt end Core.@doc " big(x)\n\nConvert a number to a maximum precision representation (typically [`BigInt`](@ref) or\n`BigFloat`). See [`BigFloat`](@ref BigFloat(::Any, rounding::RoundingMode)) for\ninformation about some pitfalls with floating-point numbers.\n" function big end big(::Type{<:Integer}) = begin BigInt end big(::Type{<:Rational}) = begin Rational{BigInt} end big(n::Integer) = begin convert(BigInt, n) end for (fJ, fC) = ((:+, :add), (:-, :sub), (:*, :mul), (:mod, :fdiv_r), (:rem, :tdiv_r), (:gcd, :gcd), (:lcm, :lcm), (:&, :and), (:|, :ior), (:xor, :xor)) @eval begin ($fJ)(x::BigInt, y::BigInt) = begin MPZ.:($fC)(x, y) end end end for (r, f) = ((RoundToZero, :tdiv_q), (RoundDown, :fdiv_q), (RoundUp, :cdiv_q)) @eval div(x::BigInt, y::BigInt, ::typeof($r)) = begin MPZ.:($f)(x, y) end end div(x::BigInt, y::BigInt) = begin div(x, y, RoundToZero) end fld(x::BigInt, y::BigInt) = begin div(x, y, RoundDown) end cld(x::BigInt, y::BigInt) = begin div(x, y, RoundUp) end x::BigInt / y::BigInt = begin float(x) / float(y) end function invmod(x::BigInt, y::BigInt) z = zero(BigInt) ya = abs(y) if ya == 1 return z end if y == 0 || MPZ.invert!(z, x, ya) == 0 throw(DomainError(y)) end if y < 0 MPZ.add!(z, y) end return z end for (fJ, fC) = ((:+, :add), (:*, :mul), (:&, :and), (:|, :ior), (:xor, :xor)) fC! = Symbol(fC, :!) @eval begin ($fJ)(a::BigInt, b::BigInt, c::BigInt) = begin MPZ.:($fC!)(MPZ.:($fC)(a, b), c) end ($fJ)(a::BigInt, b::BigInt, c::BigInt, d::BigInt) = begin MPZ.:($fC!)(MPZ.:($fC!)(MPZ.:($fC)(a, b), c), d) end ($fJ)(a::BigInt, b::BigInt, c::BigInt, d::BigInt, e::BigInt) = begin MPZ.:($fC!)(MPZ.:($fC!)(MPZ.:($fC!)(MPZ.:($fC)(a, b), c), d), e) end end end x::BigInt + c::CulongMax = begin MPZ.add_ui(x, c) end c::CulongMax + x::BigInt = begin x + c end x::BigInt - c::CulongMax = begin MPZ.sub_ui(x, c) end c::CulongMax - x::BigInt = begin MPZ.ui_sub(c, x) end x::BigInt + c::ClongMax = begin if c < 0 x - -(c % Culong) else x + convert(Culong, c) end end c::ClongMax + x::BigInt = begin if c < 0 x - -(c % Culong) else x + convert(Culong, c) end end x::BigInt - c::ClongMax = begin if c < 0 x + -(c % Culong) else x - convert(Culong, c) end end c::ClongMax - x::BigInt = begin if c < 0 -((x + -(c % Culong))) else convert(Culong, c) - x end end x::BigInt * c::CulongMax = begin MPZ.mul_ui(x, c) end c::CulongMax * x::BigInt = begin x * c end x::BigInt * c::ClongMax = begin MPZ.mul_si(x, c) end c::ClongMax * x::BigInt = begin x * c end x::BigInt / y::Union{ClongMax, CulongMax} = begin float(x) / y end x::Union{ClongMax, CulongMax} / y::BigInt = begin x / float(y) end -(x::BigInt) = begin MPZ.neg(x) end ~(x::BigInt) = begin MPZ.com(x) end x::BigInt << c::UInt = begin if c == 0 x else MPZ.mul_2exp(x, c) end end x::BigInt >> c::UInt = begin if c == 0 x else MPZ.fdiv_q_2exp(x, c) end end x::BigInt >>> c::UInt = begin x >> c end function trailing_zeros(x::BigInt) c = MPZ.scan1(x, 0) c == -1 && throw(DomainError(x, "`x` must be non-zero")) c end function trailing_ones(x::BigInt) c = MPZ.scan0(x, 0) c == -1 && throw(DomainError(x, "`x` must not be equal to -1")) c end function count_ones(x::BigInt) c = MPZ.popcount(x) c == -1 && throw(DomainError(x, "`x` cannot be negative")) c end function count_zeros(x::BigInt) c = MPZ.popcount(~x) c == -1 && throw(DomainError(x, "`x` must be negative")) c end Core.@doc " count_ones_abs(x::BigInt)\n\nNumber of ones in the binary representation of abs(x).\n" count_ones_abs(x::BigInt) = begin if iszero(x) 0 else MPZ.mpn_popcount(x) end end function top_set_bit(x::BigInt) isnegative(x) && throw(DomainError(x, "top_set_bit only supports negative arguments when they have type BitSigned.")) iszero(x) && return 0 x.size * sizeof(Limb) << 3 - leading_zeros(GC.@preserve(x, unsafe_load(x.d, x.size))) end divrem(x::BigInt, y::BigInt, ::typeof(RoundToZero) = RoundToZero) = begin MPZ.tdiv_qr(x, y) end divrem(x::BigInt, y::Integer, ::typeof(RoundToZero) = RoundToZero) = begin MPZ.tdiv_qr(x, BigInt(y)) end cmp(x::BigInt, y::BigInt) = begin sign(MPZ.cmp(x, y)) end cmp(x::BigInt, y::ClongMax) = begin sign(MPZ.cmp_si(x, y)) end cmp(x::BigInt, y::CulongMax) = begin sign(MPZ.cmp_ui(x, y)) end cmp(x::BigInt, y::Integer) = begin cmp(x, big(y)) end cmp(x::Integer, y::BigInt) = begin -(cmp(y, x)) end cmp(x::BigInt, y::CdoubleMax) = begin if isnan(y) -1 else sign(MPZ.cmp_d(x, y)) end end cmp(x::CdoubleMax, y::BigInt) = begin -(cmp(y, x)) end isqrt(x::BigInt) = begin MPZ.sqrt(x) end x::BigInt ^ y::Culong = begin MPZ.pow_ui(x, y) end function bigint_pow(x::BigInt, y::Integer) x == 1 && return x x == -1 && return if isodd(y) x else -x end if y < 0 throw(DomainError(y, "`y` cannot be negative.")) end @noinline throw1(y) = begin throw(OverflowError("exponent $(y) is too large and computation will overflow")) end if y > typemax(Culong) x == 0 && return x throw1(y) end return x ^ convert(Culong, y) end x::BigInt ^ y::BigInt = begin bigint_pow(x, y) end x::BigInt ^ y::Bool = begin if y x else one(x) end end x::BigInt ^ y::Integer = begin bigint_pow(x, y) end x::Integer ^ y::BigInt = begin bigint_pow(BigInt(x), y) end x::Bool ^ y::BigInt = begin Base.power_by_squaring(x, y) end function powermod(x::BigInt, p::BigInt, m::BigInt) r = MPZ.powm(x, p, m) return if m < 0 && r > 0 MPZ.add!(r, m) else r end end powermod(x::Integer, p::Integer, m::BigInt) = begin powermod(big(x), big(p), m) end function gcdx(a::BigInt, b::BigInt) (g, s, t) = MPZ.gcdext(a, b) if t == 0 if a == b return (g, t, s) elseif abs(a) == abs(b) return (g, t, -s) end end (g, s, t) end +(x::BigInt, y::BigInt, rest::BigInt...) = begin sum(tuple(x, y, rest...)) end sum(arr::Union{AbstractArray{BigInt}, Tuple{BigInt, Vararg{BigInt}}}) = begin foldl(MPZ.add!, arr; init = BigInt(0)) end function prod(arr::AbstractArray{BigInt}) nbits = BITS_PER_LIMB for x = arr iszero(x) && return zero(BigInt) xsize = abs(x.size) lz = GC.@preserve(x, leading_zeros(unsafe_load(x.d, xsize))) nbits += xsize * BITS_PER_LIMB - lz end init = BigInt(; nbits) MPZ.set_si!(init, 1) foldl(MPZ.mul!, arr; init) end factorial(n::BigInt) = begin if !(isnegative(n)) MPZ.fac_ui(n) else throw(DomainError(n, "`n` must not be negative.")) end end function binomial(n::BigInt, k::Integer) k < 0 && return BigInt(0) k <= typemax(Culong) && return binomial(n, Culong(k)) n < 0 && return if isodd(k) -(binomial((k - n) - 1, k)) else binomial((k - n) - 1, k) end κ = n - k κ < 0 && return BigInt(0) κ <= typemax(Culong) && return binomial(n, Culong(κ)) throw(OverflowError("Computation would exceed memory")) end binomial(n::BigInt, k::Culong) = begin MPZ.bin_ui(n, k) end x::BigInt == y::BigInt = begin cmp(x, y) == 0 end x::BigInt == i::Integer = begin cmp(x, i) == 0 end i::Integer == x::BigInt = begin cmp(x, i) == 0 end x::BigInt == f::CdoubleMax = begin if isnan(f) false else cmp(x, f) == 0 end end f::CdoubleMax == x::BigInt = begin if isnan(f) false else cmp(x, f) == 0 end end iszero(x::BigInt) = begin x.size == 0 end isone(x::BigInt) = begin x == Culong(1) end x::BigInt <= y::BigInt = begin cmp(x, y) <= 0 end x::BigInt <= i::Integer = begin cmp(x, i) <= 0 end i::Integer <= x::BigInt = begin cmp(x, i) >= 0 end x::BigInt <= f::CdoubleMax = begin if isnan(f) false else cmp(x, f) <= 0 end end f::CdoubleMax <= x::BigInt = begin if isnan(f) false else cmp(x, f) >= 0 end end x::BigInt < y::BigInt = begin cmp(x, y) < 0 end x::BigInt < i::Integer = begin cmp(x, i) < 0 end i::Integer < x::BigInt = begin cmp(x, i) > 0 end x::BigInt < f::CdoubleMax = begin if isnan(f) false else cmp(x, f) < 0 end end f::CdoubleMax < x::BigInt = begin if isnan(f) false else cmp(x, f) > 0 end end isnegative(x::BigInt) = begin x.size < 0 end ispositive(x::BigInt) = begin x.size > 0 end signbit(x::BigInt) = begin isnegative(x) end flipsign!(x::BigInt, y::Integer) = begin signbit(y) && (x.size = -(x.size)) x end flipsign(x::BigInt, y::Integer) = begin if signbit(y) -x else x end end flipsign(x::BigInt, y::BigInt) = begin if signbit(y) -x else x end end function sign(x::BigInt) isnegative(x) && return -(one(x)) ispositive(x) && return one(x) return x end show(io::IO, x::BigInt) = begin print(io, string(x)) end function string(n::BigInt; base::Integer = 10, pad::Integer = 1) base < 0 && return Base._base(Int(base), n, pad, (base > 0) & (n.size < 0)) 2 <= base <= 62 || throw(ArgumentError("base must be 2 ≤ base ≤ 62, got $(base)")) iszero(n) && (pad < 1 && return "") nd1 = ndigits(n, base = base) nd = max(nd1, pad) sv = Base.StringMemory(nd + isnegative(n)) GC.@preserve sv MPZ.get_str!((pointer(sv) + nd) - nd1, base, n) @inbounds for i = (1:nd - nd1) .+ isnegative(n) sv[i] = '0' % UInt8 end isnegative(n) && (sv[1] = '-' % UInt8) unsafe_takestring(sv) end function digits!(a::AbstractVector{T}, n::BigInt; base::Integer = 10) where T <: Integer if base ≥ 2 if base ≤ 62 s = codeunits(string(n; base)) (i, j) = (firstindex(a) - 1, length(s) + 1) lasti = min(lastindex(a), ((firstindex(a) + length(s)) - 1) - isnegative(n)) while i < lasti x = s[j -= 1] a[i += 1] = if base ≤ 36 if x > 0x39 x - 0x57 else x - 0x30 end else if x > 0x39 if x > 0x60 x - 0x3d else x - 0x37 end else x - 0x30 end end end lasti = lastindex(a) while i < lasti a[i += 1] = zero(T) end return if isnegative(n) map!(-, a, a) else a end elseif a isa StridedVector{<:Base.BitInteger} && (stride(a, 1) == 1 && (ispow2(base) && base - 1 ≤ typemax(T))) origlen = length(a) (_, writelen) = MPZ.export!(a, n; nails = 8 * sizeof(T) - trailing_zeros(base)) length(a) != origlen && resize!(a, origlen) a[var"begin" + writelen:var"end"] .= zero(T) return if isnegative(n) map!(-, a, a) else a end end end return invoke(digits!, Tuple{typeof(a), Integer}, a, n; base) end function ndigits0zpb(x::BigInt, b::Integer) b < 2 && throw(DomainError(b, "`b` cannot be less than 2.")) x.size == 0 && return 0 if ispow2(b) && 2 <= b <= 62 MPZ.sizeinbase(x, b) else n = MPZ.sizeinbase(x, 2) lb = log2(b) (q, r) = divrem(n, lb) iq = Int(q) maxerr = q * eps(lb) if r - 1.0 < maxerr if abs(x) >= big(b) ^ iq iq + 1 else iq end elseif lb - r < maxerr if abs(x) >= big(b) ^ (iq + 1) iq + 2 else iq + 1 end else iq + 1 end end end _prevpow2(x::BigInt) = begin if -2 <= x <= 2 x else flipsign!(ONE << (ndigits(x, base = 2) - 1), x) end end _nextpow2(x::BigInt) = begin if count_ones_abs(x) <= 1 x else flipsign!(ONE << ndigits(x, base = 2), x) end end Base.checked_abs(x::BigInt) = begin abs(x) end Base.checked_neg(x::BigInt) = begin -x end Base.checked_add(a::BigInt, b::BigInt) = begin a + b end Base.checked_sub(a::BigInt, b::BigInt) = begin a - b end Base.checked_mul(a::BigInt, b::BigInt) = begin a * b end Base.checked_div(a::BigInt, b::BigInt) = begin div(a, b) end Base.checked_rem(a::BigInt, b::BigInt) = begin rem(a, b) end Base.checked_fld(a::BigInt, b::BigInt) = begin fld(a, b) end Base.checked_mod(a::BigInt, b::BigInt) = begin mod(a, b) end Base.checked_cld(a::BigInt, b::BigInt) = begin cld(a, b) end Base.add_with_overflow(a::BigInt, b::BigInt) = begin (a + b, false) end Base.sub_with_overflow(a::BigInt, b::BigInt) = begin (a - b, false) end Base.mul_with_overflow(a::BigInt, b::BigInt) = begin (a * b, false) end Base.checked_pow(x::BigInt, p::Integer) = begin x ^ p end Base.checked_pow(x::Integer, p::BigInt) = begin x ^ p end Base.checked_pow(x::BigInt, p::BigInt) = begin x ^ p end Base.deepcopy_internal(x::BigInt, stackdict::IdDict) = begin get!((()->begin MPZ.set(x) end), stackdict, x)::BigInt end Base._hash_shl!(x::BigInt, n) = begin MPZ.mul_2exp!(x, n) end if Limb === UInt64 === UInt using .Base: HASH_SECRET, hash_bytes, hash_finalizer function hash_integer(n::BigInt, h::UInt) iszero(n) && return hash_integer(0, h) GC.@preserve n begin s = n.size h ⊻= s < 0 us = abs(s) leading_zero_bytes = div(leading_zeros(unsafe_load(n.d, us)), 8) hash_bytes(Ptr{UInt8}(n.d), 8us - leading_zero_bytes, h, HASH_SECRET) end end function hash(x::BigInt, h::UInt) GC.@preserve x begin sz = x.size sz == 0 && return hash(0, h) ptr = Ptr{UInt64}(x.d) if sz == 1 return hash(unsafe_load(ptr), h) elseif sz == -1 limb = unsafe_load(ptr) limb <= typemin(Int) % UInt && return hash(-(limb % Int), h) end pow = trailing_zeros(x) nd = Base.ndigits0z(x, 2) idx = pow >>> 6 + 1 shift = (pow & 63) % UInt upshift = BITS_PER_LIMB - shift asz = abs(sz) if shift == 0 limb = unsafe_load(ptr, idx) else limb1 = unsafe_load(ptr, idx) limb2 = if idx < asz unsafe_load(ptr, idx + 1) else UInt(0) end limb = limb2 << upshift | limb1 >> shift end if nd <= 1024 && nd - pow <= 53 return hash(ldexp(flipsign(Float64(limb), sz), pow), h) end h = hash_integer(pow, h) h ⊻= sz < 0 leading_zero_bytes = div(leading_zeros(unsafe_load(x.d, asz)), 8) trailing_zero_bytes = div(pow, 8) return hash_bytes(Ptr{UInt8}(x.d) + trailing_zero_bytes, 8asz - (leading_zero_bytes + trailing_zero_bytes), h, HASH_SECRET) end end end module MPQ import .Base: unsafe_rational, __throw_rational_argerror_zero import ..GMP: BigInt, MPZ, Limb, libgmp gmpq(op::Symbol) = begin (Symbol(:__gmpq_, op), libgmp) end mutable struct _MPQ num_alloc::Cint num_size::Cint num_d::Ptr{Limb} den_alloc::Cint den_size::Cint den_d::Ptr{Limb} rat::Rational{BigInt} end const mpq_t = Ref{_MPQ} _MPQ(x::BigInt, y::BigInt) = begin _MPQ(x.alloc, x.size, x.d, y.alloc, y.size, y.d, unsafe_rational(BigInt, x, y)) end _MPQ() = begin _MPQ(BigInt(), BigInt()) end _MPQ(x::Rational{BigInt}) = begin _MPQ(x.num, x.den) end function sync_rational!(xq::_MPQ) xq.rat.num.alloc = xq.num_alloc xq.rat.num.size = xq.num_size xq.rat.num.d = xq.num_d xq.rat.den.alloc = xq.den_alloc xq.rat.den.size = xq.den_size xq.rat.den.d = xq.den_d return xq.rat end function Rational{BigInt}(num::BigInt, den::BigInt) if iszero(den) iszero(num) && __throw_rational_argerror_zero(BigInt) return set_si(flipsign(1, num), 0) end xq = _MPQ(MPZ.set(num), MPZ.set(den)) ccall((:__gmpq_canonicalize, libgmp), Cvoid, (mpq_t,), xq) return sync_rational!(xq) end function set!(z::Rational{BigInt}, x::Rational{BigInt}) zq = _MPQ(z) ccall((:__gmpq_set, libgmp), Cvoid, (mpq_t, mpq_t), zq, _MPQ(x)) return sync_rational!(zq) end function set_z!(z::Rational{BigInt}, x::BigInt) zq = _MPQ(z) ccall((:__gmpq_set_z, libgmp), Cvoid, (mpq_t, MPZ.mpz_t), zq, x) return sync_rational!(zq) end for (op, T) = ((:set, Rational{BigInt}), (:set_z, BigInt)) op! = Symbol(op, :!) @eval ($op)(a::$T) = begin ($op!)(unsafe_rational(BigInt(), BigInt()), a) end end for (op, T1, T2) = ((:set_ui, Culong, Culong), (:set_si, Clong, Culong)) op! = Symbol(op, :!) @eval begin function ($op!)(z::Rational{BigInt}, a, b) zq = _MPQ(z) ccall($(gmpq(op)), Cvoid, (mpq_t, $T1, $T2), zq, a, b) return sync_rational!(zq) end ($op)(a, b) = begin ($op!)(unsafe_rational(BigInt(), BigInt()), a, b) end end end function add!(z::Rational{BigInt}, x::Rational{BigInt}, y::Rational{BigInt}) if iszero(x.den) || iszero(y.den) if iszero(x.den) && (iszero(y.den) && isnegative(x.num) != isnegative(y.num)) throw(DivideError()) end return set!(z, if iszero(x.den) x else y end) end zq = _MPQ(z) ccall((:__gmpq_add, libgmp), Cvoid, (mpq_t, mpq_t, mpq_t), zq, _MPQ(x), _MPQ(y)) return sync_rational!(zq) end function sub!(z::Rational{BigInt}, x::Rational{BigInt}, y::Rational{BigInt}) if iszero(x.den) || iszero(y.den) if iszero(x.den) && (iszero(y.den) && isnegative(x.num) == isnegative(y.num)) throw(DivideError()) end iszero(x.den) && return set!(z, x) return set_si!(z, flipsign(-1, y.num), 0) end zq = _MPQ(z) ccall((:__gmpq_sub, libgmp), Cvoid, (mpq_t, mpq_t, mpq_t), zq, _MPQ(x), _MPQ(y)) return sync_rational!(zq) end function mul!(z::Rational{BigInt}, x::Rational{BigInt}, y::Rational{BigInt}) if iszero(x.den) || iszero(y.den) if iszero(x.num) || iszero(y.num) throw(DivideError()) end return set_si!(z, ifelse(xor(isnegative(x.num), isnegative(y.num)), -1, 1), 0) end zq = _MPQ(z) ccall((:__gmpq_mul, libgmp), Cvoid, (mpq_t, mpq_t, mpq_t), zq, _MPQ(x), _MPQ(y)) return sync_rational!(zq) end function div!(z::Rational{BigInt}, x::Rational{BigInt}, y::Rational{BigInt}) if iszero(x.den) if iszero(y.den) throw(DivideError()) end isnegative(y.num) || return set!(z, x) return set_si!(z, flipsign(-1, x.num), 0) elseif iszero(y.den) return set_si!(z, 0, 1) elseif iszero(y.num) if iszero(x.num) throw(DivideError()) end return set_si!(z, flipsign(1, x.num), 0) end zq = _MPQ(z) ccall((:__gmpq_div, libgmp), Cvoid, (mpq_t, mpq_t, mpq_t), zq, _MPQ(x), _MPQ(y)) return sync_rational!(zq) end for (fJ, fC) = ((:+, :add), (:-, :sub), (:*, :mul), (://, :div)) fC! = Symbol(fC, :!) @eval begin ($fC!)(x::Rational{BigInt}, y::Rational{BigInt}) = begin ($fC!)(x, x, y) end Base.:($fJ)(x::Rational{BigInt}, y::Rational{BigInt}) = begin ($fC!)(unsafe_rational(BigInt(), BigInt()), x, y) end end end function Base.cmp(x::Rational{BigInt}, y::Rational{BigInt}) Int(ccall((:__gmpq_cmp, libgmp), Cint, (mpq_t, mpq_t), _MPQ(x), _MPQ(y))) end end end Parsing files in Base: Test Failed at /home/pkgeval/.julia/packages/CSTParser/0hXvH/test/test_check_base.jl:166 Expression: false Stacktrace: [1] top-level scope @ ~/.julia/packages/CSTParser/0hXvH/test/test_check_base.jl:166 [2] macro expansion @ /opt/julia/share/julia/stdlib/v1.13/Test/src/Test.jl:745 [inlined] ┌ Error: parsing difference │ file = "/opt/julia/bin/../share/julia/base/JuliaSyntax/test/literal_parsing.jl" └ @ Main.var"##439" ~/.julia/packages/CSTParser/0hXvH/test/test_check_base.jl:157 n == 340282366920938463463374607431768211456 n == 340282366920938463463374607431768211456 n isa BigInt && n == 340282366920938463463374607431768211456 n isa BigInt && n == 340282366920938463463374607431768211456 begin n = hexint("0x100000000000000000000000000000000") n isa BigInt && n == 340282366920938463463374607431768211456 end begin n = hexint("0x100000000000000000000000000000000") n isa BigInt && n == 340282366920938463463374607431768211456 end @test begin n = hexint("0x100000000000000000000000000000000") n isa BigInt && n == 340282366920938463463374607431768211456 end @test begin n = hexint("0x100000000000000000000000000000000") n isa BigInt && n == 340282366920938463463374607431768211456 end begin @test hexint("0xff") === UInt8(0xff) @test hexint("0x100") === UInt16(0x0100) @test hexint("0xffff") === UInt16(0xffff) @test hexint("0x10000") === UInt32(0x00010000) @test hexint("0xffffffff") === UInt32(0xffffffff) @test hexint("0x100000000") === UInt64(0x0000000100000000) @test hexint("0xffffffffffffffff") === UInt64(0xffffffffffffffff) @test hexint("0x10000000000000000") === UInt128(0x10000000000000000) @test hexint("0xffffffffffffffffffffffffffffffff") === UInt128(0xffffffffffffffffffffffffffffffff) @test begin n = hexint("0x100000000000000000000000000000000") n isa BigInt && n == 340282366920938463463374607431768211456 end end begin @test hexint("0xff") === UInt8(0xff) @test hexint("0x100") === UInt16(0x0100) @test hexint("0xffff") === UInt16(0xffff) @test hexint("0x10000") === UInt32(0x00010000) @test hexint("0xffffffff") === UInt32(0xffffffff) @test hexint("0x100000000") === UInt64(0x0000000100000000) @test hexint("0xffffffffffffffff") === UInt64(0xffffffffffffffff) @test hexint("0x10000000000000000") === UInt128(0x10000000000000000) @test hexint("0xffffffffffffffffffffffffffffffff") === UInt128(0xffffffffffffffffffffffffffffffff) @test begin n = hexint("0x100000000000000000000000000000000") n isa BigInt && n == 340282366920938463463374607431768211456 end end @testset "HexInt numeric limits for different types" begin @test hexint("0xff") === UInt8(0xff) @test hexint("0x100") === UInt16(0x0100) @test hexint("0xffff") === UInt16(0xffff) @test hexint("0x10000") === UInt32(0x00010000) @test hexint("0xffffffff") === UInt32(0xffffffff) @test hexint("0x100000000") === UInt64(0x0000000100000000) @test hexint("0xffffffffffffffff") === UInt64(0xffffffffffffffff) @test hexint("0x10000000000000000") === UInt128(0x10000000000000000) @test hexint("0xffffffffffffffffffffffffffffffff") === UInt128(0xffffffffffffffffffffffffffffffff) @test begin n = hexint("0x100000000000000000000000000000000") n isa BigInt && n == 340282366920938463463374607431768211456 end end @testset "HexInt numeric limits for different types" begin @test hexint("0xff") === UInt8(0xff) @test hexint("0x100") === UInt16(0x0100) @test hexint("0xffff") === UInt16(0xffff) @test hexint("0x10000") === UInt32(0x00010000) @test hexint("0xffffffff") === UInt32(0xffffffff) @test hexint("0x100000000") === UInt64(0x0000000100000000) @test hexint("0xffffffffffffffff") === UInt64(0xffffffffffffffff) @test hexint("0x10000000000000000") === UInt128(0x10000000000000000) @test hexint("0xffffffffffffffffffffffffffffffff") === UInt128(0xffffffffffffffffffffffffffffffff) @test begin n = hexint("0x100000000000000000000000000000000") n isa BigInt && n == 340282366920938463463374607431768211456 end end n == 340282366920938463463374607431768211456 n == 340282366920938463463374607431768211456 n isa BigInt && n == 340282366920938463463374607431768211456 n isa BigInt && n == 340282366920938463463374607431768211456 begin n = binint("0b100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000") n isa BigInt && n == 340282366920938463463374607431768211456 end begin n = binint("0b100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000") n isa BigInt && n == 340282366920938463463374607431768211456 end @test begin n = binint("0b100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000") n isa BigInt && n == 340282366920938463463374607431768211456 end @test begin n = binint("0b100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000") n isa BigInt && n == 340282366920938463463374607431768211456 end begin @test binint("0b11111111") === UInt8(0xff) @test binint("0b100000000") === UInt16(0x0100) @test binint("0b1111111111111111") === UInt16(0xffff) @test binint("0b10000000000000000") === UInt32(0x00010000) @test binint("0b11111111111111111111111111111111") === UInt32(0xffffffff) @test binint("0b100000000000000000000000000000000") === UInt64(0x0000000100000000) @test binint("0b1111111111111111111111111111111111111111111111111111111111111111") === UInt64(0xffffffffffffffff) @test binint("0b10000000000000000000000000000000000000000000000000000000000000000") === UInt128(0x10000000000000000) @test binint("0b11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111") === UInt128(0xffffffffffffffffffffffffffffffff) @test begin n = binint("0b100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000") n isa BigInt && n == 340282366920938463463374607431768211456 end end begin @test binint("0b11111111") === UInt8(0xff) @test binint("0b100000000") === UInt16(0x0100) @test binint("0b1111111111111111") === UInt16(0xffff) @test binint("0b10000000000000000") === UInt32(0x00010000) @test binint("0b11111111111111111111111111111111") === UInt32(0xffffffff) @test binint("0b100000000000000000000000000000000") === UInt64(0x0000000100000000) @test binint("0b1111111111111111111111111111111111111111111111111111111111111111") === UInt64(0xffffffffffffffff) @test binint("0b10000000000000000000000000000000000000000000000000000000000000000") === UInt128(0x10000000000000000) @test binint("0b11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111") === UInt128(0xffffffffffffffffffffffffffffffff) @test begin n = binint("0b100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000") n isa BigInt && n == 340282366920938463463374607431768211456 end end @testset "BinInt numeric limits for different types" begin @test binint("0b11111111") === UInt8(0xff) @test binint("0b100000000") === UInt16(0x0100) @test binint("0b1111111111111111") === UInt16(0xffff) @test binint("0b10000000000000000") === UInt32(0x00010000) @test binint("0b11111111111111111111111111111111") === UInt32(0xffffffff) @test binint("0b100000000000000000000000000000000") === UInt64(0x0000000100000000) @test binint("0b1111111111111111111111111111111111111111111111111111111111111111") === UInt64(0xffffffffffffffff) @test binint("0b10000000000000000000000000000000000000000000000000000000000000000") === UInt128(0x10000000000000000) @test binint("0b11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111") === UInt128(0xffffffffffffffffffffffffffffffff) @test begin n = binint("0b100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000") n isa BigInt && n == 340282366920938463463374607431768211456 end end @testset "BinInt numeric limits for different types" begin @test binint("0b11111111") === UInt8(0xff) @test binint("0b100000000") === UInt16(0x0100) @test binint("0b1111111111111111") === UInt16(0xffff) @test binint("0b10000000000000000") === UInt32(0x00010000) @test binint("0b11111111111111111111111111111111") === UInt32(0xffffffff) @test binint("0b100000000000000000000000000000000") === UInt64(0x0000000100000000) @test binint("0b1111111111111111111111111111111111111111111111111111111111111111") === UInt64(0xffffffffffffffff) @test binint("0b10000000000000000000000000000000000000000000000000000000000000000") === UInt128(0x10000000000000000) @test binint("0b11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111") === UInt128(0xffffffffffffffffffffffffffffffff) @test begin n = binint("0b100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000") n isa BigInt && n == 340282366920938463463374607431768211456 end end n == 340282366920938463463374607431768211456 n == 340282366920938463463374607431768211456 n isa BigInt && n == 340282366920938463463374607431768211456 n isa BigInt && n == 340282366920938463463374607431768211456 begin n = octint("0o4000000000000000000000000000000000000000000") n isa BigInt && n == 340282366920938463463374607431768211456 end begin n = octint("0o4000000000000000000000000000000000000000000") n isa BigInt && n == 340282366920938463463374607431768211456 end @test begin n = octint("0o4000000000000000000000000000000000000000000") n isa BigInt && n == 340282366920938463463374607431768211456 end @test begin n = octint("0o4000000000000000000000000000000000000000000") n isa BigInt && n == 340282366920938463463374607431768211456 end begin @test octint("0o377") === UInt8(0xff) @test octint("0o400") === UInt16(0x0100) @test octint("0o177777") === UInt16(0xffff) @test octint("0o200000") === UInt32(0x00010000) @test octint("0o37777777777") === UInt32(0xffffffff) @test octint("0o40000000000") === UInt64(0x0000000100000000) @test octint("0o1777777777777777777777") === UInt64(0xffffffffffffffff) @test octint("0o2000000000000000000000") === UInt128(0x10000000000000000) @test octint("0o3777777777777777777777777777777777777777777") === UInt128(0xffffffffffffffffffffffffffffffff) @test begin n = octint("0o4000000000000000000000000000000000000000000") n isa BigInt && n == 340282366920938463463374607431768211456 end end begin @test octint("0o377") === UInt8(0xff) @test octint("0o400") === UInt16(0x0100) @test octint("0o177777") === UInt16(0xffff) @test octint("0o200000") === UInt32(0x00010000) @test octint("0o37777777777") === UInt32(0xffffffff) @test octint("0o40000000000") === UInt64(0x0000000100000000) @test octint("0o1777777777777777777777") === UInt64(0xffffffffffffffff) @test octint("0o2000000000000000000000") === UInt128(0x10000000000000000) @test octint("0o3777777777777777777777777777777777777777777") === UInt128(0xffffffffffffffffffffffffffffffff) @test begin n = octint("0o4000000000000000000000000000000000000000000") n isa BigInt && n == 340282366920938463463374607431768211456 end end @testset "OctInt numeric limits for different types" begin @test octint("0o377") === UInt8(0xff) @test octint("0o400") === UInt16(0x0100) @test octint("0o177777") === UInt16(0xffff) @test octint("0o200000") === UInt32(0x00010000) @test octint("0o37777777777") === UInt32(0xffffffff) @test octint("0o40000000000") === UInt64(0x0000000100000000) @test octint("0o1777777777777777777777") === UInt64(0xffffffffffffffff) @test octint("0o2000000000000000000000") === UInt128(0x10000000000000000) @test octint("0o3777777777777777777777777777777777777777777") === UInt128(0xffffffffffffffffffffffffffffffff) @test begin n = octint("0o4000000000000000000000000000000000000000000") n isa BigInt && n == 340282366920938463463374607431768211456 end end @testset "OctInt numeric limits for different types" begin @test octint("0o377") === UInt8(0xff) @test octint("0o400") === UInt16(0x0100) @test octint("0o177777") === UInt16(0xffff) @test octint("0o200000") === UInt32(0x00010000) @test octint("0o37777777777") === UInt32(0xffffffff) @test octint("0o40000000000") === UInt64(0x0000000100000000) @test octint("0o1777777777777777777777") === UInt64(0xffffffffffffffff) @test octint("0o2000000000000000000000") === UInt128(0x10000000000000000) @test octint("0o3777777777777777777777777777777777777777777") === UInt128(0xffffffffffffffffffffffffffffffff) @test begin n = octint("0o4000000000000000000000000000000000000000000") n isa BigInt && n == 340282366920938463463374607431768211456 end end begin @testset "Signed Integers" begin @test parse_int_literal("-1") isa Int @test parse_int_literal("1") isa Int @test parse_int_literal("2147483647") isa Int @test parse_int_literal("9223372036854775807") isa Int64 @test parse_int_literal("9223372036854775808") isa Int128 @test parse_int_literal("170141183460469231731687303715884105727") isa Int128 @test parse_int_literal("170141183460469231731687303715884105728") isa BigInt end @testset "HexInt numeric limits for different types" begin @test hexint("0xff") === UInt8(0xff) @test hexint("0x100") === UInt16(0x0100) @test hexint("0xffff") === UInt16(0xffff) @test hexint("0x10000") === UInt32(0x00010000) @test hexint("0xffffffff") === UInt32(0xffffffff) @test hexint("0x100000000") === UInt64(0x0000000100000000) @test hexint("0xffffffffffffffff") === UInt64(0xffffffffffffffff) @test hexint("0x10000000000000000") === UInt128(0x10000000000000000) @test hexint("0xffffffffffffffffffffffffffffffff") === UInt128(0xffffffffffffffffffffffffffffffff) @test begin n = hexint("0x100000000000000000000000000000000") n isa BigInt && n == 340282366920938463463374607431768211456 end end @testset "HexInt string length limits for different types" begin @test hexint("0x00") === UInt8(0) @test hexint("0x000") === UInt16(0) @test hexint("0x0000") === UInt16(0) @test hexint("0x00000") === UInt32(0) @test hexint("0x00000000") === UInt32(0) @test hexint("0x000000000") === UInt64(0) @test hexint("0x0000000000000000") === UInt64(0) @test hexint("0x00000000000000000") === UInt128(0) @test hexint("0x00000000000000000000000000000000") === UInt128(0) @test begin n = hexint("0x000000000000000000000000000000000") n isa BigInt && n == 0 end end @testset "BinInt numeric limits for different types" begin @test binint("0b11111111") === UInt8(0xff) @test binint("0b100000000") === UInt16(0x0100) @test binint("0b1111111111111111") === UInt16(0xffff) @test binint("0b10000000000000000") === UInt32(0x00010000) @test binint("0b11111111111111111111111111111111") === UInt32(0xffffffff) @test binint("0b100000000000000000000000000000000") === UInt64(0x0000000100000000) @test binint("0b1111111111111111111111111111111111111111111111111111111111111111") === UInt64(0xffffffffffffffff) @test binint("0b10000000000000000000000000000000000000000000000000000000000000000") === UInt128(0x10000000000000000) @test binint("0b11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111") === UInt128(0xffffffffffffffffffffffffffffffff) @test begin n = binint("0b100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000") n isa BigInt && n == 340282366920938463463374607431768211456 end end @testset "BinInt string length limits for different types" begin @test binint("0b00000000") === UInt8(0) @test binint("0b000000000") === UInt16(0) @test binint("0b0000000000000000") === UInt16(0) @test binint("0b00000000000000000") === UInt32(0) @test binint("0b00000000000000000000000000000000") === UInt32(0) @test binint("0b000000000000000000000000000000000") === UInt64(0) @test binint("0b0000000000000000000000000000000000000000000000000000000000000000") === UInt64(0) @test binint("0b00000000000000000000000000000000000000000000000000000000000000000") === UInt128(0) @test binint("0b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000") === UInt128(0) @test begin n = binint("0b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000") n isa BigInt && n == 0 end end @testset "OctInt numeric limits for different types" begin @test octint("0o377") === UInt8(0xff) @test octint("0o400") === UInt16(0x0100) @test octint("0o177777") === UInt16(0xffff) @test octint("0o200000") === UInt32(0x00010000) @test octint("0o37777777777") === UInt32(0xffffffff) @test octint("0o40000000000") === UInt64(0x0000000100000000) @test octint("0o1777777777777777777777") === UInt64(0xffffffffffffffff) @test octint("0o2000000000000000000000") === UInt128(0x10000000000000000) @test octint("0o3777777777777777777777777777777777777777777") === UInt128(0xffffffffffffffffffffffffffffffff) @test begin n = octint("0o4000000000000000000000000000000000000000000") n isa BigInt && n == 340282366920938463463374607431768211456 end end @testset "OctInt string length limits for different types" begin @test octint("0o000") === UInt8(0) @test octint("0o0000") === UInt16(0) @test octint("0o000000") === UInt16(0) @test octint("0o0000000") === UInt32(0) @test octint("0o00000000000") === UInt32(0) @test octint("0o000000000000") === UInt64(0) @test octint("0o0000000000000000000000") === UInt64(0) @test octint("0o00000000000000000000000") === UInt128(0) @test octint("0o0000000000000000000000000000000000000000000") === UInt128(0) @test begin n = octint("0o00000000000000000000000000000000000000000000") n isa BigInt && n == 0 end end @testset "Underscore separators" begin @test parse_int_literal("10_000") === 10000 @test parse_uint_literal("0xff_ff", K"HexInt") === 0xffff @test parse_uint_literal("0b1111_1111", K"BinInt") === 0xff @test parse_uint_literal("0o177_777", K"OctInt") === 0xffff end @testset "\\minus ('\\u2212' / '−') allowed in numbers" begin @test parse_int_literal("−10") === -10 end end begin @testset "Signed Integers" begin @test parse_int_literal("-1") isa Int @test parse_int_literal("1") isa Int @test parse_int_literal("2147483647") isa Int @test parse_int_literal("9223372036854775807") isa Int64 @test parse_int_literal("9223372036854775808") isa Int128 @test parse_int_literal("170141183460469231731687303715884105727") isa Int128 @test parse_int_literal("170141183460469231731687303715884105728") isa BigInt end @testset "HexInt numeric limits for different types" begin @test hexint("0xff") === UInt8(0xff) @test hexint("0x100") === UInt16(0x0100) @test hexint("0xffff") === UInt16(0xffff) @test hexint("0x10000") === UInt32(0x00010000) @test hexint("0xffffffff") === UInt32(0xffffffff) @test hexint("0x100000000") === UInt64(0x0000000100000000) @test hexint("0xffffffffffffffff") === UInt64(0xffffffffffffffff) @test hexint("0x10000000000000000") === UInt128(0x10000000000000000) @test hexint("0xffffffffffffffffffffffffffffffff") === UInt128(0xffffffffffffffffffffffffffffffff) @test begin n = hexint("0x100000000000000000000000000000000") n isa BigInt && n == 340282366920938463463374607431768211456 end end @testset "HexInt string length limits for different types" begin @test hexint("0x00") === UInt8(0) @test hexint("0x000") === UInt16(0) @test hexint("0x0000") === UInt16(0) @test hexint("0x00000") === UInt32(0) @test hexint("0x00000000") === UInt32(0) @test hexint("0x000000000") === UInt64(0) @test hexint("0x0000000000000000") === UInt64(0) @test hexint("0x00000000000000000") === UInt128(0) @test hexint("0x00000000000000000000000000000000") === UInt128(0) @test begin n = hexint("0x000000000000000000000000000000000") n isa BigInt && n == 0 end end @testset "BinInt numeric limits for different types" begin @test binint("0b11111111") === UInt8(0xff) @test binint("0b100000000") === UInt16(0x0100) @test binint("0b1111111111111111") === UInt16(0xffff) @test binint("0b10000000000000000") === UInt32(0x00010000) @test binint("0b11111111111111111111111111111111") === UInt32(0xffffffff) @test binint("0b100000000000000000000000000000000") === UInt64(0x0000000100000000) @test binint("0b1111111111111111111111111111111111111111111111111111111111111111") === UInt64(0xffffffffffffffff) @test binint("0b10000000000000000000000000000000000000000000000000000000000000000") === UInt128(0x10000000000000000) @test binint("0b11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111") === UInt128(0xffffffffffffffffffffffffffffffff) @test begin n = binint("0b100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000") n isa BigInt && n == 340282366920938463463374607431768211456 end end @testset "BinInt string length limits for different types" begin @test binint("0b00000000") === UInt8(0) @test binint("0b000000000") === UInt16(0) @test binint("0b0000000000000000") === UInt16(0) @test binint("0b00000000000000000") === UInt32(0) @test binint("0b00000000000000000000000000000000") === UInt32(0) @test binint("0b000000000000000000000000000000000") === UInt64(0) @test binint("0b0000000000000000000000000000000000000000000000000000000000000000") === UInt64(0) @test binint("0b00000000000000000000000000000000000000000000000000000000000000000") === UInt128(0) @test binint("0b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000") === UInt128(0) @test begin n = binint("0b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000") n isa BigInt && n == 0 end end @testset "OctInt numeric limits for different types" begin @test octint("0o377") === UInt8(0xff) @test octint("0o400") === UInt16(0x0100) @test octint("0o177777") === UInt16(0xffff) @test octint("0o200000") === UInt32(0x00010000) @test octint("0o37777777777") === UInt32(0xffffffff) @test octint("0o40000000000") === UInt64(0x0000000100000000) @test octint("0o1777777777777777777777") === UInt64(0xffffffffffffffff) @test octint("0o2000000000000000000000") === UInt128(0x10000000000000000) @test octint("0o3777777777777777777777777777777777777777777") === UInt128(0xffffffffffffffffffffffffffffffff) @test begin n = octint("0o4000000000000000000000000000000000000000000") n isa BigInt && n == 340282366920938463463374607431768211456 end end @testset "OctInt string length limits for different types" begin @test octint("0o000") === UInt8(0) @test octint("0o0000") === UInt16(0) @test octint("0o000000") === UInt16(0) @test octint("0o0000000") === UInt32(0) @test octint("0o00000000000") === UInt32(0) @test octint("0o000000000000") === UInt64(0) @test octint("0o0000000000000000000000") === UInt64(0) @test octint("0o00000000000000000000000") === UInt128(0) @test octint("0o0000000000000000000000000000000000000000000") === UInt128(0) @test begin n = octint("0o00000000000000000000000000000000000000000000") n isa BigInt && n == 0 end end @testset "Underscore separators" begin @test parse_int_literal("10_000") === 10000 @test parse_uint_literal("0xff_ff", K"HexInt") === 0xffff @test parse_uint_literal("0b1111_1111", K"BinInt") === 0xff @test parse_uint_literal("0o177_777", K"OctInt") === 0xffff end @testset "\\minus ('\\u2212' / '−') allowed in numbers" begin @test parse_int_literal("−10") === -10 end end @testset "Integer parsing" begin @testset "Signed Integers" begin @test parse_int_literal("-1") isa Int @test parse_int_literal("1") isa Int @test parse_int_literal("2147483647") isa Int @test parse_int_literal("9223372036854775807") isa Int64 @test parse_int_literal("9223372036854775808") isa Int128 @test parse_int_literal("170141183460469231731687303715884105727") isa Int128 @test parse_int_literal("170141183460469231731687303715884105728") isa BigInt end @testset "HexInt numeric limits for different types" begin @test hexint("0xff") === UInt8(0xff) @test hexint("0x100") === UInt16(0x0100) @test hexint("0xffff") === UInt16(0xffff) @test hexint("0x10000") === UInt32(0x00010000) @test hexint("0xffffffff") === UInt32(0xffffffff) @test hexint("0x100000000") === UInt64(0x0000000100000000) @test hexint("0xffffffffffffffff") === UInt64(0xffffffffffffffff) @test hexint("0x10000000000000000") === UInt128(0x10000000000000000) @test hexint("0xffffffffffffffffffffffffffffffff") === UInt128(0xffffffffffffffffffffffffffffffff) @test begin n = hexint("0x100000000000000000000000000000000") n isa BigInt && n == 340282366920938463463374607431768211456 end end @testset "HexInt string length limits for different types" begin @test hexint("0x00") === UInt8(0) @test hexint("0x000") === UInt16(0) @test hexint("0x0000") === UInt16(0) @test hexint("0x00000") === UInt32(0) @test hexint("0x00000000") === UInt32(0) @test hexint("0x000000000") === UInt64(0) @test hexint("0x0000000000000000") === UInt64(0) @test hexint("0x00000000000000000") === UInt128(0) @test hexint("0x00000000000000000000000000000000") === UInt128(0) @test begin n = hexint("0x000000000000000000000000000000000") n isa BigInt && n == 0 end end @testset "BinInt numeric limits for different types" begin @test binint("0b11111111") === UInt8(0xff) @test binint("0b100000000") === UInt16(0x0100) @test binint("0b1111111111111111") === UInt16(0xffff) @test binint("0b10000000000000000") === UInt32(0x00010000) @test binint("0b11111111111111111111111111111111") === UInt32(0xffffffff) @test binint("0b100000000000000000000000000000000") === UInt64(0x0000000100000000) @test binint("0b1111111111111111111111111111111111111111111111111111111111111111") === UInt64(0xffffffffffffffff) @test binint("0b10000000000000000000000000000000000000000000000000000000000000000") === UInt128(0x10000000000000000) @test binint("0b11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111") === UInt128(0xffffffffffffffffffffffffffffffff) @test begin n = binint("0b100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000") n isa BigInt && n == 340282366920938463463374607431768211456 end end @testset "BinInt string length limits for different types" begin @test binint("0b00000000") === UInt8(0) @test binint("0b000000000") === UInt16(0) @test binint("0b0000000000000000") === UInt16(0) @test binint("0b00000000000000000") === UInt32(0) @test binint("0b00000000000000000000000000000000") === UInt32(0) @test binint("0b000000000000000000000000000000000") === UInt64(0) @test binint("0b0000000000000000000000000000000000000000000000000000000000000000") === UInt64(0) @test binint("0b00000000000000000000000000000000000000000000000000000000000000000") === UInt128(0) @test binint("0b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000") === UInt128(0) @test begin n = binint("0b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000") n isa BigInt && n == 0 end end @testset "OctInt numeric limits for different types" begin @test octint("0o377") === UInt8(0xff) @test octint("0o400") === UInt16(0x0100) @test octint("0o177777") === UInt16(0xffff) @test octint("0o200000") === UInt32(0x00010000) @test octint("0o37777777777") === UInt32(0xffffffff) @test octint("0o40000000000") === UInt64(0x0000000100000000) @test octint("0o1777777777777777777777") === UInt64(0xffffffffffffffff) @test octint("0o2000000000000000000000") === UInt128(0x10000000000000000) @test octint("0o3777777777777777777777777777777777777777777") === UInt128(0xffffffffffffffffffffffffffffffff) @test begin n = octint("0o4000000000000000000000000000000000000000000") n isa BigInt && n == 340282366920938463463374607431768211456 end end @testset "OctInt string length limits for different types" begin @test octint("0o000") === UInt8(0) @test octint("0o0000") === UInt16(0) @test octint("0o000000") === UInt16(0) @test octint("0o0000000") === UInt32(0) @test octint("0o00000000000") === UInt32(0) @test octint("0o000000000000") === UInt64(0) @test octint("0o0000000000000000000000") === UInt64(0) @test octint("0o00000000000000000000000") === UInt128(0) @test octint("0o0000000000000000000000000000000000000000000") === UInt128(0) @test begin n = octint("0o00000000000000000000000000000000000000000000") n isa BigInt && n == 0 end end @testset "Underscore separators" begin @test parse_int_literal("10_000") === 10000 @test parse_uint_literal("0xff_ff", K"HexInt") === 0xffff @test parse_uint_literal("0b1111_1111", K"BinInt") === 0xff @test parse_uint_literal("0o177_777", K"OctInt") === 0xffff end @testset "\\minus ('\\u2212' / '−') allowed in numbers" begin @test parse_int_literal("−10") === -10 end end @testset "Integer parsing" begin @testset "Signed Integers" begin @test parse_int_literal("-1") isa Int @test parse_int_literal("1") isa Int @test parse_int_literal("2147483647") isa Int @test parse_int_literal("9223372036854775807") isa Int64 @test parse_int_literal("9223372036854775808") isa Int128 @test parse_int_literal("170141183460469231731687303715884105727") isa Int128 @test parse_int_literal("170141183460469231731687303715884105728") isa BigInt end @testset "HexInt numeric limits for different types" begin @test hexint("0xff") === UInt8(0xff) @test hexint("0x100") === UInt16(0x0100) @test hexint("0xffff") === UInt16(0xffff) @test hexint("0x10000") === UInt32(0x00010000) @test hexint("0xffffffff") === UInt32(0xffffffff) @test hexint("0x100000000") === UInt64(0x0000000100000000) @test hexint("0xffffffffffffffff") === UInt64(0xffffffffffffffff) @test hexint("0x10000000000000000") === UInt128(0x10000000000000000) @test hexint("0xffffffffffffffffffffffffffffffff") === UInt128(0xffffffffffffffffffffffffffffffff) @test begin n = hexint("0x100000000000000000000000000000000") n isa BigInt && n == 340282366920938463463374607431768211456 end end @testset "HexInt string length limits for different types" begin @test hexint("0x00") === UInt8(0) @test hexint("0x000") === UInt16(0) @test hexint("0x0000") === UInt16(0) @test hexint("0x00000") === UInt32(0) @test hexint("0x00000000") === UInt32(0) @test hexint("0x000000000") === UInt64(0) @test hexint("0x0000000000000000") === UInt64(0) @test hexint("0x00000000000000000") === UInt128(0) @test hexint("0x00000000000000000000000000000000") === UInt128(0) @test begin n = hexint("0x000000000000000000000000000000000") n isa BigInt && n == 0 end end @testset "BinInt numeric limits for different types" begin @test binint("0b11111111") === UInt8(0xff) @test binint("0b100000000") === UInt16(0x0100) @test binint("0b1111111111111111") === UInt16(0xffff) @test binint("0b10000000000000000") === UInt32(0x00010000) @test binint("0b11111111111111111111111111111111") === UInt32(0xffffffff) @test binint("0b100000000000000000000000000000000") === UInt64(0x0000000100000000) @test binint("0b1111111111111111111111111111111111111111111111111111111111111111") === UInt64(0xffffffffffffffff) @test binint("0b10000000000000000000000000000000000000000000000000000000000000000") === UInt128(0x10000000000000000) @test binint("0b11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111") === UInt128(0xffffffffffffffffffffffffffffffff) @test begin n = binint("0b100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000") n isa BigInt && n == 340282366920938463463374607431768211456 end end @testset "BinInt string length limits for different types" begin @test binint("0b00000000") === UInt8(0) @test binint("0b000000000") === UInt16(0) @test binint("0b0000000000000000") === UInt16(0) @test binint("0b00000000000000000") === UInt32(0) @test binint("0b00000000000000000000000000000000") === UInt32(0) @test binint("0b000000000000000000000000000000000") === UInt64(0) @test binint("0b0000000000000000000000000000000000000000000000000000000000000000") === UInt64(0) @test binint("0b00000000000000000000000000000000000000000000000000000000000000000") === UInt128(0) @test binint("0b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000") === UInt128(0) @test begin n = binint("0b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000") n isa BigInt && n == 0 end end @testset "OctInt numeric limits for different types" begin @test octint("0o377") === UInt8(0xff) @test octint("0o400") === UInt16(0x0100) @test octint("0o177777") === UInt16(0xffff) @test octint("0o200000") === UInt32(0x00010000) @test octint("0o37777777777") === UInt32(0xffffffff) @test octint("0o40000000000") === UInt64(0x0000000100000000) @test octint("0o1777777777777777777777") === UInt64(0xffffffffffffffff) @test octint("0o2000000000000000000000") === UInt128(0x10000000000000000) @test octint("0o3777777777777777777777777777777777777777777") === UInt128(0xffffffffffffffffffffffffffffffff) @test begin n = octint("0o4000000000000000000000000000000000000000000") n isa BigInt && n == 340282366920938463463374607431768211456 end end @testset "OctInt string length limits for different types" begin @test octint("0o000") === UInt8(0) @test octint("0o0000") === UInt16(0) @test octint("0o000000") === UInt16(0) @test octint("0o0000000") === UInt32(0) @test octint("0o00000000000") === UInt32(0) @test octint("0o000000000000") === UInt64(0) @test octint("0o0000000000000000000000") === UInt64(0) @test octint("0o00000000000000000000000") === UInt128(0) @test octint("0o0000000000000000000000000000000000000000000") === UInt128(0) @test begin n = octint("0o00000000000000000000000000000000000000000000") n isa BigInt && n == 0 end end @testset "Underscore separators" begin @test parse_int_literal("10_000") === 10000 @test parse_uint_literal("0xff_ff", K"HexInt") === 0xffff @test parse_uint_literal("0b1111_1111", K"BinInt") === 0xff @test parse_uint_literal("0o177_777", K"OctInt") === 0xffff end @testset "\\minus ('\\u2212' / '−') allowed in numbers" begin @test parse_int_literal("−10") === -10 end end Parsing files in Base: Test Failed at /home/pkgeval/.julia/packages/CSTParser/0hXvH/test/test_check_base.jl:166 Expression: false Stacktrace: [1] top-level scope @ ~/.julia/packages/CSTParser/0hXvH/test/test_check_base.jl:166 [2] macro expansion @ /opt/julia/share/julia/stdlib/v1.13/Test/src/Test.jl:745 [inlined] ┌ Error: parsing difference │ file = "/opt/julia/bin/../share/julia/stdlib/v1.13/Distributed/src/workerpool.jl" └ @ Main.var"##439" ~/.julia/packages/CSTParser/0hXvH/test/test_check_base.jl:157 false begin end try wait(x) finally put!(pool, worker) end try wait(x) catch finally put!(pool, worker) end Threads.@spawn Threads.threadpool() try wait(x) finally put!(pool, worker) end Threads.@spawn Threads.threadpool() try wait(x) catch finally put!(pool, worker) end t = Threads.@spawn(Threads.threadpool(), try wait(x) finally put!(pool, worker) end) t = Threads.@spawn(Threads.threadpool(), try wait(x) catch finally put!(pool, worker) end) begin worker = take!(pool) local x try x = rc_f(f, worker, args...; kwargs...) catch put!(pool, worker) rethrow() end t = Threads.@spawn(Threads.threadpool(), try wait(x) finally put!(pool, worker) end) errormonitor(t) return x end begin worker = take!(pool) local x try x = rc_f(f, worker, args...; kwargs...) catch put!(pool, worker) rethrow() end t = Threads.@spawn(Threads.threadpool(), try wait(x) catch finally put!(pool, worker) end) errormonitor(t) return x end function remotecall_pool(rc_f::typeof(remotecall), f, pool::AbstractWorkerPool, args...; kwargs...) worker = take!(pool) local x try x = rc_f(f, worker, args...; kwargs...) catch put!(pool, worker) rethrow() end t = Threads.@spawn(Threads.threadpool(), try wait(x) finally put!(pool, worker) end) errormonitor(t) return x end function remotecall_pool(rc_f::typeof(remotecall), f, pool::AbstractWorkerPool, args...; kwargs...) worker = take!(pool) local x try x = rc_f(f, worker, args...; kwargs...) catch put!(pool, worker) rethrow() end t = Threads.@spawn(Threads.threadpool(), try wait(x) catch finally put!(pool, worker) end) errormonitor(t) return x end false begin end try wait(x) finally put!(pool, worker) end try wait(x) catch finally put!(pool, worker) end Threads.@spawn Threads.threadpool() try wait(x) finally put!(pool, worker) end Threads.@spawn Threads.threadpool() try wait(x) catch finally put!(pool, worker) end t = Threads.@spawn(Threads.threadpool(), try wait(x) finally put!(pool, worker) end) t = Threads.@spawn(Threads.threadpool(), try wait(x) catch finally put!(pool, worker) end) begin worker = take!(pool) f_ref = get(pool.map_obj2ref, (worker, f), (f, RemoteChannel(worker))) f_ref isa Tuple && (pool.map_obj2ref[(worker, f)] = f_ref[2]) local x try x = rc_f(exec_from_cache, worker, f_ref, args...; kwargs...) catch put!(pool, worker) rethrow() end t = Threads.@spawn(Threads.threadpool(), try wait(x) finally put!(pool, worker) end) errormonitor(t) return x end begin worker = take!(pool) f_ref = get(pool.map_obj2ref, (worker, f), (f, RemoteChannel(worker))) f_ref isa Tuple && (pool.map_obj2ref[(worker, f)] = f_ref[2]) local x try x = rc_f(exec_from_cache, worker, f_ref, args...; kwargs...) catch put!(pool, worker) rethrow() end t = Threads.@spawn(Threads.threadpool(), try wait(x) catch finally put!(pool, worker) end) errormonitor(t) return x end function remotecall_pool(rc_f::typeof(remotecall), f, pool::CachingPool, args...; kwargs...) worker = take!(pool) f_ref = get(pool.map_obj2ref, (worker, f), (f, RemoteChannel(worker))) f_ref isa Tuple && (pool.map_obj2ref[(worker, f)] = f_ref[2]) local x try x = rc_f(exec_from_cache, worker, f_ref, args...; kwargs...) catch put!(pool, worker) rethrow() end t = Threads.@spawn(Threads.threadpool(), try wait(x) finally put!(pool, worker) end) errormonitor(t) return x end function remotecall_pool(rc_f::typeof(remotecall), f, pool::CachingPool, args...; kwargs...) worker = take!(pool) f_ref = get(pool.map_obj2ref, (worker, f), (f, RemoteChannel(worker))) f_ref isa Tuple && (pool.map_obj2ref[(worker, f)] = f_ref[2]) local x try x = rc_f(exec_from_cache, worker, f_ref, args...; kwargs...) catch put!(pool, worker) rethrow() end t = Threads.@spawn(Threads.threadpool(), try wait(x) catch finally put!(pool, worker) end) errormonitor(t) return x end Parsing files in Base: Test Failed at /home/pkgeval/.julia/packages/CSTParser/0hXvH/test/test_check_base.jl:166 Expression: false Stacktrace: [1] top-level scope @ ~/.julia/packages/CSTParser/0hXvH/test/test_check_base.jl:166 [2] macro expansion @ /opt/julia/share/julia/stdlib/v1.13/Test/src/Test.jl:745 [inlined] Parsing files in Base: Test Failed at /home/pkgeval/.julia/packages/CSTParser/0hXvH/test/test_check_base.jl:143 Expression: cst_err == meta_err Evaluated: true == false Stacktrace: [1] top-level scope @ ~/.julia/packages/CSTParser/0hXvH/test/test_check_base.jl:143 [2] macro expansion @ /opt/julia/share/julia/stdlib/v1.13/Test/src/Test.jl:745 [inlined] ┌ Error: CSTParser.parse errored, but Meta.parse didn't. │ file = "/opt/julia/bin/../share/julia/stdlib/v1.13/InteractiveUtils/src/macros.jl" └ @ Main.var"##439" ~/.julia/packages/CSTParser/0hXvH/test/test_check_base.jl:149 ┌ Error: parsing difference │ file = "/opt/julia/bin/../share/julia/stdlib/v1.13/InteractiveUtils/test/runtests.jl" └ @ Main.var"##439" ~/.julia/packages/CSTParser/0hXvH/test/test_check_base.jl:157 @code_typed optimize = false ::Vector{Int} .= ::Int @code_typed optimize = (false::Vector{Int} .= ::Int) false false::Vector{Int} .= ::Int optimize = false optimize = (false::Vector{Int} .= ::Int) @code_typed optimize = false ::Vector{Int} .= ::Int @code_typed optimize = (false::Vector{Int} .= ::Int) (@code_typed(optimize = false, ::Vector{Int} .= ::Int))[2] (@code_typed(optimize = (false::Vector{Int} .= ::Int)))[2] (@code_typed(optimize = false, ::Vector{Int} .= ::Int))[2] == Vector{Int} (@code_typed(optimize = (false::Vector{Int} .= ::Int)))[2] == Vector{Int} @test (@code_typed(optimize = false, ::Vector{Int} .= ::Int))[2] == Vector{Int} @test (@code_typed(optimize = (false::Vector{Int} .= ::Int)))[2] == Vector{Int} @code_typed optimize = false ::Vector{Float64} .= 1 .+ ::Vector{Int} @code_typed optimize = (false::Vector{Float64} .= 1 .+ ::Vector{Int}) false false::Vector{Float64} .= 1 .+ ::Vector{Int} optimize = false optimize = (false::Vector{Float64} .= 1 .+ ::Vector{Int}) @code_typed optimize = false ::Vector{Float64} .= 1 .+ ::Vector{Int} @code_typed optimize = (false::Vector{Float64} .= 1 .+ ::Vector{Int}) (@code_typed(optimize = false, ::Vector{Float64} .= 1 .+ ::Vector{Int}))[2] (@code_typed(optimize = (false::Vector{Float64} .= 1 .+ ::Vector{Int})))[2] (@code_typed(optimize = false, ::Vector{Float64} .= 1 .+ ::Vector{Int}))[2] == Vector{Float64} (@code_typed(optimize = (false::Vector{Float64} .= 1 .+ ::Vector{Int})))[2] == Vector{Float64} @test (@code_typed(optimize = false, ::Vector{Float64} .= 1 .+ ::Vector{Int}))[2] == Vector{Float64} @test (@code_typed(optimize = (false::Vector{Float64} .= 1 .+ ::Vector{Int})))[2] == Vector{Float64} @code_typed optimize = false ::Vector{Float64} .= 1 .+ round.(base = ::Int, ::Vector{Int}; digits = 3) @code_typed optimize = (false::Vector{Float64} .= 1 .+ round.(base = ::Int, ::Vector{Int}; digits = 3)) false false::Vector{Float64} .= 1 .+ round.(base = ::Int, ::Vector{Int}; digits = 3) optimize = false optimize = (false::Vector{Float64} .= 1 .+ round.(base = ::Int, ::Vector{Int}; digits = 3)) @code_typed optimize = false ::Vector{Float64} .= 1 .+ round.(base = ::Int, ::Vector{Int}; digits = 3) @code_typed optimize = (false::Vector{Float64} .= 1 .+ round.(base = ::Int, ::Vector{Int}; digits = 3)) (@code_typed(optimize = false, ::Vector{Float64} .= 1 .+ round.(base = ::Int, ::Vector{Int}; digits = 3)))[2] (@code_typed(optimize = (false::Vector{Float64} .= 1 .+ round.(base = ::Int, ::Vector{Int}; digits = 3))))[2] (@code_typed(optimize = false, ::Vector{Float64} .= 1 .+ round.(base = ::Int, ::Vector{Int}; digits = 3)))[2] == Vector{Float64} (@code_typed(optimize = (false::Vector{Float64} .= 1 .+ round.(base = ::Int, ::Vector{Int}; digits = 3))))[2] == Vector{Float64} @test (@code_typed(optimize = false, ::Vector{Float64} .= 1 .+ round.(base = ::Int, ::Vector{Int}; digits = 3)))[2] == Vector{Float64} @test (@code_typed(optimize = (false::Vector{Float64} .= 1 .+ round.(base = ::Int, ::Vector{Int}; digits = 3))))[2] == Vector{Float64} begin @test (@which((::Vector{Int})[::Int])).name === :getindex @test (@which((::Vector{Int})[::Int] = ::Int)).name === :setindex! @test (@which((::Base.RefValue{Int}).x)).name === :getproperty @test (@which((::Base.RefValue{Int}).x = ::Int)).name === :setproperty! @test (@which(::Float64 ^ 2)).name === :literal_pow @test (@which([::Int])).name === :vect @test (@which([undef_var::Int])).name === :vect @test (@which([::Int 2])).name === :hcat @test (@which([::Int; 2])).name === :vcat @test (@which(Int[::Int 2])).name === :typed_hcat @test (@which(Int[::Int; 2])).name === :typed_vcat @test (@which([::Int 2; 3 ::Int])).name === :hvcat @test (@which(Int[::Int 2; 3 ::Int])).name === :typed_hvcat @test (@which((::Vector{Float64})')).name === :adjoint @test (@which("$(::Symbol) is a symbol")).sig === Tuple{typeof(string), Vararg{Union{Char, String, Symbol}}} @test (@which(some_x::Int + some_y::Float64)).name === :+ @test (@which(+(::Any, ::Any, ::Any, ::Any...))).sig === Tuple{typeof(+), Any, Any, Any, Vararg{Any}} @test (@which(::Any + ::Any + ::Any + ::Vararg{Any})).sig === Tuple{typeof(+), Any, Any, Any, Vararg{Any}} n = length(@code_typed(::Float64 + ::Vararg{Float64})) @test n ≥ 2 @test length(@code_typed(+(::Float64, ::Float64...))) == n @test (@which(1 + ::Float64)).sig === Tuple{typeof(+), Number, Number} @test (@which(+(((1, 2)...)))).name === :+ @test (@which((::typeof(+))(::Int, ::Float64))).sig === Tuple{typeof(+), Number, Number} @test @code_typed(::Float64 .+ ::Vector{Float64}) isa Pair @test @code_typed(::Float64 .+ ::Vector{Float64} .* ::Int) isa Pair @test (@which((::T + ::T) where T <: Number)).sig === (Tuple{typeof(+), T, T} where T <: Number) @test (@which(round(::Float64; digits = 3))).name === :round @test (@which(round(1.2; digits = ::Int))).name === :round @test (@which(round(1.2; digits::Int))).name === :round @test (@code_typed(round(::T; digits = ::T) where T <: Float64))[2] === Union{} @test (@code_typed(round(::T; digits = ::T) where T <: Int))[2] === Float64 base = 10 kwargs_1 = (; digits = 3) kwargs_2 = (; sigdigits = 3) @test (@which(round(1.2; kwargs_1...))).name === :round @test (@which(round(1.2; digits = 1, kwargs_1...))).name === :round @test (@code_typed(round(1.2; digits = ::Float64, kwargs_1...)))[2] === Float64 @test (@code_typed(round(1.2; kwargs_1..., digits = ::Float64)))[2] === Union{} @test (@which(round(1.2; digits = ::Float64, kwargs_1...))).name === :round @test (@which(round(1.2; sigdigits = ::Int, kwargs_1...))).name === :round @test (@which(round(1.2; kwargs_1..., kwargs_2..., base))).name === :round @test (@code_typed(optimize = false, round.([1.0, 2.0]; digits = ::Int64)))[2] == Vector{Float64} @test (@code_typed(optimize = false, round.(::Vector{Float64}, base = 2; digits = ::Int64)))[2] == Vector{Float64} @test (@code_typed(optimize = false, round.(base = ::Int64, ::Vector{Float64}; digits = ::Int64)))[2] == Vector{Float64} @test (@code_typed(optimize = false, [1, 2] .= ::Int))[2] == Vector{Int} @test (@code_typed(optimize = false, ::Vector{Int} .= ::Int))[2] == Vector{Int} @test (@code_typed(optimize = false, ::Vector{Float64} .= 1 .+ ::Vector{Int}))[2] == Vector{Float64} @test (@code_typed(optimize = false, ::Vector{Float64} .= 1 .+ round.(base = ::Int, ::Vector{Int}; digits = 3)))[2] == Vector{Float64} end begin @test (@which((::Vector{Int})[::Int])).name === :getindex @test (@which((::Vector{Int})[::Int] = ::Int)).name === :setindex! @test (@which((::Base.RefValue{Int}).x)).name === :getproperty @test (@which((::Base.RefValue{Int}).x = ::Int)).name === :setproperty! @test (@which(::Float64 ^ 2)).name === :literal_pow @test (@which([::Int])).name === :vect @test (@which([undef_var::Int])).name === :vect @test (@which([::Int 2])).name === :hcat @test (@which([::Int; 2])).name === :vcat @test (@which(Int[::Int 2])).name === :typed_hcat @test (@which(Int[::Int; 2])).name === :typed_vcat @test (@which([::Int 2; 3 ::Int])).name === :hvcat @test (@which(Int[::Int 2; 3 ::Int])).name === :typed_hvcat @test (@which((::Vector{Float64})')).name === :adjoint @test (@which("$(::Symbol) is a symbol")).sig === Tuple{typeof(string), Vararg{Union{Char, String, Symbol}}} @test (@which(some_x::Int + some_y::Float64)).name === :+ @test (@which(+(::Any, ::Any, ::Any, ::Any...))).sig === Tuple{typeof(+), Any, Any, Any, Vararg{Any}} @test (@which(::Any + ::Any + ::Any + ::Vararg{Any})).sig === Tuple{typeof(+), Any, Any, Any, Vararg{Any}} n = length(@code_typed(::Float64 + ::Vararg{Float64})) @test n ≥ 2 @test length(@code_typed(+(::Float64, ::Float64...))) == n @test (@which(1 + ::Float64)).sig === Tuple{typeof(+), Number, Number} @test (@which(+(((1, 2)...)))).name === :+ @test (@which((::typeof(+))(::Int, ::Float64))).sig === Tuple{typeof(+), Number, Number} @test @code_typed(::Float64 .+ ::Vector{Float64}) isa Pair @test @code_typed(::Float64 .+ ::Vector{Float64} .* ::Int) isa Pair @test (@which((::T + ::T) where T <: Number)).sig === (Tuple{typeof(+), T, T} where T <: Number) @test (@which(round(::Float64; digits = 3))).name === :round @test (@which(round(1.2; digits = ::Int))).name === :round @test (@which(round(1.2; digits::Int))).name === :round @test (@code_typed(round(::T; digits = ::T) where T <: Float64))[2] === Union{} @test (@code_typed(round(::T; digits = ::T) where T <: Int))[2] === Float64 base = 10 kwargs_1 = (; digits = 3) kwargs_2 = (; sigdigits = 3) @test (@which(round(1.2; kwargs_1...))).name === :round @test (@which(round(1.2; digits = 1, kwargs_1...))).name === :round @test (@code_typed(round(1.2; digits = ::Float64, kwargs_1...)))[2] === Float64 @test (@code_typed(round(1.2; kwargs_1..., digits = ::Float64)))[2] === Union{} @test (@which(round(1.2; digits = ::Float64, kwargs_1...))).name === :round @test (@which(round(1.2; sigdigits = ::Int, kwargs_1...))).name === :round @test (@which(round(1.2; kwargs_1..., kwargs_2..., base))).name === :round @test (@code_typed(optimize = false, round.([1.0, 2.0]; digits = ::Int64)))[2] == Vector{Float64} @test (@code_typed(optimize = false, round.(::Vector{Float64}, base = 2; digits = ::Int64)))[2] == Vector{Float64} @test (@code_typed(optimize = false, round.(base = ::Int64, ::Vector{Float64}; digits = ::Int64)))[2] == Vector{Float64} @test (@code_typed(optimize = false, [1, 2] .= ::Int))[2] == Vector{Int} @test (@code_typed(optimize = (false::Vector{Int} .= ::Int)))[2] == Vector{Int} @test (@code_typed(optimize = (false::Vector{Float64} .= 1 .+ ::Vector{Int})))[2] == Vector{Float64} @test (@code_typed(optimize = (false::Vector{Float64} .= 1 .+ round.(base = ::Int, ::Vector{Int}; digits = 3))))[2] == Vector{Float64} end @testset "Support for type annotations as arguments" begin @test (@which((::Vector{Int})[::Int])).name === :getindex @test (@which((::Vector{Int})[::Int] = ::Int)).name === :setindex! @test (@which((::Base.RefValue{Int}).x)).name === :getproperty @test (@which((::Base.RefValue{Int}).x = ::Int)).name === :setproperty! @test (@which(::Float64 ^ 2)).name === :literal_pow @test (@which([::Int])).name === :vect @test (@which([undef_var::Int])).name === :vect @test (@which([::Int 2])).name === :hcat @test (@which([::Int; 2])).name === :vcat @test (@which(Int[::Int 2])).name === :typed_hcat @test (@which(Int[::Int; 2])).name === :typed_vcat @test (@which([::Int 2; 3 ::Int])).name === :hvcat @test (@which(Int[::Int 2; 3 ::Int])).name === :typed_hvcat @test (@which((::Vector{Float64})')).name === :adjoint @test (@which("$(::Symbol) is a symbol")).sig === Tuple{typeof(string), Vararg{Union{Char, String, Symbol}}} @test (@which(some_x::Int + some_y::Float64)).name === :+ @test (@which(+(::Any, ::Any, ::Any, ::Any...))).sig === Tuple{typeof(+), Any, Any, Any, Vararg{Any}} @test (@which(::Any + ::Any + ::Any + ::Vararg{Any})).sig === Tuple{typeof(+), Any, Any, Any, Vararg{Any}} n = length(@code_typed(::Float64 + ::Vararg{Float64})) @test n ≥ 2 @test length(@code_typed(+(::Float64, ::Float64...))) == n @test (@which(1 + ::Float64)).sig === Tuple{typeof(+), Number, Number} @test (@which(+(((1, 2)...)))).name === :+ @test (@which((::typeof(+))(::Int, ::Float64))).sig === Tuple{typeof(+), Number, Number} @test @code_typed(::Float64 .+ ::Vector{Float64}) isa Pair @test @code_typed(::Float64 .+ ::Vector{Float64} .* ::Int) isa Pair @test (@which((::T + ::T) where T <: Number)).sig === (Tuple{typeof(+), T, T} where T <: Number) @test (@which(round(::Float64; digits = 3))).name === :round @test (@which(round(1.2; digits = ::Int))).name === :round @test (@which(round(1.2; digits::Int))).name === :round @test (@code_typed(round(::T; digits = ::T) where T <: Float64))[2] === Union{} @test (@code_typed(round(::T; digits = ::T) where T <: Int))[2] === Float64 base = 10 kwargs_1 = (; digits = 3) kwargs_2 = (; sigdigits = 3) @test (@which(round(1.2; kwargs_1...))).name === :round @test (@which(round(1.2; digits = 1, kwargs_1...))).name === :round @test (@code_typed(round(1.2; digits = ::Float64, kwargs_1...)))[2] === Float64 @test (@code_typed(round(1.2; kwargs_1..., digits = ::Float64)))[2] === Union{} @test (@which(round(1.2; digits = ::Float64, kwargs_1...))).name === :round @test (@which(round(1.2; sigdigits = ::Int, kwargs_1...))).name === :round @test (@which(round(1.2; kwargs_1..., kwargs_2..., base))).name === :round @test (@code_typed(optimize = false, round.([1.0, 2.0]; digits = ::Int64)))[2] == Vector{Float64} @test (@code_typed(optimize = false, round.(::Vector{Float64}, base = 2; digits = ::Int64)))[2] == Vector{Float64} @test (@code_typed(optimize = false, round.(base = ::Int64, ::Vector{Float64}; digits = ::Int64)))[2] == Vector{Float64} @test (@code_typed(optimize = false, [1, 2] .= ::Int))[2] == Vector{Int} @test (@code_typed(optimize = false, ::Vector{Int} .= ::Int))[2] == Vector{Int} @test (@code_typed(optimize = false, ::Vector{Float64} .= 1 .+ ::Vector{Int}))[2] == Vector{Float64} @test (@code_typed(optimize = false, ::Vector{Float64} .= 1 .+ round.(base = ::Int, ::Vector{Int}; digits = 3)))[2] == Vector{Float64} end @testset "Support for type annotations as arguments" begin @test (@which((::Vector{Int})[::Int])).name === :getindex @test (@which((::Vector{Int})[::Int] = ::Int)).name === :setindex! @test (@which((::Base.RefValue{Int}).x)).name === :getproperty @test (@which((::Base.RefValue{Int}).x = ::Int)).name === :setproperty! @test (@which(::Float64 ^ 2)).name === :literal_pow @test (@which([::Int])).name === :vect @test (@which([undef_var::Int])).name === :vect @test (@which([::Int 2])).name === :hcat @test (@which([::Int; 2])).name === :vcat @test (@which(Int[::Int 2])).name === :typed_hcat @test (@which(Int[::Int; 2])).name === :typed_vcat @test (@which([::Int 2; 3 ::Int])).name === :hvcat @test (@which(Int[::Int 2; 3 ::Int])).name === :typed_hvcat @test (@which((::Vector{Float64})')).name === :adjoint @test (@which("$(::Symbol) is a symbol")).sig === Tuple{typeof(string), Vararg{Union{Char, String, Symbol}}} @test (@which(some_x::Int + some_y::Float64)).name === :+ @test (@which(+(::Any, ::Any, ::Any, ::Any...))).sig === Tuple{typeof(+), Any, Any, Any, Vararg{Any}} @test (@which(::Any + ::Any + ::Any + ::Vararg{Any})).sig === Tuple{typeof(+), Any, Any, Any, Vararg{Any}} n = length(@code_typed(::Float64 + ::Vararg{Float64})) @test n ≥ 2 @test length(@code_typed(+(::Float64, ::Float64...))) == n @test (@which(1 + ::Float64)).sig === Tuple{typeof(+), Number, Number} @test (@which(+(((1, 2)...)))).name === :+ @test (@which((::typeof(+))(::Int, ::Float64))).sig === Tuple{typeof(+), Number, Number} @test @code_typed(::Float64 .+ ::Vector{Float64}) isa Pair @test @code_typed(::Float64 .+ ::Vector{Float64} .* ::Int) isa Pair @test (@which((::T + ::T) where T <: Number)).sig === (Tuple{typeof(+), T, T} where T <: Number) @test (@which(round(::Float64; digits = 3))).name === :round @test (@which(round(1.2; digits = ::Int))).name === :round @test (@which(round(1.2; digits::Int))).name === :round @test (@code_typed(round(::T; digits = ::T) where T <: Float64))[2] === Union{} @test (@code_typed(round(::T; digits = ::T) where T <: Int))[2] === Float64 base = 10 kwargs_1 = (; digits = 3) kwargs_2 = (; sigdigits = 3) @test (@which(round(1.2; kwargs_1...))).name === :round @test (@which(round(1.2; digits = 1, kwargs_1...))).name === :round @test (@code_typed(round(1.2; digits = ::Float64, kwargs_1...)))[2] === Float64 @test (@code_typed(round(1.2; kwargs_1..., digits = ::Float64)))[2] === Union{} @test (@which(round(1.2; digits = ::Float64, kwargs_1...))).name === :round @test (@which(round(1.2; sigdigits = ::Int, kwargs_1...))).name === :round @test (@which(round(1.2; kwargs_1..., kwargs_2..., base))).name === :round @test (@code_typed(optimize = false, round.([1.0, 2.0]; digits = ::Int64)))[2] == Vector{Float64} @test (@code_typed(optimize = false, round.(::Vector{Float64}, base = 2; digits = ::Int64)))[2] == Vector{Float64} @test (@code_typed(optimize = false, round.(base = ::Int64, ::Vector{Float64}; digits = ::Int64)))[2] == Vector{Float64} @test (@code_typed(optimize = false, [1, 2] .= ::Int))[2] == Vector{Int} @test (@code_typed(optimize = (false::Vector{Int} .= ::Int)))[2] == Vector{Int} @test (@code_typed(optimize = (false::Vector{Float64} .= 1 .+ ::Vector{Int})))[2] == Vector{Float64} @test (@code_typed(optimize = (false::Vector{Float64} .= 1 .+ round.(base = ::Int, ::Vector{Int}; digits = 3))))[2] == Vector{Float64} end Parsing files in Base: Test Failed at /home/pkgeval/.julia/packages/CSTParser/0hXvH/test/test_check_base.jl:166 Expression: false Stacktrace: [1] top-level scope @ ~/.julia/packages/CSTParser/0hXvH/test/test_check_base.jl:166 [2] macro expansion @ /opt/julia/share/julia/stdlib/v1.13/Test/src/Test.jl:745 [inlined] ┌ Error: parsing difference │ file = "/opt/julia/bin/../share/julia/stdlib/v1.13/Printf/test/runtests.jl" └ @ Main.var"##439" ~/.julia/packages/CSTParser/0hXvH/test/test_check_base.jl:157 Printf.@sprintf "%a" 1.5 Printf.@sprintf "%a" 1.5 Printf.@sprintf("%a", 1.5) == "0x1.8p+0" Printf.@sprintf("%a", 1.5) == "0x1.8p+0" @test Printf.@sprintf("%a", 1.5) == "0x1.8p+0" @test Printf.@sprintf("%a", 1.5) == "0x1.8p+0" begin @test Printf.@sprintf("%a", 0.0) == "0x0p+0" @test Printf.@sprintf("%a", -0.0) == "-0x0p+0" @test Printf.@sprintf("%.3a", 0.0) == "0x0.000p+0" @test Printf.@sprintf("%a", 1.5) == "0x1.8p+0" @test Printf.@sprintf("%a", 1.5f0) == "0x1.8p+0" @test Printf.@sprintf("%a", 1.5) == "0x1.8p+0" @test Printf.@sprintf("%#.0a", 1.5) == "0x2.p+0" @test Printf.@sprintf("%+30a", 1 / 3) == " +0x1.5555555555555p-2" @test Printf.@sprintf("%a", 1.5) == "0x1.8p+0" @test Printf.@sprintf("%a", 3.14) == "0x1.91eb851eb851fp+1" @test Printf.@sprintf("%.0a", 3.14) == "0x2p+1" @test Printf.@sprintf("%.1a", 3.14) == "0x1.9p+1" @test Printf.@sprintf("%.2a", 3.14) == "0x1.92p+1" @test Printf.@sprintf("%#a", 3.14) == "0x1.91eb851eb851fp+1" @test Printf.@sprintf("%#.0a", 3.14) == "0x2.p+1" @test Printf.@sprintf("%#.1a", 3.14) == "0x1.9p+1" @test Printf.@sprintf("%#.2a", 3.14) == "0x1.92p+1" @test Printf.@sprintf("%.6a", 1.5) == "0x1.800000p+0" end begin @test Printf.@sprintf("%a", 0.0) == "0x0p+0" @test Printf.@sprintf("%a", -0.0) == "-0x0p+0" @test Printf.@sprintf("%.3a", 0.0) == "0x0.000p+0" @test Printf.@sprintf("%a", 1.5) == "0x1.8p+0" @test Printf.@sprintf("%a", 1.5f0) == "0x1.8p+0" @test Printf.@sprintf("%a", 1.5) == "0x1.8p+0" @test Printf.@sprintf("%#.0a", 1.5) == "0x2.p+0" @test Printf.@sprintf("%+30a", 1 / 3) == " +0x1.5555555555555p-2" @test Printf.@sprintf("%a", 1.5) == "0x1.8p+0" @test Printf.@sprintf("%a", 3.14) == "0x1.91eb851eb851fp+1" @test Printf.@sprintf("%.0a", 3.14) == "0x2p+1" @test Printf.@sprintf("%.1a", 3.14) == "0x1.9p+1" @test Printf.@sprintf("%.2a", 3.14) == "0x1.92p+1" @test Printf.@sprintf("%#a", 3.14) == "0x1.91eb851eb851fp+1" @test Printf.@sprintf("%#.0a", 3.14) == "0x2.p+1" @test Printf.@sprintf("%#.1a", 3.14) == "0x1.9p+1" @test Printf.@sprintf("%#.2a", 3.14) == "0x1.92p+1" @test Printf.@sprintf("%.6a", 1.5) == "0x1.800000p+0" end @testset "%a" begin @test Printf.@sprintf("%a", 0.0) == "0x0p+0" @test Printf.@sprintf("%a", -0.0) == "-0x0p+0" @test Printf.@sprintf("%.3a", 0.0) == "0x0.000p+0" @test Printf.@sprintf("%a", 1.5) == "0x1.8p+0" @test Printf.@sprintf("%a", 1.5f0) == "0x1.8p+0" @test Printf.@sprintf("%a", 1.5) == "0x1.8p+0" @test Printf.@sprintf("%#.0a", 1.5) == "0x2.p+0" @test Printf.@sprintf("%+30a", 1 / 3) == " +0x1.5555555555555p-2" @test Printf.@sprintf("%a", 1.5) == "0x1.8p+0" @test Printf.@sprintf("%a", 3.14) == "0x1.91eb851eb851fp+1" @test Printf.@sprintf("%.0a", 3.14) == "0x2p+1" @test Printf.@sprintf("%.1a", 3.14) == "0x1.9p+1" @test Printf.@sprintf("%.2a", 3.14) == "0x1.92p+1" @test Printf.@sprintf("%#a", 3.14) == "0x1.91eb851eb851fp+1" @test Printf.@sprintf("%#.0a", 3.14) == "0x2.p+1" @test Printf.@sprintf("%#.1a", 3.14) == "0x1.9p+1" @test Printf.@sprintf("%#.2a", 3.14) == "0x1.92p+1" @test Printf.@sprintf("%.6a", 1.5) == "0x1.800000p+0" end @testset "%a" begin @test Printf.@sprintf("%a", 0.0) == "0x0p+0" @test Printf.@sprintf("%a", -0.0) == "-0x0p+0" @test Printf.@sprintf("%.3a", 0.0) == "0x0.000p+0" @test Printf.@sprintf("%a", 1.5) == "0x1.8p+0" @test Printf.@sprintf("%a", 1.5f0) == "0x1.8p+0" @test Printf.@sprintf("%a", 1.5) == "0x1.8p+0" @test Printf.@sprintf("%#.0a", 1.5) == "0x2.p+0" @test Printf.@sprintf("%+30a", 1 / 3) == " +0x1.5555555555555p-2" @test Printf.@sprintf("%a", 1.5) == "0x1.8p+0" @test Printf.@sprintf("%a", 3.14) == "0x1.91eb851eb851fp+1" @test Printf.@sprintf("%.0a", 3.14) == "0x2p+1" @test Printf.@sprintf("%.1a", 3.14) == "0x1.9p+1" @test Printf.@sprintf("%.2a", 3.14) == "0x1.92p+1" @test Printf.@sprintf("%#a", 3.14) == "0x1.91eb851eb851fp+1" @test Printf.@sprintf("%#.0a", 3.14) == "0x2.p+1" @test Printf.@sprintf("%#.1a", 3.14) == "0x1.9p+1" @test Printf.@sprintf("%#.2a", 3.14) == "0x1.92p+1" @test Printf.@sprintf("%.6a", 1.5) == "0x1.800000p+0" end (1.2345678e7, "1.23457e+07") (1.2345678e7, "1.23457e+07") (1.234567799999999999999999999999999999999999999999999999999999999999999999999993e6, "1.23457e+06") (1.234567799999999999999999999999999999999999999999999999999999999999999999999993e6, "1.23457e+06") (123456.7800000000000000000000000000000000000000000000000000000000000000000000004, "123457") (123456.7800000000000000000000000000000000000000000000000000000000000000000000004, "123457") (12345.67800000000000000000000000000000000000000000000000000000000000000000000007, "12345.7") (12345.67800000000000000000000000000000000000000000000000000000000000000000000007, "12345.7") ((1.2345678e7, "1.23457e+07"), (1.234567799999999999999999999999999999999999999999999999999999999999999999999993e6, "1.23457e+06"), (123456.7800000000000000000000000000000000000000000000000000000000000000000000004, "123457"), (12345.67800000000000000000000000000000000000000000000000000000000000000000000007, "12345.7")) ((1.2345678e7, "1.23457e+07"), (1.234567799999999999999999999999999999999999999999999999999999999999999999999993e6, "1.23457e+06"), (123456.7800000000000000000000000000000000000000000000000000000000000000000000004, "123457"), (12345.67800000000000000000000000000000000000000000000000000000000000000000000007, "12345.7")) (val, res) = ((1.2345678e7, "1.23457e+07"), (1.234567799999999999999999999999999999999999999999999999999999999999999999999993e6, "1.23457e+06"), (123456.7800000000000000000000000000000000000000000000000000000000000000000000004, "123457"), (12345.67800000000000000000000000000000000000000000000000000000000000000000000007, "12345.7")) (val, res) = ((1.2345678e7, "1.23457e+07"), (1.234567799999999999999999999999999999999999999999999999999999999999999999999993e6, "1.23457e+06"), (123456.7800000000000000000000000000000000000000000000000000000000000000000000004, "123457"), (12345.67800000000000000000000000000000000000000000000000000000000000000000000007, "12345.7")) for (val, res) = ((1.2345678e7, "1.23457e+07"), (1.234567799999999999999999999999999999999999999999999999999999999999999999999993e6, "1.23457e+06"), (123456.7800000000000000000000000000000000000000000000000000000000000000000000004, "123457"), (12345.67800000000000000000000000000000000000000000000000000000000000000000000007, "12345.7")) @test Printf.@sprintf("%.6g", val) == res end for (val, res) = ((1.2345678e7, "1.23457e+07"), (1.234567799999999999999999999999999999999999999999999999999999999999999999999993e6, "1.23457e+06"), (123456.7800000000000000000000000000000000000000000000000000000000000000000000004, "123457"), (12345.67800000000000000000000000000000000000000000000000000000000000000000000007, "12345.7")) @test Printf.@sprintf("%.6g", val) == res end (123.4, 123.4000000000000000000000000000000000000000000000000000000000000000000000000002) (123.4, 123.4000000000000000000000000000000000000000000000000000000000000000000000000002) num = (123.4, 123.4000000000000000000000000000000000000000000000000000000000000000000000000002) num = (123.4, 123.4000000000000000000000000000000000000000000000000000000000000000000000000002) begin (fmt, val) = (("%10.5g", " 123.4"), ("%+10.5g", " +123.4"), ("% 10.5g", " 123.4"), ("%#10.5g", " 123.40"), ("%-10.5g", "123.4 "), ("%-+10.5g", "+123.4 "), ("%010.5g", "00000123.4")) num = (123.4, 123.4000000000000000000000000000000000000000000000000000000000000000000000000002) end begin (fmt, val) = (("%10.5g", " 123.4"), ("%+10.5g", " +123.4"), ("% 10.5g", " 123.4"), ("%#10.5g", " 123.40"), ("%-10.5g", "123.4 "), ("%-+10.5g", "+123.4 "), ("%010.5g", "00000123.4")) num = (123.4, 123.4000000000000000000000000000000000000000000000000000000000000000000000000002) end for (fmt, val) = (("%10.5g", " 123.4"), ("%+10.5g", " +123.4"), ("% 10.5g", " 123.4"), ("%#10.5g", " 123.40"), ("%-10.5g", "123.4 "), ("%-+10.5g", "+123.4 "), ("%010.5g", "00000123.4")), num = (123.4, 123.4000000000000000000000000000000000000000000000000000000000000000000000000002) @test Printf.format(Printf.Format(fmt), num) == val end for (fmt, val) = (("%10.5g", " 123.4"), ("%+10.5g", " +123.4"), ("% 10.5g", " 123.4"), ("%#10.5g", " 123.40"), ("%-10.5g", "123.4 "), ("%-+10.5g", "+123.4 "), ("%010.5g", "00000123.4")), num = (123.4, 123.4000000000000000000000000000000000000000000000000000000000000000000000000002) @test Printf.format(Printf.Format(fmt), num) == val end Printf.@sprintf "%10.5g" -123.4000000000000000000000000000000000000000000000000000000000000000000000000002 Printf.@sprintf "%10.5g" -123.4000000000000000000000000000000000000000000000000000000000000000000000000002 Printf.@sprintf("%10.5g", -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) == " -123.4" Printf.@sprintf("%10.5g", -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) == " -123.4" @test Printf.@sprintf("%10.5g", -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) == " -123.4" @test Printf.@sprintf("%10.5g", -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) == " -123.4" Printf.@sprintf "%010.5g" -123.4000000000000000000000000000000000000000000000000000000000000000000000000002 Printf.@sprintf "%010.5g" -123.4000000000000000000000000000000000000000000000000000000000000000000000000002 Printf.@sprintf("%010.5g", -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) == "-0000123.4" Printf.@sprintf("%010.5g", -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) == "-0000123.4" @test Printf.@sprintf("%010.5g", -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) == "-0000123.4" @test Printf.@sprintf("%010.5g", -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) == "-0000123.4" Printf.@sprintf "%.6g" 1.234e7 Printf.@sprintf "%.6g" 1.234e7 Printf.@sprintf("%.6g", 1.234e7) == "1.234e+07" Printf.@sprintf("%.6g", 1.234e7) == "1.234e+07" @test Printf.@sprintf("%.6g", 1.234e7) == "1.234e+07" @test Printf.@sprintf("%.6g", 1.234e7) == "1.234e+07" Printf.@sprintf "%#.6g" 1.234e7 Printf.@sprintf "%#.6g" 1.234e7 Printf.@sprintf("%#.6g", 1.234e7) == "1.23400e+07" Printf.@sprintf("%#.6g", 1.234e7) == "1.23400e+07" @test Printf.@sprintf("%#.6g", 1.234e7) == "1.23400e+07" @test Printf.@sprintf("%#.6g", 1.234e7) == "1.23400e+07" begin for (val, res) = ((1.2345678e7, "1.23457e+07"), (1.2345678e6, "1.23457e+06"), (123456.78, "123457"), (12345.678, "12345.7"), (1.234e7, "1.234e+07")) @test Printf.@sprintf("%.6g", val) == res end for (val, res) = ((1.2345678e7, "1.23457e+07"), (1.234567799999999999999999999999999999999999999999999999999999999999999999999993e6, "1.23457e+06"), (123456.7800000000000000000000000000000000000000000000000000000000000000000000004, "123457"), (12345.67800000000000000000000000000000000000000000000000000000000000000000000007, "12345.7")) @test Printf.@sprintf("%.6g", val) == res end for (fmt, val) = (("%10.5g", " 123.4"), ("%+10.5g", " +123.4"), ("% 10.5g", " 123.4"), ("%#10.5g", " 123.40"), ("%-10.5g", "123.4 "), ("%-+10.5g", "+123.4 "), ("%010.5g", "00000123.4")), num = (123.4, 123.4000000000000000000000000000000000000000000000000000000000000000000000000002) @test Printf.format(Printf.Format(fmt), num) == val end @test Printf.@sprintf("%10.5g", -123.4) == " -123.4" @test Printf.@sprintf("%010.5g", -123.4) == "-0000123.4" @test Printf.@sprintf("%.6g", 1.234e7) == "1.234e+07" @test Printf.@sprintf("%#.6g", 1.234e7) == "1.23400e+07" @test Printf.@sprintf("%10.5g", -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) == " -123.4" @test Printf.@sprintf("%010.5g", -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) == "-0000123.4" @test Printf.@sprintf("%.6g", 1.234e7) == "1.234e+07" @test Printf.@sprintf("%#.6g", 1.234e7) == "1.23400e+07" @test Printf.@sprintf("%.5g", 42) == "42" @test Printf.@sprintf("%#.2g", 42) == "42." @test Printf.@sprintf("%#.5g", 42) == "42.000" @test Printf.@sprintf("%g", 0.00012) == "0.00012" @test Printf.@sprintf("%g", 1.2e-5) == "1.2e-05" @test Printf.@sprintf("%g", 123456.7) == "123457" @test Printf.@sprintf("%g", 1.2345678e6) == "1.23457e+06" for (val, res) = ((Inf, "Inf"), (-Inf, "-Inf"), (NaN, "NaN"), (-NaN, "NaN")) @test Printf.@sprintf("%g", val) == res @test Printf.@sprintf("%G", val) == res end @test Printf.@sprintf("%.15g", 0) == "0" @test Printf.@sprintf("%#.15g", 0) == "0.00000000000000" end begin for (val, res) = ((1.2345678e7, "1.23457e+07"), (1.2345678e6, "1.23457e+06"), (123456.78, "123457"), (12345.678, "12345.7"), (1.234e7, "1.234e+07")) @test Printf.@sprintf("%.6g", val) == res end for (val, res) = ((1.2345678e7, "1.23457e+07"), (1.234567799999999999999999999999999999999999999999999999999999999999999999999993e6, "1.23457e+06"), (123456.7800000000000000000000000000000000000000000000000000000000000000000000004, "123457"), (12345.67800000000000000000000000000000000000000000000000000000000000000000000007, "12345.7")) @test Printf.@sprintf("%.6g", val) == res end for (fmt, val) = (("%10.5g", " 123.4"), ("%+10.5g", " +123.4"), ("% 10.5g", " 123.4"), ("%#10.5g", " 123.40"), ("%-10.5g", "123.4 "), ("%-+10.5g", "+123.4 "), ("%010.5g", "00000123.4")), num = (123.4, 123.4000000000000000000000000000000000000000000000000000000000000000000000000002) @test Printf.format(Printf.Format(fmt), num) == val end @test Printf.@sprintf("%10.5g", -123.4) == " -123.4" @test Printf.@sprintf("%010.5g", -123.4) == "-0000123.4" @test Printf.@sprintf("%.6g", 1.234e7) == "1.234e+07" @test Printf.@sprintf("%#.6g", 1.234e7) == "1.23400e+07" @test Printf.@sprintf("%10.5g", -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) == " -123.4" @test Printf.@sprintf("%010.5g", -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) == "-0000123.4" @test Printf.@sprintf("%.6g", 1.234e7) == "1.234e+07" @test Printf.@sprintf("%#.6g", 1.234e7) == "1.23400e+07" @test Printf.@sprintf("%.5g", 42) == "42" @test Printf.@sprintf("%#.2g", 42) == "42." @test Printf.@sprintf("%#.5g", 42) == "42.000" @test Printf.@sprintf("%g", 0.00012) == "0.00012" @test Printf.@sprintf("%g", 1.2e-5) == "1.2e-05" @test Printf.@sprintf("%g", 123456.7) == "123457" @test Printf.@sprintf("%g", 1.2345678e6) == "1.23457e+06" for (val, res) = ((Inf, "Inf"), (-Inf, "-Inf"), (NaN, "NaN"), (-NaN, "NaN")) @test Printf.@sprintf("%g", val) == res @test Printf.@sprintf("%G", val) == res end @test Printf.@sprintf("%.15g", 0) == "0" @test Printf.@sprintf("%#.15g", 0) == "0.00000000000000" end @testset "%g" begin for (val, res) = ((1.2345678e7, "1.23457e+07"), (1.2345678e6, "1.23457e+06"), (123456.78, "123457"), (12345.678, "12345.7"), (1.234e7, "1.234e+07")) @test Printf.@sprintf("%.6g", val) == res end for (val, res) = ((1.2345678e7, "1.23457e+07"), (1.234567799999999999999999999999999999999999999999999999999999999999999999999993e6, "1.23457e+06"), (123456.7800000000000000000000000000000000000000000000000000000000000000000000004, "123457"), (12345.67800000000000000000000000000000000000000000000000000000000000000000000007, "12345.7")) @test Printf.@sprintf("%.6g", val) == res end for (fmt, val) = (("%10.5g", " 123.4"), ("%+10.5g", " +123.4"), ("% 10.5g", " 123.4"), ("%#10.5g", " 123.40"), ("%-10.5g", "123.4 "), ("%-+10.5g", "+123.4 "), ("%010.5g", "00000123.4")), num = (123.4, 123.4000000000000000000000000000000000000000000000000000000000000000000000000002) @test Printf.format(Printf.Format(fmt), num) == val end @test Printf.@sprintf("%10.5g", -123.4) == " -123.4" @test Printf.@sprintf("%010.5g", -123.4) == "-0000123.4" @test Printf.@sprintf("%.6g", 1.234e7) == "1.234e+07" @test Printf.@sprintf("%#.6g", 1.234e7) == "1.23400e+07" @test Printf.@sprintf("%10.5g", -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) == " -123.4" @test Printf.@sprintf("%010.5g", -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) == "-0000123.4" @test Printf.@sprintf("%.6g", 1.234e7) == "1.234e+07" @test Printf.@sprintf("%#.6g", 1.234e7) == "1.23400e+07" @test Printf.@sprintf("%.5g", 42) == "42" @test Printf.@sprintf("%#.2g", 42) == "42." @test Printf.@sprintf("%#.5g", 42) == "42.000" @test Printf.@sprintf("%g", 0.00012) == "0.00012" @test Printf.@sprintf("%g", 1.2e-5) == "1.2e-05" @test Printf.@sprintf("%g", 123456.7) == "123457" @test Printf.@sprintf("%g", 1.2345678e6) == "1.23457e+06" for (val, res) = ((Inf, "Inf"), (-Inf, "-Inf"), (NaN, "NaN"), (-NaN, "NaN")) @test Printf.@sprintf("%g", val) == res @test Printf.@sprintf("%G", val) == res end @test Printf.@sprintf("%.15g", 0) == "0" @test Printf.@sprintf("%#.15g", 0) == "0.00000000000000" end @testset "%g" begin for (val, res) = ((1.2345678e7, "1.23457e+07"), (1.2345678e6, "1.23457e+06"), (123456.78, "123457"), (12345.678, "12345.7"), (1.234e7, "1.234e+07")) @test Printf.@sprintf("%.6g", val) == res end for (val, res) = ((1.2345678e7, "1.23457e+07"), (1.234567799999999999999999999999999999999999999999999999999999999999999999999993e6, "1.23457e+06"), (123456.7800000000000000000000000000000000000000000000000000000000000000000000004, "123457"), (12345.67800000000000000000000000000000000000000000000000000000000000000000000007, "12345.7")) @test Printf.@sprintf("%.6g", val) == res end for (fmt, val) = (("%10.5g", " 123.4"), ("%+10.5g", " +123.4"), ("% 10.5g", " 123.4"), ("%#10.5g", " 123.40"), ("%-10.5g", "123.4 "), ("%-+10.5g", "+123.4 "), ("%010.5g", "00000123.4")), num = (123.4, 123.4000000000000000000000000000000000000000000000000000000000000000000000000002) @test Printf.format(Printf.Format(fmt), num) == val end @test Printf.@sprintf("%10.5g", -123.4) == " -123.4" @test Printf.@sprintf("%010.5g", -123.4) == "-0000123.4" @test Printf.@sprintf("%.6g", 1.234e7) == "1.234e+07" @test Printf.@sprintf("%#.6g", 1.234e7) == "1.23400e+07" @test Printf.@sprintf("%10.5g", -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) == " -123.4" @test Printf.@sprintf("%010.5g", -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) == "-0000123.4" @test Printf.@sprintf("%.6g", 1.234e7) == "1.234e+07" @test Printf.@sprintf("%#.6g", 1.234e7) == "1.23400e+07" @test Printf.@sprintf("%.5g", 42) == "42" @test Printf.@sprintf("%#.2g", 42) == "42." @test Printf.@sprintf("%#.5g", 42) == "42.000" @test Printf.@sprintf("%g", 0.00012) == "0.00012" @test Printf.@sprintf("%g", 1.2e-5) == "1.2e-05" @test Printf.@sprintf("%g", 123456.7) == "123457" @test Printf.@sprintf("%g", 1.2345678e6) == "1.23457e+06" for (val, res) = ((Inf, "Inf"), (-Inf, "-Inf"), (NaN, "NaN"), (-NaN, "NaN")) @test Printf.@sprintf("%g", val) == res @test Printf.@sprintf("%G", val) == res end @test Printf.@sprintf("%.15g", 0) == "0" @test Printf.@sprintf("%#.15g", 0) == "0.00000000000000" end Printf.@sprintf "%e" Inf Printf.@sprintf "%e" Inf Printf.@sprintf("%e", Inf) == "Inf" Printf.@sprintf("%e", Inf) == "Inf" @test Printf.@sprintf("%e", Inf) == "Inf" @test Printf.@sprintf("%e", Inf) == "Inf" begin @test Printf.@sprintf("%f", Inf) == "Inf" @test Printf.@sprintf("%+f", Inf) == "+Inf" @test Printf.@sprintf("% f", Inf) == " Inf" @test Printf.@sprintf("% #f", Inf) == " Inf" @test Printf.@sprintf("%07f", Inf) == " Inf" @test Printf.@sprintf("%f", -Inf) == "-Inf" @test Printf.@sprintf("%+f", -Inf) == "-Inf" @test Printf.@sprintf("%07f", -Inf) == " -Inf" @test Printf.@sprintf("%f", NaN) == "NaN" @test Printf.@sprintf("%+f", NaN) == "+NaN" @test Printf.@sprintf("% f", NaN) == " NaN" @test Printf.@sprintf("% #f", NaN) == " NaN" @test Printf.@sprintf("%07f", NaN) == " NaN" @test Printf.@sprintf("%e", Inf) == "Inf" @test Printf.@sprintf("%e", NaN) == "NaN" @test Printf.@sprintf("%.0f", 3.0e142) == "29999999999999997463140672961703247153805615792184250659629251954072073858354858644285983761764971823910371920726635399393477049701891710124032" @test Printf.@sprintf("%f", 1.234) == "1.234000" @test Printf.@sprintf("%F", 1.234) == "1.234000" @test Printf.@sprintf("%+f", 1.234) == "+1.234000" @test Printf.@sprintf("% f", 1.234) == " 1.234000" @test Printf.@sprintf("%f", -1.234) == "-1.234000" @test Printf.@sprintf("%+f", -1.234) == "-1.234000" @test Printf.@sprintf("% f", -1.234) == "-1.234000" @test Printf.@sprintf("%#f", 1.234) == "1.234000" @test Printf.@sprintf("%.2f", 1.234) == "1.23" @test Printf.@sprintf("%.2f", 1.235) == "1.24" @test Printf.@sprintf("%.2f", 0.235) == "0.23" @test Printf.@sprintf("%4.1f", 1.234) == " 1.2" @test Printf.@sprintf("%8.1f", 1.234) == " 1.2" @test Printf.@sprintf("%+8.1f", 1.234) == " +1.2" @test Printf.@sprintf("% 8.1f", 1.234) == " 1.2" @test Printf.@sprintf("% 7.1f", 1.234) == " 1.2" @test Printf.@sprintf("% 08.1f", 1.234) == " 00001.2" @test Printf.@sprintf("%08.1f", 1.234) == "000001.2" @test Printf.@sprintf("%-08.1f", 1.234) == "1.2 " @test Printf.@sprintf("%-8.1f", 1.234) == "1.2 " @test Printf.@sprintf("%08.1f", -1.234) == "-00001.2" @test Printf.@sprintf("%09.1f", -1.234) == "-000001.2" @test Printf.@sprintf("%09.1f", 1.234) == "0000001.2" @test Printf.@sprintf("%+09.1f", 1.234) == "+000001.2" @test Printf.@sprintf("% 09.1f", 1.234) == " 000001.2" @test Printf.@sprintf("%+ 09.1f", 1.234) == "+000001.2" @test Printf.@sprintf("%+ 09.1f", 1.234) == "+000001.2" @test Printf.@sprintf("%+ 09.0f", 1.234) == "+00000001" @test Printf.@sprintf("%+ #09.0f", 1.234) == "+0000001." @test Printf.@sprintf("%+7.1f", 9.96) == " +10.0" @test Printf.@sprintf("% 7.1f", 9.96) == " 10.0" end begin @test Printf.@sprintf("%f", Inf) == "Inf" @test Printf.@sprintf("%+f", Inf) == "+Inf" @test Printf.@sprintf("% f", Inf) == " Inf" @test Printf.@sprintf("% #f", Inf) == " Inf" @test Printf.@sprintf("%07f", Inf) == " Inf" @test Printf.@sprintf("%f", -Inf) == "-Inf" @test Printf.@sprintf("%+f", -Inf) == "-Inf" @test Printf.@sprintf("%07f", -Inf) == " -Inf" @test Printf.@sprintf("%f", NaN) == "NaN" @test Printf.@sprintf("%+f", NaN) == "+NaN" @test Printf.@sprintf("% f", NaN) == " NaN" @test Printf.@sprintf("% #f", NaN) == " NaN" @test Printf.@sprintf("%07f", NaN) == " NaN" @test Printf.@sprintf("%e", Inf) == "Inf" @test Printf.@sprintf("%e", NaN) == "NaN" @test Printf.@sprintf("%.0f", 3.0e142) == "29999999999999997463140672961703247153805615792184250659629251954072073858354858644285983761764971823910371920726635399393477049701891710124032" @test Printf.@sprintf("%f", 1.234) == "1.234000" @test Printf.@sprintf("%F", 1.234) == "1.234000" @test Printf.@sprintf("%+f", 1.234) == "+1.234000" @test Printf.@sprintf("% f", 1.234) == " 1.234000" @test Printf.@sprintf("%f", -1.234) == "-1.234000" @test Printf.@sprintf("%+f", -1.234) == "-1.234000" @test Printf.@sprintf("% f", -1.234) == "-1.234000" @test Printf.@sprintf("%#f", 1.234) == "1.234000" @test Printf.@sprintf("%.2f", 1.234) == "1.23" @test Printf.@sprintf("%.2f", 1.235) == "1.24" @test Printf.@sprintf("%.2f", 0.235) == "0.23" @test Printf.@sprintf("%4.1f", 1.234) == " 1.2" @test Printf.@sprintf("%8.1f", 1.234) == " 1.2" @test Printf.@sprintf("%+8.1f", 1.234) == " +1.2" @test Printf.@sprintf("% 8.1f", 1.234) == " 1.2" @test Printf.@sprintf("% 7.1f", 1.234) == " 1.2" @test Printf.@sprintf("% 08.1f", 1.234) == " 00001.2" @test Printf.@sprintf("%08.1f", 1.234) == "000001.2" @test Printf.@sprintf("%-08.1f", 1.234) == "1.2 " @test Printf.@sprintf("%-8.1f", 1.234) == "1.2 " @test Printf.@sprintf("%08.1f", -1.234) == "-00001.2" @test Printf.@sprintf("%09.1f", -1.234) == "-000001.2" @test Printf.@sprintf("%09.1f", 1.234) == "0000001.2" @test Printf.@sprintf("%+09.1f", 1.234) == "+000001.2" @test Printf.@sprintf("% 09.1f", 1.234) == " 000001.2" @test Printf.@sprintf("%+ 09.1f", 1.234) == "+000001.2" @test Printf.@sprintf("%+ 09.1f", 1.234) == "+000001.2" @test Printf.@sprintf("%+ 09.0f", 1.234) == "+00000001" @test Printf.@sprintf("%+ #09.0f", 1.234) == "+0000001." @test Printf.@sprintf("%+7.1f", 9.96) == " +10.0" @test Printf.@sprintf("% 7.1f", 9.96) == " 10.0" end @testset "%f" begin @test Printf.@sprintf("%f", Inf) == "Inf" @test Printf.@sprintf("%+f", Inf) == "+Inf" @test Printf.@sprintf("% f", Inf) == " Inf" @test Printf.@sprintf("% #f", Inf) == " Inf" @test Printf.@sprintf("%07f", Inf) == " Inf" @test Printf.@sprintf("%f", -Inf) == "-Inf" @test Printf.@sprintf("%+f", -Inf) == "-Inf" @test Printf.@sprintf("%07f", -Inf) == " -Inf" @test Printf.@sprintf("%f", NaN) == "NaN" @test Printf.@sprintf("%+f", NaN) == "+NaN" @test Printf.@sprintf("% f", NaN) == " NaN" @test Printf.@sprintf("% #f", NaN) == " NaN" @test Printf.@sprintf("%07f", NaN) == " NaN" @test Printf.@sprintf("%e", Inf) == "Inf" @test Printf.@sprintf("%e", NaN) == "NaN" @test Printf.@sprintf("%.0f", 3.0e142) == "29999999999999997463140672961703247153805615792184250659629251954072073858354858644285983761764971823910371920726635399393477049701891710124032" @test Printf.@sprintf("%f", 1.234) == "1.234000" @test Printf.@sprintf("%F", 1.234) == "1.234000" @test Printf.@sprintf("%+f", 1.234) == "+1.234000" @test Printf.@sprintf("% f", 1.234) == " 1.234000" @test Printf.@sprintf("%f", -1.234) == "-1.234000" @test Printf.@sprintf("%+f", -1.234) == "-1.234000" @test Printf.@sprintf("% f", -1.234) == "-1.234000" @test Printf.@sprintf("%#f", 1.234) == "1.234000" @test Printf.@sprintf("%.2f", 1.234) == "1.23" @test Printf.@sprintf("%.2f", 1.235) == "1.24" @test Printf.@sprintf("%.2f", 0.235) == "0.23" @test Printf.@sprintf("%4.1f", 1.234) == " 1.2" @test Printf.@sprintf("%8.1f", 1.234) == " 1.2" @test Printf.@sprintf("%+8.1f", 1.234) == " +1.2" @test Printf.@sprintf("% 8.1f", 1.234) == " 1.2" @test Printf.@sprintf("% 7.1f", 1.234) == " 1.2" @test Printf.@sprintf("% 08.1f", 1.234) == " 00001.2" @test Printf.@sprintf("%08.1f", 1.234) == "000001.2" @test Printf.@sprintf("%-08.1f", 1.234) == "1.2 " @test Printf.@sprintf("%-8.1f", 1.234) == "1.2 " @test Printf.@sprintf("%08.1f", -1.234) == "-00001.2" @test Printf.@sprintf("%09.1f", -1.234) == "-000001.2" @test Printf.@sprintf("%09.1f", 1.234) == "0000001.2" @test Printf.@sprintf("%+09.1f", 1.234) == "+000001.2" @test Printf.@sprintf("% 09.1f", 1.234) == " 000001.2" @test Printf.@sprintf("%+ 09.1f", 1.234) == "+000001.2" @test Printf.@sprintf("%+ 09.1f", 1.234) == "+000001.2" @test Printf.@sprintf("%+ 09.0f", 1.234) == "+00000001" @test Printf.@sprintf("%+ #09.0f", 1.234) == "+0000001." @test Printf.@sprintf("%+7.1f", 9.96) == " +10.0" @test Printf.@sprintf("% 7.1f", 9.96) == " 10.0" end @testset "%f" begin @test Printf.@sprintf("%f", Inf) == "Inf" @test Printf.@sprintf("%+f", Inf) == "+Inf" @test Printf.@sprintf("% f", Inf) == " Inf" @test Printf.@sprintf("% #f", Inf) == " Inf" @test Printf.@sprintf("%07f", Inf) == " Inf" @test Printf.@sprintf("%f", -Inf) == "-Inf" @test Printf.@sprintf("%+f", -Inf) == "-Inf" @test Printf.@sprintf("%07f", -Inf) == " -Inf" @test Printf.@sprintf("%f", NaN) == "NaN" @test Printf.@sprintf("%+f", NaN) == "+NaN" @test Printf.@sprintf("% f", NaN) == " NaN" @test Printf.@sprintf("% #f", NaN) == " NaN" @test Printf.@sprintf("%07f", NaN) == " NaN" @test Printf.@sprintf("%e", Inf) == "Inf" @test Printf.@sprintf("%e", NaN) == "NaN" @test Printf.@sprintf("%.0f", 3.0e142) == "29999999999999997463140672961703247153805615792184250659629251954072073858354858644285983761764971823910371920726635399393477049701891710124032" @test Printf.@sprintf("%f", 1.234) == "1.234000" @test Printf.@sprintf("%F", 1.234) == "1.234000" @test Printf.@sprintf("%+f", 1.234) == "+1.234000" @test Printf.@sprintf("% f", 1.234) == " 1.234000" @test Printf.@sprintf("%f", -1.234) == "-1.234000" @test Printf.@sprintf("%+f", -1.234) == "-1.234000" @test Printf.@sprintf("% f", -1.234) == "-1.234000" @test Printf.@sprintf("%#f", 1.234) == "1.234000" @test Printf.@sprintf("%.2f", 1.234) == "1.23" @test Printf.@sprintf("%.2f", 1.235) == "1.24" @test Printf.@sprintf("%.2f", 0.235) == "0.23" @test Printf.@sprintf("%4.1f", 1.234) == " 1.2" @test Printf.@sprintf("%8.1f", 1.234) == " 1.2" @test Printf.@sprintf("%+8.1f", 1.234) == " +1.2" @test Printf.@sprintf("% 8.1f", 1.234) == " 1.2" @test Printf.@sprintf("% 7.1f", 1.234) == " 1.2" @test Printf.@sprintf("% 08.1f", 1.234) == " 00001.2" @test Printf.@sprintf("%08.1f", 1.234) == "000001.2" @test Printf.@sprintf("%-08.1f", 1.234) == "1.2 " @test Printf.@sprintf("%-8.1f", 1.234) == "1.2 " @test Printf.@sprintf("%08.1f", -1.234) == "-00001.2" @test Printf.@sprintf("%09.1f", -1.234) == "-000001.2" @test Printf.@sprintf("%09.1f", 1.234) == "0000001.2" @test Printf.@sprintf("%+09.1f", 1.234) == "+000001.2" @test Printf.@sprintf("% 09.1f", 1.234) == " 000001.2" @test Printf.@sprintf("%+ 09.1f", 1.234) == "+000001.2" @test Printf.@sprintf("%+ 09.1f", 1.234) == "+000001.2" @test Printf.@sprintf("%+ 09.0f", 1.234) == "+00000001" @test Printf.@sprintf("%+ #09.0f", 1.234) == "+0000001." @test Printf.@sprintf("%+7.1f", 9.96) == " +10.0" @test Printf.@sprintf("% 7.1f", 9.96) == " 10.0" end Printf.@sprintf "%e" Inf Printf.@sprintf "%e" Inf Printf.@sprintf("%e", Inf) == "Inf" Printf.@sprintf("%e", Inf) == "Inf" @test Printf.@sprintf("%e", Inf) == "Inf" @test Printf.@sprintf("%e", Inf) == "Inf" Printf.@sprintf "%.0e" 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142 Printf.@sprintf "%.0e" 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142 Printf.@sprintf("%.0e", 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) == "3e+142" Printf.@sprintf("%.0e", 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) == "3e+142" @test Printf.@sprintf("%.0e", 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) == "3e+142" @test Printf.@sprintf("%.0e", 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) == "3e+142" Printf.@sprintf "%#.0e" 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142 Printf.@sprintf "%#.0e" 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142 Printf.@sprintf("%#.0e", 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) == "3.e+142" Printf.@sprintf("%#.0e", 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) == "3.e+142" @test Printf.@sprintf("%#.0e", 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) == "3.e+142" @test Printf.@sprintf("%#.0e", 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) == "3.e+142" Printf.@sprintf "%.0e" 3.000000000000000000000000000000000000000000000000000000000000000000000000000024e1042 Printf.@sprintf "%.0e" 3.000000000000000000000000000000000000000000000000000000000000000000000000000024e1042 Printf.@sprintf("%.0e", 3.000000000000000000000000000000000000000000000000000000000000000000000000000024e1042) == "3e+1042" Printf.@sprintf("%.0e", 3.000000000000000000000000000000000000000000000000000000000000000000000000000024e1042) == "3e+1042" @test Printf.@sprintf("%.0e", 3.000000000000000000000000000000000000000000000000000000000000000000000000000024e1042) == "3e+1042" @test Printf.@sprintf("%.0e", 3.000000000000000000000000000000000000000000000000000000000000000000000000000024e1042) == "3e+1042" begin @test Printf.@sprintf("%e", Inf) == "Inf" @test Printf.@sprintf("%+e", Inf) == "+Inf" @test Printf.@sprintf("% e", Inf) == " Inf" @test Printf.@sprintf("% #e", Inf) == " Inf" @test Printf.@sprintf("%07e", Inf) == " Inf" @test Printf.@sprintf("%e", -Inf) == "-Inf" @test Printf.@sprintf("%+e", -Inf) == "-Inf" @test Printf.@sprintf("%07e", -Inf) == " -Inf" @test Printf.@sprintf("%e", NaN) == "NaN" @test Printf.@sprintf("%+e", NaN) == "+NaN" @test Printf.@sprintf("% e", NaN) == " NaN" @test Printf.@sprintf("% #e", NaN) == " NaN" @test Printf.@sprintf("%07e", NaN) == " NaN" @test Printf.@sprintf("%e", Inf) == "Inf" @test Printf.@sprintf("%e", NaN) == "NaN" @test Printf.@sprintf("%.0e", 3.0e142) == "3e+142" @test Printf.@sprintf("%#.0e", 3.0e142) == "3.e+142" @test Printf.@sprintf("%.0e", 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) == "3e+142" @test Printf.@sprintf("%#.0e", 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) == "3.e+142" @test Printf.@sprintf("%.0e", 3.000000000000000000000000000000000000000000000000000000000000000000000000000024e1042) == "3e+1042" @test Printf.@sprintf("%e", 3.0e42) == "3.000000e+42" @test Printf.@sprintf("%E", 3.0e42) == "3.000000E+42" @test Printf.@sprintf("%e", 3.0e-42) == "3.000000e-42" @test Printf.@sprintf("%E", 3.0e-42) == "3.000000E-42" @test Printf.@sprintf("%e", 1.234) == "1.234000e+00" @test Printf.@sprintf("%E", 1.234) == "1.234000E+00" @test Printf.@sprintf("%+e", 1.234) == "+1.234000e+00" @test Printf.@sprintf("% e", 1.234) == " 1.234000e+00" @test Printf.@sprintf("%e", -1.234) == "-1.234000e+00" @test Printf.@sprintf("%+e", -1.234) == "-1.234000e+00" @test Printf.@sprintf("% e", -1.234) == "-1.234000e+00" @test Printf.@sprintf("%#e", 1.234) == "1.234000e+00" @test Printf.@sprintf("%.2e", 1.234) == "1.23e+00" @test Printf.@sprintf("%.2e", 1.235) == "1.24e+00" @test Printf.@sprintf("%.2e", 0.235) == "2.35e-01" @test Printf.@sprintf("%4.1e", 1.234) == "1.2e+00" @test Printf.@sprintf("%8.1e", 1.234) == " 1.2e+00" @test Printf.@sprintf("%+8.1e", 1.234) == "+1.2e+00" @test Printf.@sprintf("% 8.1e", 1.234) == " 1.2e+00" @test Printf.@sprintf("% 7.1e", 1.234) == " 1.2e+00" @test Printf.@sprintf("% 08.1e", 1.234) == " 1.2e+00" @test Printf.@sprintf("%08.1e", 1.234) == "01.2e+00" @test Printf.@sprintf("%-08.1e", 1.234) == "1.2e+00 " @test Printf.@sprintf("%-8.1e", 1.234) == "1.2e+00 " @test Printf.@sprintf("%-8.1e", 1.234) == "1.2e+00 " @test Printf.@sprintf("%08.1e", -1.234) == "-1.2e+00" @test Printf.@sprintf("%09.1e", -1.234) == "-01.2e+00" @test Printf.@sprintf("%09.1e", 1.234) == "001.2e+00" @test Printf.@sprintf("%+09.1e", 1.234) == "+01.2e+00" @test Printf.@sprintf("% 09.1e", 1.234) == " 01.2e+00" @test Printf.@sprintf("%+ 09.1e", 1.234) == "+01.2e+00" @test Printf.@sprintf("%+ 09.1e", 1.234) == "+01.2e+00" @test Printf.@sprintf("%+ 09.0e", 1.234) == "+0001e+00" @test Printf.@sprintf("%+ #09.0e", 1.234) == "+001.e+00" @test Printf.@sprintf("%+9.1e", 9.96) == " +1.0e+01" @test Printf.@sprintf("% 9.1e", 9.96) == " 1.0e+01" end begin @test Printf.@sprintf("%e", Inf) == "Inf" @test Printf.@sprintf("%+e", Inf) == "+Inf" @test Printf.@sprintf("% e", Inf) == " Inf" @test Printf.@sprintf("% #e", Inf) == " Inf" @test Printf.@sprintf("%07e", Inf) == " Inf" @test Printf.@sprintf("%e", -Inf) == "-Inf" @test Printf.@sprintf("%+e", -Inf) == "-Inf" @test Printf.@sprintf("%07e", -Inf) == " -Inf" @test Printf.@sprintf("%e", NaN) == "NaN" @test Printf.@sprintf("%+e", NaN) == "+NaN" @test Printf.@sprintf("% e", NaN) == " NaN" @test Printf.@sprintf("% #e", NaN) == " NaN" @test Printf.@sprintf("%07e", NaN) == " NaN" @test Printf.@sprintf("%e", Inf) == "Inf" @test Printf.@sprintf("%e", NaN) == "NaN" @test Printf.@sprintf("%.0e", 3.0e142) == "3e+142" @test Printf.@sprintf("%#.0e", 3.0e142) == "3.e+142" @test Printf.@sprintf("%.0e", 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) == "3e+142" @test Printf.@sprintf("%#.0e", 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) == "3.e+142" @test Printf.@sprintf("%.0e", 3.000000000000000000000000000000000000000000000000000000000000000000000000000024e1042) == "3e+1042" @test Printf.@sprintf("%e", 3.0e42) == "3.000000e+42" @test Printf.@sprintf("%E", 3.0e42) == "3.000000E+42" @test Printf.@sprintf("%e", 3.0e-42) == "3.000000e-42" @test Printf.@sprintf("%E", 3.0e-42) == "3.000000E-42" @test Printf.@sprintf("%e", 1.234) == "1.234000e+00" @test Printf.@sprintf("%E", 1.234) == "1.234000E+00" @test Printf.@sprintf("%+e", 1.234) == "+1.234000e+00" @test Printf.@sprintf("% e", 1.234) == " 1.234000e+00" @test Printf.@sprintf("%e", -1.234) == "-1.234000e+00" @test Printf.@sprintf("%+e", -1.234) == "-1.234000e+00" @test Printf.@sprintf("% e", -1.234) == "-1.234000e+00" @test Printf.@sprintf("%#e", 1.234) == "1.234000e+00" @test Printf.@sprintf("%.2e", 1.234) == "1.23e+00" @test Printf.@sprintf("%.2e", 1.235) == "1.24e+00" @test Printf.@sprintf("%.2e", 0.235) == "2.35e-01" @test Printf.@sprintf("%4.1e", 1.234) == "1.2e+00" @test Printf.@sprintf("%8.1e", 1.234) == " 1.2e+00" @test Printf.@sprintf("%+8.1e", 1.234) == "+1.2e+00" @test Printf.@sprintf("% 8.1e", 1.234) == " 1.2e+00" @test Printf.@sprintf("% 7.1e", 1.234) == " 1.2e+00" @test Printf.@sprintf("% 08.1e", 1.234) == " 1.2e+00" @test Printf.@sprintf("%08.1e", 1.234) == "01.2e+00" @test Printf.@sprintf("%-08.1e", 1.234) == "1.2e+00 " @test Printf.@sprintf("%-8.1e", 1.234) == "1.2e+00 " @test Printf.@sprintf("%-8.1e", 1.234) == "1.2e+00 " @test Printf.@sprintf("%08.1e", -1.234) == "-1.2e+00" @test Printf.@sprintf("%09.1e", -1.234) == "-01.2e+00" @test Printf.@sprintf("%09.1e", 1.234) == "001.2e+00" @test Printf.@sprintf("%+09.1e", 1.234) == "+01.2e+00" @test Printf.@sprintf("% 09.1e", 1.234) == " 01.2e+00" @test Printf.@sprintf("%+ 09.1e", 1.234) == "+01.2e+00" @test Printf.@sprintf("%+ 09.1e", 1.234) == "+01.2e+00" @test Printf.@sprintf("%+ 09.0e", 1.234) == "+0001e+00" @test Printf.@sprintf("%+ #09.0e", 1.234) == "+001.e+00" @test Printf.@sprintf("%+9.1e", 9.96) == " +1.0e+01" @test Printf.@sprintf("% 9.1e", 9.96) == " 1.0e+01" end @testset "%e" begin @test Printf.@sprintf("%e", Inf) == "Inf" @test Printf.@sprintf("%+e", Inf) == "+Inf" @test Printf.@sprintf("% e", Inf) == " Inf" @test Printf.@sprintf("% #e", Inf) == " Inf" @test Printf.@sprintf("%07e", Inf) == " Inf" @test Printf.@sprintf("%e", -Inf) == "-Inf" @test Printf.@sprintf("%+e", -Inf) == "-Inf" @test Printf.@sprintf("%07e", -Inf) == " -Inf" @test Printf.@sprintf("%e", NaN) == "NaN" @test Printf.@sprintf("%+e", NaN) == "+NaN" @test Printf.@sprintf("% e", NaN) == " NaN" @test Printf.@sprintf("% #e", NaN) == " NaN" @test Printf.@sprintf("%07e", NaN) == " NaN" @test Printf.@sprintf("%e", Inf) == "Inf" @test Printf.@sprintf("%e", NaN) == "NaN" @test Printf.@sprintf("%.0e", 3.0e142) == "3e+142" @test Printf.@sprintf("%#.0e", 3.0e142) == "3.e+142" @test Printf.@sprintf("%.0e", 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) == "3e+142" @test Printf.@sprintf("%#.0e", 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) == "3.e+142" @test Printf.@sprintf("%.0e", 3.000000000000000000000000000000000000000000000000000000000000000000000000000024e1042) == "3e+1042" @test Printf.@sprintf("%e", 3.0e42) == "3.000000e+42" @test Printf.@sprintf("%E", 3.0e42) == "3.000000E+42" @test Printf.@sprintf("%e", 3.0e-42) == "3.000000e-42" @test Printf.@sprintf("%E", 3.0e-42) == "3.000000E-42" @test Printf.@sprintf("%e", 1.234) == "1.234000e+00" @test Printf.@sprintf("%E", 1.234) == "1.234000E+00" @test Printf.@sprintf("%+e", 1.234) == "+1.234000e+00" @test Printf.@sprintf("% e", 1.234) == " 1.234000e+00" @test Printf.@sprintf("%e", -1.234) == "-1.234000e+00" @test Printf.@sprintf("%+e", -1.234) == "-1.234000e+00" @test Printf.@sprintf("% e", -1.234) == "-1.234000e+00" @test Printf.@sprintf("%#e", 1.234) == "1.234000e+00" @test Printf.@sprintf("%.2e", 1.234) == "1.23e+00" @test Printf.@sprintf("%.2e", 1.235) == "1.24e+00" @test Printf.@sprintf("%.2e", 0.235) == "2.35e-01" @test Printf.@sprintf("%4.1e", 1.234) == "1.2e+00" @test Printf.@sprintf("%8.1e", 1.234) == " 1.2e+00" @test Printf.@sprintf("%+8.1e", 1.234) == "+1.2e+00" @test Printf.@sprintf("% 8.1e", 1.234) == " 1.2e+00" @test Printf.@sprintf("% 7.1e", 1.234) == " 1.2e+00" @test Printf.@sprintf("% 08.1e", 1.234) == " 1.2e+00" @test Printf.@sprintf("%08.1e", 1.234) == "01.2e+00" @test Printf.@sprintf("%-08.1e", 1.234) == "1.2e+00 " @test Printf.@sprintf("%-8.1e", 1.234) == "1.2e+00 " @test Printf.@sprintf("%-8.1e", 1.234) == "1.2e+00 " @test Printf.@sprintf("%08.1e", -1.234) == "-1.2e+00" @test Printf.@sprintf("%09.1e", -1.234) == "-01.2e+00" @test Printf.@sprintf("%09.1e", 1.234) == "001.2e+00" @test Printf.@sprintf("%+09.1e", 1.234) == "+01.2e+00" @test Printf.@sprintf("% 09.1e", 1.234) == " 01.2e+00" @test Printf.@sprintf("%+ 09.1e", 1.234) == "+01.2e+00" @test Printf.@sprintf("%+ 09.1e", 1.234) == "+01.2e+00" @test Printf.@sprintf("%+ 09.0e", 1.234) == "+0001e+00" @test Printf.@sprintf("%+ #09.0e", 1.234) == "+001.e+00" @test Printf.@sprintf("%+9.1e", 9.96) == " +1.0e+01" @test Printf.@sprintf("% 9.1e", 9.96) == " 1.0e+01" end @testset "%e" begin @test Printf.@sprintf("%e", Inf) == "Inf" @test Printf.@sprintf("%+e", Inf) == "+Inf" @test Printf.@sprintf("% e", Inf) == " Inf" @test Printf.@sprintf("% #e", Inf) == " Inf" @test Printf.@sprintf("%07e", Inf) == " Inf" @test Printf.@sprintf("%e", -Inf) == "-Inf" @test Printf.@sprintf("%+e", -Inf) == "-Inf" @test Printf.@sprintf("%07e", -Inf) == " -Inf" @test Printf.@sprintf("%e", NaN) == "NaN" @test Printf.@sprintf("%+e", NaN) == "+NaN" @test Printf.@sprintf("% e", NaN) == " NaN" @test Printf.@sprintf("% #e", NaN) == " NaN" @test Printf.@sprintf("%07e", NaN) == " NaN" @test Printf.@sprintf("%e", Inf) == "Inf" @test Printf.@sprintf("%e", NaN) == "NaN" @test Printf.@sprintf("%.0e", 3.0e142) == "3e+142" @test Printf.@sprintf("%#.0e", 3.0e142) == "3.e+142" @test Printf.@sprintf("%.0e", 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) == "3e+142" @test Printf.@sprintf("%#.0e", 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) == "3.e+142" @test Printf.@sprintf("%.0e", 3.000000000000000000000000000000000000000000000000000000000000000000000000000024e1042) == "3e+1042" @test Printf.@sprintf("%e", 3.0e42) == "3.000000e+42" @test Printf.@sprintf("%E", 3.0e42) == "3.000000E+42" @test Printf.@sprintf("%e", 3.0e-42) == "3.000000e-42" @test Printf.@sprintf("%E", 3.0e-42) == "3.000000E-42" @test Printf.@sprintf("%e", 1.234) == "1.234000e+00" @test Printf.@sprintf("%E", 1.234) == "1.234000E+00" @test Printf.@sprintf("%+e", 1.234) == "+1.234000e+00" @test Printf.@sprintf("% e", 1.234) == " 1.234000e+00" @test Printf.@sprintf("%e", -1.234) == "-1.234000e+00" @test Printf.@sprintf("%+e", -1.234) == "-1.234000e+00" @test Printf.@sprintf("% e", -1.234) == "-1.234000e+00" @test Printf.@sprintf("%#e", 1.234) == "1.234000e+00" @test Printf.@sprintf("%.2e", 1.234) == "1.23e+00" @test Printf.@sprintf("%.2e", 1.235) == "1.24e+00" @test Printf.@sprintf("%.2e", 0.235) == "2.35e-01" @test Printf.@sprintf("%4.1e", 1.234) == "1.2e+00" @test Printf.@sprintf("%8.1e", 1.234) == " 1.2e+00" @test Printf.@sprintf("%+8.1e", 1.234) == "+1.2e+00" @test Printf.@sprintf("% 8.1e", 1.234) == " 1.2e+00" @test Printf.@sprintf("% 7.1e", 1.234) == " 1.2e+00" @test Printf.@sprintf("% 08.1e", 1.234) == " 1.2e+00" @test Printf.@sprintf("%08.1e", 1.234) == "01.2e+00" @test Printf.@sprintf("%-08.1e", 1.234) == "1.2e+00 " @test Printf.@sprintf("%-8.1e", 1.234) == "1.2e+00 " @test Printf.@sprintf("%-8.1e", 1.234) == "1.2e+00 " @test Printf.@sprintf("%08.1e", -1.234) == "-1.2e+00" @test Printf.@sprintf("%09.1e", -1.234) == "-01.2e+00" @test Printf.@sprintf("%09.1e", 1.234) == "001.2e+00" @test Printf.@sprintf("%+09.1e", 1.234) == "+01.2e+00" @test Printf.@sprintf("% 09.1e", 1.234) == " 01.2e+00" @test Printf.@sprintf("%+ 09.1e", 1.234) == "+01.2e+00" @test Printf.@sprintf("%+ 09.1e", 1.234) == "+01.2e+00" @test Printf.@sprintf("%+ 09.0e", 1.234) == "+0001e+00" @test Printf.@sprintf("%+ #09.0e", 1.234) == "+001.e+00" @test Printf.@sprintf("%+9.1e", 9.96) == " +1.0e+01" @test Printf.@sprintf("% 9.1e", 9.96) == " 1.0e+01" end (1.2345, 1.234499999999999999999999999999999999999999999999999999999999999999999999999991) (1.2345, 1.234499999999999999999999999999999999999999999999999999999999999999999999999991) num = (1.2345, 1.234499999999999999999999999999999999999999999999999999999999999999999999999991) num = (1.2345, 1.234499999999999999999999999999999999999999999999999999999999999999999999999991) begin (fmt, val) = (("%7.2f", " 1.23"), ("%-7.2f", "1.23 "), ("%07.2f", "0001.23"), ("%.0f", "1"), ("%#.0f", "1."), ("%.4e", "1.2345e+00"), ("%.4E", "1.2345E+00"), ("%.2a", "0x1.3cp+0"), ("%.2A", "0X1.3CP+0")) num = (1.2345, 1.234499999999999999999999999999999999999999999999999999999999999999999999999991) end begin (fmt, val) = (("%7.2f", " 1.23"), ("%-7.2f", "1.23 "), ("%07.2f", "0001.23"), ("%.0f", "1"), ("%#.0f", "1."), ("%.4e", "1.2345e+00"), ("%.4E", "1.2345E+00"), ("%.2a", "0x1.3cp+0"), ("%.2A", "0X1.3CP+0")) num = (1.2345, 1.234499999999999999999999999999999999999999999999999999999999999999999999999991) end for (fmt, val) = (("%7.2f", " 1.23"), ("%-7.2f", "1.23 "), ("%07.2f", "0001.23"), ("%.0f", "1"), ("%#.0f", "1."), ("%.4e", "1.2345e+00"), ("%.4E", "1.2345E+00"), ("%.2a", "0x1.3cp+0"), ("%.2A", "0X1.3CP+0")), num = (1.2345, 1.234499999999999999999999999999999999999999999999999999999999999999999999999991) @test Printf.format(Printf.Format(fmt), num) == val end for (fmt, val) = (("%7.2f", " 1.23"), ("%-7.2f", "1.23 "), ("%07.2f", "0001.23"), ("%.0f", "1"), ("%#.0f", "1."), ("%.4e", "1.2345e+00"), ("%.4E", "1.2345E+00"), ("%.2a", "0x1.3cp+0"), ("%.2A", "0X1.3CP+0")), num = (1.2345, 1.234499999999999999999999999999999999999999999999999999999999999999999999999991) @test Printf.format(Printf.Format(fmt), num) == val end (UInt16(42), UInt32(42), UInt64(42), UInt128(42), Int16(42), Int32(42), Int64(42), Int128(42), 42) (UInt16(42), UInt32(42), UInt64(42), UInt128(42), Int16(42), Int32(42), Int64(42), Int128(42), 42) num = (UInt16(42), UInt32(42), UInt64(42), UInt128(42), Int16(42), Int32(42), Int64(42), Int128(42), 42) num = (UInt16(42), UInt32(42), UInt64(42), UInt128(42), Int16(42), Int32(42), Int64(42), Int128(42), 42) begin (fmt, val) = (("%i", "42"), ("%u", "42"), ("Test: %i", "Test: 42"), ("%#x", "0x2a"), ("%x", "2a"), ("%X", "2A"), ("% i", " 42"), ("%+i", "+42"), ("%4i", " 42"), ("%-4i", "42 "), ("%f", "42.000000"), ("%g", "42"), ("%e", "4.200000e+01")) num = (UInt16(42), UInt32(42), UInt64(42), UInt128(42), Int16(42), Int32(42), Int64(42), Int128(42), 42) end begin (fmt, val) = (("%i", "42"), ("%u", "42"), ("Test: %i", "Test: 42"), ("%#x", "0x2a"), ("%x", "2a"), ("%X", "2A"), ("% i", " 42"), ("%+i", "+42"), ("%4i", " 42"), ("%-4i", "42 "), ("%f", "42.000000"), ("%g", "42"), ("%e", "4.200000e+01")) num = (UInt16(42), UInt32(42), UInt64(42), UInt128(42), Int16(42), Int32(42), Int64(42), Int128(42), 42) end for (fmt, val) = (("%i", "42"), ("%u", "42"), ("Test: %i", "Test: 42"), ("%#x", "0x2a"), ("%x", "2a"), ("%X", "2A"), ("% i", " 42"), ("%+i", "+42"), ("%4i", " 42"), ("%-4i", "42 "), ("%f", "42.000000"), ("%g", "42"), ("%e", "4.200000e+01")), num = (UInt16(42), UInt32(42), UInt64(42), UInt128(42), Int16(42), Int32(42), Int64(42), Int128(42), 42) @test Printf.format(Printf.Format(fmt), num) == val end for (fmt, val) = (("%i", "42"), ("%u", "42"), ("Test: %i", "Test: 42"), ("%#x", "0x2a"), ("%x", "2a"), ("%X", "2A"), ("% i", " 42"), ("%+i", "+42"), ("%4i", " 42"), ("%-4i", "42 "), ("%f", "42.000000"), ("%g", "42"), ("%e", "4.200000e+01")), num = (UInt16(42), UInt32(42), UInt64(42), UInt128(42), Int16(42), Int32(42), Int64(42), Int128(42), 42) @test Printf.format(Printf.Format(fmt), num) == val end begin @test Printf.@sprintf("%%") == "%" @test Printf.@sprintf("1%%") == "1%" @test Printf.@sprintf("%%1") == "%1" @test Printf.@sprintf("1%%2") == "1%2" @test Printf.@sprintf("1%%%d", 2) == "1%2" @test Printf.@sprintf("1%%2%%3") == "1%2%3" @test Printf.@sprintf("GAP[%%]") == "GAP[%]" @test Printf.@sprintf("hey there") == "hey there" @test_throws Printf.InvalidFormatStringError Printf.Format("%+") @test_throws Printf.InvalidFormatStringError Printf.Format("%.") @test_throws Printf.InvalidFormatStringError Printf.Format("%.0") @test isempty((Printf.Format("%%")).formats) @test Printf.@sprintf("%d%d", 1, 2) == "12" @test Printf.@sprintf("%d%d", [1 2]...) == "12" @test Printf.@sprintf("X%d", 2) == "X2" @test Printf.@sprintf("Ð%d", 2) == "Ð2" @test Printf.@sprintf("ༀ%d", 2) == "ༀ2" @test Printf.@sprintf("\U1ffff%d", 2) == "\U0001ffff2" @test Printf.@sprintf("%dX%d", 1, 2) == "1X2" @test Printf.@sprintf("%dÐ%d", 1, 2) == "1Ð2" @test Printf.@sprintf("%dༀ%d", 1, 2) == "1ༀ2" @test Printf.@sprintf("%d\U1ffff%d", 1, 2) == "1\U0001ffff2" @test Printf.@sprintf("%d∃%dȃ", 1, 2) == "1∃2ȃ" @test_throws Printf.InvalidFormatStringError Printf.Format("%y%d") @test_throws Printf.InvalidFormatStringError Printf.Format("%Ð%d") @test_throws Printf.InvalidFormatStringError Printf.Format("%ༀ%d") @test_throws Printf.InvalidFormatStringError Printf.Format("%\U1ffff%d") @test Printf.@sprintf("%10.5d", 4) == " 00004" @test Printf.@sprintf("%d", typemax(Int64)) == "9223372036854775807" for (fmt, val) = (("%7.2f", " 1.23"), ("%-7.2f", "1.23 "), ("%07.2f", "0001.23"), ("%.0f", "1"), ("%#.0f", "1."), ("%.4e", "1.2345e+00"), ("%.4E", "1.2345E+00"), ("%.2a", "0x1.3cp+0"), ("%.2A", "0X1.3CP+0")), num = (1.2345, 1.234499999999999999999999999999999999999999999999999999999999999999999999999991) @test Printf.format(Printf.Format(fmt), num) == val end for (fmt, val) = (("%i", "42"), ("%u", "42"), ("Test: %i", "Test: 42"), ("%#x", "0x2a"), ("%x", "2a"), ("%X", "2A"), ("% i", " 42"), ("%+i", "+42"), ("%4i", " 42"), ("%-4i", "42 "), ("%f", "42.000000"), ("%g", "42"), ("%e", "4.200000e+01")), num = (UInt16(42), UInt32(42), UInt64(42), UInt128(42), Int16(42), Int32(42), Int64(42), Int128(42), 42) @test Printf.format(Printf.Format(fmt), num) == val end for i = ((42, "", "i", "42", ""), (42, "", "d", "42", ""), (42, "", "u", "42", ""), (42, "", "x", "2a", ""), (42, "", "X", "2A", ""), (42, "", "o", "52", ""), (42, "#", "x", "2a", "0x"), (42, "#", "X", "2A", "0X"), (42, "#", "o", "052", ""), (1.2345, "", ".2f", "1.23", ""), (1.2345, "", ".2e", "1.23e+00", ""), (1.2345, "", ".2E", "1.23E+00", ""), (1.2345, "#", ".0f", "1.", ""), (1.2345, "#", ".0e", "1.e+00", ""), (1.2345, "#", ".0E", "1.E+00", ""), (1.2345, "", ".2a", "1.3cp+0", "0x"), (1.2345, "", ".2A", "1.3CP+0", "0X")) _test_flags(i...) _test_flags(-(i[1]), i[2:5]...) end @test Printf.@sprintf("Test: %s%c%C%c%#-.0f.", "t", 65, 66, 67, -42) == "Test: tABC-42.." @test Printf.@sprintf("%f %d %d %f", 1.0, [3 4]..., 5) == "1.000000 3 4 5.000000" @test Printf.@sprintf("%s %f %9.5f %d %d %d %d%d%d%d", [1:6;]..., [7, 8, 9, 10]...) == "1 2.000000 3.00000 4 5 6 78910" @test Printf.@sprintf("%s %s %s %d %d %d %f %f %f", Any[10 ^ x + y for x = 1:3, y = 1:3]...) == "11 101 1001 12 102 1002 13.000000 103.000000 1003.000000" @test Printf.@sprintf("%s %s %s %d %d %d %f %f %f %s %s %s %d %d %d %f %f %f", Any[10x + (x + 1) for x = 1:18]...) == "12 23 34 45 56 67 78.000000 89.000000 100.000000 111 122 133 144 155 166 177.000000 188.000000 199.000000" @test (Printf.@sprintf("%.330f", BigFloat(1)))[var"end"] != '\0' @test Printf.@sprintf("%f", parse(BigFloat, "1e400")) == "10000000000000000000000000000000000000000000000000000000000000000000000000000025262527574416492004687051900140830217136998040684679611623086405387447100385714565637522507383770691831689647535911648520404034824470543643098638520633064715221151920028135130764414460468236314621044034960475540018328999334468948008954289495190631358190153259681118693204411689043999084305348398480210026863210192871358464.000000" @test_throws ArgumentError Printf.@sprintf("%f", parse(BigFloat, "1e99999")) @test Printf.@sprintf("%4.2s", "a") == " a" @test Printf.@sprintf("%12.3e", pi * 1.0e100) == " 3.142e+100" @test string((Printf.Format("%a")).formats[1]) == "%a" @test string((Printf.Format("%a")).formats[1]; modifier = "R") == "%Ra" @test Printf.@sprintf("%d", 3.14) == "3" @test Printf.@sprintf("%2d", 3.14) == " 3" @test Printf.@sprintf("%2d", big(3.14)) == " 3" @test Printf.@sprintf("%s", 1) == "1" @test Printf.@sprintf("%f", 1) == "1.000000" @test Printf.@sprintf("%e", 1) == "1.000000e+00" @test Printf.@sprintf("%g", 1) == "1" @test Printf.@sprintf("%.16g", 194.4778127560983) == "194.4778127560983" @test Printf.@sprintf("%.17g", 194.4778127560983) == "194.4778127560983" @test Printf.@sprintf("%.18g", 194.4778127560983) == "194.477812756098302" @test Printf.@sprintf("%.1g", 1.7976931348623157e308) == "2e+308" @test Printf.@sprintf("%.2g", 1.7976931348623157e308) == "1.8e+308" @test Printf.@sprintf("%.3g", 1.7976931348623157e308) == "1.8e+308" @test_throws ArgumentError @sprintf("%s%%%s", "a") @test @sprintf("%s%%%s", "a", "b") == "a%b" @test @sprintf("%d", 25.5) == "26" @test @sprintf(" %.1e\n", 0.999) == " 1.0e+00\n" @test @sprintf(" %.1f", 9.999) == " 10.0" @test @sprintf("%d", 1.0e100) == "10000000000000000159028911097599180468360808563945281389781327557747838772170381060813469985856815104" @test @sprintf("%d", 3 // 1) == "3" @test @sprintf("%d", Inf) == "Inf" @test @sprintf(" %d", NaN) == " NaN" @test Printf.@sprintf("") == "" @test Printf.format(Printf.Format("")) == "" end begin @test Printf.@sprintf("%%") == "%" @test Printf.@sprintf("1%%") == "1%" @test Printf.@sprintf("%%1") == "%1" @test Printf.@sprintf("1%%2") == "1%2" @test Printf.@sprintf("1%%%d", 2) == "1%2" @test Printf.@sprintf("1%%2%%3") == "1%2%3" @test Printf.@sprintf("GAP[%%]") == "GAP[%]" @test Printf.@sprintf("hey there") == "hey there" @test_throws Printf.InvalidFormatStringError Printf.Format("%+") @test_throws Printf.InvalidFormatStringError Printf.Format("%.") @test_throws Printf.InvalidFormatStringError Printf.Format("%.0") @test isempty((Printf.Format("%%")).formats) @test Printf.@sprintf("%d%d", 1, 2) == "12" @test Printf.@sprintf("%d%d", [1 2]...) == "12" @test Printf.@sprintf("X%d", 2) == "X2" @test Printf.@sprintf("Ð%d", 2) == "Ð2" @test Printf.@sprintf("ༀ%d", 2) == "ༀ2" @test Printf.@sprintf("\U1ffff%d", 2) == "\U0001ffff2" @test Printf.@sprintf("%dX%d", 1, 2) == "1X2" @test Printf.@sprintf("%dÐ%d", 1, 2) == "1Ð2" @test Printf.@sprintf("%dༀ%d", 1, 2) == "1ༀ2" @test Printf.@sprintf("%d\U1ffff%d", 1, 2) == "1\U0001ffff2" @test Printf.@sprintf("%d∃%dȃ", 1, 2) == "1∃2ȃ" @test_throws Printf.InvalidFormatStringError Printf.Format("%y%d") @test_throws Printf.InvalidFormatStringError Printf.Format("%Ð%d") @test_throws Printf.InvalidFormatStringError Printf.Format("%ༀ%d") @test_throws Printf.InvalidFormatStringError Printf.Format("%\U1ffff%d") @test Printf.@sprintf("%10.5d", 4) == " 00004" @test Printf.@sprintf("%d", typemax(Int64)) == "9223372036854775807" for (fmt, val) = (("%7.2f", " 1.23"), ("%-7.2f", "1.23 "), ("%07.2f", "0001.23"), ("%.0f", "1"), ("%#.0f", "1."), ("%.4e", "1.2345e+00"), ("%.4E", "1.2345E+00"), ("%.2a", "0x1.3cp+0"), ("%.2A", "0X1.3CP+0")), num = (1.2345, 1.234499999999999999999999999999999999999999999999999999999999999999999999999991) @test Printf.format(Printf.Format(fmt), num) == val end for (fmt, val) = (("%i", "42"), ("%u", "42"), ("Test: %i", "Test: 42"), ("%#x", "0x2a"), ("%x", "2a"), ("%X", "2A"), ("% i", " 42"), ("%+i", "+42"), ("%4i", " 42"), ("%-4i", "42 "), ("%f", "42.000000"), ("%g", "42"), ("%e", "4.200000e+01")), num = (UInt16(42), UInt32(42), UInt64(42), UInt128(42), Int16(42), Int32(42), Int64(42), Int128(42), 42) @test Printf.format(Printf.Format(fmt), num) == val end for i = ((42, "", "i", "42", ""), (42, "", "d", "42", ""), (42, "", "u", "42", ""), (42, "", "x", "2a", ""), (42, "", "X", "2A", ""), (42, "", "o", "52", ""), (42, "#", "x", "2a", "0x"), (42, "#", "X", "2A", "0X"), (42, "#", "o", "052", ""), (1.2345, "", ".2f", "1.23", ""), (1.2345, "", ".2e", "1.23e+00", ""), (1.2345, "", ".2E", "1.23E+00", ""), (1.2345, "#", ".0f", "1.", ""), (1.2345, "#", ".0e", "1.e+00", ""), (1.2345, "#", ".0E", "1.E+00", ""), (1.2345, "", ".2a", "1.3cp+0", "0x"), (1.2345, "", ".2A", "1.3CP+0", "0X")) _test_flags(i...) _test_flags(-(i[1]), i[2:5]...) end @test Printf.@sprintf("Test: %s%c%C%c%#-.0f.", "t", 65, 66, 67, -42) == "Test: tABC-42.." @test Printf.@sprintf("%f %d %d %f", 1.0, [3 4]..., 5) == "1.000000 3 4 5.000000" @test Printf.@sprintf("%s %f %9.5f %d %d %d %d%d%d%d", [1:6;]..., [7, 8, 9, 10]...) == "1 2.000000 3.00000 4 5 6 78910" @test Printf.@sprintf("%s %s %s %d %d %d %f %f %f", Any[10 ^ x + y for x = 1:3, y = 1:3]...) == "11 101 1001 12 102 1002 13.000000 103.000000 1003.000000" @test Printf.@sprintf("%s %s %s %d %d %d %f %f %f %s %s %s %d %d %d %f %f %f", Any[10x + (x + 1) for x = 1:18]...) == "12 23 34 45 56 67 78.000000 89.000000 100.000000 111 122 133 144 155 166 177.000000 188.000000 199.000000" @test (Printf.@sprintf("%.330f", BigFloat(1)))[var"end"] != '\0' @test Printf.@sprintf("%f", parse(BigFloat, "1e400")) == "10000000000000000000000000000000000000000000000000000000000000000000000000000025262527574416492004687051900140830217136998040684679611623086405387447100385714565637522507383770691831689647535911648520404034824470543643098638520633064715221151920028135130764414460468236314621044034960475540018328999334468948008954289495190631358190153259681118693204411689043999084305348398480210026863210192871358464.000000" @test_throws ArgumentError Printf.@sprintf("%f", parse(BigFloat, "1e99999")) @test Printf.@sprintf("%4.2s", "a") == " a" @test Printf.@sprintf("%12.3e", pi * 1.0e100) == " 3.142e+100" @test string((Printf.Format("%a")).formats[1]) == "%a" @test string((Printf.Format("%a")).formats[1]; modifier = "R") == "%Ra" @test Printf.@sprintf("%d", 3.14) == "3" @test Printf.@sprintf("%2d", 3.14) == " 3" @test Printf.@sprintf("%2d", big(3.14)) == " 3" @test Printf.@sprintf("%s", 1) == "1" @test Printf.@sprintf("%f", 1) == "1.000000" @test Printf.@sprintf("%e", 1) == "1.000000e+00" @test Printf.@sprintf("%g", 1) == "1" @test Printf.@sprintf("%.16g", 194.4778127560983) == "194.4778127560983" @test Printf.@sprintf("%.17g", 194.4778127560983) == "194.4778127560983" @test Printf.@sprintf("%.18g", 194.4778127560983) == "194.477812756098302" @test Printf.@sprintf("%.1g", 1.7976931348623157e308) == "2e+308" @test Printf.@sprintf("%.2g", 1.7976931348623157e308) == "1.8e+308" @test Printf.@sprintf("%.3g", 1.7976931348623157e308) == "1.8e+308" @test_throws ArgumentError @sprintf("%s%%%s", "a") @test @sprintf("%s%%%s", "a", "b") == "a%b" @test @sprintf("%d", 25.5) == "26" @test @sprintf(" %.1e\n", 0.999) == " 1.0e+00\n" @test @sprintf(" %.1f", 9.999) == " 10.0" @test @sprintf("%d", 1.0e100) == "10000000000000000159028911097599180468360808563945281389781327557747838772170381060813469985856815104" @test @sprintf("%d", 3 // 1) == "3" @test @sprintf("%d", Inf) == "Inf" @test @sprintf(" %d", NaN) == " NaN" @test Printf.@sprintf("") == "" @test Printf.format(Printf.Format("")) == "" end @testset "basics" begin @test Printf.@sprintf("%%") == "%" @test Printf.@sprintf("1%%") == "1%" @test Printf.@sprintf("%%1") == "%1" @test Printf.@sprintf("1%%2") == "1%2" @test Printf.@sprintf("1%%%d", 2) == "1%2" @test Printf.@sprintf("1%%2%%3") == "1%2%3" @test Printf.@sprintf("GAP[%%]") == "GAP[%]" @test Printf.@sprintf("hey there") == "hey there" @test_throws Printf.InvalidFormatStringError Printf.Format("%+") @test_throws Printf.InvalidFormatStringError Printf.Format("%.") @test_throws Printf.InvalidFormatStringError Printf.Format("%.0") @test isempty((Printf.Format("%%")).formats) @test Printf.@sprintf("%d%d", 1, 2) == "12" @test Printf.@sprintf("%d%d", [1 2]...) == "12" @test Printf.@sprintf("X%d", 2) == "X2" @test Printf.@sprintf("Ð%d", 2) == "Ð2" @test Printf.@sprintf("ༀ%d", 2) == "ༀ2" @test Printf.@sprintf("\U1ffff%d", 2) == "\U0001ffff2" @test Printf.@sprintf("%dX%d", 1, 2) == "1X2" @test Printf.@sprintf("%dÐ%d", 1, 2) == "1Ð2" @test Printf.@sprintf("%dༀ%d", 1, 2) == "1ༀ2" @test Printf.@sprintf("%d\U1ffff%d", 1, 2) == "1\U0001ffff2" @test Printf.@sprintf("%d∃%dȃ", 1, 2) == "1∃2ȃ" @test_throws Printf.InvalidFormatStringError Printf.Format("%y%d") @test_throws Printf.InvalidFormatStringError Printf.Format("%Ð%d") @test_throws Printf.InvalidFormatStringError Printf.Format("%ༀ%d") @test_throws Printf.InvalidFormatStringError Printf.Format("%\U1ffff%d") @test Printf.@sprintf("%10.5d", 4) == " 00004" @test Printf.@sprintf("%d", typemax(Int64)) == "9223372036854775807" for (fmt, val) = (("%7.2f", " 1.23"), ("%-7.2f", "1.23 "), ("%07.2f", "0001.23"), ("%.0f", "1"), ("%#.0f", "1."), ("%.4e", "1.2345e+00"), ("%.4E", "1.2345E+00"), ("%.2a", "0x1.3cp+0"), ("%.2A", "0X1.3CP+0")), num = (1.2345, 1.234499999999999999999999999999999999999999999999999999999999999999999999999991) @test Printf.format(Printf.Format(fmt), num) == val end for (fmt, val) = (("%i", "42"), ("%u", "42"), ("Test: %i", "Test: 42"), ("%#x", "0x2a"), ("%x", "2a"), ("%X", "2A"), ("% i", " 42"), ("%+i", "+42"), ("%4i", " 42"), ("%-4i", "42 "), ("%f", "42.000000"), ("%g", "42"), ("%e", "4.200000e+01")), num = (UInt16(42), UInt32(42), UInt64(42), UInt128(42), Int16(42), Int32(42), Int64(42), Int128(42), 42) @test Printf.format(Printf.Format(fmt), num) == val end for i = ((42, "", "i", "42", ""), (42, "", "d", "42", ""), (42, "", "u", "42", ""), (42, "", "x", "2a", ""), (42, "", "X", "2A", ""), (42, "", "o", "52", ""), (42, "#", "x", "2a", "0x"), (42, "#", "X", "2A", "0X"), (42, "#", "o", "052", ""), (1.2345, "", ".2f", "1.23", ""), (1.2345, "", ".2e", "1.23e+00", ""), (1.2345, "", ".2E", "1.23E+00", ""), (1.2345, "#", ".0f", "1.", ""), (1.2345, "#", ".0e", "1.e+00", ""), (1.2345, "#", ".0E", "1.E+00", ""), (1.2345, "", ".2a", "1.3cp+0", "0x"), (1.2345, "", ".2A", "1.3CP+0", "0X")) _test_flags(i...) _test_flags(-(i[1]), i[2:5]...) end @test Printf.@sprintf("Test: %s%c%C%c%#-.0f.", "t", 65, 66, 67, -42) == "Test: tABC-42.." @test Printf.@sprintf("%f %d %d %f", 1.0, [3 4]..., 5) == "1.000000 3 4 5.000000" @test Printf.@sprintf("%s %f %9.5f %d %d %d %d%d%d%d", [1:6;]..., [7, 8, 9, 10]...) == "1 2.000000 3.00000 4 5 6 78910" @test Printf.@sprintf("%s %s %s %d %d %d %f %f %f", Any[10 ^ x + y for x = 1:3, y = 1:3]...) == "11 101 1001 12 102 1002 13.000000 103.000000 1003.000000" @test Printf.@sprintf("%s %s %s %d %d %d %f %f %f %s %s %s %d %d %d %f %f %f", Any[10x + (x + 1) for x = 1:18]...) == "12 23 34 45 56 67 78.000000 89.000000 100.000000 111 122 133 144 155 166 177.000000 188.000000 199.000000" @test (Printf.@sprintf("%.330f", BigFloat(1)))[var"end"] != '\0' @test Printf.@sprintf("%f", parse(BigFloat, "1e400")) == "10000000000000000000000000000000000000000000000000000000000000000000000000000025262527574416492004687051900140830217136998040684679611623086405387447100385714565637522507383770691831689647535911648520404034824470543643098638520633064715221151920028135130764414460468236314621044034960475540018328999334468948008954289495190631358190153259681118693204411689043999084305348398480210026863210192871358464.000000" @test_throws ArgumentError Printf.@sprintf("%f", parse(BigFloat, "1e99999")) @test Printf.@sprintf("%4.2s", "a") == " a" @test Printf.@sprintf("%12.3e", pi * 1.0e100) == " 3.142e+100" @test string((Printf.Format("%a")).formats[1]) == "%a" @test string((Printf.Format("%a")).formats[1]; modifier = "R") == "%Ra" @test Printf.@sprintf("%d", 3.14) == "3" @test Printf.@sprintf("%2d", 3.14) == " 3" @test Printf.@sprintf("%2d", big(3.14)) == " 3" @test Printf.@sprintf("%s", 1) == "1" @test Printf.@sprintf("%f", 1) == "1.000000" @test Printf.@sprintf("%e", 1) == "1.000000e+00" @test Printf.@sprintf("%g", 1) == "1" @test Printf.@sprintf("%.16g", 194.4778127560983) == "194.4778127560983" @test Printf.@sprintf("%.17g", 194.4778127560983) == "194.4778127560983" @test Printf.@sprintf("%.18g", 194.4778127560983) == "194.477812756098302" @test Printf.@sprintf("%.1g", 1.7976931348623157e308) == "2e+308" @test Printf.@sprintf("%.2g", 1.7976931348623157e308) == "1.8e+308" @test Printf.@sprintf("%.3g", 1.7976931348623157e308) == "1.8e+308" @test_throws ArgumentError @sprintf("%s%%%s", "a") @test @sprintf("%s%%%s", "a", "b") == "a%b" @test @sprintf("%d", 25.5) == "26" @test @sprintf(" %.1e\n", 0.999) == " 1.0e+00\n" @test @sprintf(" %.1f", 9.999) == " 10.0" @test @sprintf("%d", 1.0e100) == "10000000000000000159028911097599180468360808563945281389781327557747838772170381060813469985856815104" @test @sprintf("%d", 3 // 1) == "3" @test @sprintf("%d", Inf) == "Inf" @test @sprintf(" %d", NaN) == " NaN" @test Printf.@sprintf("") == "" @test Printf.format(Printf.Format("")) == "" end @testset "basics" begin @test Printf.@sprintf("%%") == "%" @test Printf.@sprintf("1%%") == "1%" @test Printf.@sprintf("%%1") == "%1" @test Printf.@sprintf("1%%2") == "1%2" @test Printf.@sprintf("1%%%d", 2) == "1%2" @test Printf.@sprintf("1%%2%%3") == "1%2%3" @test Printf.@sprintf("GAP[%%]") == "GAP[%]" @test Printf.@sprintf("hey there") == "hey there" @test_throws Printf.InvalidFormatStringError Printf.Format("%+") @test_throws Printf.InvalidFormatStringError Printf.Format("%.") @test_throws Printf.InvalidFormatStringError Printf.Format("%.0") @test isempty((Printf.Format("%%")).formats) @test Printf.@sprintf("%d%d", 1, 2) == "12" @test Printf.@sprintf("%d%d", [1 2]...) == "12" @test Printf.@sprintf("X%d", 2) == "X2" @test Printf.@sprintf("Ð%d", 2) == "Ð2" @test Printf.@sprintf("ༀ%d", 2) == "ༀ2" @test Printf.@sprintf("\U1ffff%d", 2) == "\U0001ffff2" @test Printf.@sprintf("%dX%d", 1, 2) == "1X2" @test Printf.@sprintf("%dÐ%d", 1, 2) == "1Ð2" @test Printf.@sprintf("%dༀ%d", 1, 2) == "1ༀ2" @test Printf.@sprintf("%d\U1ffff%d", 1, 2) == "1\U0001ffff2" @test Printf.@sprintf("%d∃%dȃ", 1, 2) == "1∃2ȃ" @test_throws Printf.InvalidFormatStringError Printf.Format("%y%d") @test_throws Printf.InvalidFormatStringError Printf.Format("%Ð%d") @test_throws Printf.InvalidFormatStringError Printf.Format("%ༀ%d") @test_throws Printf.InvalidFormatStringError Printf.Format("%\U1ffff%d") @test Printf.@sprintf("%10.5d", 4) == " 00004" @test Printf.@sprintf("%d", typemax(Int64)) == "9223372036854775807" for (fmt, val) = (("%7.2f", " 1.23"), ("%-7.2f", "1.23 "), ("%07.2f", "0001.23"), ("%.0f", "1"), ("%#.0f", "1."), ("%.4e", "1.2345e+00"), ("%.4E", "1.2345E+00"), ("%.2a", "0x1.3cp+0"), ("%.2A", "0X1.3CP+0")), num = (1.2345, 1.234499999999999999999999999999999999999999999999999999999999999999999999999991) @test Printf.format(Printf.Format(fmt), num) == val end for (fmt, val) = (("%i", "42"), ("%u", "42"), ("Test: %i", "Test: 42"), ("%#x", "0x2a"), ("%x", "2a"), ("%X", "2A"), ("% i", " 42"), ("%+i", "+42"), ("%4i", " 42"), ("%-4i", "42 "), ("%f", "42.000000"), ("%g", "42"), ("%e", "4.200000e+01")), num = (UInt16(42), UInt32(42), UInt64(42), UInt128(42), Int16(42), Int32(42), Int64(42), Int128(42), 42) @test Printf.format(Printf.Format(fmt), num) == val end for i = ((42, "", "i", "42", ""), (42, "", "d", "42", ""), (42, "", "u", "42", ""), (42, "", "x", "2a", ""), (42, "", "X", "2A", ""), (42, "", "o", "52", ""), (42, "#", "x", "2a", "0x"), (42, "#", "X", "2A", "0X"), (42, "#", "o", "052", ""), (1.2345, "", ".2f", "1.23", ""), (1.2345, "", ".2e", "1.23e+00", ""), (1.2345, "", ".2E", "1.23E+00", ""), (1.2345, "#", ".0f", "1.", ""), (1.2345, "#", ".0e", "1.e+00", ""), (1.2345, "#", ".0E", "1.E+00", ""), (1.2345, "", ".2a", "1.3cp+0", "0x"), (1.2345, "", ".2A", "1.3CP+0", "0X")) _test_flags(i...) _test_flags(-(i[1]), i[2:5]...) end @test Printf.@sprintf("Test: %s%c%C%c%#-.0f.", "t", 65, 66, 67, -42) == "Test: tABC-42.." @test Printf.@sprintf("%f %d %d %f", 1.0, [3 4]..., 5) == "1.000000 3 4 5.000000" @test Printf.@sprintf("%s %f %9.5f %d %d %d %d%d%d%d", [1:6;]..., [7, 8, 9, 10]...) == "1 2.000000 3.00000 4 5 6 78910" @test Printf.@sprintf("%s %s %s %d %d %d %f %f %f", Any[10 ^ x + y for x = 1:3, y = 1:3]...) == "11 101 1001 12 102 1002 13.000000 103.000000 1003.000000" @test Printf.@sprintf("%s %s %s %d %d %d %f %f %f %s %s %s %d %d %d %f %f %f", Any[10x + (x + 1) for x = 1:18]...) == "12 23 34 45 56 67 78.000000 89.000000 100.000000 111 122 133 144 155 166 177.000000 188.000000 199.000000" @test (Printf.@sprintf("%.330f", BigFloat(1)))[var"end"] != '\0' @test Printf.@sprintf("%f", parse(BigFloat, "1e400")) == "10000000000000000000000000000000000000000000000000000000000000000000000000000025262527574416492004687051900140830217136998040684679611623086405387447100385714565637522507383770691831689647535911648520404034824470543643098638520633064715221151920028135130764414460468236314621044034960475540018328999334468948008954289495190631358190153259681118693204411689043999084305348398480210026863210192871358464.000000" @test_throws ArgumentError Printf.@sprintf("%f", parse(BigFloat, "1e99999")) @test Printf.@sprintf("%4.2s", "a") == " a" @test Printf.@sprintf("%12.3e", pi * 1.0e100) == " 3.142e+100" @test string((Printf.Format("%a")).formats[1]) == "%a" @test string((Printf.Format("%a")).formats[1]; modifier = "R") == "%Ra" @test Printf.@sprintf("%d", 3.14) == "3" @test Printf.@sprintf("%2d", 3.14) == " 3" @test Printf.@sprintf("%2d", big(3.14)) == " 3" @test Printf.@sprintf("%s", 1) == "1" @test Printf.@sprintf("%f", 1) == "1.000000" @test Printf.@sprintf("%e", 1) == "1.000000e+00" @test Printf.@sprintf("%g", 1) == "1" @test Printf.@sprintf("%.16g", 194.4778127560983) == "194.4778127560983" @test Printf.@sprintf("%.17g", 194.4778127560983) == "194.4778127560983" @test Printf.@sprintf("%.18g", 194.4778127560983) == "194.477812756098302" @test Printf.@sprintf("%.1g", 1.7976931348623157e308) == "2e+308" @test Printf.@sprintf("%.2g", 1.7976931348623157e308) == "1.8e+308" @test Printf.@sprintf("%.3g", 1.7976931348623157e308) == "1.8e+308" @test_throws ArgumentError @sprintf("%s%%%s", "a") @test @sprintf("%s%%%s", "a", "b") == "a%b" @test @sprintf("%d", 25.5) == "26" @test @sprintf(" %.1e\n", 0.999) == " 1.0e+00\n" @test @sprintf(" %.1f", 9.999) == " 10.0" @test @sprintf("%d", 1.0e100) == "10000000000000000159028911097599180468360808563945281389781327557747838772170381060813469985856815104" @test @sprintf("%d", 3 // 1) == "3" @test @sprintf("%d", Inf) == "Inf" @test @sprintf(" %d", NaN) == " NaN" @test Printf.@sprintf("") == "" @test Printf.format(Printf.Format("")) == "" end Printf.@sprintf "%*.*g" 10 5 -123.4000000000000000000000000000000000000000000000000000000000000000000000000002 Printf.@sprintf "%*.*g" 10 5 -123.4000000000000000000000000000000000000000000000000000000000000000000000000002 Printf.@sprintf "%10.5g" -123.4000000000000000000000000000000000000000000000000000000000000000000000000002 Printf.@sprintf "%10.5g" -123.4000000000000000000000000000000000000000000000000000000000000000000000000002 Printf.@sprintf("%*.*g", 10, 5, -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) == Printf.@sprintf("%10.5g", -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) Printf.@sprintf("%*.*g", 10, 5, -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) == Printf.@sprintf("%10.5g", -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) @test Printf.@sprintf("%*.*g", 10, 5, -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) == Printf.@sprintf("%10.5g", -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) @test Printf.@sprintf("%*.*g", 10, 5, -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) == Printf.@sprintf("%10.5g", -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) Printf.@sprintf "%0*.*g" 10 5 -123.4000000000000000000000000000000000000000000000000000000000000000000000000002 Printf.@sprintf "%0*.*g" 10 5 -123.4000000000000000000000000000000000000000000000000000000000000000000000000002 Printf.@sprintf "%010.5g" -123.4000000000000000000000000000000000000000000000000000000000000000000000000002 Printf.@sprintf "%010.5g" -123.4000000000000000000000000000000000000000000000000000000000000000000000000002 Printf.@sprintf("%0*.*g", 10, 5, -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) == Printf.@sprintf("%010.5g", -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) Printf.@sprintf("%0*.*g", 10, 5, -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) == Printf.@sprintf("%010.5g", -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) @test Printf.@sprintf("%0*.*g", 10, 5, -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) == Printf.@sprintf("%010.5g", -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) @test Printf.@sprintf("%0*.*g", 10, 5, -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) == Printf.@sprintf("%010.5g", -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) Printf.@sprintf "%.*g" 6 1.234e7 Printf.@sprintf "%.*g" 6 1.234e7 Printf.@sprintf "%.6g" 1.234e7 Printf.@sprintf "%.6g" 1.234e7 Printf.@sprintf("%.*g", 6, 1.234e7) == Printf.@sprintf("%.6g", 1.234e7) Printf.@sprintf("%.*g", 6, 1.234e7) == Printf.@sprintf("%.6g", 1.234e7) @test Printf.@sprintf("%.*g", 6, 1.234e7) == Printf.@sprintf("%.6g", 1.234e7) @test Printf.@sprintf("%.*g", 6, 1.234e7) == Printf.@sprintf("%.6g", 1.234e7) Printf.@sprintf "%#.*g" 6 1.234e7 Printf.@sprintf "%#.*g" 6 1.234e7 Printf.@sprintf "%#.6g" 1.234e7 Printf.@sprintf "%#.6g" 1.234e7 Printf.@sprintf("%#.*g", 6, 1.234e7) == Printf.@sprintf("%#.6g", 1.234e7) Printf.@sprintf("%#.*g", 6, 1.234e7) == Printf.@sprintf("%#.6g", 1.234e7) @test Printf.@sprintf("%#.*g", 6, 1.234e7) == Printf.@sprintf("%#.6g", 1.234e7) @test Printf.@sprintf("%#.*g", 6, 1.234e7) == Printf.@sprintf("%#.6g", 1.234e7) Printf.@sprintf "%*.*e" 10 4 Inf Printf.@sprintf "%*.*e" 10 4 Inf Printf.@sprintf "%10.4e" Inf Printf.@sprintf "%10.4e" Inf Printf.@sprintf("%*.*e", 10, 4, Inf) == Printf.@sprintf("%10.4e", Inf) Printf.@sprintf("%*.*e", 10, 4, Inf) == Printf.@sprintf("%10.4e", Inf) @test Printf.@sprintf("%*.*e", 10, 4, Inf) == Printf.@sprintf("%10.4e", Inf) @test Printf.@sprintf("%*.*e", 10, 4, Inf) == Printf.@sprintf("%10.4e", Inf) Printf.@sprintf "%.*e" 0 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142 Printf.@sprintf "%.*e" 0 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142 Printf.@sprintf "%.0e" 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142 Printf.@sprintf "%.0e" 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142 Printf.@sprintf("%.*e", 0, 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) == Printf.@sprintf("%.0e", 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) Printf.@sprintf("%.*e", 0, 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) == Printf.@sprintf("%.0e", 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) @test Printf.@sprintf("%.*e", 0, 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) == Printf.@sprintf("%.0e", 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) @test Printf.@sprintf("%.*e", 0, 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) == Printf.@sprintf("%.0e", 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) Printf.@sprintf "%#.*e" 0 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142 Printf.@sprintf "%#.*e" 0 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142 Printf.@sprintf "%#.0e" 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142 Printf.@sprintf "%#.0e" 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142 Printf.@sprintf("%#.*e", 0, 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) == Printf.@sprintf("%#.0e", 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) Printf.@sprintf("%#.*e", 0, 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) == Printf.@sprintf("%#.0e", 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) @test Printf.@sprintf("%#.*e", 0, 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) == Printf.@sprintf("%#.0e", 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) @test Printf.@sprintf("%#.*e", 0, 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) == Printf.@sprintf("%#.0e", 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) Printf.@sprintf "%.*e" 0 3.000000000000000000000000000000000000000000000000000000000000000000000000000024e1042 Printf.@sprintf "%.*e" 0 3.000000000000000000000000000000000000000000000000000000000000000000000000000024e1042 Printf.@sprintf "%.0e" 3.000000000000000000000000000000000000000000000000000000000000000000000000000024e1042 Printf.@sprintf "%.0e" 3.000000000000000000000000000000000000000000000000000000000000000000000000000024e1042 Printf.@sprintf("%.*e", 0, 3.000000000000000000000000000000000000000000000000000000000000000000000000000024e1042) == Printf.@sprintf("%.0e", 3.000000000000000000000000000000000000000000000000000000000000000000000000000024e1042) Printf.@sprintf("%.*e", 0, 3.000000000000000000000000000000000000000000000000000000000000000000000000000024e1042) == Printf.@sprintf("%.0e", 3.000000000000000000000000000000000000000000000000000000000000000000000000000024e1042) @test Printf.@sprintf("%.*e", 0, 3.000000000000000000000000000000000000000000000000000000000000000000000000000024e1042) == Printf.@sprintf("%.0e", 3.000000000000000000000000000000000000000000000000000000000000000000000000000024e1042) @test Printf.@sprintf("%.*e", 0, 3.000000000000000000000000000000000000000000000000000000000000000000000000000024e1042) == Printf.@sprintf("%.0e", 3.000000000000000000000000000000000000000000000000000000000000000000000000000024e1042) begin @test Printf.@sprintf("%*d", 10, 12) == " 12" @test Printf.@sprintf("%.*d", 4, 12) == "0012" @test Printf.@sprintf("%*.*d", 10, 4, 12) == " 0012" @test Printf.@sprintf("%+*.*d", 10, 4, 12) == " +0012" @test Printf.@sprintf("%0*.*d", 10, 4, 12) == " 0012" @test Printf.@sprintf("%*d%*d%*d", 4, 12, 4, 13, 4, 14) == " 12 13 14" @test Printf.@sprintf("%*d%*d%*d", 4, 12, 5, 13, 6, 14) == " 12 13 14" @test Printf.@sprintf("%*p", 20, 0) == Printf.@sprintf("%20p", 0) @test Printf.@sprintf("%-*p", 20, 0) == Printf.@sprintf("%-20p", 0) @test Printf.@sprintf("%*p", 20, C_NULL) == Printf.@sprintf("%20p", C_NULL) @test Printf.@sprintf("%-*p", 20, C_NULL) == Printf.@sprintf("%-20p", C_NULL) @test Printf.@sprintf("%.*a", 0, 3.14) == Printf.@sprintf("%.0a", 3.14) @test Printf.@sprintf("%.*a", 1, 3.14) == Printf.@sprintf("%.1a", 3.14) @test Printf.@sprintf("%.*a", 2, 3.14) == Printf.@sprintf("%.2a", 3.14) @test Printf.@sprintf("%#.*a", 0, 3.14) == Printf.@sprintf("%#.0a", 3.14) @test Printf.@sprintf("%#.*a", 1, 3.14) == Printf.@sprintf("%#.1a", 3.14) @test Printf.@sprintf("%#.*a", 2, 3.14) == Printf.@sprintf("%#.2a", 3.14) @test Printf.@sprintf("%.*a", 6, 1.5) == Printf.@sprintf("%.6a", 1.5) @test Printf.@sprintf("%*.*g", 10, 5, -123.4) == Printf.@sprintf("%10.5g", -123.4) @test Printf.@sprintf("%0*.*g", 10, 5, -123.4) == Printf.@sprintf("%010.5g", -123.4) @test Printf.@sprintf("%.*g", 6, 1.234e7) == Printf.@sprintf("%.6g", 1.234e7) @test Printf.@sprintf("%#.*g", 6, 1.234e7) == Printf.@sprintf("%#.6g", 1.234e7) @test Printf.@sprintf("%*.*g", 10, 5, -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) == Printf.@sprintf("%10.5g", -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) @test Printf.@sprintf("%0*.*g", 10, 5, -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) == Printf.@sprintf("%010.5g", -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) @test Printf.@sprintf("%.*g", 6, 1.234e7) == Printf.@sprintf("%.6g", 1.234e7) @test Printf.@sprintf("%#.*g", 6, 1.234e7) == Printf.@sprintf("%#.6g", 1.234e7) @test Printf.@sprintf("%.*g", 5, 42) == Printf.@sprintf("%.5g", 42) @test Printf.@sprintf("%#.*g", 2, 42) == Printf.@sprintf("%#.2g", 42) @test Printf.@sprintf("%#.*g", 5, 42) == Printf.@sprintf("%#.5g", 42) @test Printf.@sprintf("%.*g", 15, 0) == Printf.@sprintf("%.15g", 0) @test Printf.@sprintf("%#.*g", 15, 0) == Printf.@sprintf("%#.15g", 0) @test Printf.@sprintf("%.*f", 0, 3.0e142) == Printf.@sprintf("%.0f", 3.0e142) @test Printf.@sprintf("%.*f", 2, 1.234) == Printf.@sprintf("%.2f", 1.234) @test Printf.@sprintf("%.*f", 2, 1.235) == Printf.@sprintf("%.2f", 1.235) @test Printf.@sprintf("%.*f", 2, 0.235) == Printf.@sprintf("%.2f", 0.235) @test Printf.@sprintf("%*.*f", 4, 1, 1.234) == Printf.@sprintf("%4.1f", 1.234) @test Printf.@sprintf("%*.*f", 8, 1, 1.234) == Printf.@sprintf("%8.1f", 1.234) @test Printf.@sprintf("%+*.*f", 8, 1, 1.234) == Printf.@sprintf("%+8.1f", 1.234) @test Printf.@sprintf("% *.*f", 8, 1, 1.234) == Printf.@sprintf("% 8.1f", 1.234) @test Printf.@sprintf("% *.*f", 7, 1, 1.234) == Printf.@sprintf("% 7.1f", 1.234) @test Printf.@sprintf("% 0*.*f", 8, 1, 1.234) == Printf.@sprintf("% 08.1f", 1.234) @test Printf.@sprintf("%0*.*f", 8, 1, 1.234) == Printf.@sprintf("%08.1f", 1.234) @test Printf.@sprintf("%-0*.*f", 8, 1, 1.234) == Printf.@sprintf("%-08.1f", 1.234) @test Printf.@sprintf("%-*.*f", 8, 1, 1.234) == Printf.@sprintf("%-8.1f", 1.234) @test Printf.@sprintf("%0*.*f", 8, 1, -1.234) == Printf.@sprintf("%08.1f", -1.234) @test Printf.@sprintf("%0*.*f", 9, 1, -1.234) == Printf.@sprintf("%09.1f", -1.234) @test Printf.@sprintf("%0*.*f", 9, 1, 1.234) == Printf.@sprintf("%09.1f", 1.234) @test Printf.@sprintf("%+0*.*f", 9, 1, 1.234) == Printf.@sprintf("%+09.1f", 1.234) @test Printf.@sprintf("% 0*.*f", 9, 1, 1.234) == Printf.@sprintf("% 09.1f", 1.234) @test Printf.@sprintf("%+ 0*.*f", 9, 1, 1.234) == Printf.@sprintf("%+ 09.1f", 1.234) @test Printf.@sprintf("%+ 0*.*f", 9, 1, 1.234) == Printf.@sprintf("%+ 09.1f", 1.234) @test Printf.@sprintf("%+ 0*.*f", 9, 0, 1.234) == Printf.@sprintf("%+ 09.0f", 1.234) @test Printf.@sprintf("%+ #0*.*f", 9, 0, 1.234) == Printf.@sprintf("%+ #09.0f", 1.234) @test Printf.@sprintf("%*.*e", 10, 4, Inf) == Printf.@sprintf("%10.4e", Inf) @test Printf.@sprintf("%*.*e", 10, 4, NaN) == Printf.@sprintf("%10.4e", NaN) @test Printf.@sprintf("%*.*e", 10, 4, Inf) == Printf.@sprintf("%10.4e", Inf) @test Printf.@sprintf("%*.*e", 10, 4, NaN) == Printf.@sprintf("%10.4e", NaN) @test Printf.@sprintf("%.*e", 0, 3.0e142) == Printf.@sprintf("%.0e", 3.0e142) @test Printf.@sprintf("%#.*e", 0, 3.0e142) == Printf.@sprintf("%#.0e", 3.0e142) @test Printf.@sprintf("%.*e", 0, 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) == Printf.@sprintf("%.0e", 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) @test Printf.@sprintf("%#.*e", 0, 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) == Printf.@sprintf("%#.0e", 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) @test Printf.@sprintf("%.*e", 0, 3.000000000000000000000000000000000000000000000000000000000000000000000000000024e1042) == Printf.@sprintf("%.0e", 3.000000000000000000000000000000000000000000000000000000000000000000000000000024e1042) @test Printf.@sprintf("%.*e", 2, 1.234) == Printf.@sprintf("%.2e", 1.234) @test Printf.@sprintf("%.*e", 2, 1.235) == Printf.@sprintf("%.2e", 1.235) @test Printf.@sprintf("%.*e", 2, 0.235) == Printf.@sprintf("%.2e", 0.235) @test Printf.@sprintf("%*.*e", 4, 1, 1.234) == Printf.@sprintf("%4.1e", 1.234) @test Printf.@sprintf("%*.*e", 8, 1, 1.234) == Printf.@sprintf("%8.1e", 1.234) @test Printf.@sprintf("%+*.*e", 8, 1, 1.234) == Printf.@sprintf("%+8.1e", 1.234) @test Printf.@sprintf("% *.*e", 8, 1, 1.234) == Printf.@sprintf("% 8.1e", 1.234) @test Printf.@sprintf("% *.*e", 7, 1, 1.234) == Printf.@sprintf("% 7.1e", 1.234) @test Printf.@sprintf("% 0*.*e", 8, 1, 1.234) == Printf.@sprintf("% 08.1e", 1.234) @test Printf.@sprintf("%0*.*e", 8, 1, 1.234) == Printf.@sprintf("%08.1e", 1.234) @test Printf.@sprintf("%-0*.*e", 8, 1, 1.234) == Printf.@sprintf("%-08.1e", 1.234) @test Printf.@sprintf("%-*.*e", 8, 1, 1.234) == Printf.@sprintf("%-8.1e", 1.234) @test Printf.@sprintf("%-*.*e", 8, 1, 1.234) == Printf.@sprintf("%-8.1e", 1.234) @test Printf.@sprintf("%0*.*e", 8, 1, -1.234) == Printf.@sprintf("%08.1e", -1.234) @test Printf.@sprintf("%0*.*e", 9, 1, -1.234) == Printf.@sprintf("%09.1e", -1.234) @test Printf.@sprintf("%0*.*e", 9, 1, 1.234) == Printf.@sprintf("%09.1e", 1.234) @test Printf.@sprintf("%+0*.*e", 9, 1, 1.234) == Printf.@sprintf("%+09.1e", 1.234) @test Printf.@sprintf("% 0*.*e", 9, 1, 1.234) == Printf.@sprintf("% 09.1e", 1.234) @test Printf.@sprintf("%+ 0*.*e", 9, 1, 1.234) == Printf.@sprintf("%+ 09.1e", 1.234) @test Printf.@sprintf("%+ 0*.*e", 9, 1, 1.234) == Printf.@sprintf("%+ 09.1e", 1.234) @test Printf.@sprintf("%+ 0*.*e", 9, 0, 1.234) == Printf.@sprintf("%+ 09.0e", 1.234) @test Printf.@sprintf("%+ #0*.*e", 9, 0, 1.234) == Printf.@sprintf("%+ #09.0e", 1.234) @test Printf.@sprintf("%.*s", 1, "foo") == Printf.@sprintf("%.1s", "foo") @test Printf.@sprintf("%*s", 1, "Hallo heimur") == Printf.@sprintf("%1s", "Hallo heimur") @test Printf.@sprintf("%*s", 20, "Hallo") == Printf.@sprintf("%20s", "Hallo") @test Printf.@sprintf("%-*s", 20, "Hallo") == Printf.@sprintf("%-20s", "Hallo") @test Printf.@sprintf("%0-*s", 20, "Hallo") == Printf.@sprintf("%0-20s", "Hallo") @test Printf.@sprintf("%.*s", 20, "Hallo heimur") == Printf.@sprintf("%.20s", "Hallo heimur") @test Printf.@sprintf("%*.*s", 20, 5, "Hallo heimur") == Printf.@sprintf("%20.5s", "Hallo heimur") @test Printf.@sprintf("%.*s", 0, "Hallo heimur") == Printf.@sprintf("%.0s", "Hallo heimur") @test Printf.@sprintf("%*.*s", 20, 0, "Hallo heimur") == Printf.@sprintf("%20.0s", "Hallo heimur") @test Printf.@sprintf("%.s", "Hallo heimur") == Printf.@sprintf("%.s", "Hallo heimur") @test Printf.@sprintf("%*.s", 20, "Hallo heimur") == Printf.@sprintf("%20.s", "Hallo heimur") @test Printf.@sprintf("%*sø", 4, "ø") == Printf.@sprintf("%4sø", "ø") @test Printf.@sprintf("%-*sø", 4, "ø") == Printf.@sprintf("%-4sø", "ø") @test Printf.@sprintf("%*s", 8, "test") == Printf.@sprintf("%8s", "test") @test Printf.@sprintf("%-*s", 8, "test") == Printf.@sprintf("%-8s", "test") @test Printf.@sprintf("%#*s", 8, :test) == Printf.@sprintf("%#8s", :test) @test Printf.@sprintf("%#-*s", 8, :test) == Printf.@sprintf("%#-8s", :test) @test Printf.@sprintf("%*.*s", 8, 3, "test") == Printf.@sprintf("%8.3s", "test") @test Printf.@sprintf("%#*.*s", 8, 3, "test") == Printf.@sprintf("%#8.3s", "test") @test Printf.@sprintf("%-*.*s", 8, 3, "test") == Printf.@sprintf("%-8.3s", "test") @test Printf.@sprintf("%#-*.*s", 8, 3, "test") == Printf.@sprintf("%#-8.3s", "test") @test Printf.@sprintf("%.*s", 3, "test") == Printf.@sprintf("%.3s", "test") @test Printf.@sprintf("%#.*s", 3, "test") == Printf.@sprintf("%#.3s", "test") @test Printf.@sprintf("%-.*s", 3, "test") == Printf.@sprintf("%-.3s", "test") @test Printf.@sprintf("%#-.*s", 3, "test") == Printf.@sprintf("%#-.3s", "test") @test Printf.@sprintf("%*c", 3, 'a') == Printf.@sprintf("%3c", 'a') @test Printf.@sprintf("%*c", 1, 'x') == Printf.@sprintf("%1c", 'x') @test Printf.@sprintf("%*c", 20, 'x') == Printf.@sprintf("%20c", 'x') @test Printf.@sprintf("%-*c", 20, 'x') == Printf.@sprintf("%-20c", 'x') @test Printf.@sprintf("%-0*c", 20, 'x') == Printf.@sprintf("%-020c", 'x') @test Printf.@sprintf("%*c", 3, 'A') == Printf.@sprintf("%3c", 'A') @test Printf.@sprintf("%-*c", 3, 'A') == Printf.@sprintf("%-3c", 'A') @test Printf.@sprintf("%*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f", 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345) == Printf.@sprintf("%4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f", 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345) @test (Printf.@sprintf("%.*f", 330, BigFloat(1)))[var"end"] != '\0' @test Printf.@sprintf("%*.*s", 4, 2, "a") == Printf.@sprintf("%4.2s", "a") @test Printf.@sprintf("%*.*e", 12, 3, pi * 1.0e100) == Printf.@sprintf("%12.3e", pi * 1.0e100) @test Printf.@sprintf("%*d", 2, 3.14) == Printf.@sprintf("%*d", 2, 3.14) @test Printf.@sprintf("%*d", 2, big(3.14)) == Printf.@sprintf("%*d", 2, big(3.14)) @test Printf.@sprintf(" %.*e\n", 1, 0.999) == Printf.@sprintf(" %.1e\n", 0.999) @test Printf.@sprintf(" %.*f", 1, 9.999) == Printf.@sprintf(" %.1f", 9.999) @test Printf.@sprintf("%*d", 10, 12) == Printf.@sprintf("%10d", 12) @test Printf.@sprintf("%.*d", 4, 12) == Printf.@sprintf("%.4d", 12) @test Printf.@sprintf("%*.*d", 10, 4, 12) == Printf.@sprintf("%10.4d", 12) @test Printf.@sprintf("%+*.*d", 10, 4, 12) == Printf.@sprintf("%+10.4d", 12) @test Printf.@sprintf("%0*.*d", 10, 4, 12) == Printf.@sprintf("%010.4d", 12) @test Printf.@sprintf("% *d", 5, 42) == Printf.@sprintf("% 5d", 42) @test Printf.@sprintf("% *d", 5, -42) == Printf.@sprintf("% 5d", -42) @test Printf.@sprintf("% *d", 15, 42) == Printf.@sprintf("% 15d", 42) @test Printf.@sprintf("% *d", 15, -42) == Printf.@sprintf("% 15d", -42) @test Printf.@sprintf("%+*d", 5, 42) == Printf.@sprintf("%+5d", 42) @test Printf.@sprintf("%+*d", 5, -42) == Printf.@sprintf("%+5d", -42) @test Printf.@sprintf("%+*d", 15, 42) == Printf.@sprintf("%+15d", 42) @test Printf.@sprintf("%+*d", 15, -42) == Printf.@sprintf("%+15d", -42) @test Printf.@sprintf("%*d", 0, 42) == Printf.@sprintf("%0d", 42) @test Printf.@sprintf("%*d", 0, -42) == Printf.@sprintf("%0d", -42) @test Printf.@sprintf("%-*d", 5, 42) == Printf.@sprintf("%-5d", 42) @test Printf.@sprintf("%-*d", 5, -42) == Printf.@sprintf("%-5d", -42) @test Printf.@sprintf("%-*d", 15, 42) == Printf.@sprintf("%-15d", 42) @test Printf.@sprintf("%-*d", 15, -42) == Printf.@sprintf("%-15d", -42) @test Printf.@sprintf("%+*lld", 8, 100) == Printf.@sprintf("%+8lld", 100) @test Printf.@sprintf("%+.*lld", 8, 100) == Printf.@sprintf("%+.8lld", 100) @test Printf.@sprintf("%+*.*lld", 10, 8, 100) == Printf.@sprintf("%+10.8lld", 100) @test Printf.@sprintf("%-*.*lld", 1, 5, -100) == Printf.@sprintf("%-1.5lld", -100) @test Printf.@sprintf("%*lld", 5, 100) == Printf.@sprintf("%5lld", 100) @test Printf.@sprintf("%*lld", 5, -100) == Printf.@sprintf("%5lld", -100) @test Printf.@sprintf("%-*lld", 5, 100) == Printf.@sprintf("%-5lld", 100) @test Printf.@sprintf("%-*lld", 5, -100) == Printf.@sprintf("%-5lld", -100) @test Printf.@sprintf("%-.*lld", 5, 100) == Printf.@sprintf("%-.5lld", 100) @test Printf.@sprintf("%-.*lld", 5, -100) == Printf.@sprintf("%-.5lld", -100) @test Printf.@sprintf("%-*.*lld", 8, 5, 100) == Printf.@sprintf("%-8.5lld", 100) @test Printf.@sprintf("%-*.*lld", 8, 5, -100) == Printf.@sprintf("%-8.5lld", -100) @test Printf.@sprintf("%0*lld", 5, 100) == Printf.@sprintf("%05lld", 100) @test Printf.@sprintf("%0*lld", 5, -100) == Printf.@sprintf("%05lld", -100) @test Printf.@sprintf("% *lld", 5, 100) == Printf.@sprintf("% 5lld", 100) @test Printf.@sprintf("% *lld", 5, -100) == Printf.@sprintf("% 5lld", -100) @test Printf.@sprintf("% .*lld", 5, 100) == Printf.@sprintf("% .5lld", 100) @test Printf.@sprintf("% .*lld", 5, -100) == Printf.@sprintf("% .5lld", -100) @test Printf.@sprintf("% *.*lld", 8, 5, 100) == Printf.@sprintf("% 8.5lld", 100) @test Printf.@sprintf("% *.*lld", 8, 5, -100) == Printf.@sprintf("% 8.5lld", -100) @test Printf.@sprintf("%.*lld", 0, 0) == Printf.@sprintf("%.0lld", 0) @test Printf.@sprintf("%#+*.*llx", 21, 18, -100) == Printf.@sprintf("%#+21.18llx", -100) @test Printf.@sprintf("%#.*llo", 25, -100) == Printf.@sprintf("%#.25llo", -100) @test Printf.@sprintf("%#+*.*llo", 24, 20, -100) == Printf.@sprintf("%#+24.20llo", -100) @test Printf.@sprintf("%#+*.*llX", 18, 21, -100) == Printf.@sprintf("%#+18.21llX", -100) @test Printf.@sprintf("%#+*.*llo", 20, 24, -100) == Printf.@sprintf("%#+20.24llo", -100) @test Printf.@sprintf("%#+*.*llu", 25, 22, -1) == Printf.@sprintf("%#+25.22llu", -1) @test Printf.@sprintf("%#+*.*llu", 30, 25, -1) == Printf.@sprintf("%#+30.25llu", -1) @test Printf.@sprintf("%+#*.*lld", 25, 22, -1) == Printf.@sprintf("%+#25.22lld", -1) @test Printf.@sprintf("%#-*.*llo", 8, 5, 100) == Printf.@sprintf("%#-8.5llo", 100) @test Printf.@sprintf("%#-+ 0*.*lld", 8, 5, 100) == Printf.@sprintf("%#-+ 08.5lld", 100) @test Printf.@sprintf("%#-+ 0*.*lld", 8, 5, 100) == Printf.@sprintf("%#-+ 08.5lld", 100) @test Printf.@sprintf("%.*lld", 40, 1) == Printf.@sprintf("%.40lld", 1) @test Printf.@sprintf("% .*lld", 40, 1) == Printf.@sprintf("% .40lld", 1) @test Printf.@sprintf("% .*d", 40, 1) == Printf.@sprintf("% .40d", 1) @test Printf.@sprintf("%#0*x", 12, 1) == Printf.@sprintf("%#012x", 1) @test Printf.@sprintf("%#0*.*x", 4, 8, 1) == Printf.@sprintf("%#04.8x", 1) @test Printf.@sprintf("%#-0*.*x", 8, 2, 1) == Printf.@sprintf("%#-08.2x", 1) @test Printf.@sprintf("%#0*o", 8, 1) == Printf.@sprintf("%#08o", 1) @test Printf.@sprintf("%*d", 20, 1024) == Printf.@sprintf("%20d", 1024) @test Printf.@sprintf("%*d", 20, -1024) == Printf.@sprintf("%20d", -1024) @test Printf.@sprintf("%*i", 20, 1024) == Printf.@sprintf("%20i", 1024) @test Printf.@sprintf("%*i", 20, -1024) == Printf.@sprintf("%20i", -1024) @test Printf.@sprintf("%*u", 20, 1024) == Printf.@sprintf("%20u", 1024) @test Printf.@sprintf("%*u", 20, UInt(4294966272)) == Printf.@sprintf("%20u", UInt(4294966272)) @test Printf.@sprintf("%*o", 20, 511) == Printf.@sprintf("%20o", 511) @test Printf.@sprintf("%*o", 20, UInt(4294966785)) == Printf.@sprintf("%20o", UInt(4294966785)) @test Printf.@sprintf("%*x", 20, 305441741) == Printf.@sprintf("%20x", 305441741) @test Printf.@sprintf("%*x", 20, UInt(3989525555)) == Printf.@sprintf("%20x", UInt(3989525555)) @test Printf.@sprintf("%*X", 20, 305441741) == Printf.@sprintf("%20X", 305441741) @test Printf.@sprintf("%*X", 20, UInt(3989525555)) == Printf.@sprintf("%20X", UInt(3989525555)) @test Printf.@sprintf("%-*d", 20, 1024) == Printf.@sprintf("%-20d", 1024) @test Printf.@sprintf("%-*d", 20, -1024) == Printf.@sprintf("%-20d", -1024) @test Printf.@sprintf("%-*i", 20, 1024) == Printf.@sprintf("%-20i", 1024) @test Printf.@sprintf("%-*i", 20, -1024) == Printf.@sprintf("%-20i", -1024) @test Printf.@sprintf("%-*u", 20, 1024) == Printf.@sprintf("%-20u", 1024) @test Printf.@sprintf("%-*u", 20, UInt(4294966272)) == Printf.@sprintf("%-20u", UInt(4294966272)) @test Printf.@sprintf("%-*o", 20, 511) == Printf.@sprintf("%-20o", 511) @test Printf.@sprintf("%-*o", 20, UInt(4294966785)) == Printf.@sprintf("%-20o", UInt(4294966785)) @test Printf.@sprintf("%-*x", 20, 305441741) == Printf.@sprintf("%-20x", 305441741) @test Printf.@sprintf("%-*x", 20, UInt(3989525555)) == Printf.@sprintf("%-20x", UInt(3989525555)) @test Printf.@sprintf("%-*X", 20, 305441741) == Printf.@sprintf("%-20X", 305441741) @test Printf.@sprintf("%-*X", 20, UInt(3989525555)) == Printf.@sprintf("%-20X", UInt(3989525555)) @test Printf.@sprintf("%0*d", 20, 1024) == Printf.@sprintf("%020d", 1024) @test Printf.@sprintf("%0*d", 20, -1024) == Printf.@sprintf("%020d", -1024) @test Printf.@sprintf("%0*i", 20, 1024) == Printf.@sprintf("%020i", 1024) @test Printf.@sprintf("%0*i", 20, -1024) == Printf.@sprintf("%020i", -1024) @test Printf.@sprintf("%0*u", 20, 1024) == Printf.@sprintf("%020u", 1024) @test Printf.@sprintf("%0*u", 20, UInt(4294966272)) == Printf.@sprintf("%020u", UInt(4294966272)) @test Printf.@sprintf("%0*o", 20, 511) == Printf.@sprintf("%020o", 511) @test Printf.@sprintf("%0*o", 20, UInt(4294966785)) == Printf.@sprintf("%020o", UInt(4294966785)) @test Printf.@sprintf("%0*x", 20, 305441741) == Printf.@sprintf("%020x", 305441741) @test Printf.@sprintf("%0*x", 20, UInt(3989525555)) == Printf.@sprintf("%020x", UInt(3989525555)) @test Printf.@sprintf("%0*X", 20, 305441741) == Printf.@sprintf("%020X", 305441741) @test Printf.@sprintf("%0*X", 20, UInt(3989525555)) == Printf.@sprintf("%020X", UInt(3989525555)) @test Printf.@sprintf("%#*o", 20, 511) == Printf.@sprintf("%#20o", 511) @test Printf.@sprintf("%#*o", 20, UInt(4294966785)) == Printf.@sprintf("%#20o", UInt(4294966785)) @test Printf.@sprintf("%#*x", 20, 305441741) == Printf.@sprintf("%#20x", 305441741) @test Printf.@sprintf("%#*x", 20, UInt(3989525555)) == Printf.@sprintf("%#20x", UInt(3989525555)) @test Printf.@sprintf("%#*X", 20, 305441741) == Printf.@sprintf("%#20X", 305441741) @test Printf.@sprintf("%#*X", 20, UInt(3989525555)) == Printf.@sprintf("%#20X", UInt(3989525555)) @test Printf.@sprintf("%#0*o", 20, 511) == Printf.@sprintf("%#020o", 511) @test Printf.@sprintf("%#0*o", 20, UInt(4294966785)) == Printf.@sprintf("%#020o", UInt(4294966785)) @test Printf.@sprintf("%#0*x", 20, 305441741) == Printf.@sprintf("%#020x", 305441741) @test Printf.@sprintf("%#0*x", 20, UInt(3989525555)) == Printf.@sprintf("%#020x", UInt(3989525555)) @test Printf.@sprintf("%#0*X", 20, 305441741) == Printf.@sprintf("%#020X", 305441741) @test Printf.@sprintf("%#0*X", 20, UInt(3989525555)) == Printf.@sprintf("%#020X", UInt(3989525555)) @test Printf.@sprintf("%0-*d", 20, 1024) == Printf.@sprintf("%0-20d", 1024) @test Printf.@sprintf("%0-*d", 20, -1024) == Printf.@sprintf("%0-20d", -1024) @test Printf.@sprintf("%0-*i", 20, 1024) == Printf.@sprintf("%0-20i", 1024) @test Printf.@sprintf("%0-*i", 20, -1024) == Printf.@sprintf("%0-20i", -1024) @test Printf.@sprintf("%0-*u", 20, 1024) == Printf.@sprintf("%0-20u", 1024) @test Printf.@sprintf("%0-*u", 20, UInt(4294966272)) == Printf.@sprintf("%0-20u", UInt(4294966272)) @test Printf.@sprintf("%-0*o", 20, 511) == Printf.@sprintf("%-020o", 511) @test Printf.@sprintf("%-0*o", 20, UInt(4294966785)) == Printf.@sprintf("%-020o", UInt(4294966785)) @test Printf.@sprintf("%-0*x", 20, 305441741) == Printf.@sprintf("%-020x", 305441741) @test Printf.@sprintf("%-0*x", 20, UInt(3989525555)) == Printf.@sprintf("%-020x", UInt(3989525555)) @test Printf.@sprintf("%-0*X", 20, 305441741) == Printf.@sprintf("%-020X", 305441741) @test Printf.@sprintf("%-0*X", 20, UInt(3989525555)) == Printf.@sprintf("%-020X", UInt(3989525555)) @test Printf.@sprintf("%.*d", 20, 1024) == Printf.@sprintf("%.20d", 1024) @test Printf.@sprintf("%.*d", 20, -1024) == Printf.@sprintf("%.20d", -1024) @test Printf.@sprintf("%.*i", 20, 1024) == Printf.@sprintf("%.20i", 1024) @test Printf.@sprintf("%.*i", 20, -1024) == Printf.@sprintf("%.20i", -1024) @test Printf.@sprintf("%.*u", 20, 1024) == Printf.@sprintf("%.20u", 1024) @test Printf.@sprintf("%.*u", 20, UInt(4294966272)) == Printf.@sprintf("%.20u", UInt(4294966272)) @test Printf.@sprintf("%.*o", 20, 511) == Printf.@sprintf("%.20o", 511) @test Printf.@sprintf("%.*o", 20, UInt(4294966785)) == Printf.@sprintf("%.20o", UInt(4294966785)) @test Printf.@sprintf("%.*x", 20, 305441741) == Printf.@sprintf("%.20x", 305441741) @test Printf.@sprintf("%.*x", 20, UInt(3989525555)) == Printf.@sprintf("%.20x", UInt(3989525555)) @test Printf.@sprintf("%.*X", 20, 305441741) == Printf.@sprintf("%.20X", 305441741) @test Printf.@sprintf("%.*X", 20, UInt(3989525555)) == Printf.@sprintf("%.20X", UInt(3989525555)) @test Printf.@sprintf("%*.*d", 20, 5, 1024) == Printf.@sprintf("%20.5d", 1024) @test Printf.@sprintf("%*.*d", 20, 5, -1024) == Printf.@sprintf("%20.5d", -1024) @test Printf.@sprintf("%*.*i", 20, 5, 1024) == Printf.@sprintf("%20.5i", 1024) @test Printf.@sprintf("%*.*i", 20, 5, -1024) == Printf.@sprintf("%20.5i", -1024) @test Printf.@sprintf("%*.*u", 20, 5, 1024) == Printf.@sprintf("%20.5u", 1024) @test Printf.@sprintf("%*.*u", 20, 5, UInt(4294966272)) == Printf.@sprintf("%20.5u", UInt(4294966272)) @test Printf.@sprintf("%*.*o", 20, 5, 511) == Printf.@sprintf("%20.5o", 511) @test Printf.@sprintf("%*.*o", 20, 5, UInt(4294966785)) == Printf.@sprintf("%20.5o", UInt(4294966785)) @test Printf.@sprintf("%*.*x", 20, 5, 305441741) == Printf.@sprintf("%20.5x", 305441741) @test Printf.@sprintf("%*.*x", 20, 10, UInt(3989525555)) == Printf.@sprintf("%20.10x", UInt(3989525555)) @test Printf.@sprintf("%*.*X", 20, 5, 305441741) == Printf.@sprintf("%20.5X", 305441741) @test Printf.@sprintf("%*.*X", 20, 10, UInt(3989525555)) == Printf.@sprintf("%20.10X", UInt(3989525555)) @test Printf.@sprintf("%0*.*d", 20, 5, 1024) == Printf.@sprintf("%020.5d", 1024) @test Printf.@sprintf("%0*.*d", 20, 5, -1024) == Printf.@sprintf("%020.5d", -1024) @test Printf.@sprintf("%0*.*i", 20, 5, 1024) == Printf.@sprintf("%020.5i", 1024) @test Printf.@sprintf("%0*.*i", 20, 5, -1024) == Printf.@sprintf("%020.5i", -1024) @test Printf.@sprintf("%0*.*u", 20, 5, 1024) == Printf.@sprintf("%020.5u", 1024) @test Printf.@sprintf("%0*.*u", 20, 5, UInt(4294966272)) == Printf.@sprintf("%020.5u", UInt(4294966272)) @test Printf.@sprintf("%0*.*o", 20, 5, 511) == Printf.@sprintf("%020.5o", 511) @test Printf.@sprintf("%0*.*o", 20, 5, UInt(4294966785)) == Printf.@sprintf("%020.5o", UInt(4294966785)) @test Printf.@sprintf("%0*.*x", 20, 5, 305441741) == Printf.@sprintf("%020.5x", 305441741) @test Printf.@sprintf("%0*.*x", 20, 10, UInt(3989525555)) == Printf.@sprintf("%020.10x", UInt(3989525555)) @test Printf.@sprintf("%0*.*X", 20, 5, 305441741) == Printf.@sprintf("%020.5X", 305441741) @test Printf.@sprintf("%0*.*X", 20, 10, UInt(3989525555)) == Printf.@sprintf("%020.10X", UInt(3989525555)) @test Printf.@sprintf("%*.0d", 20, 1024) == Printf.@sprintf("%20.0d", 1024) @test Printf.@sprintf("%*.d", 20, -1024) == Printf.@sprintf("%20.d", -1024) @test Printf.@sprintf("%*.d", 20, 0) == Printf.@sprintf("%20.d", 0) @test Printf.@sprintf("%*.0i", 20, 1024) == Printf.@sprintf("%20.0i", 1024) @test Printf.@sprintf("%*.i", 20, -1024) == Printf.@sprintf("%20.i", -1024) @test Printf.@sprintf("%*.i", 20, 0) == Printf.@sprintf("%20.i", 0) @test Printf.@sprintf("%*.u", 20, 1024) == Printf.@sprintf("%20.u", 1024) @test Printf.@sprintf("%*.0u", 20, UInt(4294966272)) == Printf.@sprintf("%20.0u", UInt(4294966272)) @test Printf.@sprintf("%*.u", 20, UInt(0)) == Printf.@sprintf("%20.u", UInt(0)) @test Printf.@sprintf("%*.o", 20, 511) == Printf.@sprintf("%20.o", 511) @test Printf.@sprintf("%*.0o", 20, UInt(4294966785)) == Printf.@sprintf("%20.0o", UInt(4294966785)) @test Printf.@sprintf("%*.o", 20, UInt(0)) == Printf.@sprintf("%20.o", UInt(0)) @test Printf.@sprintf("%*.x", 20, 305441741) == Printf.@sprintf("%20.x", 305441741) @test Printf.@sprintf("%*.0x", 20, UInt(3989525555)) == Printf.@sprintf("%20.0x", UInt(3989525555)) @test Printf.@sprintf("%*.x", 20, UInt(0)) == Printf.@sprintf("%20.x", UInt(0)) @test Printf.@sprintf("%*.X", 20, 305441741) == Printf.@sprintf("%20.X", 305441741) @test Printf.@sprintf("%*.0X", 20, UInt(3989525555)) == Printf.@sprintf("%20.0X", UInt(3989525555)) @test Printf.@sprintf("%*.X", 20, UInt(0)) == Printf.@sprintf("%20.X", UInt(0)) x = Ref{Int}() y = Ref{Int}() @test begin Printf.@sprintf "%10s%n" "😉" x Printf.@sprintf "%*s%n" 10 "😉" y x[] == y[] end @test begin Printf.@sprintf "%10s%n" "1234" x Printf.@sprintf "%*s%n" 10 "1234" y x[] == y[] end end begin @test Printf.@sprintf("%*d", 10, 12) == " 12" @test Printf.@sprintf("%.*d", 4, 12) == "0012" @test Printf.@sprintf("%*.*d", 10, 4, 12) == " 0012" @test Printf.@sprintf("%+*.*d", 10, 4, 12) == " +0012" @test Printf.@sprintf("%0*.*d", 10, 4, 12) == " 0012" @test Printf.@sprintf("%*d%*d%*d", 4, 12, 4, 13, 4, 14) == " 12 13 14" @test Printf.@sprintf("%*d%*d%*d", 4, 12, 5, 13, 6, 14) == " 12 13 14" @test Printf.@sprintf("%*p", 20, 0) == Printf.@sprintf("%20p", 0) @test Printf.@sprintf("%-*p", 20, 0) == Printf.@sprintf("%-20p", 0) @test Printf.@sprintf("%*p", 20, C_NULL) == Printf.@sprintf("%20p", C_NULL) @test Printf.@sprintf("%-*p", 20, C_NULL) == Printf.@sprintf("%-20p", C_NULL) @test Printf.@sprintf("%.*a", 0, 3.14) == Printf.@sprintf("%.0a", 3.14) @test Printf.@sprintf("%.*a", 1, 3.14) == Printf.@sprintf("%.1a", 3.14) @test Printf.@sprintf("%.*a", 2, 3.14) == Printf.@sprintf("%.2a", 3.14) @test Printf.@sprintf("%#.*a", 0, 3.14) == Printf.@sprintf("%#.0a", 3.14) @test Printf.@sprintf("%#.*a", 1, 3.14) == Printf.@sprintf("%#.1a", 3.14) @test Printf.@sprintf("%#.*a", 2, 3.14) == Printf.@sprintf("%#.2a", 3.14) @test Printf.@sprintf("%.*a", 6, 1.5) == Printf.@sprintf("%.6a", 1.5) @test Printf.@sprintf("%*.*g", 10, 5, -123.4) == Printf.@sprintf("%10.5g", -123.4) @test Printf.@sprintf("%0*.*g", 10, 5, -123.4) == Printf.@sprintf("%010.5g", -123.4) @test Printf.@sprintf("%.*g", 6, 1.234e7) == Printf.@sprintf("%.6g", 1.234e7) @test Printf.@sprintf("%#.*g", 6, 1.234e7) == Printf.@sprintf("%#.6g", 1.234e7) @test Printf.@sprintf("%*.*g", 10, 5, -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) == Printf.@sprintf("%10.5g", -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) @test Printf.@sprintf("%0*.*g", 10, 5, -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) == Printf.@sprintf("%010.5g", -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) @test Printf.@sprintf("%.*g", 6, 1.234e7) == Printf.@sprintf("%.6g", 1.234e7) @test Printf.@sprintf("%#.*g", 6, 1.234e7) == Printf.@sprintf("%#.6g", 1.234e7) @test Printf.@sprintf("%.*g", 5, 42) == Printf.@sprintf("%.5g", 42) @test Printf.@sprintf("%#.*g", 2, 42) == Printf.@sprintf("%#.2g", 42) @test Printf.@sprintf("%#.*g", 5, 42) == Printf.@sprintf("%#.5g", 42) @test Printf.@sprintf("%.*g", 15, 0) == Printf.@sprintf("%.15g", 0) @test Printf.@sprintf("%#.*g", 15, 0) == Printf.@sprintf("%#.15g", 0) @test Printf.@sprintf("%.*f", 0, 3.0e142) == Printf.@sprintf("%.0f", 3.0e142) @test Printf.@sprintf("%.*f", 2, 1.234) == Printf.@sprintf("%.2f", 1.234) @test Printf.@sprintf("%.*f", 2, 1.235) == Printf.@sprintf("%.2f", 1.235) @test Printf.@sprintf("%.*f", 2, 0.235) == Printf.@sprintf("%.2f", 0.235) @test Printf.@sprintf("%*.*f", 4, 1, 1.234) == Printf.@sprintf("%4.1f", 1.234) @test Printf.@sprintf("%*.*f", 8, 1, 1.234) == Printf.@sprintf("%8.1f", 1.234) @test Printf.@sprintf("%+*.*f", 8, 1, 1.234) == Printf.@sprintf("%+8.1f", 1.234) @test Printf.@sprintf("% *.*f", 8, 1, 1.234) == Printf.@sprintf("% 8.1f", 1.234) @test Printf.@sprintf("% *.*f", 7, 1, 1.234) == Printf.@sprintf("% 7.1f", 1.234) @test Printf.@sprintf("% 0*.*f", 8, 1, 1.234) == Printf.@sprintf("% 08.1f", 1.234) @test Printf.@sprintf("%0*.*f", 8, 1, 1.234) == Printf.@sprintf("%08.1f", 1.234) @test Printf.@sprintf("%-0*.*f", 8, 1, 1.234) == Printf.@sprintf("%-08.1f", 1.234) @test Printf.@sprintf("%-*.*f", 8, 1, 1.234) == Printf.@sprintf("%-8.1f", 1.234) @test Printf.@sprintf("%0*.*f", 8, 1, -1.234) == Printf.@sprintf("%08.1f", -1.234) @test Printf.@sprintf("%0*.*f", 9, 1, -1.234) == Printf.@sprintf("%09.1f", -1.234) @test Printf.@sprintf("%0*.*f", 9, 1, 1.234) == Printf.@sprintf("%09.1f", 1.234) @test Printf.@sprintf("%+0*.*f", 9, 1, 1.234) == Printf.@sprintf("%+09.1f", 1.234) @test Printf.@sprintf("% 0*.*f", 9, 1, 1.234) == Printf.@sprintf("% 09.1f", 1.234) @test Printf.@sprintf("%+ 0*.*f", 9, 1, 1.234) == Printf.@sprintf("%+ 09.1f", 1.234) @test Printf.@sprintf("%+ 0*.*f", 9, 1, 1.234) == Printf.@sprintf("%+ 09.1f", 1.234) @test Printf.@sprintf("%+ 0*.*f", 9, 0, 1.234) == Printf.@sprintf("%+ 09.0f", 1.234) @test Printf.@sprintf("%+ #0*.*f", 9, 0, 1.234) == Printf.@sprintf("%+ #09.0f", 1.234) @test Printf.@sprintf("%*.*e", 10, 4, Inf) == Printf.@sprintf("%10.4e", Inf) @test Printf.@sprintf("%*.*e", 10, 4, NaN) == Printf.@sprintf("%10.4e", NaN) @test Printf.@sprintf("%*.*e", 10, 4, Inf) == Printf.@sprintf("%10.4e", Inf) @test Printf.@sprintf("%*.*e", 10, 4, NaN) == Printf.@sprintf("%10.4e", NaN) @test Printf.@sprintf("%.*e", 0, 3.0e142) == Printf.@sprintf("%.0e", 3.0e142) @test Printf.@sprintf("%#.*e", 0, 3.0e142) == Printf.@sprintf("%#.0e", 3.0e142) @test Printf.@sprintf("%.*e", 0, 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) == Printf.@sprintf("%.0e", 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) @test Printf.@sprintf("%#.*e", 0, 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) == Printf.@sprintf("%#.0e", 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) @test Printf.@sprintf("%.*e", 0, 3.000000000000000000000000000000000000000000000000000000000000000000000000000024e1042) == Printf.@sprintf("%.0e", 3.000000000000000000000000000000000000000000000000000000000000000000000000000024e1042) @test Printf.@sprintf("%.*e", 2, 1.234) == Printf.@sprintf("%.2e", 1.234) @test Printf.@sprintf("%.*e", 2, 1.235) == Printf.@sprintf("%.2e", 1.235) @test Printf.@sprintf("%.*e", 2, 0.235) == Printf.@sprintf("%.2e", 0.235) @test Printf.@sprintf("%*.*e", 4, 1, 1.234) == Printf.@sprintf("%4.1e", 1.234) @test Printf.@sprintf("%*.*e", 8, 1, 1.234) == Printf.@sprintf("%8.1e", 1.234) @test Printf.@sprintf("%+*.*e", 8, 1, 1.234) == Printf.@sprintf("%+8.1e", 1.234) @test Printf.@sprintf("% *.*e", 8, 1, 1.234) == Printf.@sprintf("% 8.1e", 1.234) @test Printf.@sprintf("% *.*e", 7, 1, 1.234) == Printf.@sprintf("% 7.1e", 1.234) @test Printf.@sprintf("% 0*.*e", 8, 1, 1.234) == Printf.@sprintf("% 08.1e", 1.234) @test Printf.@sprintf("%0*.*e", 8, 1, 1.234) == Printf.@sprintf("%08.1e", 1.234) @test Printf.@sprintf("%-0*.*e", 8, 1, 1.234) == Printf.@sprintf("%-08.1e", 1.234) @test Printf.@sprintf("%-*.*e", 8, 1, 1.234) == Printf.@sprintf("%-8.1e", 1.234) @test Printf.@sprintf("%-*.*e", 8, 1, 1.234) == Printf.@sprintf("%-8.1e", 1.234) @test Printf.@sprintf("%0*.*e", 8, 1, -1.234) == Printf.@sprintf("%08.1e", -1.234) @test Printf.@sprintf("%0*.*e", 9, 1, -1.234) == Printf.@sprintf("%09.1e", -1.234) @test Printf.@sprintf("%0*.*e", 9, 1, 1.234) == Printf.@sprintf("%09.1e", 1.234) @test Printf.@sprintf("%+0*.*e", 9, 1, 1.234) == Printf.@sprintf("%+09.1e", 1.234) @test Printf.@sprintf("% 0*.*e", 9, 1, 1.234) == Printf.@sprintf("% 09.1e", 1.234) @test Printf.@sprintf("%+ 0*.*e", 9, 1, 1.234) == Printf.@sprintf("%+ 09.1e", 1.234) @test Printf.@sprintf("%+ 0*.*e", 9, 1, 1.234) == Printf.@sprintf("%+ 09.1e", 1.234) @test Printf.@sprintf("%+ 0*.*e", 9, 0, 1.234) == Printf.@sprintf("%+ 09.0e", 1.234) @test Printf.@sprintf("%+ #0*.*e", 9, 0, 1.234) == Printf.@sprintf("%+ #09.0e", 1.234) @test Printf.@sprintf("%.*s", 1, "foo") == Printf.@sprintf("%.1s", "foo") @test Printf.@sprintf("%*s", 1, "Hallo heimur") == Printf.@sprintf("%1s", "Hallo heimur") @test Printf.@sprintf("%*s", 20, "Hallo") == Printf.@sprintf("%20s", "Hallo") @test Printf.@sprintf("%-*s", 20, "Hallo") == Printf.@sprintf("%-20s", "Hallo") @test Printf.@sprintf("%0-*s", 20, "Hallo") == Printf.@sprintf("%0-20s", "Hallo") @test Printf.@sprintf("%.*s", 20, "Hallo heimur") == Printf.@sprintf("%.20s", "Hallo heimur") @test Printf.@sprintf("%*.*s", 20, 5, "Hallo heimur") == Printf.@sprintf("%20.5s", "Hallo heimur") @test Printf.@sprintf("%.*s", 0, "Hallo heimur") == Printf.@sprintf("%.0s", "Hallo heimur") @test Printf.@sprintf("%*.*s", 20, 0, "Hallo heimur") == Printf.@sprintf("%20.0s", "Hallo heimur") @test Printf.@sprintf("%.s", "Hallo heimur") == Printf.@sprintf("%.s", "Hallo heimur") @test Printf.@sprintf("%*.s", 20, "Hallo heimur") == Printf.@sprintf("%20.s", "Hallo heimur") @test Printf.@sprintf("%*sø", 4, "ø") == Printf.@sprintf("%4sø", "ø") @test Printf.@sprintf("%-*sø", 4, "ø") == Printf.@sprintf("%-4sø", "ø") @test Printf.@sprintf("%*s", 8, "test") == Printf.@sprintf("%8s", "test") @test Printf.@sprintf("%-*s", 8, "test") == Printf.@sprintf("%-8s", "test") @test Printf.@sprintf("%#*s", 8, :test) == Printf.@sprintf("%#8s", :test) @test Printf.@sprintf("%#-*s", 8, :test) == Printf.@sprintf("%#-8s", :test) @test Printf.@sprintf("%*.*s", 8, 3, "test") == Printf.@sprintf("%8.3s", "test") @test Printf.@sprintf("%#*.*s", 8, 3, "test") == Printf.@sprintf("%#8.3s", "test") @test Printf.@sprintf("%-*.*s", 8, 3, "test") == Printf.@sprintf("%-8.3s", "test") @test Printf.@sprintf("%#-*.*s", 8, 3, "test") == Printf.@sprintf("%#-8.3s", "test") @test Printf.@sprintf("%.*s", 3, "test") == Printf.@sprintf("%.3s", "test") @test Printf.@sprintf("%#.*s", 3, "test") == Printf.@sprintf("%#.3s", "test") @test Printf.@sprintf("%-.*s", 3, "test") == Printf.@sprintf("%-.3s", "test") @test Printf.@sprintf("%#-.*s", 3, "test") == Printf.@sprintf("%#-.3s", "test") @test Printf.@sprintf("%*c", 3, 'a') == Printf.@sprintf("%3c", 'a') @test Printf.@sprintf("%*c", 1, 'x') == Printf.@sprintf("%1c", 'x') @test Printf.@sprintf("%*c", 20, 'x') == Printf.@sprintf("%20c", 'x') @test Printf.@sprintf("%-*c", 20, 'x') == Printf.@sprintf("%-20c", 'x') @test Printf.@sprintf("%-0*c", 20, 'x') == Printf.@sprintf("%-020c", 'x') @test Printf.@sprintf("%*c", 3, 'A') == Printf.@sprintf("%3c", 'A') @test Printf.@sprintf("%-*c", 3, 'A') == Printf.@sprintf("%-3c", 'A') @test Printf.@sprintf("%*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f", 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345) == Printf.@sprintf("%4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f", 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345) @test (Printf.@sprintf("%.*f", 330, BigFloat(1)))[var"end"] != '\0' @test Printf.@sprintf("%*.*s", 4, 2, "a") == Printf.@sprintf("%4.2s", "a") @test Printf.@sprintf("%*.*e", 12, 3, pi * 1.0e100) == Printf.@sprintf("%12.3e", pi * 1.0e100) @test Printf.@sprintf("%*d", 2, 3.14) == Printf.@sprintf("%*d", 2, 3.14) @test Printf.@sprintf("%*d", 2, big(3.14)) == Printf.@sprintf("%*d", 2, big(3.14)) @test Printf.@sprintf(" %.*e\n", 1, 0.999) == Printf.@sprintf(" %.1e\n", 0.999) @test Printf.@sprintf(" %.*f", 1, 9.999) == Printf.@sprintf(" %.1f", 9.999) @test Printf.@sprintf("%*d", 10, 12) == Printf.@sprintf("%10d", 12) @test Printf.@sprintf("%.*d", 4, 12) == Printf.@sprintf("%.4d", 12) @test Printf.@sprintf("%*.*d", 10, 4, 12) == Printf.@sprintf("%10.4d", 12) @test Printf.@sprintf("%+*.*d", 10, 4, 12) == Printf.@sprintf("%+10.4d", 12) @test Printf.@sprintf("%0*.*d", 10, 4, 12) == Printf.@sprintf("%010.4d", 12) @test Printf.@sprintf("% *d", 5, 42) == Printf.@sprintf("% 5d", 42) @test Printf.@sprintf("% *d", 5, -42) == Printf.@sprintf("% 5d", -42) @test Printf.@sprintf("% *d", 15, 42) == Printf.@sprintf("% 15d", 42) @test Printf.@sprintf("% *d", 15, -42) == Printf.@sprintf("% 15d", -42) @test Printf.@sprintf("%+*d", 5, 42) == Printf.@sprintf("%+5d", 42) @test Printf.@sprintf("%+*d", 5, -42) == Printf.@sprintf("%+5d", -42) @test Printf.@sprintf("%+*d", 15, 42) == Printf.@sprintf("%+15d", 42) @test Printf.@sprintf("%+*d", 15, -42) == Printf.@sprintf("%+15d", -42) @test Printf.@sprintf("%*d", 0, 42) == Printf.@sprintf("%0d", 42) @test Printf.@sprintf("%*d", 0, -42) == Printf.@sprintf("%0d", -42) @test Printf.@sprintf("%-*d", 5, 42) == Printf.@sprintf("%-5d", 42) @test Printf.@sprintf("%-*d", 5, -42) == Printf.@sprintf("%-5d", -42) @test Printf.@sprintf("%-*d", 15, 42) == Printf.@sprintf("%-15d", 42) @test Printf.@sprintf("%-*d", 15, -42) == Printf.@sprintf("%-15d", -42) @test Printf.@sprintf("%+*lld", 8, 100) == Printf.@sprintf("%+8lld", 100) @test Printf.@sprintf("%+.*lld", 8, 100) == Printf.@sprintf("%+.8lld", 100) @test Printf.@sprintf("%+*.*lld", 10, 8, 100) == Printf.@sprintf("%+10.8lld", 100) @test Printf.@sprintf("%-*.*lld", 1, 5, -100) == Printf.@sprintf("%-1.5lld", -100) @test Printf.@sprintf("%*lld", 5, 100) == Printf.@sprintf("%5lld", 100) @test Printf.@sprintf("%*lld", 5, -100) == Printf.@sprintf("%5lld", -100) @test Printf.@sprintf("%-*lld", 5, 100) == Printf.@sprintf("%-5lld", 100) @test Printf.@sprintf("%-*lld", 5, -100) == Printf.@sprintf("%-5lld", -100) @test Printf.@sprintf("%-.*lld", 5, 100) == Printf.@sprintf("%-.5lld", 100) @test Printf.@sprintf("%-.*lld", 5, -100) == Printf.@sprintf("%-.5lld", -100) @test Printf.@sprintf("%-*.*lld", 8, 5, 100) == Printf.@sprintf("%-8.5lld", 100) @test Printf.@sprintf("%-*.*lld", 8, 5, -100) == Printf.@sprintf("%-8.5lld", -100) @test Printf.@sprintf("%0*lld", 5, 100) == Printf.@sprintf("%05lld", 100) @test Printf.@sprintf("%0*lld", 5, -100) == Printf.@sprintf("%05lld", -100) @test Printf.@sprintf("% *lld", 5, 100) == Printf.@sprintf("% 5lld", 100) @test Printf.@sprintf("% *lld", 5, -100) == Printf.@sprintf("% 5lld", -100) @test Printf.@sprintf("% .*lld", 5, 100) == Printf.@sprintf("% .5lld", 100) @test Printf.@sprintf("% .*lld", 5, -100) == Printf.@sprintf("% .5lld", -100) @test Printf.@sprintf("% *.*lld", 8, 5, 100) == Printf.@sprintf("% 8.5lld", 100) @test Printf.@sprintf("% *.*lld", 8, 5, -100) == Printf.@sprintf("% 8.5lld", -100) @test Printf.@sprintf("%.*lld", 0, 0) == Printf.@sprintf("%.0lld", 0) @test Printf.@sprintf("%#+*.*llx", 21, 18, -100) == Printf.@sprintf("%#+21.18llx", -100) @test Printf.@sprintf("%#.*llo", 25, -100) == Printf.@sprintf("%#.25llo", -100) @test Printf.@sprintf("%#+*.*llo", 24, 20, -100) == Printf.@sprintf("%#+24.20llo", -100) @test Printf.@sprintf("%#+*.*llX", 18, 21, -100) == Printf.@sprintf("%#+18.21llX", -100) @test Printf.@sprintf("%#+*.*llo", 20, 24, -100) == Printf.@sprintf("%#+20.24llo", -100) @test Printf.@sprintf("%#+*.*llu", 25, 22, -1) == Printf.@sprintf("%#+25.22llu", -1) @test Printf.@sprintf("%#+*.*llu", 30, 25, -1) == Printf.@sprintf("%#+30.25llu", -1) @test Printf.@sprintf("%+#*.*lld", 25, 22, -1) == Printf.@sprintf("%+#25.22lld", -1) @test Printf.@sprintf("%#-*.*llo", 8, 5, 100) == Printf.@sprintf("%#-8.5llo", 100) @test Printf.@sprintf("%#-+ 0*.*lld", 8, 5, 100) == Printf.@sprintf("%#-+ 08.5lld", 100) @test Printf.@sprintf("%#-+ 0*.*lld", 8, 5, 100) == Printf.@sprintf("%#-+ 08.5lld", 100) @test Printf.@sprintf("%.*lld", 40, 1) == Printf.@sprintf("%.40lld", 1) @test Printf.@sprintf("% .*lld", 40, 1) == Printf.@sprintf("% .40lld", 1) @test Printf.@sprintf("% .*d", 40, 1) == Printf.@sprintf("% .40d", 1) @test Printf.@sprintf("%#0*x", 12, 1) == Printf.@sprintf("%#012x", 1) @test Printf.@sprintf("%#0*.*x", 4, 8, 1) == Printf.@sprintf("%#04.8x", 1) @test Printf.@sprintf("%#-0*.*x", 8, 2, 1) == Printf.@sprintf("%#-08.2x", 1) @test Printf.@sprintf("%#0*o", 8, 1) == Printf.@sprintf("%#08o", 1) @test Printf.@sprintf("%*d", 20, 1024) == Printf.@sprintf("%20d", 1024) @test Printf.@sprintf("%*d", 20, -1024) == Printf.@sprintf("%20d", -1024) @test Printf.@sprintf("%*i", 20, 1024) == Printf.@sprintf("%20i", 1024) @test Printf.@sprintf("%*i", 20, -1024) == Printf.@sprintf("%20i", -1024) @test Printf.@sprintf("%*u", 20, 1024) == Printf.@sprintf("%20u", 1024) @test Printf.@sprintf("%*u", 20, UInt(4294966272)) == Printf.@sprintf("%20u", UInt(4294966272)) @test Printf.@sprintf("%*o", 20, 511) == Printf.@sprintf("%20o", 511) @test Printf.@sprintf("%*o", 20, UInt(4294966785)) == Printf.@sprintf("%20o", UInt(4294966785)) @test Printf.@sprintf("%*x", 20, 305441741) == Printf.@sprintf("%20x", 305441741) @test Printf.@sprintf("%*x", 20, UInt(3989525555)) == Printf.@sprintf("%20x", UInt(3989525555)) @test Printf.@sprintf("%*X", 20, 305441741) == Printf.@sprintf("%20X", 305441741) @test Printf.@sprintf("%*X", 20, UInt(3989525555)) == Printf.@sprintf("%20X", UInt(3989525555)) @test Printf.@sprintf("%-*d", 20, 1024) == Printf.@sprintf("%-20d", 1024) @test Printf.@sprintf("%-*d", 20, -1024) == Printf.@sprintf("%-20d", -1024) @test Printf.@sprintf("%-*i", 20, 1024) == Printf.@sprintf("%-20i", 1024) @test Printf.@sprintf("%-*i", 20, -1024) == Printf.@sprintf("%-20i", -1024) @test Printf.@sprintf("%-*u", 20, 1024) == Printf.@sprintf("%-20u", 1024) @test Printf.@sprintf("%-*u", 20, UInt(4294966272)) == Printf.@sprintf("%-20u", UInt(4294966272)) @test Printf.@sprintf("%-*o", 20, 511) == Printf.@sprintf("%-20o", 511) @test Printf.@sprintf("%-*o", 20, UInt(4294966785)) == Printf.@sprintf("%-20o", UInt(4294966785)) @test Printf.@sprintf("%-*x", 20, 305441741) == Printf.@sprintf("%-20x", 305441741) @test Printf.@sprintf("%-*x", 20, UInt(3989525555)) == Printf.@sprintf("%-20x", UInt(3989525555)) @test Printf.@sprintf("%-*X", 20, 305441741) == Printf.@sprintf("%-20X", 305441741) @test Printf.@sprintf("%-*X", 20, UInt(3989525555)) == Printf.@sprintf("%-20X", UInt(3989525555)) @test Printf.@sprintf("%0*d", 20, 1024) == Printf.@sprintf("%020d", 1024) @test Printf.@sprintf("%0*d", 20, -1024) == Printf.@sprintf("%020d", -1024) @test Printf.@sprintf("%0*i", 20, 1024) == Printf.@sprintf("%020i", 1024) @test Printf.@sprintf("%0*i", 20, -1024) == Printf.@sprintf("%020i", -1024) @test Printf.@sprintf("%0*u", 20, 1024) == Printf.@sprintf("%020u", 1024) @test Printf.@sprintf("%0*u", 20, UInt(4294966272)) == Printf.@sprintf("%020u", UInt(4294966272)) @test Printf.@sprintf("%0*o", 20, 511) == Printf.@sprintf("%020o", 511) @test Printf.@sprintf("%0*o", 20, UInt(4294966785)) == Printf.@sprintf("%020o", UInt(4294966785)) @test Printf.@sprintf("%0*x", 20, 305441741) == Printf.@sprintf("%020x", 305441741) @test Printf.@sprintf("%0*x", 20, UInt(3989525555)) == Printf.@sprintf("%020x", UInt(3989525555)) @test Printf.@sprintf("%0*X", 20, 305441741) == Printf.@sprintf("%020X", 305441741) @test Printf.@sprintf("%0*X", 20, UInt(3989525555)) == Printf.@sprintf("%020X", UInt(3989525555)) @test Printf.@sprintf("%#*o", 20, 511) == Printf.@sprintf("%#20o", 511) @test Printf.@sprintf("%#*o", 20, UInt(4294966785)) == Printf.@sprintf("%#20o", UInt(4294966785)) @test Printf.@sprintf("%#*x", 20, 305441741) == Printf.@sprintf("%#20x", 305441741) @test Printf.@sprintf("%#*x", 20, UInt(3989525555)) == Printf.@sprintf("%#20x", UInt(3989525555)) @test Printf.@sprintf("%#*X", 20, 305441741) == Printf.@sprintf("%#20X", 305441741) @test Printf.@sprintf("%#*X", 20, UInt(3989525555)) == Printf.@sprintf("%#20X", UInt(3989525555)) @test Printf.@sprintf("%#0*o", 20, 511) == Printf.@sprintf("%#020o", 511) @test Printf.@sprintf("%#0*o", 20, UInt(4294966785)) == Printf.@sprintf("%#020o", UInt(4294966785)) @test Printf.@sprintf("%#0*x", 20, 305441741) == Printf.@sprintf("%#020x", 305441741) @test Printf.@sprintf("%#0*x", 20, UInt(3989525555)) == Printf.@sprintf("%#020x", UInt(3989525555)) @test Printf.@sprintf("%#0*X", 20, 305441741) == Printf.@sprintf("%#020X", 305441741) @test Printf.@sprintf("%#0*X", 20, UInt(3989525555)) == Printf.@sprintf("%#020X", UInt(3989525555)) @test Printf.@sprintf("%0-*d", 20, 1024) == Printf.@sprintf("%0-20d", 1024) @test Printf.@sprintf("%0-*d", 20, -1024) == Printf.@sprintf("%0-20d", -1024) @test Printf.@sprintf("%0-*i", 20, 1024) == Printf.@sprintf("%0-20i", 1024) @test Printf.@sprintf("%0-*i", 20, -1024) == Printf.@sprintf("%0-20i", -1024) @test Printf.@sprintf("%0-*u", 20, 1024) == Printf.@sprintf("%0-20u", 1024) @test Printf.@sprintf("%0-*u", 20, UInt(4294966272)) == Printf.@sprintf("%0-20u", UInt(4294966272)) @test Printf.@sprintf("%-0*o", 20, 511) == Printf.@sprintf("%-020o", 511) @test Printf.@sprintf("%-0*o", 20, UInt(4294966785)) == Printf.@sprintf("%-020o", UInt(4294966785)) @test Printf.@sprintf("%-0*x", 20, 305441741) == Printf.@sprintf("%-020x", 305441741) @test Printf.@sprintf("%-0*x", 20, UInt(3989525555)) == Printf.@sprintf("%-020x", UInt(3989525555)) @test Printf.@sprintf("%-0*X", 20, 305441741) == Printf.@sprintf("%-020X", 305441741) @test Printf.@sprintf("%-0*X", 20, UInt(3989525555)) == Printf.@sprintf("%-020X", UInt(3989525555)) @test Printf.@sprintf("%.*d", 20, 1024) == Printf.@sprintf("%.20d", 1024) @test Printf.@sprintf("%.*d", 20, -1024) == Printf.@sprintf("%.20d", -1024) @test Printf.@sprintf("%.*i", 20, 1024) == Printf.@sprintf("%.20i", 1024) @test Printf.@sprintf("%.*i", 20, -1024) == Printf.@sprintf("%.20i", -1024) @test Printf.@sprintf("%.*u", 20, 1024) == Printf.@sprintf("%.20u", 1024) @test Printf.@sprintf("%.*u", 20, UInt(4294966272)) == Printf.@sprintf("%.20u", UInt(4294966272)) @test Printf.@sprintf("%.*o", 20, 511) == Printf.@sprintf("%.20o", 511) @test Printf.@sprintf("%.*o", 20, UInt(4294966785)) == Printf.@sprintf("%.20o", UInt(4294966785)) @test Printf.@sprintf("%.*x", 20, 305441741) == Printf.@sprintf("%.20x", 305441741) @test Printf.@sprintf("%.*x", 20, UInt(3989525555)) == Printf.@sprintf("%.20x", UInt(3989525555)) @test Printf.@sprintf("%.*X", 20, 305441741) == Printf.@sprintf("%.20X", 305441741) @test Printf.@sprintf("%.*X", 20, UInt(3989525555)) == Printf.@sprintf("%.20X", UInt(3989525555)) @test Printf.@sprintf("%*.*d", 20, 5, 1024) == Printf.@sprintf("%20.5d", 1024) @test Printf.@sprintf("%*.*d", 20, 5, -1024) == Printf.@sprintf("%20.5d", -1024) @test Printf.@sprintf("%*.*i", 20, 5, 1024) == Printf.@sprintf("%20.5i", 1024) @test Printf.@sprintf("%*.*i", 20, 5, -1024) == Printf.@sprintf("%20.5i", -1024) @test Printf.@sprintf("%*.*u", 20, 5, 1024) == Printf.@sprintf("%20.5u", 1024) @test Printf.@sprintf("%*.*u", 20, 5, UInt(4294966272)) == Printf.@sprintf("%20.5u", UInt(4294966272)) @test Printf.@sprintf("%*.*o", 20, 5, 511) == Printf.@sprintf("%20.5o", 511) @test Printf.@sprintf("%*.*o", 20, 5, UInt(4294966785)) == Printf.@sprintf("%20.5o", UInt(4294966785)) @test Printf.@sprintf("%*.*x", 20, 5, 305441741) == Printf.@sprintf("%20.5x", 305441741) @test Printf.@sprintf("%*.*x", 20, 10, UInt(3989525555)) == Printf.@sprintf("%20.10x", UInt(3989525555)) @test Printf.@sprintf("%*.*X", 20, 5, 305441741) == Printf.@sprintf("%20.5X", 305441741) @test Printf.@sprintf("%*.*X", 20, 10, UInt(3989525555)) == Printf.@sprintf("%20.10X", UInt(3989525555)) @test Printf.@sprintf("%0*.*d", 20, 5, 1024) == Printf.@sprintf("%020.5d", 1024) @test Printf.@sprintf("%0*.*d", 20, 5, -1024) == Printf.@sprintf("%020.5d", -1024) @test Printf.@sprintf("%0*.*i", 20, 5, 1024) == Printf.@sprintf("%020.5i", 1024) @test Printf.@sprintf("%0*.*i", 20, 5, -1024) == Printf.@sprintf("%020.5i", -1024) @test Printf.@sprintf("%0*.*u", 20, 5, 1024) == Printf.@sprintf("%020.5u", 1024) @test Printf.@sprintf("%0*.*u", 20, 5, UInt(4294966272)) == Printf.@sprintf("%020.5u", UInt(4294966272)) @test Printf.@sprintf("%0*.*o", 20, 5, 511) == Printf.@sprintf("%020.5o", 511) @test Printf.@sprintf("%0*.*o", 20, 5, UInt(4294966785)) == Printf.@sprintf("%020.5o", UInt(4294966785)) @test Printf.@sprintf("%0*.*x", 20, 5, 305441741) == Printf.@sprintf("%020.5x", 305441741) @test Printf.@sprintf("%0*.*x", 20, 10, UInt(3989525555)) == Printf.@sprintf("%020.10x", UInt(3989525555)) @test Printf.@sprintf("%0*.*X", 20, 5, 305441741) == Printf.@sprintf("%020.5X", 305441741) @test Printf.@sprintf("%0*.*X", 20, 10, UInt(3989525555)) == Printf.@sprintf("%020.10X", UInt(3989525555)) @test Printf.@sprintf("%*.0d", 20, 1024) == Printf.@sprintf("%20.0d", 1024) @test Printf.@sprintf("%*.d", 20, -1024) == Printf.@sprintf("%20.d", -1024) @test Printf.@sprintf("%*.d", 20, 0) == Printf.@sprintf("%20.d", 0) @test Printf.@sprintf("%*.0i", 20, 1024) == Printf.@sprintf("%20.0i", 1024) @test Printf.@sprintf("%*.i", 20, -1024) == Printf.@sprintf("%20.i", -1024) @test Printf.@sprintf("%*.i", 20, 0) == Printf.@sprintf("%20.i", 0) @test Printf.@sprintf("%*.u", 20, 1024) == Printf.@sprintf("%20.u", 1024) @test Printf.@sprintf("%*.0u", 20, UInt(4294966272)) == Printf.@sprintf("%20.0u", UInt(4294966272)) @test Printf.@sprintf("%*.u", 20, UInt(0)) == Printf.@sprintf("%20.u", UInt(0)) @test Printf.@sprintf("%*.o", 20, 511) == Printf.@sprintf("%20.o", 511) @test Printf.@sprintf("%*.0o", 20, UInt(4294966785)) == Printf.@sprintf("%20.0o", UInt(4294966785)) @test Printf.@sprintf("%*.o", 20, UInt(0)) == Printf.@sprintf("%20.o", UInt(0)) @test Printf.@sprintf("%*.x", 20, 305441741) == Printf.@sprintf("%20.x", 305441741) @test Printf.@sprintf("%*.0x", 20, UInt(3989525555)) == Printf.@sprintf("%20.0x", UInt(3989525555)) @test Printf.@sprintf("%*.x", 20, UInt(0)) == Printf.@sprintf("%20.x", UInt(0)) @test Printf.@sprintf("%*.X", 20, 305441741) == Printf.@sprintf("%20.X", 305441741) @test Printf.@sprintf("%*.0X", 20, UInt(3989525555)) == Printf.@sprintf("%20.0X", UInt(3989525555)) @test Printf.@sprintf("%*.X", 20, UInt(0)) == Printf.@sprintf("%20.X", UInt(0)) x = Ref{Int}() y = Ref{Int}() @test begin Printf.@sprintf "%10s%n" "😉" x Printf.@sprintf "%*s%n" 10 "😉" y x[] == y[] end @test begin Printf.@sprintf "%10s%n" "1234" x Printf.@sprintf "%*s%n" 10 "1234" y x[] == y[] end end @testset "dynamic" begin @test Printf.@sprintf("%*d", 10, 12) == " 12" @test Printf.@sprintf("%.*d", 4, 12) == "0012" @test Printf.@sprintf("%*.*d", 10, 4, 12) == " 0012" @test Printf.@sprintf("%+*.*d", 10, 4, 12) == " +0012" @test Printf.@sprintf("%0*.*d", 10, 4, 12) == " 0012" @test Printf.@sprintf("%*d%*d%*d", 4, 12, 4, 13, 4, 14) == " 12 13 14" @test Printf.@sprintf("%*d%*d%*d", 4, 12, 5, 13, 6, 14) == " 12 13 14" @test Printf.@sprintf("%*p", 20, 0) == Printf.@sprintf("%20p", 0) @test Printf.@sprintf("%-*p", 20, 0) == Printf.@sprintf("%-20p", 0) @test Printf.@sprintf("%*p", 20, C_NULL) == Printf.@sprintf("%20p", C_NULL) @test Printf.@sprintf("%-*p", 20, C_NULL) == Printf.@sprintf("%-20p", C_NULL) @test Printf.@sprintf("%.*a", 0, 3.14) == Printf.@sprintf("%.0a", 3.14) @test Printf.@sprintf("%.*a", 1, 3.14) == Printf.@sprintf("%.1a", 3.14) @test Printf.@sprintf("%.*a", 2, 3.14) == Printf.@sprintf("%.2a", 3.14) @test Printf.@sprintf("%#.*a", 0, 3.14) == Printf.@sprintf("%#.0a", 3.14) @test Printf.@sprintf("%#.*a", 1, 3.14) == Printf.@sprintf("%#.1a", 3.14) @test Printf.@sprintf("%#.*a", 2, 3.14) == Printf.@sprintf("%#.2a", 3.14) @test Printf.@sprintf("%.*a", 6, 1.5) == Printf.@sprintf("%.6a", 1.5) @test Printf.@sprintf("%*.*g", 10, 5, -123.4) == Printf.@sprintf("%10.5g", -123.4) @test Printf.@sprintf("%0*.*g", 10, 5, -123.4) == Printf.@sprintf("%010.5g", -123.4) @test Printf.@sprintf("%.*g", 6, 1.234e7) == Printf.@sprintf("%.6g", 1.234e7) @test Printf.@sprintf("%#.*g", 6, 1.234e7) == Printf.@sprintf("%#.6g", 1.234e7) @test Printf.@sprintf("%*.*g", 10, 5, -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) == Printf.@sprintf("%10.5g", -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) @test Printf.@sprintf("%0*.*g", 10, 5, -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) == Printf.@sprintf("%010.5g", -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) @test Printf.@sprintf("%.*g", 6, 1.234e7) == Printf.@sprintf("%.6g", 1.234e7) @test Printf.@sprintf("%#.*g", 6, 1.234e7) == Printf.@sprintf("%#.6g", 1.234e7) @test Printf.@sprintf("%.*g", 5, 42) == Printf.@sprintf("%.5g", 42) @test Printf.@sprintf("%#.*g", 2, 42) == Printf.@sprintf("%#.2g", 42) @test Printf.@sprintf("%#.*g", 5, 42) == Printf.@sprintf("%#.5g", 42) @test Printf.@sprintf("%.*g", 15, 0) == Printf.@sprintf("%.15g", 0) @test Printf.@sprintf("%#.*g", 15, 0) == Printf.@sprintf("%#.15g", 0) @test Printf.@sprintf("%.*f", 0, 3.0e142) == Printf.@sprintf("%.0f", 3.0e142) @test Printf.@sprintf("%.*f", 2, 1.234) == Printf.@sprintf("%.2f", 1.234) @test Printf.@sprintf("%.*f", 2, 1.235) == Printf.@sprintf("%.2f", 1.235) @test Printf.@sprintf("%.*f", 2, 0.235) == Printf.@sprintf("%.2f", 0.235) @test Printf.@sprintf("%*.*f", 4, 1, 1.234) == Printf.@sprintf("%4.1f", 1.234) @test Printf.@sprintf("%*.*f", 8, 1, 1.234) == Printf.@sprintf("%8.1f", 1.234) @test Printf.@sprintf("%+*.*f", 8, 1, 1.234) == Printf.@sprintf("%+8.1f", 1.234) @test Printf.@sprintf("% *.*f", 8, 1, 1.234) == Printf.@sprintf("% 8.1f", 1.234) @test Printf.@sprintf("% *.*f", 7, 1, 1.234) == Printf.@sprintf("% 7.1f", 1.234) @test Printf.@sprintf("% 0*.*f", 8, 1, 1.234) == Printf.@sprintf("% 08.1f", 1.234) @test Printf.@sprintf("%0*.*f", 8, 1, 1.234) == Printf.@sprintf("%08.1f", 1.234) @test Printf.@sprintf("%-0*.*f", 8, 1, 1.234) == Printf.@sprintf("%-08.1f", 1.234) @test Printf.@sprintf("%-*.*f", 8, 1, 1.234) == Printf.@sprintf("%-8.1f", 1.234) @test Printf.@sprintf("%0*.*f", 8, 1, -1.234) == Printf.@sprintf("%08.1f", -1.234) @test Printf.@sprintf("%0*.*f", 9, 1, -1.234) == Printf.@sprintf("%09.1f", -1.234) @test Printf.@sprintf("%0*.*f", 9, 1, 1.234) == Printf.@sprintf("%09.1f", 1.234) @test Printf.@sprintf("%+0*.*f", 9, 1, 1.234) == Printf.@sprintf("%+09.1f", 1.234) @test Printf.@sprintf("% 0*.*f", 9, 1, 1.234) == Printf.@sprintf("% 09.1f", 1.234) @test Printf.@sprintf("%+ 0*.*f", 9, 1, 1.234) == Printf.@sprintf("%+ 09.1f", 1.234) @test Printf.@sprintf("%+ 0*.*f", 9, 1, 1.234) == Printf.@sprintf("%+ 09.1f", 1.234) @test Printf.@sprintf("%+ 0*.*f", 9, 0, 1.234) == Printf.@sprintf("%+ 09.0f", 1.234) @test Printf.@sprintf("%+ #0*.*f", 9, 0, 1.234) == Printf.@sprintf("%+ #09.0f", 1.234) @test Printf.@sprintf("%*.*e", 10, 4, Inf) == Printf.@sprintf("%10.4e", Inf) @test Printf.@sprintf("%*.*e", 10, 4, NaN) == Printf.@sprintf("%10.4e", NaN) @test Printf.@sprintf("%*.*e", 10, 4, Inf) == Printf.@sprintf("%10.4e", Inf) @test Printf.@sprintf("%*.*e", 10, 4, NaN) == Printf.@sprintf("%10.4e", NaN) @test Printf.@sprintf("%.*e", 0, 3.0e142) == Printf.@sprintf("%.0e", 3.0e142) @test Printf.@sprintf("%#.*e", 0, 3.0e142) == Printf.@sprintf("%#.0e", 3.0e142) @test Printf.@sprintf("%.*e", 0, 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) == Printf.@sprintf("%.0e", 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) @test Printf.@sprintf("%#.*e", 0, 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) == Printf.@sprintf("%#.0e", 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) @test Printf.@sprintf("%.*e", 0, 3.000000000000000000000000000000000000000000000000000000000000000000000000000024e1042) == Printf.@sprintf("%.0e", 3.000000000000000000000000000000000000000000000000000000000000000000000000000024e1042) @test Printf.@sprintf("%.*e", 2, 1.234) == Printf.@sprintf("%.2e", 1.234) @test Printf.@sprintf("%.*e", 2, 1.235) == Printf.@sprintf("%.2e", 1.235) @test Printf.@sprintf("%.*e", 2, 0.235) == Printf.@sprintf("%.2e", 0.235) @test Printf.@sprintf("%*.*e", 4, 1, 1.234) == Printf.@sprintf("%4.1e", 1.234) @test Printf.@sprintf("%*.*e", 8, 1, 1.234) == Printf.@sprintf("%8.1e", 1.234) @test Printf.@sprintf("%+*.*e", 8, 1, 1.234) == Printf.@sprintf("%+8.1e", 1.234) @test Printf.@sprintf("% *.*e", 8, 1, 1.234) == Printf.@sprintf("% 8.1e", 1.234) @test Printf.@sprintf("% *.*e", 7, 1, 1.234) == Printf.@sprintf("% 7.1e", 1.234) @test Printf.@sprintf("% 0*.*e", 8, 1, 1.234) == Printf.@sprintf("% 08.1e", 1.234) @test Printf.@sprintf("%0*.*e", 8, 1, 1.234) == Printf.@sprintf("%08.1e", 1.234) @test Printf.@sprintf("%-0*.*e", 8, 1, 1.234) == Printf.@sprintf("%-08.1e", 1.234) @test Printf.@sprintf("%-*.*e", 8, 1, 1.234) == Printf.@sprintf("%-8.1e", 1.234) @test Printf.@sprintf("%-*.*e", 8, 1, 1.234) == Printf.@sprintf("%-8.1e", 1.234) @test Printf.@sprintf("%0*.*e", 8, 1, -1.234) == Printf.@sprintf("%08.1e", -1.234) @test Printf.@sprintf("%0*.*e", 9, 1, -1.234) == Printf.@sprintf("%09.1e", -1.234) @test Printf.@sprintf("%0*.*e", 9, 1, 1.234) == Printf.@sprintf("%09.1e", 1.234) @test Printf.@sprintf("%+0*.*e", 9, 1, 1.234) == Printf.@sprintf("%+09.1e", 1.234) @test Printf.@sprintf("% 0*.*e", 9, 1, 1.234) == Printf.@sprintf("% 09.1e", 1.234) @test Printf.@sprintf("%+ 0*.*e", 9, 1, 1.234) == Printf.@sprintf("%+ 09.1e", 1.234) @test Printf.@sprintf("%+ 0*.*e", 9, 1, 1.234) == Printf.@sprintf("%+ 09.1e", 1.234) @test Printf.@sprintf("%+ 0*.*e", 9, 0, 1.234) == Printf.@sprintf("%+ 09.0e", 1.234) @test Printf.@sprintf("%+ #0*.*e", 9, 0, 1.234) == Printf.@sprintf("%+ #09.0e", 1.234) @test Printf.@sprintf("%.*s", 1, "foo") == Printf.@sprintf("%.1s", "foo") @test Printf.@sprintf("%*s", 1, "Hallo heimur") == Printf.@sprintf("%1s", "Hallo heimur") @test Printf.@sprintf("%*s", 20, "Hallo") == Printf.@sprintf("%20s", "Hallo") @test Printf.@sprintf("%-*s", 20, "Hallo") == Printf.@sprintf("%-20s", "Hallo") @test Printf.@sprintf("%0-*s", 20, "Hallo") == Printf.@sprintf("%0-20s", "Hallo") @test Printf.@sprintf("%.*s", 20, "Hallo heimur") == Printf.@sprintf("%.20s", "Hallo heimur") @test Printf.@sprintf("%*.*s", 20, 5, "Hallo heimur") == Printf.@sprintf("%20.5s", "Hallo heimur") @test Printf.@sprintf("%.*s", 0, "Hallo heimur") == Printf.@sprintf("%.0s", "Hallo heimur") @test Printf.@sprintf("%*.*s", 20, 0, "Hallo heimur") == Printf.@sprintf("%20.0s", "Hallo heimur") @test Printf.@sprintf("%.s", "Hallo heimur") == Printf.@sprintf("%.s", "Hallo heimur") @test Printf.@sprintf("%*.s", 20, "Hallo heimur") == Printf.@sprintf("%20.s", "Hallo heimur") @test Printf.@sprintf("%*sø", 4, "ø") == Printf.@sprintf("%4sø", "ø") @test Printf.@sprintf("%-*sø", 4, "ø") == Printf.@sprintf("%-4sø", "ø") @test Printf.@sprintf("%*s", 8, "test") == Printf.@sprintf("%8s", "test") @test Printf.@sprintf("%-*s", 8, "test") == Printf.@sprintf("%-8s", "test") @test Printf.@sprintf("%#*s", 8, :test) == Printf.@sprintf("%#8s", :test) @test Printf.@sprintf("%#-*s", 8, :test) == Printf.@sprintf("%#-8s", :test) @test Printf.@sprintf("%*.*s", 8, 3, "test") == Printf.@sprintf("%8.3s", "test") @test Printf.@sprintf("%#*.*s", 8, 3, "test") == Printf.@sprintf("%#8.3s", "test") @test Printf.@sprintf("%-*.*s", 8, 3, "test") == Printf.@sprintf("%-8.3s", "test") @test Printf.@sprintf("%#-*.*s", 8, 3, "test") == Printf.@sprintf("%#-8.3s", "test") @test Printf.@sprintf("%.*s", 3, "test") == Printf.@sprintf("%.3s", "test") @test Printf.@sprintf("%#.*s", 3, "test") == Printf.@sprintf("%#.3s", "test") @test Printf.@sprintf("%-.*s", 3, "test") == Printf.@sprintf("%-.3s", "test") @test Printf.@sprintf("%#-.*s", 3, "test") == Printf.@sprintf("%#-.3s", "test") @test Printf.@sprintf("%*c", 3, 'a') == Printf.@sprintf("%3c", 'a') @test Printf.@sprintf("%*c", 1, 'x') == Printf.@sprintf("%1c", 'x') @test Printf.@sprintf("%*c", 20, 'x') == Printf.@sprintf("%20c", 'x') @test Printf.@sprintf("%-*c", 20, 'x') == Printf.@sprintf("%-20c", 'x') @test Printf.@sprintf("%-0*c", 20, 'x') == Printf.@sprintf("%-020c", 'x') @test Printf.@sprintf("%*c", 3, 'A') == Printf.@sprintf("%3c", 'A') @test Printf.@sprintf("%-*c", 3, 'A') == Printf.@sprintf("%-3c", 'A') @test Printf.@sprintf("%*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f", 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345) == Printf.@sprintf("%4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f", 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345) @test (Printf.@sprintf("%.*f", 330, BigFloat(1)))[var"end"] != '\0' @test Printf.@sprintf("%*.*s", 4, 2, "a") == Printf.@sprintf("%4.2s", "a") @test Printf.@sprintf("%*.*e", 12, 3, pi * 1.0e100) == Printf.@sprintf("%12.3e", pi * 1.0e100) @test Printf.@sprintf("%*d", 2, 3.14) == Printf.@sprintf("%*d", 2, 3.14) @test Printf.@sprintf("%*d", 2, big(3.14)) == Printf.@sprintf("%*d", 2, big(3.14)) @test Printf.@sprintf(" %.*e\n", 1, 0.999) == Printf.@sprintf(" %.1e\n", 0.999) @test Printf.@sprintf(" %.*f", 1, 9.999) == Printf.@sprintf(" %.1f", 9.999) @test Printf.@sprintf("%*d", 10, 12) == Printf.@sprintf("%10d", 12) @test Printf.@sprintf("%.*d", 4, 12) == Printf.@sprintf("%.4d", 12) @test Printf.@sprintf("%*.*d", 10, 4, 12) == Printf.@sprintf("%10.4d", 12) @test Printf.@sprintf("%+*.*d", 10, 4, 12) == Printf.@sprintf("%+10.4d", 12) @test Printf.@sprintf("%0*.*d", 10, 4, 12) == Printf.@sprintf("%010.4d", 12) @test Printf.@sprintf("% *d", 5, 42) == Printf.@sprintf("% 5d", 42) @test Printf.@sprintf("% *d", 5, -42) == Printf.@sprintf("% 5d", -42) @test Printf.@sprintf("% *d", 15, 42) == Printf.@sprintf("% 15d", 42) @test Printf.@sprintf("% *d", 15, -42) == Printf.@sprintf("% 15d", -42) @test Printf.@sprintf("%+*d", 5, 42) == Printf.@sprintf("%+5d", 42) @test Printf.@sprintf("%+*d", 5, -42) == Printf.@sprintf("%+5d", -42) @test Printf.@sprintf("%+*d", 15, 42) == Printf.@sprintf("%+15d", 42) @test Printf.@sprintf("%+*d", 15, -42) == Printf.@sprintf("%+15d", -42) @test Printf.@sprintf("%*d", 0, 42) == Printf.@sprintf("%0d", 42) @test Printf.@sprintf("%*d", 0, -42) == Printf.@sprintf("%0d", -42) @test Printf.@sprintf("%-*d", 5, 42) == Printf.@sprintf("%-5d", 42) @test Printf.@sprintf("%-*d", 5, -42) == Printf.@sprintf("%-5d", -42) @test Printf.@sprintf("%-*d", 15, 42) == Printf.@sprintf("%-15d", 42) @test Printf.@sprintf("%-*d", 15, -42) == Printf.@sprintf("%-15d", -42) @test Printf.@sprintf("%+*lld", 8, 100) == Printf.@sprintf("%+8lld", 100) @test Printf.@sprintf("%+.*lld", 8, 100) == Printf.@sprintf("%+.8lld", 100) @test Printf.@sprintf("%+*.*lld", 10, 8, 100) == Printf.@sprintf("%+10.8lld", 100) @test Printf.@sprintf("%-*.*lld", 1, 5, -100) == Printf.@sprintf("%-1.5lld", -100) @test Printf.@sprintf("%*lld", 5, 100) == Printf.@sprintf("%5lld", 100) @test Printf.@sprintf("%*lld", 5, -100) == Printf.@sprintf("%5lld", -100) @test Printf.@sprintf("%-*lld", 5, 100) == Printf.@sprintf("%-5lld", 100) @test Printf.@sprintf("%-*lld", 5, -100) == Printf.@sprintf("%-5lld", -100) @test Printf.@sprintf("%-.*lld", 5, 100) == Printf.@sprintf("%-.5lld", 100) @test Printf.@sprintf("%-.*lld", 5, -100) == Printf.@sprintf("%-.5lld", -100) @test Printf.@sprintf("%-*.*lld", 8, 5, 100) == Printf.@sprintf("%-8.5lld", 100) @test Printf.@sprintf("%-*.*lld", 8, 5, -100) == Printf.@sprintf("%-8.5lld", -100) @test Printf.@sprintf("%0*lld", 5, 100) == Printf.@sprintf("%05lld", 100) @test Printf.@sprintf("%0*lld", 5, -100) == Printf.@sprintf("%05lld", -100) @test Printf.@sprintf("% *lld", 5, 100) == Printf.@sprintf("% 5lld", 100) @test Printf.@sprintf("% *lld", 5, -100) == Printf.@sprintf("% 5lld", -100) @test Printf.@sprintf("% .*lld", 5, 100) == Printf.@sprintf("% .5lld", 100) @test Printf.@sprintf("% .*lld", 5, -100) == Printf.@sprintf("% .5lld", -100) @test Printf.@sprintf("% *.*lld", 8, 5, 100) == Printf.@sprintf("% 8.5lld", 100) @test Printf.@sprintf("% *.*lld", 8, 5, -100) == Printf.@sprintf("% 8.5lld", -100) @test Printf.@sprintf("%.*lld", 0, 0) == Printf.@sprintf("%.0lld", 0) @test Printf.@sprintf("%#+*.*llx", 21, 18, -100) == Printf.@sprintf("%#+21.18llx", -100) @test Printf.@sprintf("%#.*llo", 25, -100) == Printf.@sprintf("%#.25llo", -100) @test Printf.@sprintf("%#+*.*llo", 24, 20, -100) == Printf.@sprintf("%#+24.20llo", -100) @test Printf.@sprintf("%#+*.*llX", 18, 21, -100) == Printf.@sprintf("%#+18.21llX", -100) @test Printf.@sprintf("%#+*.*llo", 20, 24, -100) == Printf.@sprintf("%#+20.24llo", -100) @test Printf.@sprintf("%#+*.*llu", 25, 22, -1) == Printf.@sprintf("%#+25.22llu", -1) @test Printf.@sprintf("%#+*.*llu", 30, 25, -1) == Printf.@sprintf("%#+30.25llu", -1) @test Printf.@sprintf("%+#*.*lld", 25, 22, -1) == Printf.@sprintf("%+#25.22lld", -1) @test Printf.@sprintf("%#-*.*llo", 8, 5, 100) == Printf.@sprintf("%#-8.5llo", 100) @test Printf.@sprintf("%#-+ 0*.*lld", 8, 5, 100) == Printf.@sprintf("%#-+ 08.5lld", 100) @test Printf.@sprintf("%#-+ 0*.*lld", 8, 5, 100) == Printf.@sprintf("%#-+ 08.5lld", 100) @test Printf.@sprintf("%.*lld", 40, 1) == Printf.@sprintf("%.40lld", 1) @test Printf.@sprintf("% .*lld", 40, 1) == Printf.@sprintf("% .40lld", 1) @test Printf.@sprintf("% .*d", 40, 1) == Printf.@sprintf("% .40d", 1) @test Printf.@sprintf("%#0*x", 12, 1) == Printf.@sprintf("%#012x", 1) @test Printf.@sprintf("%#0*.*x", 4, 8, 1) == Printf.@sprintf("%#04.8x", 1) @test Printf.@sprintf("%#-0*.*x", 8, 2, 1) == Printf.@sprintf("%#-08.2x", 1) @test Printf.@sprintf("%#0*o", 8, 1) == Printf.@sprintf("%#08o", 1) @test Printf.@sprintf("%*d", 20, 1024) == Printf.@sprintf("%20d", 1024) @test Printf.@sprintf("%*d", 20, -1024) == Printf.@sprintf("%20d", -1024) @test Printf.@sprintf("%*i", 20, 1024) == Printf.@sprintf("%20i", 1024) @test Printf.@sprintf("%*i", 20, -1024) == Printf.@sprintf("%20i", -1024) @test Printf.@sprintf("%*u", 20, 1024) == Printf.@sprintf("%20u", 1024) @test Printf.@sprintf("%*u", 20, UInt(4294966272)) == Printf.@sprintf("%20u", UInt(4294966272)) @test Printf.@sprintf("%*o", 20, 511) == Printf.@sprintf("%20o", 511) @test Printf.@sprintf("%*o", 20, UInt(4294966785)) == Printf.@sprintf("%20o", UInt(4294966785)) @test Printf.@sprintf("%*x", 20, 305441741) == Printf.@sprintf("%20x", 305441741) @test Printf.@sprintf("%*x", 20, UInt(3989525555)) == Printf.@sprintf("%20x", UInt(3989525555)) @test Printf.@sprintf("%*X", 20, 305441741) == Printf.@sprintf("%20X", 305441741) @test Printf.@sprintf("%*X", 20, UInt(3989525555)) == Printf.@sprintf("%20X", UInt(3989525555)) @test Printf.@sprintf("%-*d", 20, 1024) == Printf.@sprintf("%-20d", 1024) @test Printf.@sprintf("%-*d", 20, -1024) == Printf.@sprintf("%-20d", -1024) @test Printf.@sprintf("%-*i", 20, 1024) == Printf.@sprintf("%-20i", 1024) @test Printf.@sprintf("%-*i", 20, -1024) == Printf.@sprintf("%-20i", -1024) @test Printf.@sprintf("%-*u", 20, 1024) == Printf.@sprintf("%-20u", 1024) @test Printf.@sprintf("%-*u", 20, UInt(4294966272)) == Printf.@sprintf("%-20u", UInt(4294966272)) @test Printf.@sprintf("%-*o", 20, 511) == Printf.@sprintf("%-20o", 511) @test Printf.@sprintf("%-*o", 20, UInt(4294966785)) == Printf.@sprintf("%-20o", UInt(4294966785)) @test Printf.@sprintf("%-*x", 20, 305441741) == Printf.@sprintf("%-20x", 305441741) @test Printf.@sprintf("%-*x", 20, UInt(3989525555)) == Printf.@sprintf("%-20x", UInt(3989525555)) @test Printf.@sprintf("%-*X", 20, 305441741) == Printf.@sprintf("%-20X", 305441741) @test Printf.@sprintf("%-*X", 20, UInt(3989525555)) == Printf.@sprintf("%-20X", UInt(3989525555)) @test Printf.@sprintf("%0*d", 20, 1024) == Printf.@sprintf("%020d", 1024) @test Printf.@sprintf("%0*d", 20, -1024) == Printf.@sprintf("%020d", -1024) @test Printf.@sprintf("%0*i", 20, 1024) == Printf.@sprintf("%020i", 1024) @test Printf.@sprintf("%0*i", 20, -1024) == Printf.@sprintf("%020i", -1024) @test Printf.@sprintf("%0*u", 20, 1024) == Printf.@sprintf("%020u", 1024) @test Printf.@sprintf("%0*u", 20, UInt(4294966272)) == Printf.@sprintf("%020u", UInt(4294966272)) @test Printf.@sprintf("%0*o", 20, 511) == Printf.@sprintf("%020o", 511) @test Printf.@sprintf("%0*o", 20, UInt(4294966785)) == Printf.@sprintf("%020o", UInt(4294966785)) @test Printf.@sprintf("%0*x", 20, 305441741) == Printf.@sprintf("%020x", 305441741) @test Printf.@sprintf("%0*x", 20, UInt(3989525555)) == Printf.@sprintf("%020x", UInt(3989525555)) @test Printf.@sprintf("%0*X", 20, 305441741) == Printf.@sprintf("%020X", 305441741) @test Printf.@sprintf("%0*X", 20, UInt(3989525555)) == Printf.@sprintf("%020X", UInt(3989525555)) @test Printf.@sprintf("%#*o", 20, 511) == Printf.@sprintf("%#20o", 511) @test Printf.@sprintf("%#*o", 20, UInt(4294966785)) == Printf.@sprintf("%#20o", UInt(4294966785)) @test Printf.@sprintf("%#*x", 20, 305441741) == Printf.@sprintf("%#20x", 305441741) @test Printf.@sprintf("%#*x", 20, UInt(3989525555)) == Printf.@sprintf("%#20x", UInt(3989525555)) @test Printf.@sprintf("%#*X", 20, 305441741) == Printf.@sprintf("%#20X", 305441741) @test Printf.@sprintf("%#*X", 20, UInt(3989525555)) == Printf.@sprintf("%#20X", UInt(3989525555)) @test Printf.@sprintf("%#0*o", 20, 511) == Printf.@sprintf("%#020o", 511) @test Printf.@sprintf("%#0*o", 20, UInt(4294966785)) == Printf.@sprintf("%#020o", UInt(4294966785)) @test Printf.@sprintf("%#0*x", 20, 305441741) == Printf.@sprintf("%#020x", 305441741) @test Printf.@sprintf("%#0*x", 20, UInt(3989525555)) == Printf.@sprintf("%#020x", UInt(3989525555)) @test Printf.@sprintf("%#0*X", 20, 305441741) == Printf.@sprintf("%#020X", 305441741) @test Printf.@sprintf("%#0*X", 20, UInt(3989525555)) == Printf.@sprintf("%#020X", UInt(3989525555)) @test Printf.@sprintf("%0-*d", 20, 1024) == Printf.@sprintf("%0-20d", 1024) @test Printf.@sprintf("%0-*d", 20, -1024) == Printf.@sprintf("%0-20d", -1024) @test Printf.@sprintf("%0-*i", 20, 1024) == Printf.@sprintf("%0-20i", 1024) @test Printf.@sprintf("%0-*i", 20, -1024) == Printf.@sprintf("%0-20i", -1024) @test Printf.@sprintf("%0-*u", 20, 1024) == Printf.@sprintf("%0-20u", 1024) @test Printf.@sprintf("%0-*u", 20, UInt(4294966272)) == Printf.@sprintf("%0-20u", UInt(4294966272)) @test Printf.@sprintf("%-0*o", 20, 511) == Printf.@sprintf("%-020o", 511) @test Printf.@sprintf("%-0*o", 20, UInt(4294966785)) == Printf.@sprintf("%-020o", UInt(4294966785)) @test Printf.@sprintf("%-0*x", 20, 305441741) == Printf.@sprintf("%-020x", 305441741) @test Printf.@sprintf("%-0*x", 20, UInt(3989525555)) == Printf.@sprintf("%-020x", UInt(3989525555)) @test Printf.@sprintf("%-0*X", 20, 305441741) == Printf.@sprintf("%-020X", 305441741) @test Printf.@sprintf("%-0*X", 20, UInt(3989525555)) == Printf.@sprintf("%-020X", UInt(3989525555)) @test Printf.@sprintf("%.*d", 20, 1024) == Printf.@sprintf("%.20d", 1024) @test Printf.@sprintf("%.*d", 20, -1024) == Printf.@sprintf("%.20d", -1024) @test Printf.@sprintf("%.*i", 20, 1024) == Printf.@sprintf("%.20i", 1024) @test Printf.@sprintf("%.*i", 20, -1024) == Printf.@sprintf("%.20i", -1024) @test Printf.@sprintf("%.*u", 20, 1024) == Printf.@sprintf("%.20u", 1024) @test Printf.@sprintf("%.*u", 20, UInt(4294966272)) == Printf.@sprintf("%.20u", UInt(4294966272)) @test Printf.@sprintf("%.*o", 20, 511) == Printf.@sprintf("%.20o", 511) @test Printf.@sprintf("%.*o", 20, UInt(4294966785)) == Printf.@sprintf("%.20o", UInt(4294966785)) @test Printf.@sprintf("%.*x", 20, 305441741) == Printf.@sprintf("%.20x", 305441741) @test Printf.@sprintf("%.*x", 20, UInt(3989525555)) == Printf.@sprintf("%.20x", UInt(3989525555)) @test Printf.@sprintf("%.*X", 20, 305441741) == Printf.@sprintf("%.20X", 305441741) @test Printf.@sprintf("%.*X", 20, UInt(3989525555)) == Printf.@sprintf("%.20X", UInt(3989525555)) @test Printf.@sprintf("%*.*d", 20, 5, 1024) == Printf.@sprintf("%20.5d", 1024) @test Printf.@sprintf("%*.*d", 20, 5, -1024) == Printf.@sprintf("%20.5d", -1024) @test Printf.@sprintf("%*.*i", 20, 5, 1024) == Printf.@sprintf("%20.5i", 1024) @test Printf.@sprintf("%*.*i", 20, 5, -1024) == Printf.@sprintf("%20.5i", -1024) @test Printf.@sprintf("%*.*u", 20, 5, 1024) == Printf.@sprintf("%20.5u", 1024) @test Printf.@sprintf("%*.*u", 20, 5, UInt(4294966272)) == Printf.@sprintf("%20.5u", UInt(4294966272)) @test Printf.@sprintf("%*.*o", 20, 5, 511) == Printf.@sprintf("%20.5o", 511) @test Printf.@sprintf("%*.*o", 20, 5, UInt(4294966785)) == Printf.@sprintf("%20.5o", UInt(4294966785)) @test Printf.@sprintf("%*.*x", 20, 5, 305441741) == Printf.@sprintf("%20.5x", 305441741) @test Printf.@sprintf("%*.*x", 20, 10, UInt(3989525555)) == Printf.@sprintf("%20.10x", UInt(3989525555)) @test Printf.@sprintf("%*.*X", 20, 5, 305441741) == Printf.@sprintf("%20.5X", 305441741) @test Printf.@sprintf("%*.*X", 20, 10, UInt(3989525555)) == Printf.@sprintf("%20.10X", UInt(3989525555)) @test Printf.@sprintf("%0*.*d", 20, 5, 1024) == Printf.@sprintf("%020.5d", 1024) @test Printf.@sprintf("%0*.*d", 20, 5, -1024) == Printf.@sprintf("%020.5d", -1024) @test Printf.@sprintf("%0*.*i", 20, 5, 1024) == Printf.@sprintf("%020.5i", 1024) @test Printf.@sprintf("%0*.*i", 20, 5, -1024) == Printf.@sprintf("%020.5i", -1024) @test Printf.@sprintf("%0*.*u", 20, 5, 1024) == Printf.@sprintf("%020.5u", 1024) @test Printf.@sprintf("%0*.*u", 20, 5, UInt(4294966272)) == Printf.@sprintf("%020.5u", UInt(4294966272)) @test Printf.@sprintf("%0*.*o", 20, 5, 511) == Printf.@sprintf("%020.5o", 511) @test Printf.@sprintf("%0*.*o", 20, 5, UInt(4294966785)) == Printf.@sprintf("%020.5o", UInt(4294966785)) @test Printf.@sprintf("%0*.*x", 20, 5, 305441741) == Printf.@sprintf("%020.5x", 305441741) @test Printf.@sprintf("%0*.*x", 20, 10, UInt(3989525555)) == Printf.@sprintf("%020.10x", UInt(3989525555)) @test Printf.@sprintf("%0*.*X", 20, 5, 305441741) == Printf.@sprintf("%020.5X", 305441741) @test Printf.@sprintf("%0*.*X", 20, 10, UInt(3989525555)) == Printf.@sprintf("%020.10X", UInt(3989525555)) @test Printf.@sprintf("%*.0d", 20, 1024) == Printf.@sprintf("%20.0d", 1024) @test Printf.@sprintf("%*.d", 20, -1024) == Printf.@sprintf("%20.d", -1024) @test Printf.@sprintf("%*.d", 20, 0) == Printf.@sprintf("%20.d", 0) @test Printf.@sprintf("%*.0i", 20, 1024) == Printf.@sprintf("%20.0i", 1024) @test Printf.@sprintf("%*.i", 20, -1024) == Printf.@sprintf("%20.i", -1024) @test Printf.@sprintf("%*.i", 20, 0) == Printf.@sprintf("%20.i", 0) @test Printf.@sprintf("%*.u", 20, 1024) == Printf.@sprintf("%20.u", 1024) @test Printf.@sprintf("%*.0u", 20, UInt(4294966272)) == Printf.@sprintf("%20.0u", UInt(4294966272)) @test Printf.@sprintf("%*.u", 20, UInt(0)) == Printf.@sprintf("%20.u", UInt(0)) @test Printf.@sprintf("%*.o", 20, 511) == Printf.@sprintf("%20.o", 511) @test Printf.@sprintf("%*.0o", 20, UInt(4294966785)) == Printf.@sprintf("%20.0o", UInt(4294966785)) @test Printf.@sprintf("%*.o", 20, UInt(0)) == Printf.@sprintf("%20.o", UInt(0)) @test Printf.@sprintf("%*.x", 20, 305441741) == Printf.@sprintf("%20.x", 305441741) @test Printf.@sprintf("%*.0x", 20, UInt(3989525555)) == Printf.@sprintf("%20.0x", UInt(3989525555)) @test Printf.@sprintf("%*.x", 20, UInt(0)) == Printf.@sprintf("%20.x", UInt(0)) @test Printf.@sprintf("%*.X", 20, 305441741) == Printf.@sprintf("%20.X", 305441741) @test Printf.@sprintf("%*.0X", 20, UInt(3989525555)) == Printf.@sprintf("%20.0X", UInt(3989525555)) @test Printf.@sprintf("%*.X", 20, UInt(0)) == Printf.@sprintf("%20.X", UInt(0)) x = Ref{Int}() y = Ref{Int}() @test begin Printf.@sprintf "%10s%n" "😉" x Printf.@sprintf "%*s%n" 10 "😉" y x[] == y[] end @test begin Printf.@sprintf "%10s%n" "1234" x Printf.@sprintf "%*s%n" 10 "1234" y x[] == y[] end end @testset "dynamic" begin @test Printf.@sprintf("%*d", 10, 12) == " 12" @test Printf.@sprintf("%.*d", 4, 12) == "0012" @test Printf.@sprintf("%*.*d", 10, 4, 12) == " 0012" @test Printf.@sprintf("%+*.*d", 10, 4, 12) == " +0012" @test Printf.@sprintf("%0*.*d", 10, 4, 12) == " 0012" @test Printf.@sprintf("%*d%*d%*d", 4, 12, 4, 13, 4, 14) == " 12 13 14" @test Printf.@sprintf("%*d%*d%*d", 4, 12, 5, 13, 6, 14) == " 12 13 14" @test Printf.@sprintf("%*p", 20, 0) == Printf.@sprintf("%20p", 0) @test Printf.@sprintf("%-*p", 20, 0) == Printf.@sprintf("%-20p", 0) @test Printf.@sprintf("%*p", 20, C_NULL) == Printf.@sprintf("%20p", C_NULL) @test Printf.@sprintf("%-*p", 20, C_NULL) == Printf.@sprintf("%-20p", C_NULL) @test Printf.@sprintf("%.*a", 0, 3.14) == Printf.@sprintf("%.0a", 3.14) @test Printf.@sprintf("%.*a", 1, 3.14) == Printf.@sprintf("%.1a", 3.14) @test Printf.@sprintf("%.*a", 2, 3.14) == Printf.@sprintf("%.2a", 3.14) @test Printf.@sprintf("%#.*a", 0, 3.14) == Printf.@sprintf("%#.0a", 3.14) @test Printf.@sprintf("%#.*a", 1, 3.14) == Printf.@sprintf("%#.1a", 3.14) @test Printf.@sprintf("%#.*a", 2, 3.14) == Printf.@sprintf("%#.2a", 3.14) @test Printf.@sprintf("%.*a", 6, 1.5) == Printf.@sprintf("%.6a", 1.5) @test Printf.@sprintf("%*.*g", 10, 5, -123.4) == Printf.@sprintf("%10.5g", -123.4) @test Printf.@sprintf("%0*.*g", 10, 5, -123.4) == Printf.@sprintf("%010.5g", -123.4) @test Printf.@sprintf("%.*g", 6, 1.234e7) == Printf.@sprintf("%.6g", 1.234e7) @test Printf.@sprintf("%#.*g", 6, 1.234e7) == Printf.@sprintf("%#.6g", 1.234e7) @test Printf.@sprintf("%*.*g", 10, 5, -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) == Printf.@sprintf("%10.5g", -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) @test Printf.@sprintf("%0*.*g", 10, 5, -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) == Printf.@sprintf("%010.5g", -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) @test Printf.@sprintf("%.*g", 6, 1.234e7) == Printf.@sprintf("%.6g", 1.234e7) @test Printf.@sprintf("%#.*g", 6, 1.234e7) == Printf.@sprintf("%#.6g", 1.234e7) @test Printf.@sprintf("%.*g", 5, 42) == Printf.@sprintf("%.5g", 42) @test Printf.@sprintf("%#.*g", 2, 42) == Printf.@sprintf("%#.2g", 42) @test Printf.@sprintf("%#.*g", 5, 42) == Printf.@sprintf("%#.5g", 42) @test Printf.@sprintf("%.*g", 15, 0) == Printf.@sprintf("%.15g", 0) @test Printf.@sprintf("%#.*g", 15, 0) == Printf.@sprintf("%#.15g", 0) @test Printf.@sprintf("%.*f", 0, 3.0e142) == Printf.@sprintf("%.0f", 3.0e142) @test Printf.@sprintf("%.*f", 2, 1.234) == Printf.@sprintf("%.2f", 1.234) @test Printf.@sprintf("%.*f", 2, 1.235) == Printf.@sprintf("%.2f", 1.235) @test Printf.@sprintf("%.*f", 2, 0.235) == Printf.@sprintf("%.2f", 0.235) @test Printf.@sprintf("%*.*f", 4, 1, 1.234) == Printf.@sprintf("%4.1f", 1.234) @test Printf.@sprintf("%*.*f", 8, 1, 1.234) == Printf.@sprintf("%8.1f", 1.234) @test Printf.@sprintf("%+*.*f", 8, 1, 1.234) == Printf.@sprintf("%+8.1f", 1.234) @test Printf.@sprintf("% *.*f", 8, 1, 1.234) == Printf.@sprintf("% 8.1f", 1.234) @test Printf.@sprintf("% *.*f", 7, 1, 1.234) == Printf.@sprintf("% 7.1f", 1.234) @test Printf.@sprintf("% 0*.*f", 8, 1, 1.234) == Printf.@sprintf("% 08.1f", 1.234) @test Printf.@sprintf("%0*.*f", 8, 1, 1.234) == Printf.@sprintf("%08.1f", 1.234) @test Printf.@sprintf("%-0*.*f", 8, 1, 1.234) == Printf.@sprintf("%-08.1f", 1.234) @test Printf.@sprintf("%-*.*f", 8, 1, 1.234) == Printf.@sprintf("%-8.1f", 1.234) @test Printf.@sprintf("%0*.*f", 8, 1, -1.234) == Printf.@sprintf("%08.1f", -1.234) @test Printf.@sprintf("%0*.*f", 9, 1, -1.234) == Printf.@sprintf("%09.1f", -1.234) @test Printf.@sprintf("%0*.*f", 9, 1, 1.234) == Printf.@sprintf("%09.1f", 1.234) @test Printf.@sprintf("%+0*.*f", 9, 1, 1.234) == Printf.@sprintf("%+09.1f", 1.234) @test Printf.@sprintf("% 0*.*f", 9, 1, 1.234) == Printf.@sprintf("% 09.1f", 1.234) @test Printf.@sprintf("%+ 0*.*f", 9, 1, 1.234) == Printf.@sprintf("%+ 09.1f", 1.234) @test Printf.@sprintf("%+ 0*.*f", 9, 1, 1.234) == Printf.@sprintf("%+ 09.1f", 1.234) @test Printf.@sprintf("%+ 0*.*f", 9, 0, 1.234) == Printf.@sprintf("%+ 09.0f", 1.234) @test Printf.@sprintf("%+ #0*.*f", 9, 0, 1.234) == Printf.@sprintf("%+ #09.0f", 1.234) @test Printf.@sprintf("%*.*e", 10, 4, Inf) == Printf.@sprintf("%10.4e", Inf) @test Printf.@sprintf("%*.*e", 10, 4, NaN) == Printf.@sprintf("%10.4e", NaN) @test Printf.@sprintf("%*.*e", 10, 4, Inf) == Printf.@sprintf("%10.4e", Inf) @test Printf.@sprintf("%*.*e", 10, 4, NaN) == Printf.@sprintf("%10.4e", NaN) @test Printf.@sprintf("%.*e", 0, 3.0e142) == Printf.@sprintf("%.0e", 3.0e142) @test Printf.@sprintf("%#.*e", 0, 3.0e142) == Printf.@sprintf("%#.0e", 3.0e142) @test Printf.@sprintf("%.*e", 0, 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) == Printf.@sprintf("%.0e", 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) @test Printf.@sprintf("%#.*e", 0, 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) == Printf.@sprintf("%#.0e", 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) @test Printf.@sprintf("%.*e", 0, 3.000000000000000000000000000000000000000000000000000000000000000000000000000024e1042) == Printf.@sprintf("%.0e", 3.000000000000000000000000000000000000000000000000000000000000000000000000000024e1042) @test Printf.@sprintf("%.*e", 2, 1.234) == Printf.@sprintf("%.2e", 1.234) @test Printf.@sprintf("%.*e", 2, 1.235) == Printf.@sprintf("%.2e", 1.235) @test Printf.@sprintf("%.*e", 2, 0.235) == Printf.@sprintf("%.2e", 0.235) @test Printf.@sprintf("%*.*e", 4, 1, 1.234) == Printf.@sprintf("%4.1e", 1.234) @test Printf.@sprintf("%*.*e", 8, 1, 1.234) == Printf.@sprintf("%8.1e", 1.234) @test Printf.@sprintf("%+*.*e", 8, 1, 1.234) == Printf.@sprintf("%+8.1e", 1.234) @test Printf.@sprintf("% *.*e", 8, 1, 1.234) == Printf.@sprintf("% 8.1e", 1.234) @test Printf.@sprintf("% *.*e", 7, 1, 1.234) == Printf.@sprintf("% 7.1e", 1.234) @test Printf.@sprintf("% 0*.*e", 8, 1, 1.234) == Printf.@sprintf("% 08.1e", 1.234) @test Printf.@sprintf("%0*.*e", 8, 1, 1.234) == Printf.@sprintf("%08.1e", 1.234) @test Printf.@sprintf("%-0*.*e", 8, 1, 1.234) == Printf.@sprintf("%-08.1e", 1.234) @test Printf.@sprintf("%-*.*e", 8, 1, 1.234) == Printf.@sprintf("%-8.1e", 1.234) @test Printf.@sprintf("%-*.*e", 8, 1, 1.234) == Printf.@sprintf("%-8.1e", 1.234) @test Printf.@sprintf("%0*.*e", 8, 1, -1.234) == Printf.@sprintf("%08.1e", -1.234) @test Printf.@sprintf("%0*.*e", 9, 1, -1.234) == Printf.@sprintf("%09.1e", -1.234) @test Printf.@sprintf("%0*.*e", 9, 1, 1.234) == Printf.@sprintf("%09.1e", 1.234) @test Printf.@sprintf("%+0*.*e", 9, 1, 1.234) == Printf.@sprintf("%+09.1e", 1.234) @test Printf.@sprintf("% 0*.*e", 9, 1, 1.234) == Printf.@sprintf("% 09.1e", 1.234) @test Printf.@sprintf("%+ 0*.*e", 9, 1, 1.234) == Printf.@sprintf("%+ 09.1e", 1.234) @test Printf.@sprintf("%+ 0*.*e", 9, 1, 1.234) == Printf.@sprintf("%+ 09.1e", 1.234) @test Printf.@sprintf("%+ 0*.*e", 9, 0, 1.234) == Printf.@sprintf("%+ 09.0e", 1.234) @test Printf.@sprintf("%+ #0*.*e", 9, 0, 1.234) == Printf.@sprintf("%+ #09.0e", 1.234) @test Printf.@sprintf("%.*s", 1, "foo") == Printf.@sprintf("%.1s", "foo") @test Printf.@sprintf("%*s", 1, "Hallo heimur") == Printf.@sprintf("%1s", "Hallo heimur") @test Printf.@sprintf("%*s", 20, "Hallo") == Printf.@sprintf("%20s", "Hallo") @test Printf.@sprintf("%-*s", 20, "Hallo") == Printf.@sprintf("%-20s", "Hallo") @test Printf.@sprintf("%0-*s", 20, "Hallo") == Printf.@sprintf("%0-20s", "Hallo") @test Printf.@sprintf("%.*s", 20, "Hallo heimur") == Printf.@sprintf("%.20s", "Hallo heimur") @test Printf.@sprintf("%*.*s", 20, 5, "Hallo heimur") == Printf.@sprintf("%20.5s", "Hallo heimur") @test Printf.@sprintf("%.*s", 0, "Hallo heimur") == Printf.@sprintf("%.0s", "Hallo heimur") @test Printf.@sprintf("%*.*s", 20, 0, "Hallo heimur") == Printf.@sprintf("%20.0s", "Hallo heimur") @test Printf.@sprintf("%.s", "Hallo heimur") == Printf.@sprintf("%.s", "Hallo heimur") @test Printf.@sprintf("%*.s", 20, "Hallo heimur") == Printf.@sprintf("%20.s", "Hallo heimur") @test Printf.@sprintf("%*sø", 4, "ø") == Printf.@sprintf("%4sø", "ø") @test Printf.@sprintf("%-*sø", 4, "ø") == Printf.@sprintf("%-4sø", "ø") @test Printf.@sprintf("%*s", 8, "test") == Printf.@sprintf("%8s", "test") @test Printf.@sprintf("%-*s", 8, "test") == Printf.@sprintf("%-8s", "test") @test Printf.@sprintf("%#*s", 8, :test) == Printf.@sprintf("%#8s", :test) @test Printf.@sprintf("%#-*s", 8, :test) == Printf.@sprintf("%#-8s", :test) @test Printf.@sprintf("%*.*s", 8, 3, "test") == Printf.@sprintf("%8.3s", "test") @test Printf.@sprintf("%#*.*s", 8, 3, "test") == Printf.@sprintf("%#8.3s", "test") @test Printf.@sprintf("%-*.*s", 8, 3, "test") == Printf.@sprintf("%-8.3s", "test") @test Printf.@sprintf("%#-*.*s", 8, 3, "test") == Printf.@sprintf("%#-8.3s", "test") @test Printf.@sprintf("%.*s", 3, "test") == Printf.@sprintf("%.3s", "test") @test Printf.@sprintf("%#.*s", 3, "test") == Printf.@sprintf("%#.3s", "test") @test Printf.@sprintf("%-.*s", 3, "test") == Printf.@sprintf("%-.3s", "test") @test Printf.@sprintf("%#-.*s", 3, "test") == Printf.@sprintf("%#-.3s", "test") @test Printf.@sprintf("%*c", 3, 'a') == Printf.@sprintf("%3c", 'a') @test Printf.@sprintf("%*c", 1, 'x') == Printf.@sprintf("%1c", 'x') @test Printf.@sprintf("%*c", 20, 'x') == Printf.@sprintf("%20c", 'x') @test Printf.@sprintf("%-*c", 20, 'x') == Printf.@sprintf("%-20c", 'x') @test Printf.@sprintf("%-0*c", 20, 'x') == Printf.@sprintf("%-020c", 'x') @test Printf.@sprintf("%*c", 3, 'A') == Printf.@sprintf("%3c", 'A') @test Printf.@sprintf("%-*c", 3, 'A') == Printf.@sprintf("%-3c", 'A') @test Printf.@sprintf("%*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f", 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345) == Printf.@sprintf("%4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f", 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345) @test (Printf.@sprintf("%.*f", 330, BigFloat(1)))[var"end"] != '\0' @test Printf.@sprintf("%*.*s", 4, 2, "a") == Printf.@sprintf("%4.2s", "a") @test Printf.@sprintf("%*.*e", 12, 3, pi * 1.0e100) == Printf.@sprintf("%12.3e", pi * 1.0e100) @test Printf.@sprintf("%*d", 2, 3.14) == Printf.@sprintf("%*d", 2, 3.14) @test Printf.@sprintf("%*d", 2, big(3.14)) == Printf.@sprintf("%*d", 2, big(3.14)) @test Printf.@sprintf(" %.*e\n", 1, 0.999) == Printf.@sprintf(" %.1e\n", 0.999) @test Printf.@sprintf(" %.*f", 1, 9.999) == Printf.@sprintf(" %.1f", 9.999) @test Printf.@sprintf("%*d", 10, 12) == Printf.@sprintf("%10d", 12) @test Printf.@sprintf("%.*d", 4, 12) == Printf.@sprintf("%.4d", 12) @test Printf.@sprintf("%*.*d", 10, 4, 12) == Printf.@sprintf("%10.4d", 12) @test Printf.@sprintf("%+*.*d", 10, 4, 12) == Printf.@sprintf("%+10.4d", 12) @test Printf.@sprintf("%0*.*d", 10, 4, 12) == Printf.@sprintf("%010.4d", 12) @test Printf.@sprintf("% *d", 5, 42) == Printf.@sprintf("% 5d", 42) @test Printf.@sprintf("% *d", 5, -42) == Printf.@sprintf("% 5d", -42) @test Printf.@sprintf("% *d", 15, 42) == Printf.@sprintf("% 15d", 42) @test Printf.@sprintf("% *d", 15, -42) == Printf.@sprintf("% 15d", -42) @test Printf.@sprintf("%+*d", 5, 42) == Printf.@sprintf("%+5d", 42) @test Printf.@sprintf("%+*d", 5, -42) == Printf.@sprintf("%+5d", -42) @test Printf.@sprintf("%+*d", 15, 42) == Printf.@sprintf("%+15d", 42) @test Printf.@sprintf("%+*d", 15, -42) == Printf.@sprintf("%+15d", -42) @test Printf.@sprintf("%*d", 0, 42) == Printf.@sprintf("%0d", 42) @test Printf.@sprintf("%*d", 0, -42) == Printf.@sprintf("%0d", -42) @test Printf.@sprintf("%-*d", 5, 42) == Printf.@sprintf("%-5d", 42) @test Printf.@sprintf("%-*d", 5, -42) == Printf.@sprintf("%-5d", -42) @test Printf.@sprintf("%-*d", 15, 42) == Printf.@sprintf("%-15d", 42) @test Printf.@sprintf("%-*d", 15, -42) == Printf.@sprintf("%-15d", -42) @test Printf.@sprintf("%+*lld", 8, 100) == Printf.@sprintf("%+8lld", 100) @test Printf.@sprintf("%+.*lld", 8, 100) == Printf.@sprintf("%+.8lld", 100) @test Printf.@sprintf("%+*.*lld", 10, 8, 100) == Printf.@sprintf("%+10.8lld", 100) @test Printf.@sprintf("%-*.*lld", 1, 5, -100) == Printf.@sprintf("%-1.5lld", -100) @test Printf.@sprintf("%*lld", 5, 100) == Printf.@sprintf("%5lld", 100) @test Printf.@sprintf("%*lld", 5, -100) == Printf.@sprintf("%5lld", -100) @test Printf.@sprintf("%-*lld", 5, 100) == Printf.@sprintf("%-5lld", 100) @test Printf.@sprintf("%-*lld", 5, -100) == Printf.@sprintf("%-5lld", -100) @test Printf.@sprintf("%-.*lld", 5, 100) == Printf.@sprintf("%-.5lld", 100) @test Printf.@sprintf("%-.*lld", 5, -100) == Printf.@sprintf("%-.5lld", -100) @test Printf.@sprintf("%-*.*lld", 8, 5, 100) == Printf.@sprintf("%-8.5lld", 100) @test Printf.@sprintf("%-*.*lld", 8, 5, -100) == Printf.@sprintf("%-8.5lld", -100) @test Printf.@sprintf("%0*lld", 5, 100) == Printf.@sprintf("%05lld", 100) @test Printf.@sprintf("%0*lld", 5, -100) == Printf.@sprintf("%05lld", -100) @test Printf.@sprintf("% *lld", 5, 100) == Printf.@sprintf("% 5lld", 100) @test Printf.@sprintf("% *lld", 5, -100) == Printf.@sprintf("% 5lld", -100) @test Printf.@sprintf("% .*lld", 5, 100) == Printf.@sprintf("% .5lld", 100) @test Printf.@sprintf("% .*lld", 5, -100) == Printf.@sprintf("% .5lld", -100) @test Printf.@sprintf("% *.*lld", 8, 5, 100) == Printf.@sprintf("% 8.5lld", 100) @test Printf.@sprintf("% *.*lld", 8, 5, -100) == Printf.@sprintf("% 8.5lld", -100) @test Printf.@sprintf("%.*lld", 0, 0) == Printf.@sprintf("%.0lld", 0) @test Printf.@sprintf("%#+*.*llx", 21, 18, -100) == Printf.@sprintf("%#+21.18llx", -100) @test Printf.@sprintf("%#.*llo", 25, -100) == Printf.@sprintf("%#.25llo", -100) @test Printf.@sprintf("%#+*.*llo", 24, 20, -100) == Printf.@sprintf("%#+24.20llo", -100) @test Printf.@sprintf("%#+*.*llX", 18, 21, -100) == Printf.@sprintf("%#+18.21llX", -100) @test Printf.@sprintf("%#+*.*llo", 20, 24, -100) == Printf.@sprintf("%#+20.24llo", -100) @test Printf.@sprintf("%#+*.*llu", 25, 22, -1) == Printf.@sprintf("%#+25.22llu", -1) @test Printf.@sprintf("%#+*.*llu", 30, 25, -1) == Printf.@sprintf("%#+30.25llu", -1) @test Printf.@sprintf("%+#*.*lld", 25, 22, -1) == Printf.@sprintf("%+#25.22lld", -1) @test Printf.@sprintf("%#-*.*llo", 8, 5, 100) == Printf.@sprintf("%#-8.5llo", 100) @test Printf.@sprintf("%#-+ 0*.*lld", 8, 5, 100) == Printf.@sprintf("%#-+ 08.5lld", 100) @test Printf.@sprintf("%#-+ 0*.*lld", 8, 5, 100) == Printf.@sprintf("%#-+ 08.5lld", 100) @test Printf.@sprintf("%.*lld", 40, 1) == Printf.@sprintf("%.40lld", 1) @test Printf.@sprintf("% .*lld", 40, 1) == Printf.@sprintf("% .40lld", 1) @test Printf.@sprintf("% .*d", 40, 1) == Printf.@sprintf("% .40d", 1) @test Printf.@sprintf("%#0*x", 12, 1) == Printf.@sprintf("%#012x", 1) @test Printf.@sprintf("%#0*.*x", 4, 8, 1) == Printf.@sprintf("%#04.8x", 1) @test Printf.@sprintf("%#-0*.*x", 8, 2, 1) == Printf.@sprintf("%#-08.2x", 1) @test Printf.@sprintf("%#0*o", 8, 1) == Printf.@sprintf("%#08o", 1) @test Printf.@sprintf("%*d", 20, 1024) == Printf.@sprintf("%20d", 1024) @test Printf.@sprintf("%*d", 20, -1024) == Printf.@sprintf("%20d", -1024) @test Printf.@sprintf("%*i", 20, 1024) == Printf.@sprintf("%20i", 1024) @test Printf.@sprintf("%*i", 20, -1024) == Printf.@sprintf("%20i", -1024) @test Printf.@sprintf("%*u", 20, 1024) == Printf.@sprintf("%20u", 1024) @test Printf.@sprintf("%*u", 20, UInt(4294966272)) == Printf.@sprintf("%20u", UInt(4294966272)) @test Printf.@sprintf("%*o", 20, 511) == Printf.@sprintf("%20o", 511) @test Printf.@sprintf("%*o", 20, UInt(4294966785)) == Printf.@sprintf("%20o", UInt(4294966785)) @test Printf.@sprintf("%*x", 20, 305441741) == Printf.@sprintf("%20x", 305441741) @test Printf.@sprintf("%*x", 20, UInt(3989525555)) == Printf.@sprintf("%20x", UInt(3989525555)) @test Printf.@sprintf("%*X", 20, 305441741) == Printf.@sprintf("%20X", 305441741) @test Printf.@sprintf("%*X", 20, UInt(3989525555)) == Printf.@sprintf("%20X", UInt(3989525555)) @test Printf.@sprintf("%-*d", 20, 1024) == Printf.@sprintf("%-20d", 1024) @test Printf.@sprintf("%-*d", 20, -1024) == Printf.@sprintf("%-20d", -1024) @test Printf.@sprintf("%-*i", 20, 1024) == Printf.@sprintf("%-20i", 1024) @test Printf.@sprintf("%-*i", 20, -1024) == Printf.@sprintf("%-20i", -1024) @test Printf.@sprintf("%-*u", 20, 1024) == Printf.@sprintf("%-20u", 1024) @test Printf.@sprintf("%-*u", 20, UInt(4294966272)) == Printf.@sprintf("%-20u", UInt(4294966272)) @test Printf.@sprintf("%-*o", 20, 511) == Printf.@sprintf("%-20o", 511) @test Printf.@sprintf("%-*o", 20, UInt(4294966785)) == Printf.@sprintf("%-20o", UInt(4294966785)) @test Printf.@sprintf("%-*x", 20, 305441741) == Printf.@sprintf("%-20x", 305441741) @test Printf.@sprintf("%-*x", 20, UInt(3989525555)) == Printf.@sprintf("%-20x", UInt(3989525555)) @test Printf.@sprintf("%-*X", 20, 305441741) == Printf.@sprintf("%-20X", 305441741) @test Printf.@sprintf("%-*X", 20, UInt(3989525555)) == Printf.@sprintf("%-20X", UInt(3989525555)) @test Printf.@sprintf("%0*d", 20, 1024) == Printf.@sprintf("%020d", 1024) @test Printf.@sprintf("%0*d", 20, -1024) == Printf.@sprintf("%020d", -1024) @test Printf.@sprintf("%0*i", 20, 1024) == Printf.@sprintf("%020i", 1024) @test Printf.@sprintf("%0*i", 20, -1024) == Printf.@sprintf("%020i", -1024) @test Printf.@sprintf("%0*u", 20, 1024) == Printf.@sprintf("%020u", 1024) @test Printf.@sprintf("%0*u", 20, UInt(4294966272)) == Printf.@sprintf("%020u", UInt(4294966272)) @test Printf.@sprintf("%0*o", 20, 511) == Printf.@sprintf("%020o", 511) @test Printf.@sprintf("%0*o", 20, UInt(4294966785)) == Printf.@sprintf("%020o", UInt(4294966785)) @test Printf.@sprintf("%0*x", 20, 305441741) == Printf.@sprintf("%020x", 305441741) @test Printf.@sprintf("%0*x", 20, UInt(3989525555)) == Printf.@sprintf("%020x", UInt(3989525555)) @test Printf.@sprintf("%0*X", 20, 305441741) == Printf.@sprintf("%020X", 305441741) @test Printf.@sprintf("%0*X", 20, UInt(3989525555)) == Printf.@sprintf("%020X", UInt(3989525555)) @test Printf.@sprintf("%#*o", 20, 511) == Printf.@sprintf("%#20o", 511) @test Printf.@sprintf("%#*o", 20, UInt(4294966785)) == Printf.@sprintf("%#20o", UInt(4294966785)) @test Printf.@sprintf("%#*x", 20, 305441741) == Printf.@sprintf("%#20x", 305441741) @test Printf.@sprintf("%#*x", 20, UInt(3989525555)) == Printf.@sprintf("%#20x", UInt(3989525555)) @test Printf.@sprintf("%#*X", 20, 305441741) == Printf.@sprintf("%#20X", 305441741) @test Printf.@sprintf("%#*X", 20, UInt(3989525555)) == Printf.@sprintf("%#20X", UInt(3989525555)) @test Printf.@sprintf("%#0*o", 20, 511) == Printf.@sprintf("%#020o", 511) @test Printf.@sprintf("%#0*o", 20, UInt(4294966785)) == Printf.@sprintf("%#020o", UInt(4294966785)) @test Printf.@sprintf("%#0*x", 20, 305441741) == Printf.@sprintf("%#020x", 305441741) @test Printf.@sprintf("%#0*x", 20, UInt(3989525555)) == Printf.@sprintf("%#020x", UInt(3989525555)) @test Printf.@sprintf("%#0*X", 20, 305441741) == Printf.@sprintf("%#020X", 305441741) @test Printf.@sprintf("%#0*X", 20, UInt(3989525555)) == Printf.@sprintf("%#020X", UInt(3989525555)) @test Printf.@sprintf("%0-*d", 20, 1024) == Printf.@sprintf("%0-20d", 1024) @test Printf.@sprintf("%0-*d", 20, -1024) == Printf.@sprintf("%0-20d", -1024) @test Printf.@sprintf("%0-*i", 20, 1024) == Printf.@sprintf("%0-20i", 1024) @test Printf.@sprintf("%0-*i", 20, -1024) == Printf.@sprintf("%0-20i", -1024) @test Printf.@sprintf("%0-*u", 20, 1024) == Printf.@sprintf("%0-20u", 1024) @test Printf.@sprintf("%0-*u", 20, UInt(4294966272)) == Printf.@sprintf("%0-20u", UInt(4294966272)) @test Printf.@sprintf("%-0*o", 20, 511) == Printf.@sprintf("%-020o", 511) @test Printf.@sprintf("%-0*o", 20, UInt(4294966785)) == Printf.@sprintf("%-020o", UInt(4294966785)) @test Printf.@sprintf("%-0*x", 20, 305441741) == Printf.@sprintf("%-020x", 305441741) @test Printf.@sprintf("%-0*x", 20, UInt(3989525555)) == Printf.@sprintf("%-020x", UInt(3989525555)) @test Printf.@sprintf("%-0*X", 20, 305441741) == Printf.@sprintf("%-020X", 305441741) @test Printf.@sprintf("%-0*X", 20, UInt(3989525555)) == Printf.@sprintf("%-020X", UInt(3989525555)) @test Printf.@sprintf("%.*d", 20, 1024) == Printf.@sprintf("%.20d", 1024) @test Printf.@sprintf("%.*d", 20, -1024) == Printf.@sprintf("%.20d", -1024) @test Printf.@sprintf("%.*i", 20, 1024) == Printf.@sprintf("%.20i", 1024) @test Printf.@sprintf("%.*i", 20, -1024) == Printf.@sprintf("%.20i", -1024) @test Printf.@sprintf("%.*u", 20, 1024) == Printf.@sprintf("%.20u", 1024) @test Printf.@sprintf("%.*u", 20, UInt(4294966272)) == Printf.@sprintf("%.20u", UInt(4294966272)) @test Printf.@sprintf("%.*o", 20, 511) == Printf.@sprintf("%.20o", 511) @test Printf.@sprintf("%.*o", 20, UInt(4294966785)) == Printf.@sprintf("%.20o", UInt(4294966785)) @test Printf.@sprintf("%.*x", 20, 305441741) == Printf.@sprintf("%.20x", 305441741) @test Printf.@sprintf("%.*x", 20, UInt(3989525555)) == Printf.@sprintf("%.20x", UInt(3989525555)) @test Printf.@sprintf("%.*X", 20, 305441741) == Printf.@sprintf("%.20X", 305441741) @test Printf.@sprintf("%.*X", 20, UInt(3989525555)) == Printf.@sprintf("%.20X", UInt(3989525555)) @test Printf.@sprintf("%*.*d", 20, 5, 1024) == Printf.@sprintf("%20.5d", 1024) @test Printf.@sprintf("%*.*d", 20, 5, -1024) == Printf.@sprintf("%20.5d", -1024) @test Printf.@sprintf("%*.*i", 20, 5, 1024) == Printf.@sprintf("%20.5i", 1024) @test Printf.@sprintf("%*.*i", 20, 5, -1024) == Printf.@sprintf("%20.5i", -1024) @test Printf.@sprintf("%*.*u", 20, 5, 1024) == Printf.@sprintf("%20.5u", 1024) @test Printf.@sprintf("%*.*u", 20, 5, UInt(4294966272)) == Printf.@sprintf("%20.5u", UInt(4294966272)) @test Printf.@sprintf("%*.*o", 20, 5, 511) == Printf.@sprintf("%20.5o", 511) @test Printf.@sprintf("%*.*o", 20, 5, UInt(4294966785)) == Printf.@sprintf("%20.5o", UInt(4294966785)) @test Printf.@sprintf("%*.*x", 20, 5, 305441741) == Printf.@sprintf("%20.5x", 305441741) @test Printf.@sprintf("%*.*x", 20, 10, UInt(3989525555)) == Printf.@sprintf("%20.10x", UInt(3989525555)) @test Printf.@sprintf("%*.*X", 20, 5, 305441741) == Printf.@sprintf("%20.5X", 305441741) @test Printf.@sprintf("%*.*X", 20, 10, UInt(3989525555)) == Printf.@sprintf("%20.10X", UInt(3989525555)) @test Printf.@sprintf("%0*.*d", 20, 5, 1024) == Printf.@sprintf("%020.5d", 1024) @test Printf.@sprintf("%0*.*d", 20, 5, -1024) == Printf.@sprintf("%020.5d", -1024) @test Printf.@sprintf("%0*.*i", 20, 5, 1024) == Printf.@sprintf("%020.5i", 1024) @test Printf.@sprintf("%0*.*i", 20, 5, -1024) == Printf.@sprintf("%020.5i", -1024) @test Printf.@sprintf("%0*.*u", 20, 5, 1024) == Printf.@sprintf("%020.5u", 1024) @test Printf.@sprintf("%0*.*u", 20, 5, UInt(4294966272)) == Printf.@sprintf("%020.5u", UInt(4294966272)) @test Printf.@sprintf("%0*.*o", 20, 5, 511) == Printf.@sprintf("%020.5o", 511) @test Printf.@sprintf("%0*.*o", 20, 5, UInt(4294966785)) == Printf.@sprintf("%020.5o", UInt(4294966785)) @test Printf.@sprintf("%0*.*x", 20, 5, 305441741) == Printf.@sprintf("%020.5x", 305441741) @test Printf.@sprintf("%0*.*x", 20, 10, UInt(3989525555)) == Printf.@sprintf("%020.10x", UInt(3989525555)) @test Printf.@sprintf("%0*.*X", 20, 5, 305441741) == Printf.@sprintf("%020.5X", 305441741) @test Printf.@sprintf("%0*.*X", 20, 10, UInt(3989525555)) == Printf.@sprintf("%020.10X", UInt(3989525555)) @test Printf.@sprintf("%*.0d", 20, 1024) == Printf.@sprintf("%20.0d", 1024) @test Printf.@sprintf("%*.d", 20, -1024) == Printf.@sprintf("%20.d", -1024) @test Printf.@sprintf("%*.d", 20, 0) == Printf.@sprintf("%20.d", 0) @test Printf.@sprintf("%*.0i", 20, 1024) == Printf.@sprintf("%20.0i", 1024) @test Printf.@sprintf("%*.i", 20, -1024) == Printf.@sprintf("%20.i", -1024) @test Printf.@sprintf("%*.i", 20, 0) == Printf.@sprintf("%20.i", 0) @test Printf.@sprintf("%*.u", 20, 1024) == Printf.@sprintf("%20.u", 1024) @test Printf.@sprintf("%*.0u", 20, UInt(4294966272)) == Printf.@sprintf("%20.0u", UInt(4294966272)) @test Printf.@sprintf("%*.u", 20, UInt(0)) == Printf.@sprintf("%20.u", UInt(0)) @test Printf.@sprintf("%*.o", 20, 511) == Printf.@sprintf("%20.o", 511) @test Printf.@sprintf("%*.0o", 20, UInt(4294966785)) == Printf.@sprintf("%20.0o", UInt(4294966785)) @test Printf.@sprintf("%*.o", 20, UInt(0)) == Printf.@sprintf("%20.o", UInt(0)) @test Printf.@sprintf("%*.x", 20, 305441741) == Printf.@sprintf("%20.x", 305441741) @test Printf.@sprintf("%*.0x", 20, UInt(3989525555)) == Printf.@sprintf("%20.0x", UInt(3989525555)) @test Printf.@sprintf("%*.x", 20, UInt(0)) == Printf.@sprintf("%20.x", UInt(0)) @test Printf.@sprintf("%*.X", 20, 305441741) == Printf.@sprintf("%20.X", 305441741) @test Printf.@sprintf("%*.0X", 20, UInt(3989525555)) == Printf.@sprintf("%20.0X", UInt(3989525555)) @test Printf.@sprintf("%*.X", 20, UInt(0)) == Printf.@sprintf("%20.X", UInt(0)) x = Ref{Int}() y = Ref{Int}() @test begin Printf.@sprintf "%10s%n" "😉" x Printf.@sprintf "%*s%n" 10 "😉" y x[] == y[] end @test begin Printf.@sprintf "%10s%n" "1234" x Printf.@sprintf "%*s%n" 10 "1234" y x[] == y[] end end begin @testset "%p" begin if Sys.WORD_SIZE == 64 @test Printf.@sprintf("%20p", 0) == " 0x0000000000000000" @test Printf.@sprintf("%-20p", 0) == "0x0000000000000000 " @test Printf.@sprintf("%20p", C_NULL) == " 0x0000000000000000" @test @sprintf("%-20p", C_NULL) == "0x0000000000000000 " elseif Sys.WORD_SIZE == 32 @test Printf.@sprintf("%20p", 0) == " 0x00000000" @test Printf.@sprintf("%-20p", 0) == "0x00000000 " @test @sprintf("%20p", C_NULL) == " 0x00000000" @test @sprintf("%-20p", C_NULL) == "0x00000000 " end @test @sprintf("%p", 0xfffffffffffe0000) == "0xfffffffffffe0000" end @testset "%a" begin @test Printf.@sprintf("%a", 0.0) == "0x0p+0" @test Printf.@sprintf("%a", -0.0) == "-0x0p+0" @test Printf.@sprintf("%.3a", 0.0) == "0x0.000p+0" @test Printf.@sprintf("%a", 1.5) == "0x1.8p+0" @test Printf.@sprintf("%a", 1.5f0) == "0x1.8p+0" @test Printf.@sprintf("%a", 1.5) == "0x1.8p+0" @test Printf.@sprintf("%#.0a", 1.5) == "0x2.p+0" @test Printf.@sprintf("%+30a", 1 / 3) == " +0x1.5555555555555p-2" @test Printf.@sprintf("%a", 1.5) == "0x1.8p+0" @test Printf.@sprintf("%a", 3.14) == "0x1.91eb851eb851fp+1" @test Printf.@sprintf("%.0a", 3.14) == "0x2p+1" @test Printf.@sprintf("%.1a", 3.14) == "0x1.9p+1" @test Printf.@sprintf("%.2a", 3.14) == "0x1.92p+1" @test Printf.@sprintf("%#a", 3.14) == "0x1.91eb851eb851fp+1" @test Printf.@sprintf("%#.0a", 3.14) == "0x2.p+1" @test Printf.@sprintf("%#.1a", 3.14) == "0x1.9p+1" @test Printf.@sprintf("%#.2a", 3.14) == "0x1.92p+1" @test Printf.@sprintf("%.6a", 1.5) == "0x1.800000p+0" end @testset "%g" begin for (val, res) = ((1.2345678e7, "1.23457e+07"), (1.2345678e6, "1.23457e+06"), (123456.78, "123457"), (12345.678, "12345.7"), (1.234e7, "1.234e+07")) @test Printf.@sprintf("%.6g", val) == res end for (val, res) = ((1.2345678e7, "1.23457e+07"), (1.234567799999999999999999999999999999999999999999999999999999999999999999999993e6, "1.23457e+06"), (123456.7800000000000000000000000000000000000000000000000000000000000000000000004, "123457"), (12345.67800000000000000000000000000000000000000000000000000000000000000000000007, "12345.7")) @test Printf.@sprintf("%.6g", val) == res end for (fmt, val) = (("%10.5g", " 123.4"), ("%+10.5g", " +123.4"), ("% 10.5g", " 123.4"), ("%#10.5g", " 123.40"), ("%-10.5g", "123.4 "), ("%-+10.5g", "+123.4 "), ("%010.5g", "00000123.4")), num = (123.4, 123.4000000000000000000000000000000000000000000000000000000000000000000000000002) @test Printf.format(Printf.Format(fmt), num) == val end @test Printf.@sprintf("%10.5g", -123.4) == " -123.4" @test Printf.@sprintf("%010.5g", -123.4) == "-0000123.4" @test Printf.@sprintf("%.6g", 1.234e7) == "1.234e+07" @test Printf.@sprintf("%#.6g", 1.234e7) == "1.23400e+07" @test Printf.@sprintf("%10.5g", -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) == " -123.4" @test Printf.@sprintf("%010.5g", -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) == "-0000123.4" @test Printf.@sprintf("%.6g", 1.234e7) == "1.234e+07" @test Printf.@sprintf("%#.6g", 1.234e7) == "1.23400e+07" @test Printf.@sprintf("%.5g", 42) == "42" @test Printf.@sprintf("%#.2g", 42) == "42." @test Printf.@sprintf("%#.5g", 42) == "42.000" @test Printf.@sprintf("%g", 0.00012) == "0.00012" @test Printf.@sprintf("%g", 1.2e-5) == "1.2e-05" @test Printf.@sprintf("%g", 123456.7) == "123457" @test Printf.@sprintf("%g", 1.2345678e6) == "1.23457e+06" for (val, res) = ((Inf, "Inf"), (-Inf, "-Inf"), (NaN, "NaN"), (-NaN, "NaN")) @test Printf.@sprintf("%g", val) == res @test Printf.@sprintf("%G", val) == res end @test Printf.@sprintf("%.15g", 0) == "0" @test Printf.@sprintf("%#.15g", 0) == "0.00000000000000" end @testset "%f" begin @test Printf.@sprintf("%f", Inf) == "Inf" @test Printf.@sprintf("%+f", Inf) == "+Inf" @test Printf.@sprintf("% f", Inf) == " Inf" @test Printf.@sprintf("% #f", Inf) == " Inf" @test Printf.@sprintf("%07f", Inf) == " Inf" @test Printf.@sprintf("%f", -Inf) == "-Inf" @test Printf.@sprintf("%+f", -Inf) == "-Inf" @test Printf.@sprintf("%07f", -Inf) == " -Inf" @test Printf.@sprintf("%f", NaN) == "NaN" @test Printf.@sprintf("%+f", NaN) == "+NaN" @test Printf.@sprintf("% f", NaN) == " NaN" @test Printf.@sprintf("% #f", NaN) == " NaN" @test Printf.@sprintf("%07f", NaN) == " NaN" @test Printf.@sprintf("%e", Inf) == "Inf" @test Printf.@sprintf("%e", NaN) == "NaN" @test Printf.@sprintf("%.0f", 3.0e142) == "29999999999999997463140672961703247153805615792184250659629251954072073858354858644285983761764971823910371920726635399393477049701891710124032" @test Printf.@sprintf("%f", 1.234) == "1.234000" @test Printf.@sprintf("%F", 1.234) == "1.234000" @test Printf.@sprintf("%+f", 1.234) == "+1.234000" @test Printf.@sprintf("% f", 1.234) == " 1.234000" @test Printf.@sprintf("%f", -1.234) == "-1.234000" @test Printf.@sprintf("%+f", -1.234) == "-1.234000" @test Printf.@sprintf("% f", -1.234) == "-1.234000" @test Printf.@sprintf("%#f", 1.234) == "1.234000" @test Printf.@sprintf("%.2f", 1.234) == "1.23" @test Printf.@sprintf("%.2f", 1.235) == "1.24" @test Printf.@sprintf("%.2f", 0.235) == "0.23" @test Printf.@sprintf("%4.1f", 1.234) == " 1.2" @test Printf.@sprintf("%8.1f", 1.234) == " 1.2" @test Printf.@sprintf("%+8.1f", 1.234) == " +1.2" @test Printf.@sprintf("% 8.1f", 1.234) == " 1.2" @test Printf.@sprintf("% 7.1f", 1.234) == " 1.2" @test Printf.@sprintf("% 08.1f", 1.234) == " 00001.2" @test Printf.@sprintf("%08.1f", 1.234) == "000001.2" @test Printf.@sprintf("%-08.1f", 1.234) == "1.2 " @test Printf.@sprintf("%-8.1f", 1.234) == "1.2 " @test Printf.@sprintf("%08.1f", -1.234) == "-00001.2" @test Printf.@sprintf("%09.1f", -1.234) == "-000001.2" @test Printf.@sprintf("%09.1f", 1.234) == "0000001.2" @test Printf.@sprintf("%+09.1f", 1.234) == "+000001.2" @test Printf.@sprintf("% 09.1f", 1.234) == " 000001.2" @test Printf.@sprintf("%+ 09.1f", 1.234) == "+000001.2" @test Printf.@sprintf("%+ 09.1f", 1.234) == "+000001.2" @test Printf.@sprintf("%+ 09.0f", 1.234) == "+00000001" @test Printf.@sprintf("%+ #09.0f", 1.234) == "+0000001." @test Printf.@sprintf("%+7.1f", 9.96) == " +10.0" @test Printf.@sprintf("% 7.1f", 9.96) == " 10.0" end @testset "%e" begin @test Printf.@sprintf("%e", Inf) == "Inf" @test Printf.@sprintf("%+e", Inf) == "+Inf" @test Printf.@sprintf("% e", Inf) == " Inf" @test Printf.@sprintf("% #e", Inf) == " Inf" @test Printf.@sprintf("%07e", Inf) == " Inf" @test Printf.@sprintf("%e", -Inf) == "-Inf" @test Printf.@sprintf("%+e", -Inf) == "-Inf" @test Printf.@sprintf("%07e", -Inf) == " -Inf" @test Printf.@sprintf("%e", NaN) == "NaN" @test Printf.@sprintf("%+e", NaN) == "+NaN" @test Printf.@sprintf("% e", NaN) == " NaN" @test Printf.@sprintf("% #e", NaN) == " NaN" @test Printf.@sprintf("%07e", NaN) == " NaN" @test Printf.@sprintf("%e", Inf) == "Inf" @test Printf.@sprintf("%e", NaN) == "NaN" @test Printf.@sprintf("%.0e", 3.0e142) == "3e+142" @test Printf.@sprintf("%#.0e", 3.0e142) == "3.e+142" @test Printf.@sprintf("%.0e", 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) == "3e+142" @test Printf.@sprintf("%#.0e", 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) == "3.e+142" @test Printf.@sprintf("%.0e", 3.000000000000000000000000000000000000000000000000000000000000000000000000000024e1042) == "3e+1042" @test Printf.@sprintf("%e", 3.0e42) == "3.000000e+42" @test Printf.@sprintf("%E", 3.0e42) == "3.000000E+42" @test Printf.@sprintf("%e", 3.0e-42) == "3.000000e-42" @test Printf.@sprintf("%E", 3.0e-42) == "3.000000E-42" @test Printf.@sprintf("%e", 1.234) == "1.234000e+00" @test Printf.@sprintf("%E", 1.234) == "1.234000E+00" @test Printf.@sprintf("%+e", 1.234) == "+1.234000e+00" @test Printf.@sprintf("% e", 1.234) == " 1.234000e+00" @test Printf.@sprintf("%e", -1.234) == "-1.234000e+00" @test Printf.@sprintf("%+e", -1.234) == "-1.234000e+00" @test Printf.@sprintf("% e", -1.234) == "-1.234000e+00" @test Printf.@sprintf("%#e", 1.234) == "1.234000e+00" @test Printf.@sprintf("%.2e", 1.234) == "1.23e+00" @test Printf.@sprintf("%.2e", 1.235) == "1.24e+00" @test Printf.@sprintf("%.2e", 0.235) == "2.35e-01" @test Printf.@sprintf("%4.1e", 1.234) == "1.2e+00" @test Printf.@sprintf("%8.1e", 1.234) == " 1.2e+00" @test Printf.@sprintf("%+8.1e", 1.234) == "+1.2e+00" @test Printf.@sprintf("% 8.1e", 1.234) == " 1.2e+00" @test Printf.@sprintf("% 7.1e", 1.234) == " 1.2e+00" @test Printf.@sprintf("% 08.1e", 1.234) == " 1.2e+00" @test Printf.@sprintf("%08.1e", 1.234) == "01.2e+00" @test Printf.@sprintf("%-08.1e", 1.234) == "1.2e+00 " @test Printf.@sprintf("%-8.1e", 1.234) == "1.2e+00 " @test Printf.@sprintf("%-8.1e", 1.234) == "1.2e+00 " @test Printf.@sprintf("%08.1e", -1.234) == "-1.2e+00" @test Printf.@sprintf("%09.1e", -1.234) == "-01.2e+00" @test Printf.@sprintf("%09.1e", 1.234) == "001.2e+00" @test Printf.@sprintf("%+09.1e", 1.234) == "+01.2e+00" @test Printf.@sprintf("% 09.1e", 1.234) == " 01.2e+00" @test Printf.@sprintf("%+ 09.1e", 1.234) == "+01.2e+00" @test Printf.@sprintf("%+ 09.1e", 1.234) == "+01.2e+00" @test Printf.@sprintf("%+ 09.0e", 1.234) == "+0001e+00" @test Printf.@sprintf("%+ #09.0e", 1.234) == "+001.e+00" @test Printf.@sprintf("%+9.1e", 9.96) == " +1.0e+01" @test Printf.@sprintf("% 9.1e", 9.96) == " 1.0e+01" end @testset "strings" begin @test Printf.@sprintf("Hallo heimur") == "Hallo heimur" @test Printf.@sprintf("+%s+", "hello") == "+hello+" @test Printf.@sprintf("%.1s", "foo") == "f" @test Printf.@sprintf("%s", "%%%%") == "%%%%" @test Printf.@sprintf("%s", "Hallo heimur") == "Hallo heimur" @test Printf.@sprintf("%+s", "Hallo heimur") == "Hallo heimur" @test Printf.@sprintf("% s", "Hallo heimur") == "Hallo heimur" @test Printf.@sprintf("%+ s", "Hallo heimur") == "Hallo heimur" @test Printf.@sprintf("%1s", "Hallo heimur") == "Hallo heimur" @test Printf.@sprintf("%20s", "Hallo") == " Hallo" @test Printf.@sprintf("%-20s", "Hallo") == "Hallo " @test Printf.@sprintf("%0-20s", "Hallo") == "Hallo " @test Printf.@sprintf("%.20s", "Hallo heimur") == "Hallo heimur" @test Printf.@sprintf("%20.5s", "Hallo heimur") == " Hallo" @test Printf.@sprintf("%.0s", "Hallo heimur") == "" @test Printf.@sprintf("%20.0s", "Hallo heimur") == " " @test Printf.@sprintf("%.s", "Hallo heimur") == "" @test Printf.@sprintf("%20.s", "Hallo heimur") == " " @test Printf.@sprintf("%s", "test") == "test" @test Printf.@sprintf("%s", "tést") == "tést" @test Printf.@sprintf("ø%sø", "hey") == "øheyø" @test Printf.@sprintf("%4sø", "ø") == " øø" @test Printf.@sprintf("%-4sø", "ø") == "ø ø" @test Printf.@sprintf("%8s", "test") == " test" @test Printf.@sprintf("%-8s", "test") == "test " @test Printf.@sprintf("%s", :test) == "test" @test Printf.@sprintf("%#s", :test) == ":test" @test Printf.@sprintf("%#8s", :test) == " :test" @test Printf.@sprintf("%#-8s", :test) == ":test " @test Printf.@sprintf("%8.3s", "test") == " tes" @test Printf.@sprintf("%#8.3s", "test") == " \"te" @test Printf.@sprintf("%-8.3s", "test") == "tes " @test Printf.@sprintf("%#-8.3s", "test") == "\"te " @test Printf.@sprintf("%.3s", "test") == "tes" @test Printf.@sprintf("%#.3s", "test") == "\"te" @test Printf.@sprintf("%-.3s", "test") == "tes" @test Printf.@sprintf("%#-.3s", "test") == "\"te" @test Printf.@sprintf("%.2s", "föó") == "fö" @test Printf.@sprintf("%5s", "föó") == " föó" @test Printf.@sprintf("%6s", "😍🍕") == " 😍🍕" @test Printf.@sprintf("%2c", '🍕') == "🍕" @test Printf.@sprintf("%3c", '🍕') == " 🍕" end @testset "chars" begin @test Printf.@sprintf("%c", 'a') == "a" @test Printf.@sprintf("%c", 32) == " " @test Printf.@sprintf("%c", 36) == "\$" @test Printf.@sprintf("%3c", 'a') == " a" @test Printf.@sprintf("%c", 'x') == "x" @test Printf.@sprintf("%+c", 'x') == "x" @test Printf.@sprintf("% c", 'x') == "x" @test Printf.@sprintf("%+ c", 'x') == "x" @test Printf.@sprintf("%1c", 'x') == "x" @test Printf.@sprintf("%20c", 'x') == " x" @test Printf.@sprintf("%-20c", 'x') == "x " @test Printf.@sprintf("%-020c", 'x') == "x " @test Printf.@sprintf("%c", 65) == "A" @test Printf.@sprintf("%c", 'A') == "A" @test Printf.@sprintf("%3c", 'A') == " A" @test Printf.@sprintf("%-3c", 'A') == "A " @test Printf.@sprintf("%c", 248) == "ø" @test Printf.@sprintf("%c", 'ø') == "ø" @test Printf.@sprintf("%c", "ø") == "ø" @test Printf.@sprintf("%c", '𐀀') == "𐀀" end function _test_flags(val, vflag::AbstractString, fmt::AbstractString, res::AbstractString, prefix::AbstractString) vflag = string("%", vflag) space_fmt = string(length(res) + length(prefix) + 3, fmt) fsign = string(if val < 0 "-" else "+" end, prefix) nsign = string(if val < 0 "-" else " " end, prefix) osign = if val < 0 string("-", prefix) else string(prefix, "0") end esign = string(if val < 0 "-" else "" end, prefix) esignend = if val < 0 "" else " " end for (flag::AbstractString, ans::AbstractString) = (("", string(" ", nsign, res)), ("+", string(" ", fsign, res)), (" ", string(" ", nsign, res)), ("0", string(osign, "00", res)), ("-", string(esign, res, " ", esignend)), ("0+", string(fsign, "00", res)), ("0 ", string(nsign, "00", res)), ("-+", string(fsign, res, " ")), ("- ", string(nsign, res, " "))) fmt_string = string(vflag, flag, space_fmt) fmtd = Printf.format(Printf.Format(fmt_string), val) @test fmtd == ans end end @testset "basics" begin @test Printf.@sprintf("%%") == "%" @test Printf.@sprintf("1%%") == "1%" @test Printf.@sprintf("%%1") == "%1" @test Printf.@sprintf("1%%2") == "1%2" @test Printf.@sprintf("1%%%d", 2) == "1%2" @test Printf.@sprintf("1%%2%%3") == "1%2%3" @test Printf.@sprintf("GAP[%%]") == "GAP[%]" @test Printf.@sprintf("hey there") == "hey there" @test_throws Printf.InvalidFormatStringError Printf.Format("%+") @test_throws Printf.InvalidFormatStringError Printf.Format("%.") @test_throws Printf.InvalidFormatStringError Printf.Format("%.0") @test isempty((Printf.Format("%%")).formats) @test Printf.@sprintf("%d%d", 1, 2) == "12" @test Printf.@sprintf("%d%d", [1 2]...) == "12" @test Printf.@sprintf("X%d", 2) == "X2" @test Printf.@sprintf("Ð%d", 2) == "Ð2" @test Printf.@sprintf("ༀ%d", 2) == "ༀ2" @test Printf.@sprintf("\U1ffff%d", 2) == "\U0001ffff2" @test Printf.@sprintf("%dX%d", 1, 2) == "1X2" @test Printf.@sprintf("%dÐ%d", 1, 2) == "1Ð2" @test Printf.@sprintf("%dༀ%d", 1, 2) == "1ༀ2" @test Printf.@sprintf("%d\U1ffff%d", 1, 2) == "1\U0001ffff2" @test Printf.@sprintf("%d∃%dȃ", 1, 2) == "1∃2ȃ" @test_throws Printf.InvalidFormatStringError Printf.Format("%y%d") @test_throws Printf.InvalidFormatStringError Printf.Format("%Ð%d") @test_throws Printf.InvalidFormatStringError Printf.Format("%ༀ%d") @test_throws Printf.InvalidFormatStringError Printf.Format("%\U1ffff%d") @test Printf.@sprintf("%10.5d", 4) == " 00004" @test Printf.@sprintf("%d", typemax(Int64)) == "9223372036854775807" for (fmt, val) = (("%7.2f", " 1.23"), ("%-7.2f", "1.23 "), ("%07.2f", "0001.23"), ("%.0f", "1"), ("%#.0f", "1."), ("%.4e", "1.2345e+00"), ("%.4E", "1.2345E+00"), ("%.2a", "0x1.3cp+0"), ("%.2A", "0X1.3CP+0")), num = (1.2345, 1.234499999999999999999999999999999999999999999999999999999999999999999999999991) @test Printf.format(Printf.Format(fmt), num) == val end for (fmt, val) = (("%i", "42"), ("%u", "42"), ("Test: %i", "Test: 42"), ("%#x", "0x2a"), ("%x", "2a"), ("%X", "2A"), ("% i", " 42"), ("%+i", "+42"), ("%4i", " 42"), ("%-4i", "42 "), ("%f", "42.000000"), ("%g", "42"), ("%e", "4.200000e+01")), num = (UInt16(42), UInt32(42), UInt64(42), UInt128(42), Int16(42), Int32(42), Int64(42), Int128(42), 42) @test Printf.format(Printf.Format(fmt), num) == val end for i = ((42, "", "i", "42", ""), (42, "", "d", "42", ""), (42, "", "u", "42", ""), (42, "", "x", "2a", ""), (42, "", "X", "2A", ""), (42, "", "o", "52", ""), (42, "#", "x", "2a", "0x"), (42, "#", "X", "2A", "0X"), (42, "#", "o", "052", ""), (1.2345, "", ".2f", "1.23", ""), (1.2345, "", ".2e", "1.23e+00", ""), (1.2345, "", ".2E", "1.23E+00", ""), (1.2345, "#", ".0f", "1.", ""), (1.2345, "#", ".0e", "1.e+00", ""), (1.2345, "#", ".0E", "1.E+00", ""), (1.2345, "", ".2a", "1.3cp+0", "0x"), (1.2345, "", ".2A", "1.3CP+0", "0X")) _test_flags(i...) _test_flags(-(i[1]), i[2:5]...) end @test Printf.@sprintf("Test: %s%c%C%c%#-.0f.", "t", 65, 66, 67, -42) == "Test: tABC-42.." @test Printf.@sprintf("%f %d %d %f", 1.0, [3 4]..., 5) == "1.000000 3 4 5.000000" @test Printf.@sprintf("%s %f %9.5f %d %d %d %d%d%d%d", [1:6;]..., [7, 8, 9, 10]...) == "1 2.000000 3.00000 4 5 6 78910" @test Printf.@sprintf("%s %s %s %d %d %d %f %f %f", Any[10 ^ x + y for x = 1:3, y = 1:3]...) == "11 101 1001 12 102 1002 13.000000 103.000000 1003.000000" @test Printf.@sprintf("%s %s %s %d %d %d %f %f %f %s %s %s %d %d %d %f %f %f", Any[10x + (x + 1) for x = 1:18]...) == "12 23 34 45 56 67 78.000000 89.000000 100.000000 111 122 133 144 155 166 177.000000 188.000000 199.000000" @test (Printf.@sprintf("%.330f", BigFloat(1)))[var"end"] != '\0' @test Printf.@sprintf("%f", parse(BigFloat, "1e400")) == "10000000000000000000000000000000000000000000000000000000000000000000000000000025262527574416492004687051900140830217136998040684679611623086405387447100385714565637522507383770691831689647535911648520404034824470543643098638520633064715221151920028135130764414460468236314621044034960475540018328999334468948008954289495190631358190153259681118693204411689043999084305348398480210026863210192871358464.000000" @test_throws ArgumentError Printf.@sprintf("%f", parse(BigFloat, "1e99999")) @test Printf.@sprintf("%4.2s", "a") == " a" @test Printf.@sprintf("%12.3e", pi * 1.0e100) == " 3.142e+100" @test string((Printf.Format("%a")).formats[1]) == "%a" @test string((Printf.Format("%a")).formats[1]; modifier = "R") == "%Ra" @test Printf.@sprintf("%d", 3.14) == "3" @test Printf.@sprintf("%2d", 3.14) == " 3" @test Printf.@sprintf("%2d", big(3.14)) == " 3" @test Printf.@sprintf("%s", 1) == "1" @test Printf.@sprintf("%f", 1) == "1.000000" @test Printf.@sprintf("%e", 1) == "1.000000e+00" @test Printf.@sprintf("%g", 1) == "1" @test Printf.@sprintf("%.16g", 194.4778127560983) == "194.4778127560983" @test Printf.@sprintf("%.17g", 194.4778127560983) == "194.4778127560983" @test Printf.@sprintf("%.18g", 194.4778127560983) == "194.477812756098302" @test Printf.@sprintf("%.1g", 1.7976931348623157e308) == "2e+308" @test Printf.@sprintf("%.2g", 1.7976931348623157e308) == "1.8e+308" @test Printf.@sprintf("%.3g", 1.7976931348623157e308) == "1.8e+308" @test_throws ArgumentError @sprintf("%s%%%s", "a") @test @sprintf("%s%%%s", "a", "b") == "a%b" @test @sprintf("%d", 25.5) == "26" @test @sprintf(" %.1e\n", 0.999) == " 1.0e+00\n" @test @sprintf(" %.1f", 9.999) == " 10.0" @test @sprintf("%d", 1.0e100) == "10000000000000000159028911097599180468360808563945281389781327557747838772170381060813469985856815104" @test @sprintf("%d", 3 // 1) == "3" @test @sprintf("%d", Inf) == "Inf" @test @sprintf(" %d", NaN) == " NaN" @test Printf.@sprintf("") == "" @test Printf.format(Printf.Format("")) == "" end @testset "integers" begin @test Printf.@sprintf("% d", 42) == " 42" @test Printf.@sprintf("% d", -42) == "-42" @test Printf.@sprintf("% 5d", 42) == " 42" @test Printf.@sprintf("% 5d", -42) == " -42" @test Printf.@sprintf("% 15d", 42) == " 42" @test Printf.@sprintf("% 15d", -42) == " -42" @test Printf.@sprintf("%+d", 42) == "+42" @test Printf.@sprintf("%+d", -42) == "-42" @test Printf.@sprintf("%+5d", 42) == " +42" @test Printf.@sprintf("%+5d", -42) == " -42" @test Printf.@sprintf("%+15d", 42) == " +42" @test Printf.@sprintf("%+15d", -42) == " -42" @test Printf.@sprintf("%0d", 42) == "42" @test Printf.@sprintf("%0d", -42) == "-42" @test Printf.@sprintf("%05d", 42) == "00042" @test Printf.@sprintf("%05d", -42) == "-0042" @test Printf.@sprintf("%015d", 42) == "000000000000042" @test Printf.@sprintf("%015d", -42) == "-00000000000042" @test Printf.@sprintf("%-d", 42) == "42" @test Printf.@sprintf("%-d", -42) == "-42" @test Printf.@sprintf("%-5d", 42) == "42 " @test Printf.@sprintf("%-5d", -42) == "-42 " @test Printf.@sprintf("%-15d", 42) == "42 " @test Printf.@sprintf("%-15d", -42) == "-42 " @test Printf.@sprintf("%-0d", 42) == "42" @test Printf.@sprintf("%-0d", -42) == "-42" @test Printf.@sprintf("%-05d", 42) == "42 " @test Printf.@sprintf("%-05d", -42) == "-42 " @test Printf.@sprintf("%-015d", 42) == "42 " @test Printf.@sprintf("%-015d", -42) == "-42 " @test Printf.@sprintf("%0-d", 42) == "42" @test Printf.@sprintf("%0-d", -42) == "-42" @test Printf.@sprintf("%0-5d", 42) == "42 " @test Printf.@sprintf("%0-5d", -42) == "-42 " @test Printf.@sprintf("%0-15d", 42) == "42 " @test Printf.@sprintf("%0-15d", -42) == "-42 " @test_throws Printf.InvalidFormatStringError Printf.Format("%d %") @test Printf.@sprintf("%lld", 18446744065119617025) == "18446744065119617025" @test Printf.@sprintf("%+8lld", 100) == " +100" @test Printf.@sprintf("%+.8lld", 100) == "+00000100" @test Printf.@sprintf("%+10.8lld", 100) == " +00000100" @test_throws Printf.InvalidFormatStringError Printf.Format("%_1lld") @test Printf.@sprintf("%-1.5lld", -100) == "-00100" @test Printf.@sprintf("%5lld", 100) == " 100" @test Printf.@sprintf("%5lld", -100) == " -100" @test Printf.@sprintf("%-5lld", 100) == "100 " @test Printf.@sprintf("%-5lld", -100) == "-100 " @test Printf.@sprintf("%-.5lld", 100) == "00100" @test Printf.@sprintf("%-.5lld", -100) == "-00100" @test Printf.@sprintf("%-8.5lld", 100) == "00100 " @test Printf.@sprintf("%-8.5lld", -100) == "-00100 " @test Printf.@sprintf("%05lld", 100) == "00100" @test Printf.@sprintf("%05lld", -100) == "-0100" @test Printf.@sprintf("% lld", 100) == " 100" @test Printf.@sprintf("% lld", -100) == "-100" @test Printf.@sprintf("% 5lld", 100) == " 100" @test Printf.@sprintf("% 5lld", -100) == " -100" @test Printf.@sprintf("% .5lld", 100) == " 00100" @test Printf.@sprintf("% .5lld", -100) == "-00100" @test Printf.@sprintf("% 8.5lld", 100) == " 00100" @test Printf.@sprintf("% 8.5lld", -100) == " -00100" @test Printf.@sprintf("%.0lld", 0) == "0" @test Printf.@sprintf("%#+21.18llx", -100) == "-0x000000000000000064" @test Printf.@sprintf("%#.25llo", -100) == "-00000000000000000000000144" @test Printf.@sprintf("%#+24.20llo", -100) == " -000000000000000000144" @test Printf.@sprintf("%#+18.21llX", -100) == "-0X000000000000000000064" @test Printf.@sprintf("%#+20.24llo", -100) == "-0000000000000000000000144" @test Printf.@sprintf("%#+25.22llu", -1) == " -0000000000000000000001" @test Printf.@sprintf("%#+25.22llu", -1) == " -0000000000000000000001" @test Printf.@sprintf("%#+30.25llu", -1) == " -0000000000000000000000001" @test Printf.@sprintf("%+#25.22lld", -1) == " -0000000000000000000001" @test Printf.@sprintf("%#-8.5llo", 100) == "000144 " @test Printf.@sprintf("%#-+ 08.5lld", 100) == "+00100 " @test Printf.@sprintf("%#-+ 08.5lld", 100) == "+00100 " @test Printf.@sprintf("%.40lld", 1) == "0000000000000000000000000000000000000001" @test Printf.@sprintf("% .40lld", 1) == " 0000000000000000000000000000000000000001" @test Printf.@sprintf("% .40d", 1) == " 0000000000000000000000000000000000000001" @test Printf.@sprintf("%lld", 18446744065119617025) == "18446744065119617025" @test Printf.@sprintf("+%d+", 10) == "+10+" @test Printf.@sprintf("%#012x", 1) == "0x0000000001" @test Printf.@sprintf("%#04.8x", 1) == "0x00000001" @test Printf.@sprintf("%#-08.2x", 1) == "0x01 " @test Printf.@sprintf("%#08o", 1) == "00000001" @test Printf.@sprintf("%d", 1024) == "1024" @test Printf.@sprintf("%d", -1024) == "-1024" @test Printf.@sprintf("%i", 1024) == "1024" @test Printf.@sprintf("%i", -1024) == "-1024" @test Printf.@sprintf("%u", 1024) == "1024" @test Printf.@sprintf("%u", UInt(4294966272)) == "4294966272" @test Printf.@sprintf("%o", 511) == "777" @test Printf.@sprintf("%o", UInt(4294966785)) == "37777777001" @test Printf.@sprintf("%x", 305441741) == "1234abcd" @test Printf.@sprintf("%x", UInt(3989525555)) == "edcb5433" @test Printf.@sprintf("%X", 305441741) == "1234ABCD" @test Printf.@sprintf("%X", UInt(3989525555)) == "EDCB5433" @test Printf.@sprintf("%+d", 1024) == "+1024" @test Printf.@sprintf("%+d", -1024) == "-1024" @test Printf.@sprintf("%+i", 1024) == "+1024" @test Printf.@sprintf("%+i", -1024) == "-1024" @test Printf.@sprintf("%+u", 1024) == "+1024" @test Printf.@sprintf("%+u", UInt(4294966272)) == "+4294966272" @test Printf.@sprintf("%+o", 511) == "+777" @test Printf.@sprintf("%+o", UInt(4294966785)) == "+37777777001" @test Printf.@sprintf("%+x", 305441741) == "+1234abcd" @test Printf.@sprintf("%+x", UInt(3989525555)) == "+edcb5433" @test Printf.@sprintf("%+X", 305441741) == "+1234ABCD" @test Printf.@sprintf("%+X", UInt(3989525555)) == "+EDCB5433" @test Printf.@sprintf("% d", 1024) == " 1024" @test Printf.@sprintf("% d", -1024) == "-1024" @test Printf.@sprintf("% i", 1024) == " 1024" @test Printf.@sprintf("% i", -1024) == "-1024" @test Printf.@sprintf("% u", 1024) == " 1024" @test Printf.@sprintf("% u", UInt(4294966272)) == " 4294966272" @test Printf.@sprintf("% o", 511) == " 777" @test Printf.@sprintf("% o", UInt(4294966785)) == " 37777777001" @test Printf.@sprintf("% x", 305441741) == " 1234abcd" @test Printf.@sprintf("% x", UInt(3989525555)) == " edcb5433" @test Printf.@sprintf("% X", 305441741) == " 1234ABCD" @test Printf.@sprintf("% X", UInt(3989525555)) == " EDCB5433" @test Printf.@sprintf("%+ d", 1024) == "+1024" @test Printf.@sprintf("%+ d", -1024) == "-1024" @test Printf.@sprintf("%+ i", 1024) == "+1024" @test Printf.@sprintf("%+ i", -1024) == "-1024" @test Printf.@sprintf("%+ u", 1024) == "+1024" @test Printf.@sprintf("%+ u", UInt(4294966272)) == "+4294966272" @test Printf.@sprintf("%+ o", 511) == "+777" @test Printf.@sprintf("%+ o", UInt(4294966785)) == "+37777777001" @test Printf.@sprintf("%+ x", 305441741) == "+1234abcd" @test Printf.@sprintf("%+ x", UInt(3989525555)) == "+edcb5433" @test Printf.@sprintf("%+ X", 305441741) == "+1234ABCD" @test Printf.@sprintf("%+ X", UInt(3989525555)) == "+EDCB5433" @test Printf.@sprintf("%#o", 511) == "0777" @test Printf.@sprintf("%#o", UInt(4294966785)) == "037777777001" @test Printf.@sprintf("%#x", 305441741) == "0x1234abcd" @test Printf.@sprintf("%#x", UInt(3989525555)) == "0xedcb5433" @test Printf.@sprintf("%#X", 305441741) == "0X1234ABCD" @test Printf.@sprintf("%#X", UInt(3989525555)) == "0XEDCB5433" @test Printf.@sprintf("%#o", UInt(0)) == "00" @test Printf.@sprintf("%#x", UInt(0)) == "0x0" @test Printf.@sprintf("%#X", UInt(0)) == "0X0" @test Printf.@sprintf("%1d", 1024) == "1024" @test Printf.@sprintf("%1d", -1024) == "-1024" @test Printf.@sprintf("%1i", 1024) == "1024" @test Printf.@sprintf("%1i", -1024) == "-1024" @test Printf.@sprintf("%1u", 1024) == "1024" @test Printf.@sprintf("%1u", UInt(4294966272)) == "4294966272" @test Printf.@sprintf("%1o", 511) == "777" @test Printf.@sprintf("%1o", UInt(4294966785)) == "37777777001" @test Printf.@sprintf("%1x", 305441741) == "1234abcd" @test Printf.@sprintf("%1x", UInt(3989525555)) == "edcb5433" @test Printf.@sprintf("%1X", 305441741) == "1234ABCD" @test Printf.@sprintf("%1X", UInt(3989525555)) == "EDCB5433" @test Printf.@sprintf("%20d", 1024) == " 1024" @test Printf.@sprintf("%20d", -1024) == " -1024" @test Printf.@sprintf("%20i", 1024) == " 1024" @test Printf.@sprintf("%20i", -1024) == " -1024" @test Printf.@sprintf("%20u", 1024) == " 1024" @test Printf.@sprintf("%20u", UInt(4294966272)) == " 4294966272" @test Printf.@sprintf("%20o", 511) == " 777" @test Printf.@sprintf("%20o", UInt(4294966785)) == " 37777777001" @test Printf.@sprintf("%20x", 305441741) == " 1234abcd" @test Printf.@sprintf("%20x", UInt(3989525555)) == " edcb5433" @test Printf.@sprintf("%20X", 305441741) == " 1234ABCD" @test Printf.@sprintf("%20X", UInt(3989525555)) == " EDCB5433" @test Printf.@sprintf("%-20d", 1024) == "1024 " @test Printf.@sprintf("%-20d", -1024) == "-1024 " @test Printf.@sprintf("%-20i", 1024) == "1024 " @test Printf.@sprintf("%-20i", -1024) == "-1024 " @test Printf.@sprintf("%-20u", 1024) == "1024 " @test Printf.@sprintf("%-20u", UInt(4294966272)) == "4294966272 " @test Printf.@sprintf("%-20o", 511) == "777 " @test Printf.@sprintf("%-20o", UInt(4294966785)) == "37777777001 " @test Printf.@sprintf("%-20x", 305441741) == "1234abcd " @test Printf.@sprintf("%-20x", UInt(3989525555)) == "edcb5433 " @test Printf.@sprintf("%-20X", 305441741) == "1234ABCD " @test Printf.@sprintf("%-20X", UInt(3989525555)) == "EDCB5433 " @test Printf.@sprintf("%020d", 1024) == "00000000000000001024" @test Printf.@sprintf("%020d", -1024) == "-0000000000000001024" @test Printf.@sprintf("%020i", 1024) == "00000000000000001024" @test Printf.@sprintf("%020i", -1024) == "-0000000000000001024" @test Printf.@sprintf("%020u", 1024) == "00000000000000001024" @test Printf.@sprintf("%020u", UInt(4294966272)) == "00000000004294966272" @test Printf.@sprintf("%020o", 511) == "00000000000000000777" @test Printf.@sprintf("%020o", UInt(4294966785)) == "00000000037777777001" @test Printf.@sprintf("%020x", 305441741) == "0000000000001234abcd" @test Printf.@sprintf("%020x", UInt(3989525555)) == "000000000000edcb5433" @test Printf.@sprintf("%020X", 305441741) == "0000000000001234ABCD" @test Printf.@sprintf("%020X", UInt(3989525555)) == "000000000000EDCB5433" @test Printf.@sprintf("%#20o", 511) == " 0777" @test Printf.@sprintf("%#20o", UInt(4294966785)) == " 037777777001" @test Printf.@sprintf("%#20x", 305441741) == " 0x1234abcd" @test Printf.@sprintf("%#20x", UInt(3989525555)) == " 0xedcb5433" @test Printf.@sprintf("%#20X", 305441741) == " 0X1234ABCD" @test Printf.@sprintf("%#20X", UInt(3989525555)) == " 0XEDCB5433" @test Printf.@sprintf("%#020o", 511) == "00000000000000000777" @test Printf.@sprintf("%#020o", UInt(4294966785)) == "00000000037777777001" @test Printf.@sprintf("%#020x", 305441741) == "0x00000000001234abcd" @test Printf.@sprintf("%#020x", UInt(3989525555)) == "0x0000000000edcb5433" @test Printf.@sprintf("%#020X", 305441741) == "0X00000000001234ABCD" @test Printf.@sprintf("%#020X", UInt(3989525555)) == "0X0000000000EDCB5433" @test Printf.@sprintf("%0-20d", 1024) == "1024 " @test Printf.@sprintf("%0-20d", -1024) == "-1024 " @test Printf.@sprintf("%0-20i", 1024) == "1024 " @test Printf.@sprintf("%0-20i", -1024) == "-1024 " @test Printf.@sprintf("%0-20u", 1024) == "1024 " @test Printf.@sprintf("%0-20u", UInt(4294966272)) == "4294966272 " @test Printf.@sprintf("%-020o", 511) == "777 " @test Printf.@sprintf("%-020o", UInt(4294966785)) == "37777777001 " @test Printf.@sprintf("%-020x", 305441741) == "1234abcd " @test Printf.@sprintf("%-020x", UInt(3989525555)) == "edcb5433 " @test Printf.@sprintf("%-020X", 305441741) == "1234ABCD " @test Printf.@sprintf("%-020X", UInt(3989525555)) == "EDCB5433 " @test Printf.@sprintf("%.20d", 1024) == "00000000000000001024" @test Printf.@sprintf("%.20d", -1024) == "-00000000000000001024" @test Printf.@sprintf("%.20i", 1024) == "00000000000000001024" @test Printf.@sprintf("%.20i", -1024) == "-00000000000000001024" @test Printf.@sprintf("%.20u", 1024) == "00000000000000001024" @test Printf.@sprintf("%.20u", UInt(4294966272)) == "00000000004294966272" @test Printf.@sprintf("%.20o", 511) == "00000000000000000777" @test Printf.@sprintf("%.20o", UInt(4294966785)) == "00000000037777777001" @test Printf.@sprintf("%.20x", 305441741) == "0000000000001234abcd" @test Printf.@sprintf("%.20x", UInt(3989525555)) == "000000000000edcb5433" @test Printf.@sprintf("%.20X", 305441741) == "0000000000001234ABCD" @test Printf.@sprintf("%.20X", UInt(3989525555)) == "000000000000EDCB5433" @test Printf.@sprintf("%20.5d", 1024) == " 01024" @test Printf.@sprintf("%20.5d", -1024) == " -01024" @test Printf.@sprintf("%20.5i", 1024) == " 01024" @test Printf.@sprintf("%20.5i", -1024) == " -01024" @test Printf.@sprintf("%20.5u", 1024) == " 01024" @test Printf.@sprintf("%20.5u", UInt(4294966272)) == " 4294966272" @test Printf.@sprintf("%20.5o", 511) == " 00777" @test Printf.@sprintf("%20.5o", UInt(4294966785)) == " 37777777001" @test Printf.@sprintf("%20.5x", 305441741) == " 1234abcd" @test Printf.@sprintf("%20.10x", UInt(3989525555)) == " 00edcb5433" @test Printf.@sprintf("%20.5X", 305441741) == " 1234ABCD" @test Printf.@sprintf("%20.10X", UInt(3989525555)) == " 00EDCB5433" @test Printf.@sprintf("%020.5d", 1024) == " 01024" @test Printf.@sprintf("%020.5d", -1024) == " -01024" @test Printf.@sprintf("%020.5i", 1024) == " 01024" @test Printf.@sprintf("%020.5i", -1024) == " -01024" @test Printf.@sprintf("%020.5u", 1024) == " 01024" @test Printf.@sprintf("%020.5u", UInt(4294966272)) == " 4294966272" @test Printf.@sprintf("%020.5o", 511) == " 00777" @test Printf.@sprintf("%020.5o", UInt(4294966785)) == " 37777777001" @test Printf.@sprintf("%020.5x", 305441741) == " 1234abcd" @test Printf.@sprintf("%020.10x", UInt(3989525555)) == " 00edcb5433" @test Printf.@sprintf("%020.5X", 305441741) == " 1234ABCD" @test Printf.@sprintf("%020.10X", UInt(3989525555)) == " 00EDCB5433" @test Printf.@sprintf("%20.0d", 1024) == " 1024" @test Printf.@sprintf("%20.d", -1024) == " -1024" @test Printf.@sprintf("%20.d", 0) == " 0" @test Printf.@sprintf("%20.0i", 1024) == " 1024" @test Printf.@sprintf("%20.i", -1024) == " -1024" @test Printf.@sprintf("%20.i", 0) == " 0" @test Printf.@sprintf("%20.u", 1024) == " 1024" @test Printf.@sprintf("%20.0u", UInt(4294966272)) == " 4294966272" @test Printf.@sprintf("%20.u", UInt(0)) == " 0" @test Printf.@sprintf("%20.o", 511) == " 777" @test Printf.@sprintf("%20.0o", UInt(4294966785)) == " 37777777001" @test Printf.@sprintf("%20.o", UInt(0)) == " 0" @test Printf.@sprintf("%20.x", 305441741) == " 1234abcd" @test Printf.@sprintf("%20.0x", UInt(3989525555)) == " edcb5433" @test Printf.@sprintf("%20.x", UInt(0)) == " 0" @test Printf.@sprintf("%20.X", 305441741) == " 1234ABCD" @test Printf.@sprintf("%20.0X", UInt(3989525555)) == " EDCB5433" @test Printf.@sprintf("%20.X", UInt(0)) == " 0" @test Printf.@sprintf("%4d", typemin(Int8)) == "-128" @test Printf.@sprintf("%4d", typemax(Int8)) == " 127" @test Printf.@sprintf("%6d", typemin(Int16)) == "-32768" @test Printf.@sprintf("%6d", typemax(Int16)) == " 32767" @test Printf.@sprintf("%11d", typemin(Int32)) == "-2147483648" @test Printf.@sprintf("%11d", typemax(Int32)) == " 2147483647" @test Printf.@sprintf("%20d", typemin(Int64)) == "-9223372036854775808" @test Printf.@sprintf("%20d", typemax(Int64)) == " 9223372036854775807" @test Printf.@sprintf("%40d", typemin(Int128)) == "-170141183460469231731687303715884105728" @test Printf.@sprintf("%40d", typemax(Int128)) == " 170141183460469231731687303715884105727" end @testset "%n" begin x = Ref{Int}() @test begin Printf.@sprintf "%d4%n" 123 x x[] == 4 end @test begin Printf.@sprintf "%s%n" "😉" x x[] == 4 end @test begin Printf.@sprintf "%s%n" "1234" x x[] == 4 end end @testset "dynamic" begin @test Printf.@sprintf("%*d", 10, 12) == " 12" @test Printf.@sprintf("%.*d", 4, 12) == "0012" @test Printf.@sprintf("%*.*d", 10, 4, 12) == " 0012" @test Printf.@sprintf("%+*.*d", 10, 4, 12) == " +0012" @test Printf.@sprintf("%0*.*d", 10, 4, 12) == " 0012" @test Printf.@sprintf("%*d%*d%*d", 4, 12, 4, 13, 4, 14) == " 12 13 14" @test Printf.@sprintf("%*d%*d%*d", 4, 12, 5, 13, 6, 14) == " 12 13 14" @test Printf.@sprintf("%*p", 20, 0) == Printf.@sprintf("%20p", 0) @test Printf.@sprintf("%-*p", 20, 0) == Printf.@sprintf("%-20p", 0) @test Printf.@sprintf("%*p", 20, C_NULL) == Printf.@sprintf("%20p", C_NULL) @test Printf.@sprintf("%-*p", 20, C_NULL) == Printf.@sprintf("%-20p", C_NULL) @test Printf.@sprintf("%.*a", 0, 3.14) == Printf.@sprintf("%.0a", 3.14) @test Printf.@sprintf("%.*a", 1, 3.14) == Printf.@sprintf("%.1a", 3.14) @test Printf.@sprintf("%.*a", 2, 3.14) == Printf.@sprintf("%.2a", 3.14) @test Printf.@sprintf("%#.*a", 0, 3.14) == Printf.@sprintf("%#.0a", 3.14) @test Printf.@sprintf("%#.*a", 1, 3.14) == Printf.@sprintf("%#.1a", 3.14) @test Printf.@sprintf("%#.*a", 2, 3.14) == Printf.@sprintf("%#.2a", 3.14) @test Printf.@sprintf("%.*a", 6, 1.5) == Printf.@sprintf("%.6a", 1.5) @test Printf.@sprintf("%*.*g", 10, 5, -123.4) == Printf.@sprintf("%10.5g", -123.4) @test Printf.@sprintf("%0*.*g", 10, 5, -123.4) == Printf.@sprintf("%010.5g", -123.4) @test Printf.@sprintf("%.*g", 6, 1.234e7) == Printf.@sprintf("%.6g", 1.234e7) @test Printf.@sprintf("%#.*g", 6, 1.234e7) == Printf.@sprintf("%#.6g", 1.234e7) @test Printf.@sprintf("%*.*g", 10, 5, -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) == Printf.@sprintf("%10.5g", -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) @test Printf.@sprintf("%0*.*g", 10, 5, -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) == Printf.@sprintf("%010.5g", -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) @test Printf.@sprintf("%.*g", 6, 1.234e7) == Printf.@sprintf("%.6g", 1.234e7) @test Printf.@sprintf("%#.*g", 6, 1.234e7) == Printf.@sprintf("%#.6g", 1.234e7) @test Printf.@sprintf("%.*g", 5, 42) == Printf.@sprintf("%.5g", 42) @test Printf.@sprintf("%#.*g", 2, 42) == Printf.@sprintf("%#.2g", 42) @test Printf.@sprintf("%#.*g", 5, 42) == Printf.@sprintf("%#.5g", 42) @test Printf.@sprintf("%.*g", 15, 0) == Printf.@sprintf("%.15g", 0) @test Printf.@sprintf("%#.*g", 15, 0) == Printf.@sprintf("%#.15g", 0) @test Printf.@sprintf("%.*f", 0, 3.0e142) == Printf.@sprintf("%.0f", 3.0e142) @test Printf.@sprintf("%.*f", 2, 1.234) == Printf.@sprintf("%.2f", 1.234) @test Printf.@sprintf("%.*f", 2, 1.235) == Printf.@sprintf("%.2f", 1.235) @test Printf.@sprintf("%.*f", 2, 0.235) == Printf.@sprintf("%.2f", 0.235) @test Printf.@sprintf("%*.*f", 4, 1, 1.234) == Printf.@sprintf("%4.1f", 1.234) @test Printf.@sprintf("%*.*f", 8, 1, 1.234) == Printf.@sprintf("%8.1f", 1.234) @test Printf.@sprintf("%+*.*f", 8, 1, 1.234) == Printf.@sprintf("%+8.1f", 1.234) @test Printf.@sprintf("% *.*f", 8, 1, 1.234) == Printf.@sprintf("% 8.1f", 1.234) @test Printf.@sprintf("% *.*f", 7, 1, 1.234) == Printf.@sprintf("% 7.1f", 1.234) @test Printf.@sprintf("% 0*.*f", 8, 1, 1.234) == Printf.@sprintf("% 08.1f", 1.234) @test Printf.@sprintf("%0*.*f", 8, 1, 1.234) == Printf.@sprintf("%08.1f", 1.234) @test Printf.@sprintf("%-0*.*f", 8, 1, 1.234) == Printf.@sprintf("%-08.1f", 1.234) @test Printf.@sprintf("%-*.*f", 8, 1, 1.234) == Printf.@sprintf("%-8.1f", 1.234) @test Printf.@sprintf("%0*.*f", 8, 1, -1.234) == Printf.@sprintf("%08.1f", -1.234) @test Printf.@sprintf("%0*.*f", 9, 1, -1.234) == Printf.@sprintf("%09.1f", -1.234) @test Printf.@sprintf("%0*.*f", 9, 1, 1.234) == Printf.@sprintf("%09.1f", 1.234) @test Printf.@sprintf("%+0*.*f", 9, 1, 1.234) == Printf.@sprintf("%+09.1f", 1.234) @test Printf.@sprintf("% 0*.*f", 9, 1, 1.234) == Printf.@sprintf("% 09.1f", 1.234) @test Printf.@sprintf("%+ 0*.*f", 9, 1, 1.234) == Printf.@sprintf("%+ 09.1f", 1.234) @test Printf.@sprintf("%+ 0*.*f", 9, 1, 1.234) == Printf.@sprintf("%+ 09.1f", 1.234) @test Printf.@sprintf("%+ 0*.*f", 9, 0, 1.234) == Printf.@sprintf("%+ 09.0f", 1.234) @test Printf.@sprintf("%+ #0*.*f", 9, 0, 1.234) == Printf.@sprintf("%+ #09.0f", 1.234) @test Printf.@sprintf("%*.*e", 10, 4, Inf) == Printf.@sprintf("%10.4e", Inf) @test Printf.@sprintf("%*.*e", 10, 4, NaN) == Printf.@sprintf("%10.4e", NaN) @test Printf.@sprintf("%*.*e", 10, 4, Inf) == Printf.@sprintf("%10.4e", Inf) @test Printf.@sprintf("%*.*e", 10, 4, NaN) == Printf.@sprintf("%10.4e", NaN) @test Printf.@sprintf("%.*e", 0, 3.0e142) == Printf.@sprintf("%.0e", 3.0e142) @test Printf.@sprintf("%#.*e", 0, 3.0e142) == Printf.@sprintf("%#.0e", 3.0e142) @test Printf.@sprintf("%.*e", 0, 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) == Printf.@sprintf("%.0e", 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) @test Printf.@sprintf("%#.*e", 0, 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) == Printf.@sprintf("%#.0e", 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) @test Printf.@sprintf("%.*e", 0, 3.000000000000000000000000000000000000000000000000000000000000000000000000000024e1042) == Printf.@sprintf("%.0e", 3.000000000000000000000000000000000000000000000000000000000000000000000000000024e1042) @test Printf.@sprintf("%.*e", 2, 1.234) == Printf.@sprintf("%.2e", 1.234) @test Printf.@sprintf("%.*e", 2, 1.235) == Printf.@sprintf("%.2e", 1.235) @test Printf.@sprintf("%.*e", 2, 0.235) == Printf.@sprintf("%.2e", 0.235) @test Printf.@sprintf("%*.*e", 4, 1, 1.234) == Printf.@sprintf("%4.1e", 1.234) @test Printf.@sprintf("%*.*e", 8, 1, 1.234) == Printf.@sprintf("%8.1e", 1.234) @test Printf.@sprintf("%+*.*e", 8, 1, 1.234) == Printf.@sprintf("%+8.1e", 1.234) @test Printf.@sprintf("% *.*e", 8, 1, 1.234) == Printf.@sprintf("% 8.1e", 1.234) @test Printf.@sprintf("% *.*e", 7, 1, 1.234) == Printf.@sprintf("% 7.1e", 1.234) @test Printf.@sprintf("% 0*.*e", 8, 1, 1.234) == Printf.@sprintf("% 08.1e", 1.234) @test Printf.@sprintf("%0*.*e", 8, 1, 1.234) == Printf.@sprintf("%08.1e", 1.234) @test Printf.@sprintf("%-0*.*e", 8, 1, 1.234) == Printf.@sprintf("%-08.1e", 1.234) @test Printf.@sprintf("%-*.*e", 8, 1, 1.234) == Printf.@sprintf("%-8.1e", 1.234) @test Printf.@sprintf("%-*.*e", 8, 1, 1.234) == Printf.@sprintf("%-8.1e", 1.234) @test Printf.@sprintf("%0*.*e", 8, 1, -1.234) == Printf.@sprintf("%08.1e", -1.234) @test Printf.@sprintf("%0*.*e", 9, 1, -1.234) == Printf.@sprintf("%09.1e", -1.234) @test Printf.@sprintf("%0*.*e", 9, 1, 1.234) == Printf.@sprintf("%09.1e", 1.234) @test Printf.@sprintf("%+0*.*e", 9, 1, 1.234) == Printf.@sprintf("%+09.1e", 1.234) @test Printf.@sprintf("% 0*.*e", 9, 1, 1.234) == Printf.@sprintf("% 09.1e", 1.234) @test Printf.@sprintf("%+ 0*.*e", 9, 1, 1.234) == Printf.@sprintf("%+ 09.1e", 1.234) @test Printf.@sprintf("%+ 0*.*e", 9, 1, 1.234) == Printf.@sprintf("%+ 09.1e", 1.234) @test Printf.@sprintf("%+ 0*.*e", 9, 0, 1.234) == Printf.@sprintf("%+ 09.0e", 1.234) @test Printf.@sprintf("%+ #0*.*e", 9, 0, 1.234) == Printf.@sprintf("%+ #09.0e", 1.234) @test Printf.@sprintf("%.*s", 1, "foo") == Printf.@sprintf("%.1s", "foo") @test Printf.@sprintf("%*s", 1, "Hallo heimur") == Printf.@sprintf("%1s", "Hallo heimur") @test Printf.@sprintf("%*s", 20, "Hallo") == Printf.@sprintf("%20s", "Hallo") @test Printf.@sprintf("%-*s", 20, "Hallo") == Printf.@sprintf("%-20s", "Hallo") @test Printf.@sprintf("%0-*s", 20, "Hallo") == Printf.@sprintf("%0-20s", "Hallo") @test Printf.@sprintf("%.*s", 20, "Hallo heimur") == Printf.@sprintf("%.20s", "Hallo heimur") @test Printf.@sprintf("%*.*s", 20, 5, "Hallo heimur") == Printf.@sprintf("%20.5s", "Hallo heimur") @test Printf.@sprintf("%.*s", 0, "Hallo heimur") == Printf.@sprintf("%.0s", "Hallo heimur") @test Printf.@sprintf("%*.*s", 20, 0, "Hallo heimur") == Printf.@sprintf("%20.0s", "Hallo heimur") @test Printf.@sprintf("%.s", "Hallo heimur") == Printf.@sprintf("%.s", "Hallo heimur") @test Printf.@sprintf("%*.s", 20, "Hallo heimur") == Printf.@sprintf("%20.s", "Hallo heimur") @test Printf.@sprintf("%*sø", 4, "ø") == Printf.@sprintf("%4sø", "ø") @test Printf.@sprintf("%-*sø", 4, "ø") == Printf.@sprintf("%-4sø", "ø") @test Printf.@sprintf("%*s", 8, "test") == Printf.@sprintf("%8s", "test") @test Printf.@sprintf("%-*s", 8, "test") == Printf.@sprintf("%-8s", "test") @test Printf.@sprintf("%#*s", 8, :test) == Printf.@sprintf("%#8s", :test) @test Printf.@sprintf("%#-*s", 8, :test) == Printf.@sprintf("%#-8s", :test) @test Printf.@sprintf("%*.*s", 8, 3, "test") == Printf.@sprintf("%8.3s", "test") @test Printf.@sprintf("%#*.*s", 8, 3, "test") == Printf.@sprintf("%#8.3s", "test") @test Printf.@sprintf("%-*.*s", 8, 3, "test") == Printf.@sprintf("%-8.3s", "test") @test Printf.@sprintf("%#-*.*s", 8, 3, "test") == Printf.@sprintf("%#-8.3s", "test") @test Printf.@sprintf("%.*s", 3, "test") == Printf.@sprintf("%.3s", "test") @test Printf.@sprintf("%#.*s", 3, "test") == Printf.@sprintf("%#.3s", "test") @test Printf.@sprintf("%-.*s", 3, "test") == Printf.@sprintf("%-.3s", "test") @test Printf.@sprintf("%#-.*s", 3, "test") == Printf.@sprintf("%#-.3s", "test") @test Printf.@sprintf("%*c", 3, 'a') == Printf.@sprintf("%3c", 'a') @test Printf.@sprintf("%*c", 1, 'x') == Printf.@sprintf("%1c", 'x') @test Printf.@sprintf("%*c", 20, 'x') == Printf.@sprintf("%20c", 'x') @test Printf.@sprintf("%-*c", 20, 'x') == Printf.@sprintf("%-20c", 'x') @test Printf.@sprintf("%-0*c", 20, 'x') == Printf.@sprintf("%-020c", 'x') @test Printf.@sprintf("%*c", 3, 'A') == Printf.@sprintf("%3c", 'A') @test Printf.@sprintf("%-*c", 3, 'A') == Printf.@sprintf("%-3c", 'A') @test Printf.@sprintf("%*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f", 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345) == Printf.@sprintf("%4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f", 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345) @test (Printf.@sprintf("%.*f", 330, BigFloat(1)))[var"end"] != '\0' @test Printf.@sprintf("%*.*s", 4, 2, "a") == Printf.@sprintf("%4.2s", "a") @test Printf.@sprintf("%*.*e", 12, 3, pi * 1.0e100) == Printf.@sprintf("%12.3e", pi * 1.0e100) @test Printf.@sprintf("%*d", 2, 3.14) == Printf.@sprintf("%*d", 2, 3.14) @test Printf.@sprintf("%*d", 2, big(3.14)) == Printf.@sprintf("%*d", 2, big(3.14)) @test Printf.@sprintf(" %.*e\n", 1, 0.999) == Printf.@sprintf(" %.1e\n", 0.999) @test Printf.@sprintf(" %.*f", 1, 9.999) == Printf.@sprintf(" %.1f", 9.999) @test Printf.@sprintf("%*d", 10, 12) == Printf.@sprintf("%10d", 12) @test Printf.@sprintf("%.*d", 4, 12) == Printf.@sprintf("%.4d", 12) @test Printf.@sprintf("%*.*d", 10, 4, 12) == Printf.@sprintf("%10.4d", 12) @test Printf.@sprintf("%+*.*d", 10, 4, 12) == Printf.@sprintf("%+10.4d", 12) @test Printf.@sprintf("%0*.*d", 10, 4, 12) == Printf.@sprintf("%010.4d", 12) @test Printf.@sprintf("% *d", 5, 42) == Printf.@sprintf("% 5d", 42) @test Printf.@sprintf("% *d", 5, -42) == Printf.@sprintf("% 5d", -42) @test Printf.@sprintf("% *d", 15, 42) == Printf.@sprintf("% 15d", 42) @test Printf.@sprintf("% *d", 15, -42) == Printf.@sprintf("% 15d", -42) @test Printf.@sprintf("%+*d", 5, 42) == Printf.@sprintf("%+5d", 42) @test Printf.@sprintf("%+*d", 5, -42) == Printf.@sprintf("%+5d", -42) @test Printf.@sprintf("%+*d", 15, 42) == Printf.@sprintf("%+15d", 42) @test Printf.@sprintf("%+*d", 15, -42) == Printf.@sprintf("%+15d", -42) @test Printf.@sprintf("%*d", 0, 42) == Printf.@sprintf("%0d", 42) @test Printf.@sprintf("%*d", 0, -42) == Printf.@sprintf("%0d", -42) @test Printf.@sprintf("%-*d", 5, 42) == Printf.@sprintf("%-5d", 42) @test Printf.@sprintf("%-*d", 5, -42) == Printf.@sprintf("%-5d", -42) @test Printf.@sprintf("%-*d", 15, 42) == Printf.@sprintf("%-15d", 42) @test Printf.@sprintf("%-*d", 15, -42) == Printf.@sprintf("%-15d", -42) @test Printf.@sprintf("%+*lld", 8, 100) == Printf.@sprintf("%+8lld", 100) @test Printf.@sprintf("%+.*lld", 8, 100) == Printf.@sprintf("%+.8lld", 100) @test Printf.@sprintf("%+*.*lld", 10, 8, 100) == Printf.@sprintf("%+10.8lld", 100) @test Printf.@sprintf("%-*.*lld", 1, 5, -100) == Printf.@sprintf("%-1.5lld", -100) @test Printf.@sprintf("%*lld", 5, 100) == Printf.@sprintf("%5lld", 100) @test Printf.@sprintf("%*lld", 5, -100) == Printf.@sprintf("%5lld", -100) @test Printf.@sprintf("%-*lld", 5, 100) == Printf.@sprintf("%-5lld", 100) @test Printf.@sprintf("%-*lld", 5, -100) == Printf.@sprintf("%-5lld", -100) @test Printf.@sprintf("%-.*lld", 5, 100) == Printf.@sprintf("%-.5lld", 100) @test Printf.@sprintf("%-.*lld", 5, -100) == Printf.@sprintf("%-.5lld", -100) @test Printf.@sprintf("%-*.*lld", 8, 5, 100) == Printf.@sprintf("%-8.5lld", 100) @test Printf.@sprintf("%-*.*lld", 8, 5, -100) == Printf.@sprintf("%-8.5lld", -100) @test Printf.@sprintf("%0*lld", 5, 100) == Printf.@sprintf("%05lld", 100) @test Printf.@sprintf("%0*lld", 5, -100) == Printf.@sprintf("%05lld", -100) @test Printf.@sprintf("% *lld", 5, 100) == Printf.@sprintf("% 5lld", 100) @test Printf.@sprintf("% *lld", 5, -100) == Printf.@sprintf("% 5lld", -100) @test Printf.@sprintf("% .*lld", 5, 100) == Printf.@sprintf("% .5lld", 100) @test Printf.@sprintf("% .*lld", 5, -100) == Printf.@sprintf("% .5lld", -100) @test Printf.@sprintf("% *.*lld", 8, 5, 100) == Printf.@sprintf("% 8.5lld", 100) @test Printf.@sprintf("% *.*lld", 8, 5, -100) == Printf.@sprintf("% 8.5lld", -100) @test Printf.@sprintf("%.*lld", 0, 0) == Printf.@sprintf("%.0lld", 0) @test Printf.@sprintf("%#+*.*llx", 21, 18, -100) == Printf.@sprintf("%#+21.18llx", -100) @test Printf.@sprintf("%#.*llo", 25, -100) == Printf.@sprintf("%#.25llo", -100) @test Printf.@sprintf("%#+*.*llo", 24, 20, -100) == Printf.@sprintf("%#+24.20llo", -100) @test Printf.@sprintf("%#+*.*llX", 18, 21, -100) == Printf.@sprintf("%#+18.21llX", -100) @test Printf.@sprintf("%#+*.*llo", 20, 24, -100) == Printf.@sprintf("%#+20.24llo", -100) @test Printf.@sprintf("%#+*.*llu", 25, 22, -1) == Printf.@sprintf("%#+25.22llu", -1) @test Printf.@sprintf("%#+*.*llu", 30, 25, -1) == Printf.@sprintf("%#+30.25llu", -1) @test Printf.@sprintf("%+#*.*lld", 25, 22, -1) == Printf.@sprintf("%+#25.22lld", -1) @test Printf.@sprintf("%#-*.*llo", 8, 5, 100) == Printf.@sprintf("%#-8.5llo", 100) @test Printf.@sprintf("%#-+ 0*.*lld", 8, 5, 100) == Printf.@sprintf("%#-+ 08.5lld", 100) @test Printf.@sprintf("%#-+ 0*.*lld", 8, 5, 100) == Printf.@sprintf("%#-+ 08.5lld", 100) @test Printf.@sprintf("%.*lld", 40, 1) == Printf.@sprintf("%.40lld", 1) @test Printf.@sprintf("% .*lld", 40, 1) == Printf.@sprintf("% .40lld", 1) @test Printf.@sprintf("% .*d", 40, 1) == Printf.@sprintf("% .40d", 1) @test Printf.@sprintf("%#0*x", 12, 1) == Printf.@sprintf("%#012x", 1) @test Printf.@sprintf("%#0*.*x", 4, 8, 1) == Printf.@sprintf("%#04.8x", 1) @test Printf.@sprintf("%#-0*.*x", 8, 2, 1) == Printf.@sprintf("%#-08.2x", 1) @test Printf.@sprintf("%#0*o", 8, 1) == Printf.@sprintf("%#08o", 1) @test Printf.@sprintf("%*d", 20, 1024) == Printf.@sprintf("%20d", 1024) @test Printf.@sprintf("%*d", 20, -1024) == Printf.@sprintf("%20d", -1024) @test Printf.@sprintf("%*i", 20, 1024) == Printf.@sprintf("%20i", 1024) @test Printf.@sprintf("%*i", 20, -1024) == Printf.@sprintf("%20i", -1024) @test Printf.@sprintf("%*u", 20, 1024) == Printf.@sprintf("%20u", 1024) @test Printf.@sprintf("%*u", 20, UInt(4294966272)) == Printf.@sprintf("%20u", UInt(4294966272)) @test Printf.@sprintf("%*o", 20, 511) == Printf.@sprintf("%20o", 511) @test Printf.@sprintf("%*o", 20, UInt(4294966785)) == Printf.@sprintf("%20o", UInt(4294966785)) @test Printf.@sprintf("%*x", 20, 305441741) == Printf.@sprintf("%20x", 305441741) @test Printf.@sprintf("%*x", 20, UInt(3989525555)) == Printf.@sprintf("%20x", UInt(3989525555)) @test Printf.@sprintf("%*X", 20, 305441741) == Printf.@sprintf("%20X", 305441741) @test Printf.@sprintf("%*X", 20, UInt(3989525555)) == Printf.@sprintf("%20X", UInt(3989525555)) @test Printf.@sprintf("%-*d", 20, 1024) == Printf.@sprintf("%-20d", 1024) @test Printf.@sprintf("%-*d", 20, -1024) == Printf.@sprintf("%-20d", -1024) @test Printf.@sprintf("%-*i", 20, 1024) == Printf.@sprintf("%-20i", 1024) @test Printf.@sprintf("%-*i", 20, -1024) == Printf.@sprintf("%-20i", -1024) @test Printf.@sprintf("%-*u", 20, 1024) == Printf.@sprintf("%-20u", 1024) @test Printf.@sprintf("%-*u", 20, UInt(4294966272)) == Printf.@sprintf("%-20u", UInt(4294966272)) @test Printf.@sprintf("%-*o", 20, 511) == Printf.@sprintf("%-20o", 511) @test Printf.@sprintf("%-*o", 20, UInt(4294966785)) == Printf.@sprintf("%-20o", UInt(4294966785)) @test Printf.@sprintf("%-*x", 20, 305441741) == Printf.@sprintf("%-20x", 305441741) @test Printf.@sprintf("%-*x", 20, UInt(3989525555)) == Printf.@sprintf("%-20x", UInt(3989525555)) @test Printf.@sprintf("%-*X", 20, 305441741) == Printf.@sprintf("%-20X", 305441741) @test Printf.@sprintf("%-*X", 20, UInt(3989525555)) == Printf.@sprintf("%-20X", UInt(3989525555)) @test Printf.@sprintf("%0*d", 20, 1024) == Printf.@sprintf("%020d", 1024) @test Printf.@sprintf("%0*d", 20, -1024) == Printf.@sprintf("%020d", -1024) @test Printf.@sprintf("%0*i", 20, 1024) == Printf.@sprintf("%020i", 1024) @test Printf.@sprintf("%0*i", 20, -1024) == Printf.@sprintf("%020i", -1024) @test Printf.@sprintf("%0*u", 20, 1024) == Printf.@sprintf("%020u", 1024) @test Printf.@sprintf("%0*u", 20, UInt(4294966272)) == Printf.@sprintf("%020u", UInt(4294966272)) @test Printf.@sprintf("%0*o", 20, 511) == Printf.@sprintf("%020o", 511) @test Printf.@sprintf("%0*o", 20, UInt(4294966785)) == Printf.@sprintf("%020o", UInt(4294966785)) @test Printf.@sprintf("%0*x", 20, 305441741) == Printf.@sprintf("%020x", 305441741) @test Printf.@sprintf("%0*x", 20, UInt(3989525555)) == Printf.@sprintf("%020x", UInt(3989525555)) @test Printf.@sprintf("%0*X", 20, 305441741) == Printf.@sprintf("%020X", 305441741) @test Printf.@sprintf("%0*X", 20, UInt(3989525555)) == Printf.@sprintf("%020X", UInt(3989525555)) @test Printf.@sprintf("%#*o", 20, 511) == Printf.@sprintf("%#20o", 511) @test Printf.@sprintf("%#*o", 20, UInt(4294966785)) == Printf.@sprintf("%#20o", UInt(4294966785)) @test Printf.@sprintf("%#*x", 20, 305441741) == Printf.@sprintf("%#20x", 305441741) @test Printf.@sprintf("%#*x", 20, UInt(3989525555)) == Printf.@sprintf("%#20x", UInt(3989525555)) @test Printf.@sprintf("%#*X", 20, 305441741) == Printf.@sprintf("%#20X", 305441741) @test Printf.@sprintf("%#*X", 20, UInt(3989525555)) == Printf.@sprintf("%#20X", UInt(3989525555)) @test Printf.@sprintf("%#0*o", 20, 511) == Printf.@sprintf("%#020o", 511) @test Printf.@sprintf("%#0*o", 20, UInt(4294966785)) == Printf.@sprintf("%#020o", UInt(4294966785)) @test Printf.@sprintf("%#0*x", 20, 305441741) == Printf.@sprintf("%#020x", 305441741) @test Printf.@sprintf("%#0*x", 20, UInt(3989525555)) == Printf.@sprintf("%#020x", UInt(3989525555)) @test Printf.@sprintf("%#0*X", 20, 305441741) == Printf.@sprintf("%#020X", 305441741) @test Printf.@sprintf("%#0*X", 20, UInt(3989525555)) == Printf.@sprintf("%#020X", UInt(3989525555)) @test Printf.@sprintf("%0-*d", 20, 1024) == Printf.@sprintf("%0-20d", 1024) @test Printf.@sprintf("%0-*d", 20, -1024) == Printf.@sprintf("%0-20d", -1024) @test Printf.@sprintf("%0-*i", 20, 1024) == Printf.@sprintf("%0-20i", 1024) @test Printf.@sprintf("%0-*i", 20, -1024) == Printf.@sprintf("%0-20i", -1024) @test Printf.@sprintf("%0-*u", 20, 1024) == Printf.@sprintf("%0-20u", 1024) @test Printf.@sprintf("%0-*u", 20, UInt(4294966272)) == Printf.@sprintf("%0-20u", UInt(4294966272)) @test Printf.@sprintf("%-0*o", 20, 511) == Printf.@sprintf("%-020o", 511) @test Printf.@sprintf("%-0*o", 20, UInt(4294966785)) == Printf.@sprintf("%-020o", UInt(4294966785)) @test Printf.@sprintf("%-0*x", 20, 305441741) == Printf.@sprintf("%-020x", 305441741) @test Printf.@sprintf("%-0*x", 20, UInt(3989525555)) == Printf.@sprintf("%-020x", UInt(3989525555)) @test Printf.@sprintf("%-0*X", 20, 305441741) == Printf.@sprintf("%-020X", 305441741) @test Printf.@sprintf("%-0*X", 20, UInt(3989525555)) == Printf.@sprintf("%-020X", UInt(3989525555)) @test Printf.@sprintf("%.*d", 20, 1024) == Printf.@sprintf("%.20d", 1024) @test Printf.@sprintf("%.*d", 20, -1024) == Printf.@sprintf("%.20d", -1024) @test Printf.@sprintf("%.*i", 20, 1024) == Printf.@sprintf("%.20i", 1024) @test Printf.@sprintf("%.*i", 20, -1024) == Printf.@sprintf("%.20i", -1024) @test Printf.@sprintf("%.*u", 20, 1024) == Printf.@sprintf("%.20u", 1024) @test Printf.@sprintf("%.*u", 20, UInt(4294966272)) == Printf.@sprintf("%.20u", UInt(4294966272)) @test Printf.@sprintf("%.*o", 20, 511) == Printf.@sprintf("%.20o", 511) @test Printf.@sprintf("%.*o", 20, UInt(4294966785)) == Printf.@sprintf("%.20o", UInt(4294966785)) @test Printf.@sprintf("%.*x", 20, 305441741) == Printf.@sprintf("%.20x", 305441741) @test Printf.@sprintf("%.*x", 20, UInt(3989525555)) == Printf.@sprintf("%.20x", UInt(3989525555)) @test Printf.@sprintf("%.*X", 20, 305441741) == Printf.@sprintf("%.20X", 305441741) @test Printf.@sprintf("%.*X", 20, UInt(3989525555)) == Printf.@sprintf("%.20X", UInt(3989525555)) @test Printf.@sprintf("%*.*d", 20, 5, 1024) == Printf.@sprintf("%20.5d", 1024) @test Printf.@sprintf("%*.*d", 20, 5, -1024) == Printf.@sprintf("%20.5d", -1024) @test Printf.@sprintf("%*.*i", 20, 5, 1024) == Printf.@sprintf("%20.5i", 1024) @test Printf.@sprintf("%*.*i", 20, 5, -1024) == Printf.@sprintf("%20.5i", -1024) @test Printf.@sprintf("%*.*u", 20, 5, 1024) == Printf.@sprintf("%20.5u", 1024) @test Printf.@sprintf("%*.*u", 20, 5, UInt(4294966272)) == Printf.@sprintf("%20.5u", UInt(4294966272)) @test Printf.@sprintf("%*.*o", 20, 5, 511) == Printf.@sprintf("%20.5o", 511) @test Printf.@sprintf("%*.*o", 20, 5, UInt(4294966785)) == Printf.@sprintf("%20.5o", UInt(4294966785)) @test Printf.@sprintf("%*.*x", 20, 5, 305441741) == Printf.@sprintf("%20.5x", 305441741) @test Printf.@sprintf("%*.*x", 20, 10, UInt(3989525555)) == Printf.@sprintf("%20.10x", UInt(3989525555)) @test Printf.@sprintf("%*.*X", 20, 5, 305441741) == Printf.@sprintf("%20.5X", 305441741) @test Printf.@sprintf("%*.*X", 20, 10, UInt(3989525555)) == Printf.@sprintf("%20.10X", UInt(3989525555)) @test Printf.@sprintf("%0*.*d", 20, 5, 1024) == Printf.@sprintf("%020.5d", 1024) @test Printf.@sprintf("%0*.*d", 20, 5, -1024) == Printf.@sprintf("%020.5d", -1024) @test Printf.@sprintf("%0*.*i", 20, 5, 1024) == Printf.@sprintf("%020.5i", 1024) @test Printf.@sprintf("%0*.*i", 20, 5, -1024) == Printf.@sprintf("%020.5i", -1024) @test Printf.@sprintf("%0*.*u", 20, 5, 1024) == Printf.@sprintf("%020.5u", 1024) @test Printf.@sprintf("%0*.*u", 20, 5, UInt(4294966272)) == Printf.@sprintf("%020.5u", UInt(4294966272)) @test Printf.@sprintf("%0*.*o", 20, 5, 511) == Printf.@sprintf("%020.5o", 511) @test Printf.@sprintf("%0*.*o", 20, 5, UInt(4294966785)) == Printf.@sprintf("%020.5o", UInt(4294966785)) @test Printf.@sprintf("%0*.*x", 20, 5, 305441741) == Printf.@sprintf("%020.5x", 305441741) @test Printf.@sprintf("%0*.*x", 20, 10, UInt(3989525555)) == Printf.@sprintf("%020.10x", UInt(3989525555)) @test Printf.@sprintf("%0*.*X", 20, 5, 305441741) == Printf.@sprintf("%020.5X", 305441741) @test Printf.@sprintf("%0*.*X", 20, 10, UInt(3989525555)) == Printf.@sprintf("%020.10X", UInt(3989525555)) @test Printf.@sprintf("%*.0d", 20, 1024) == Printf.@sprintf("%20.0d", 1024) @test Printf.@sprintf("%*.d", 20, -1024) == Printf.@sprintf("%20.d", -1024) @test Printf.@sprintf("%*.d", 20, 0) == Printf.@sprintf("%20.d", 0) @test Printf.@sprintf("%*.0i", 20, 1024) == Printf.@sprintf("%20.0i", 1024) @test Printf.@sprintf("%*.i", 20, -1024) == Printf.@sprintf("%20.i", -1024) @test Printf.@sprintf("%*.i", 20, 0) == Printf.@sprintf("%20.i", 0) @test Printf.@sprintf("%*.u", 20, 1024) == Printf.@sprintf("%20.u", 1024) @test Printf.@sprintf("%*.0u", 20, UInt(4294966272)) == Printf.@sprintf("%20.0u", UInt(4294966272)) @test Printf.@sprintf("%*.u", 20, UInt(0)) == Printf.@sprintf("%20.u", UInt(0)) @test Printf.@sprintf("%*.o", 20, 511) == Printf.@sprintf("%20.o", 511) @test Printf.@sprintf("%*.0o", 20, UInt(4294966785)) == Printf.@sprintf("%20.0o", UInt(4294966785)) @test Printf.@sprintf("%*.o", 20, UInt(0)) == Printf.@sprintf("%20.o", UInt(0)) @test Printf.@sprintf("%*.x", 20, 305441741) == Printf.@sprintf("%20.x", 305441741) @test Printf.@sprintf("%*.0x", 20, UInt(3989525555)) == Printf.@sprintf("%20.0x", UInt(3989525555)) @test Printf.@sprintf("%*.x", 20, UInt(0)) == Printf.@sprintf("%20.x", UInt(0)) @test Printf.@sprintf("%*.X", 20, 305441741) == Printf.@sprintf("%20.X", 305441741) @test Printf.@sprintf("%*.0X", 20, UInt(3989525555)) == Printf.@sprintf("%20.0X", UInt(3989525555)) @test Printf.@sprintf("%*.X", 20, UInt(0)) == Printf.@sprintf("%20.X", UInt(0)) x = Ref{Int}() y = Ref{Int}() @test begin Printf.@sprintf "%10s%n" "😉" x Printf.@sprintf "%*s%n" 10 "😉" y x[] == y[] end @test begin Printf.@sprintf "%10s%n" "1234" x Printf.@sprintf "%*s%n" 10 "1234" y x[] == y[] end end @testset "length modifiers" begin @test_throws Printf.InvalidFormatStringError Printf.Format("%h") @test_throws Printf.InvalidFormatStringError Printf.Format("%hh") @test_throws Printf.InvalidFormatStringError Printf.Format("%z") end @testset "Docstrings" begin @test isempty(Docs.undocumented_names(Printf)) end @test @sprintf("%.160g", 1.38e-23) == "1.380000000000000060010582465734078799297660966782642624395399644741944111814291318296454846858978271484375e-23" end begin @testset "%p" begin if Sys.WORD_SIZE == 64 @test Printf.@sprintf("%20p", 0) == " 0x0000000000000000" @test Printf.@sprintf("%-20p", 0) == "0x0000000000000000 " @test Printf.@sprintf("%20p", C_NULL) == " 0x0000000000000000" @test @sprintf("%-20p", C_NULL) == "0x0000000000000000 " elseif Sys.WORD_SIZE == 32 @test Printf.@sprintf("%20p", 0) == " 0x00000000" @test Printf.@sprintf("%-20p", 0) == "0x00000000 " @test @sprintf("%20p", C_NULL) == " 0x00000000" @test @sprintf("%-20p", C_NULL) == "0x00000000 " end @test @sprintf("%p", 0xfffffffffffe0000) == "0xfffffffffffe0000" end @testset "%a" begin @test Printf.@sprintf("%a", 0.0) == "0x0p+0" @test Printf.@sprintf("%a", -0.0) == "-0x0p+0" @test Printf.@sprintf("%.3a", 0.0) == "0x0.000p+0" @test Printf.@sprintf("%a", 1.5) == "0x1.8p+0" @test Printf.@sprintf("%a", 1.5f0) == "0x1.8p+0" @test Printf.@sprintf("%a", 1.5) == "0x1.8p+0" @test Printf.@sprintf("%#.0a", 1.5) == "0x2.p+0" @test Printf.@sprintf("%+30a", 1 / 3) == " +0x1.5555555555555p-2" @test Printf.@sprintf("%a", 1.5) == "0x1.8p+0" @test Printf.@sprintf("%a", 3.14) == "0x1.91eb851eb851fp+1" @test Printf.@sprintf("%.0a", 3.14) == "0x2p+1" @test Printf.@sprintf("%.1a", 3.14) == "0x1.9p+1" @test Printf.@sprintf("%.2a", 3.14) == "0x1.92p+1" @test Printf.@sprintf("%#a", 3.14) == "0x1.91eb851eb851fp+1" @test Printf.@sprintf("%#.0a", 3.14) == "0x2.p+1" @test Printf.@sprintf("%#.1a", 3.14) == "0x1.9p+1" @test Printf.@sprintf("%#.2a", 3.14) == "0x1.92p+1" @test Printf.@sprintf("%.6a", 1.5) == "0x1.800000p+0" end @testset "%g" begin for (val, res) = ((1.2345678e7, "1.23457e+07"), (1.2345678e6, "1.23457e+06"), (123456.78, "123457"), (12345.678, "12345.7"), (1.234e7, "1.234e+07")) @test Printf.@sprintf("%.6g", val) == res end for (val, res) = ((1.2345678e7, "1.23457e+07"), (1.234567799999999999999999999999999999999999999999999999999999999999999999999993e6, "1.23457e+06"), (123456.7800000000000000000000000000000000000000000000000000000000000000000000004, "123457"), (12345.67800000000000000000000000000000000000000000000000000000000000000000000007, "12345.7")) @test Printf.@sprintf("%.6g", val) == res end for (fmt, val) = (("%10.5g", " 123.4"), ("%+10.5g", " +123.4"), ("% 10.5g", " 123.4"), ("%#10.5g", " 123.40"), ("%-10.5g", "123.4 "), ("%-+10.5g", "+123.4 "), ("%010.5g", "00000123.4")), num = (123.4, 123.4000000000000000000000000000000000000000000000000000000000000000000000000002) @test Printf.format(Printf.Format(fmt), num) == val end @test Printf.@sprintf("%10.5g", -123.4) == " -123.4" @test Printf.@sprintf("%010.5g", -123.4) == "-0000123.4" @test Printf.@sprintf("%.6g", 1.234e7) == "1.234e+07" @test Printf.@sprintf("%#.6g", 1.234e7) == "1.23400e+07" @test Printf.@sprintf("%10.5g", -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) == " -123.4" @test Printf.@sprintf("%010.5g", -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) == "-0000123.4" @test Printf.@sprintf("%.6g", 1.234e7) == "1.234e+07" @test Printf.@sprintf("%#.6g", 1.234e7) == "1.23400e+07" @test Printf.@sprintf("%.5g", 42) == "42" @test Printf.@sprintf("%#.2g", 42) == "42." @test Printf.@sprintf("%#.5g", 42) == "42.000" @test Printf.@sprintf("%g", 0.00012) == "0.00012" @test Printf.@sprintf("%g", 1.2e-5) == "1.2e-05" @test Printf.@sprintf("%g", 123456.7) == "123457" @test Printf.@sprintf("%g", 1.2345678e6) == "1.23457e+06" for (val, res) = ((Inf, "Inf"), (-Inf, "-Inf"), (NaN, "NaN"), (-NaN, "NaN")) @test Printf.@sprintf("%g", val) == res @test Printf.@sprintf("%G", val) == res end @test Printf.@sprintf("%.15g", 0) == "0" @test Printf.@sprintf("%#.15g", 0) == "0.00000000000000" end @testset "%f" begin @test Printf.@sprintf("%f", Inf) == "Inf" @test Printf.@sprintf("%+f", Inf) == "+Inf" @test Printf.@sprintf("% f", Inf) == " Inf" @test Printf.@sprintf("% #f", Inf) == " Inf" @test Printf.@sprintf("%07f", Inf) == " Inf" @test Printf.@sprintf("%f", -Inf) == "-Inf" @test Printf.@sprintf("%+f", -Inf) == "-Inf" @test Printf.@sprintf("%07f", -Inf) == " -Inf" @test Printf.@sprintf("%f", NaN) == "NaN" @test Printf.@sprintf("%+f", NaN) == "+NaN" @test Printf.@sprintf("% f", NaN) == " NaN" @test Printf.@sprintf("% #f", NaN) == " NaN" @test Printf.@sprintf("%07f", NaN) == " NaN" @test Printf.@sprintf("%e", Inf) == "Inf" @test Printf.@sprintf("%e", NaN) == "NaN" @test Printf.@sprintf("%.0f", 3.0e142) == "29999999999999997463140672961703247153805615792184250659629251954072073858354858644285983761764971823910371920726635399393477049701891710124032" @test Printf.@sprintf("%f", 1.234) == "1.234000" @test Printf.@sprintf("%F", 1.234) == "1.234000" @test Printf.@sprintf("%+f", 1.234) == "+1.234000" @test Printf.@sprintf("% f", 1.234) == " 1.234000" @test Printf.@sprintf("%f", -1.234) == "-1.234000" @test Printf.@sprintf("%+f", -1.234) == "-1.234000" @test Printf.@sprintf("% f", -1.234) == "-1.234000" @test Printf.@sprintf("%#f", 1.234) == "1.234000" @test Printf.@sprintf("%.2f", 1.234) == "1.23" @test Printf.@sprintf("%.2f", 1.235) == "1.24" @test Printf.@sprintf("%.2f", 0.235) == "0.23" @test Printf.@sprintf("%4.1f", 1.234) == " 1.2" @test Printf.@sprintf("%8.1f", 1.234) == " 1.2" @test Printf.@sprintf("%+8.1f", 1.234) == " +1.2" @test Printf.@sprintf("% 8.1f", 1.234) == " 1.2" @test Printf.@sprintf("% 7.1f", 1.234) == " 1.2" @test Printf.@sprintf("% 08.1f", 1.234) == " 00001.2" @test Printf.@sprintf("%08.1f", 1.234) == "000001.2" @test Printf.@sprintf("%-08.1f", 1.234) == "1.2 " @test Printf.@sprintf("%-8.1f", 1.234) == "1.2 " @test Printf.@sprintf("%08.1f", -1.234) == "-00001.2" @test Printf.@sprintf("%09.1f", -1.234) == "-000001.2" @test Printf.@sprintf("%09.1f", 1.234) == "0000001.2" @test Printf.@sprintf("%+09.1f", 1.234) == "+000001.2" @test Printf.@sprintf("% 09.1f", 1.234) == " 000001.2" @test Printf.@sprintf("%+ 09.1f", 1.234) == "+000001.2" @test Printf.@sprintf("%+ 09.1f", 1.234) == "+000001.2" @test Printf.@sprintf("%+ 09.0f", 1.234) == "+00000001" @test Printf.@sprintf("%+ #09.0f", 1.234) == "+0000001." @test Printf.@sprintf("%+7.1f", 9.96) == " +10.0" @test Printf.@sprintf("% 7.1f", 9.96) == " 10.0" end @testset "%e" begin @test Printf.@sprintf("%e", Inf) == "Inf" @test Printf.@sprintf("%+e", Inf) == "+Inf" @test Printf.@sprintf("% e", Inf) == " Inf" @test Printf.@sprintf("% #e", Inf) == " Inf" @test Printf.@sprintf("%07e", Inf) == " Inf" @test Printf.@sprintf("%e", -Inf) == "-Inf" @test Printf.@sprintf("%+e", -Inf) == "-Inf" @test Printf.@sprintf("%07e", -Inf) == " -Inf" @test Printf.@sprintf("%e", NaN) == "NaN" @test Printf.@sprintf("%+e", NaN) == "+NaN" @test Printf.@sprintf("% e", NaN) == " NaN" @test Printf.@sprintf("% #e", NaN) == " NaN" @test Printf.@sprintf("%07e", NaN) == " NaN" @test Printf.@sprintf("%e", Inf) == "Inf" @test Printf.@sprintf("%e", NaN) == "NaN" @test Printf.@sprintf("%.0e", 3.0e142) == "3e+142" @test Printf.@sprintf("%#.0e", 3.0e142) == "3.e+142" @test Printf.@sprintf("%.0e", 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) == "3e+142" @test Printf.@sprintf("%#.0e", 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) == "3.e+142" @test Printf.@sprintf("%.0e", 3.000000000000000000000000000000000000000000000000000000000000000000000000000024e1042) == "3e+1042" @test Printf.@sprintf("%e", 3.0e42) == "3.000000e+42" @test Printf.@sprintf("%E", 3.0e42) == "3.000000E+42" @test Printf.@sprintf("%e", 3.0e-42) == "3.000000e-42" @test Printf.@sprintf("%E", 3.0e-42) == "3.000000E-42" @test Printf.@sprintf("%e", 1.234) == "1.234000e+00" @test Printf.@sprintf("%E", 1.234) == "1.234000E+00" @test Printf.@sprintf("%+e", 1.234) == "+1.234000e+00" @test Printf.@sprintf("% e", 1.234) == " 1.234000e+00" @test Printf.@sprintf("%e", -1.234) == "-1.234000e+00" @test Printf.@sprintf("%+e", -1.234) == "-1.234000e+00" @test Printf.@sprintf("% e", -1.234) == "-1.234000e+00" @test Printf.@sprintf("%#e", 1.234) == "1.234000e+00" @test Printf.@sprintf("%.2e", 1.234) == "1.23e+00" @test Printf.@sprintf("%.2e", 1.235) == "1.24e+00" @test Printf.@sprintf("%.2e", 0.235) == "2.35e-01" @test Printf.@sprintf("%4.1e", 1.234) == "1.2e+00" @test Printf.@sprintf("%8.1e", 1.234) == " 1.2e+00" @test Printf.@sprintf("%+8.1e", 1.234) == "+1.2e+00" @test Printf.@sprintf("% 8.1e", 1.234) == " 1.2e+00" @test Printf.@sprintf("% 7.1e", 1.234) == " 1.2e+00" @test Printf.@sprintf("% 08.1e", 1.234) == " 1.2e+00" @test Printf.@sprintf("%08.1e", 1.234) == "01.2e+00" @test Printf.@sprintf("%-08.1e", 1.234) == "1.2e+00 " @test Printf.@sprintf("%-8.1e", 1.234) == "1.2e+00 " @test Printf.@sprintf("%-8.1e", 1.234) == "1.2e+00 " @test Printf.@sprintf("%08.1e", -1.234) == "-1.2e+00" @test Printf.@sprintf("%09.1e", -1.234) == "-01.2e+00" @test Printf.@sprintf("%09.1e", 1.234) == "001.2e+00" @test Printf.@sprintf("%+09.1e", 1.234) == "+01.2e+00" @test Printf.@sprintf("% 09.1e", 1.234) == " 01.2e+00" @test Printf.@sprintf("%+ 09.1e", 1.234) == "+01.2e+00" @test Printf.@sprintf("%+ 09.1e", 1.234) == "+01.2e+00" @test Printf.@sprintf("%+ 09.0e", 1.234) == "+0001e+00" @test Printf.@sprintf("%+ #09.0e", 1.234) == "+001.e+00" @test Printf.@sprintf("%+9.1e", 9.96) == " +1.0e+01" @test Printf.@sprintf("% 9.1e", 9.96) == " 1.0e+01" end @testset "strings" begin @test Printf.@sprintf("Hallo heimur") == "Hallo heimur" @test Printf.@sprintf("+%s+", "hello") == "+hello+" @test Printf.@sprintf("%.1s", "foo") == "f" @test Printf.@sprintf("%s", "%%%%") == "%%%%" @test Printf.@sprintf("%s", "Hallo heimur") == "Hallo heimur" @test Printf.@sprintf("%+s", "Hallo heimur") == "Hallo heimur" @test Printf.@sprintf("% s", "Hallo heimur") == "Hallo heimur" @test Printf.@sprintf("%+ s", "Hallo heimur") == "Hallo heimur" @test Printf.@sprintf("%1s", "Hallo heimur") == "Hallo heimur" @test Printf.@sprintf("%20s", "Hallo") == " Hallo" @test Printf.@sprintf("%-20s", "Hallo") == "Hallo " @test Printf.@sprintf("%0-20s", "Hallo") == "Hallo " @test Printf.@sprintf("%.20s", "Hallo heimur") == "Hallo heimur" @test Printf.@sprintf("%20.5s", "Hallo heimur") == " Hallo" @test Printf.@sprintf("%.0s", "Hallo heimur") == "" @test Printf.@sprintf("%20.0s", "Hallo heimur") == " " @test Printf.@sprintf("%.s", "Hallo heimur") == "" @test Printf.@sprintf("%20.s", "Hallo heimur") == " " @test Printf.@sprintf("%s", "test") == "test" @test Printf.@sprintf("%s", "tést") == "tést" @test Printf.@sprintf("ø%sø", "hey") == "øheyø" @test Printf.@sprintf("%4sø", "ø") == " øø" @test Printf.@sprintf("%-4sø", "ø") == "ø ø" @test Printf.@sprintf("%8s", "test") == " test" @test Printf.@sprintf("%-8s", "test") == "test " @test Printf.@sprintf("%s", :test) == "test" @test Printf.@sprintf("%#s", :test) == ":test" @test Printf.@sprintf("%#8s", :test) == " :test" @test Printf.@sprintf("%#-8s", :test) == ":test " @test Printf.@sprintf("%8.3s", "test") == " tes" @test Printf.@sprintf("%#8.3s", "test") == " \"te" @test Printf.@sprintf("%-8.3s", "test") == "tes " @test Printf.@sprintf("%#-8.3s", "test") == "\"te " @test Printf.@sprintf("%.3s", "test") == "tes" @test Printf.@sprintf("%#.3s", "test") == "\"te" @test Printf.@sprintf("%-.3s", "test") == "tes" @test Printf.@sprintf("%#-.3s", "test") == "\"te" @test Printf.@sprintf("%.2s", "föó") == "fö" @test Printf.@sprintf("%5s", "föó") == " föó" @test Printf.@sprintf("%6s", "😍🍕") == " 😍🍕" @test Printf.@sprintf("%2c", '🍕') == "🍕" @test Printf.@sprintf("%3c", '🍕') == " 🍕" end @testset "chars" begin @test Printf.@sprintf("%c", 'a') == "a" @test Printf.@sprintf("%c", 32) == " " @test Printf.@sprintf("%c", 36) == "\$" @test Printf.@sprintf("%3c", 'a') == " a" @test Printf.@sprintf("%c", 'x') == "x" @test Printf.@sprintf("%+c", 'x') == "x" @test Printf.@sprintf("% c", 'x') == "x" @test Printf.@sprintf("%+ c", 'x') == "x" @test Printf.@sprintf("%1c", 'x') == "x" @test Printf.@sprintf("%20c", 'x') == " x" @test Printf.@sprintf("%-20c", 'x') == "x " @test Printf.@sprintf("%-020c", 'x') == "x " @test Printf.@sprintf("%c", 65) == "A" @test Printf.@sprintf("%c", 'A') == "A" @test Printf.@sprintf("%3c", 'A') == " A" @test Printf.@sprintf("%-3c", 'A') == "A " @test Printf.@sprintf("%c", 248) == "ø" @test Printf.@sprintf("%c", 'ø') == "ø" @test Printf.@sprintf("%c", "ø") == "ø" @test Printf.@sprintf("%c", '𐀀') == "𐀀" end function _test_flags(val, vflag::AbstractString, fmt::AbstractString, res::AbstractString, prefix::AbstractString) vflag = string("%", vflag) space_fmt = string(length(res) + length(prefix) + 3, fmt) fsign = string(if val < 0 "-" else "+" end, prefix) nsign = string(if val < 0 "-" else " " end, prefix) osign = if val < 0 string("-", prefix) else string(prefix, "0") end esign = string(if val < 0 "-" else "" end, prefix) esignend = if val < 0 "" else " " end for (flag::AbstractString, ans::AbstractString) = (("", string(" ", nsign, res)), ("+", string(" ", fsign, res)), (" ", string(" ", nsign, res)), ("0", string(osign, "00", res)), ("-", string(esign, res, " ", esignend)), ("0+", string(fsign, "00", res)), ("0 ", string(nsign, "00", res)), ("-+", string(fsign, res, " ")), ("- ", string(nsign, res, " "))) fmt_string = string(vflag, flag, space_fmt) fmtd = Printf.format(Printf.Format(fmt_string), val) @test fmtd == ans end end @testset "basics" begin @test Printf.@sprintf("%%") == "%" @test Printf.@sprintf("1%%") == "1%" @test Printf.@sprintf("%%1") == "%1" @test Printf.@sprintf("1%%2") == "1%2" @test Printf.@sprintf("1%%%d", 2) == "1%2" @test Printf.@sprintf("1%%2%%3") == "1%2%3" @test Printf.@sprintf("GAP[%%]") == "GAP[%]" @test Printf.@sprintf("hey there") == "hey there" @test_throws Printf.InvalidFormatStringError Printf.Format("%+") @test_throws Printf.InvalidFormatStringError Printf.Format("%.") @test_throws Printf.InvalidFormatStringError Printf.Format("%.0") @test isempty((Printf.Format("%%")).formats) @test Printf.@sprintf("%d%d", 1, 2) == "12" @test Printf.@sprintf("%d%d", [1 2]...) == "12" @test Printf.@sprintf("X%d", 2) == "X2" @test Printf.@sprintf("Ð%d", 2) == "Ð2" @test Printf.@sprintf("ༀ%d", 2) == "ༀ2" @test Printf.@sprintf("\U1ffff%d", 2) == "\U0001ffff2" @test Printf.@sprintf("%dX%d", 1, 2) == "1X2" @test Printf.@sprintf("%dÐ%d", 1, 2) == "1Ð2" @test Printf.@sprintf("%dༀ%d", 1, 2) == "1ༀ2" @test Printf.@sprintf("%d\U1ffff%d", 1, 2) == "1\U0001ffff2" @test Printf.@sprintf("%d∃%dȃ", 1, 2) == "1∃2ȃ" @test_throws Printf.InvalidFormatStringError Printf.Format("%y%d") @test_throws Printf.InvalidFormatStringError Printf.Format("%Ð%d") @test_throws Printf.InvalidFormatStringError Printf.Format("%ༀ%d") @test_throws Printf.InvalidFormatStringError Printf.Format("%\U1ffff%d") @test Printf.@sprintf("%10.5d", 4) == " 00004" @test Printf.@sprintf("%d", typemax(Int64)) == "9223372036854775807" for (fmt, val) = (("%7.2f", " 1.23"), ("%-7.2f", "1.23 "), ("%07.2f", "0001.23"), ("%.0f", "1"), ("%#.0f", "1."), ("%.4e", "1.2345e+00"), ("%.4E", "1.2345E+00"), ("%.2a", "0x1.3cp+0"), ("%.2A", "0X1.3CP+0")), num = (1.2345, 1.234499999999999999999999999999999999999999999999999999999999999999999999999991) @test Printf.format(Printf.Format(fmt), num) == val end for (fmt, val) = (("%i", "42"), ("%u", "42"), ("Test: %i", "Test: 42"), ("%#x", "0x2a"), ("%x", "2a"), ("%X", "2A"), ("% i", " 42"), ("%+i", "+42"), ("%4i", " 42"), ("%-4i", "42 "), ("%f", "42.000000"), ("%g", "42"), ("%e", "4.200000e+01")), num = (UInt16(42), UInt32(42), UInt64(42), UInt128(42), Int16(42), Int32(42), Int64(42), Int128(42), 42) @test Printf.format(Printf.Format(fmt), num) == val end for i = ((42, "", "i", "42", ""), (42, "", "d", "42", ""), (42, "", "u", "42", ""), (42, "", "x", "2a", ""), (42, "", "X", "2A", ""), (42, "", "o", "52", ""), (42, "#", "x", "2a", "0x"), (42, "#", "X", "2A", "0X"), (42, "#", "o", "052", ""), (1.2345, "", ".2f", "1.23", ""), (1.2345, "", ".2e", "1.23e+00", ""), (1.2345, "", ".2E", "1.23E+00", ""), (1.2345, "#", ".0f", "1.", ""), (1.2345, "#", ".0e", "1.e+00", ""), (1.2345, "#", ".0E", "1.E+00", ""), (1.2345, "", ".2a", "1.3cp+0", "0x"), (1.2345, "", ".2A", "1.3CP+0", "0X")) _test_flags(i...) _test_flags(-(i[1]), i[2:5]...) end @test Printf.@sprintf("Test: %s%c%C%c%#-.0f.", "t", 65, 66, 67, -42) == "Test: tABC-42.." @test Printf.@sprintf("%f %d %d %f", 1.0, [3 4]..., 5) == "1.000000 3 4 5.000000" @test Printf.@sprintf("%s %f %9.5f %d %d %d %d%d%d%d", [1:6;]..., [7, 8, 9, 10]...) == "1 2.000000 3.00000 4 5 6 78910" @test Printf.@sprintf("%s %s %s %d %d %d %f %f %f", Any[10 ^ x + y for x = 1:3, y = 1:3]...) == "11 101 1001 12 102 1002 13.000000 103.000000 1003.000000" @test Printf.@sprintf("%s %s %s %d %d %d %f %f %f %s %s %s %d %d %d %f %f %f", Any[10x + (x + 1) for x = 1:18]...) == "12 23 34 45 56 67 78.000000 89.000000 100.000000 111 122 133 144 155 166 177.000000 188.000000 199.000000" @test (Printf.@sprintf("%.330f", BigFloat(1)))[var"end"] != '\0' @test Printf.@sprintf("%f", parse(BigFloat, "1e400")) == "10000000000000000000000000000000000000000000000000000000000000000000000000000025262527574416492004687051900140830217136998040684679611623086405387447100385714565637522507383770691831689647535911648520404034824470543643098638520633064715221151920028135130764414460468236314621044034960475540018328999334468948008954289495190631358190153259681118693204411689043999084305348398480210026863210192871358464.000000" @test_throws ArgumentError Printf.@sprintf("%f", parse(BigFloat, "1e99999")) @test Printf.@sprintf("%4.2s", "a") == " a" @test Printf.@sprintf("%12.3e", pi * 1.0e100) == " 3.142e+100" @test string((Printf.Format("%a")).formats[1]) == "%a" @test string((Printf.Format("%a")).formats[1]; modifier = "R") == "%Ra" @test Printf.@sprintf("%d", 3.14) == "3" @test Printf.@sprintf("%2d", 3.14) == " 3" @test Printf.@sprintf("%2d", big(3.14)) == " 3" @test Printf.@sprintf("%s", 1) == "1" @test Printf.@sprintf("%f", 1) == "1.000000" @test Printf.@sprintf("%e", 1) == "1.000000e+00" @test Printf.@sprintf("%g", 1) == "1" @test Printf.@sprintf("%.16g", 194.4778127560983) == "194.4778127560983" @test Printf.@sprintf("%.17g", 194.4778127560983) == "194.4778127560983" @test Printf.@sprintf("%.18g", 194.4778127560983) == "194.477812756098302" @test Printf.@sprintf("%.1g", 1.7976931348623157e308) == "2e+308" @test Printf.@sprintf("%.2g", 1.7976931348623157e308) == "1.8e+308" @test Printf.@sprintf("%.3g", 1.7976931348623157e308) == "1.8e+308" @test_throws ArgumentError @sprintf("%s%%%s", "a") @test @sprintf("%s%%%s", "a", "b") == "a%b" @test @sprintf("%d", 25.5) == "26" @test @sprintf(" %.1e\n", 0.999) == " 1.0e+00\n" @test @sprintf(" %.1f", 9.999) == " 10.0" @test @sprintf("%d", 1.0e100) == "10000000000000000159028911097599180468360808563945281389781327557747838772170381060813469985856815104" @test @sprintf("%d", 3 // 1) == "3" @test @sprintf("%d", Inf) == "Inf" @test @sprintf(" %d", NaN) == " NaN" @test Printf.@sprintf("") == "" @test Printf.format(Printf.Format("")) == "" end @testset "integers" begin @test Printf.@sprintf("% d", 42) == " 42" @test Printf.@sprintf("% d", -42) == "-42" @test Printf.@sprintf("% 5d", 42) == " 42" @test Printf.@sprintf("% 5d", -42) == " -42" @test Printf.@sprintf("% 15d", 42) == " 42" @test Printf.@sprintf("% 15d", -42) == " -42" @test Printf.@sprintf("%+d", 42) == "+42" @test Printf.@sprintf("%+d", -42) == "-42" @test Printf.@sprintf("%+5d", 42) == " +42" @test Printf.@sprintf("%+5d", -42) == " -42" @test Printf.@sprintf("%+15d", 42) == " +42" @test Printf.@sprintf("%+15d", -42) == " -42" @test Printf.@sprintf("%0d", 42) == "42" @test Printf.@sprintf("%0d", -42) == "-42" @test Printf.@sprintf("%05d", 42) == "00042" @test Printf.@sprintf("%05d", -42) == "-0042" @test Printf.@sprintf("%015d", 42) == "000000000000042" @test Printf.@sprintf("%015d", -42) == "-00000000000042" @test Printf.@sprintf("%-d", 42) == "42" @test Printf.@sprintf("%-d", -42) == "-42" @test Printf.@sprintf("%-5d", 42) == "42 " @test Printf.@sprintf("%-5d", -42) == "-42 " @test Printf.@sprintf("%-15d", 42) == "42 " @test Printf.@sprintf("%-15d", -42) == "-42 " @test Printf.@sprintf("%-0d", 42) == "42" @test Printf.@sprintf("%-0d", -42) == "-42" @test Printf.@sprintf("%-05d", 42) == "42 " @test Printf.@sprintf("%-05d", -42) == "-42 " @test Printf.@sprintf("%-015d", 42) == "42 " @test Printf.@sprintf("%-015d", -42) == "-42 " @test Printf.@sprintf("%0-d", 42) == "42" @test Printf.@sprintf("%0-d", -42) == "-42" @test Printf.@sprintf("%0-5d", 42) == "42 " @test Printf.@sprintf("%0-5d", -42) == "-42 " @test Printf.@sprintf("%0-15d", 42) == "42 " @test Printf.@sprintf("%0-15d", -42) == "-42 " @test_throws Printf.InvalidFormatStringError Printf.Format("%d %") @test Printf.@sprintf("%lld", 18446744065119617025) == "18446744065119617025" @test Printf.@sprintf("%+8lld", 100) == " +100" @test Printf.@sprintf("%+.8lld", 100) == "+00000100" @test Printf.@sprintf("%+10.8lld", 100) == " +00000100" @test_throws Printf.InvalidFormatStringError Printf.Format("%_1lld") @test Printf.@sprintf("%-1.5lld", -100) == "-00100" @test Printf.@sprintf("%5lld", 100) == " 100" @test Printf.@sprintf("%5lld", -100) == " -100" @test Printf.@sprintf("%-5lld", 100) == "100 " @test Printf.@sprintf("%-5lld", -100) == "-100 " @test Printf.@sprintf("%-.5lld", 100) == "00100" @test Printf.@sprintf("%-.5lld", -100) == "-00100" @test Printf.@sprintf("%-8.5lld", 100) == "00100 " @test Printf.@sprintf("%-8.5lld", -100) == "-00100 " @test Printf.@sprintf("%05lld", 100) == "00100" @test Printf.@sprintf("%05lld", -100) == "-0100" @test Printf.@sprintf("% lld", 100) == " 100" @test Printf.@sprintf("% lld", -100) == "-100" @test Printf.@sprintf("% 5lld", 100) == " 100" @test Printf.@sprintf("% 5lld", -100) == " -100" @test Printf.@sprintf("% .5lld", 100) == " 00100" @test Printf.@sprintf("% .5lld", -100) == "-00100" @test Printf.@sprintf("% 8.5lld", 100) == " 00100" @test Printf.@sprintf("% 8.5lld", -100) == " -00100" @test Printf.@sprintf("%.0lld", 0) == "0" @test Printf.@sprintf("%#+21.18llx", -100) == "-0x000000000000000064" @test Printf.@sprintf("%#.25llo", -100) == "-00000000000000000000000144" @test Printf.@sprintf("%#+24.20llo", -100) == " -000000000000000000144" @test Printf.@sprintf("%#+18.21llX", -100) == "-0X000000000000000000064" @test Printf.@sprintf("%#+20.24llo", -100) == "-0000000000000000000000144" @test Printf.@sprintf("%#+25.22llu", -1) == " -0000000000000000000001" @test Printf.@sprintf("%#+25.22llu", -1) == " -0000000000000000000001" @test Printf.@sprintf("%#+30.25llu", -1) == " -0000000000000000000000001" @test Printf.@sprintf("%+#25.22lld", -1) == " -0000000000000000000001" @test Printf.@sprintf("%#-8.5llo", 100) == "000144 " @test Printf.@sprintf("%#-+ 08.5lld", 100) == "+00100 " @test Printf.@sprintf("%#-+ 08.5lld", 100) == "+00100 " @test Printf.@sprintf("%.40lld", 1) == "0000000000000000000000000000000000000001" @test Printf.@sprintf("% .40lld", 1) == " 0000000000000000000000000000000000000001" @test Printf.@sprintf("% .40d", 1) == " 0000000000000000000000000000000000000001" @test Printf.@sprintf("%lld", 18446744065119617025) == "18446744065119617025" @test Printf.@sprintf("+%d+", 10) == "+10+" @test Printf.@sprintf("%#012x", 1) == "0x0000000001" @test Printf.@sprintf("%#04.8x", 1) == "0x00000001" @test Printf.@sprintf("%#-08.2x", 1) == "0x01 " @test Printf.@sprintf("%#08o", 1) == "00000001" @test Printf.@sprintf("%d", 1024) == "1024" @test Printf.@sprintf("%d", -1024) == "-1024" @test Printf.@sprintf("%i", 1024) == "1024" @test Printf.@sprintf("%i", -1024) == "-1024" @test Printf.@sprintf("%u", 1024) == "1024" @test Printf.@sprintf("%u", UInt(4294966272)) == "4294966272" @test Printf.@sprintf("%o", 511) == "777" @test Printf.@sprintf("%o", UInt(4294966785)) == "37777777001" @test Printf.@sprintf("%x", 305441741) == "1234abcd" @test Printf.@sprintf("%x", UInt(3989525555)) == "edcb5433" @test Printf.@sprintf("%X", 305441741) == "1234ABCD" @test Printf.@sprintf("%X", UInt(3989525555)) == "EDCB5433" @test Printf.@sprintf("%+d", 1024) == "+1024" @test Printf.@sprintf("%+d", -1024) == "-1024" @test Printf.@sprintf("%+i", 1024) == "+1024" @test Printf.@sprintf("%+i", -1024) == "-1024" @test Printf.@sprintf("%+u", 1024) == "+1024" @test Printf.@sprintf("%+u", UInt(4294966272)) == "+4294966272" @test Printf.@sprintf("%+o", 511) == "+777" @test Printf.@sprintf("%+o", UInt(4294966785)) == "+37777777001" @test Printf.@sprintf("%+x", 305441741) == "+1234abcd" @test Printf.@sprintf("%+x", UInt(3989525555)) == "+edcb5433" @test Printf.@sprintf("%+X", 305441741) == "+1234ABCD" @test Printf.@sprintf("%+X", UInt(3989525555)) == "+EDCB5433" @test Printf.@sprintf("% d", 1024) == " 1024" @test Printf.@sprintf("% d", -1024) == "-1024" @test Printf.@sprintf("% i", 1024) == " 1024" @test Printf.@sprintf("% i", -1024) == "-1024" @test Printf.@sprintf("% u", 1024) == " 1024" @test Printf.@sprintf("% u", UInt(4294966272)) == " 4294966272" @test Printf.@sprintf("% o", 511) == " 777" @test Printf.@sprintf("% o", UInt(4294966785)) == " 37777777001" @test Printf.@sprintf("% x", 305441741) == " 1234abcd" @test Printf.@sprintf("% x", UInt(3989525555)) == " edcb5433" @test Printf.@sprintf("% X", 305441741) == " 1234ABCD" @test Printf.@sprintf("% X", UInt(3989525555)) == " EDCB5433" @test Printf.@sprintf("%+ d", 1024) == "+1024" @test Printf.@sprintf("%+ d", -1024) == "-1024" @test Printf.@sprintf("%+ i", 1024) == "+1024" @test Printf.@sprintf("%+ i", -1024) == "-1024" @test Printf.@sprintf("%+ u", 1024) == "+1024" @test Printf.@sprintf("%+ u", UInt(4294966272)) == "+4294966272" @test Printf.@sprintf("%+ o", 511) == "+777" @test Printf.@sprintf("%+ o", UInt(4294966785)) == "+37777777001" @test Printf.@sprintf("%+ x", 305441741) == "+1234abcd" @test Printf.@sprintf("%+ x", UInt(3989525555)) == "+edcb5433" @test Printf.@sprintf("%+ X", 305441741) == "+1234ABCD" @test Printf.@sprintf("%+ X", UInt(3989525555)) == "+EDCB5433" @test Printf.@sprintf("%#o", 511) == "0777" @test Printf.@sprintf("%#o", UInt(4294966785)) == "037777777001" @test Printf.@sprintf("%#x", 305441741) == "0x1234abcd" @test Printf.@sprintf("%#x", UInt(3989525555)) == "0xedcb5433" @test Printf.@sprintf("%#X", 305441741) == "0X1234ABCD" @test Printf.@sprintf("%#X", UInt(3989525555)) == "0XEDCB5433" @test Printf.@sprintf("%#o", UInt(0)) == "00" @test Printf.@sprintf("%#x", UInt(0)) == "0x0" @test Printf.@sprintf("%#X", UInt(0)) == "0X0" @test Printf.@sprintf("%1d", 1024) == "1024" @test Printf.@sprintf("%1d", -1024) == "-1024" @test Printf.@sprintf("%1i", 1024) == "1024" @test Printf.@sprintf("%1i", -1024) == "-1024" @test Printf.@sprintf("%1u", 1024) == "1024" @test Printf.@sprintf("%1u", UInt(4294966272)) == "4294966272" @test Printf.@sprintf("%1o", 511) == "777" @test Printf.@sprintf("%1o", UInt(4294966785)) == "37777777001" @test Printf.@sprintf("%1x", 305441741) == "1234abcd" @test Printf.@sprintf("%1x", UInt(3989525555)) == "edcb5433" @test Printf.@sprintf("%1X", 305441741) == "1234ABCD" @test Printf.@sprintf("%1X", UInt(3989525555)) == "EDCB5433" @test Printf.@sprintf("%20d", 1024) == " 1024" @test Printf.@sprintf("%20d", -1024) == " -1024" @test Printf.@sprintf("%20i", 1024) == " 1024" @test Printf.@sprintf("%20i", -1024) == " -1024" @test Printf.@sprintf("%20u", 1024) == " 1024" @test Printf.@sprintf("%20u", UInt(4294966272)) == " 4294966272" @test Printf.@sprintf("%20o", 511) == " 777" @test Printf.@sprintf("%20o", UInt(4294966785)) == " 37777777001" @test Printf.@sprintf("%20x", 305441741) == " 1234abcd" @test Printf.@sprintf("%20x", UInt(3989525555)) == " edcb5433" @test Printf.@sprintf("%20X", 305441741) == " 1234ABCD" @test Printf.@sprintf("%20X", UInt(3989525555)) == " EDCB5433" @test Printf.@sprintf("%-20d", 1024) == "1024 " @test Printf.@sprintf("%-20d", -1024) == "-1024 " @test Printf.@sprintf("%-20i", 1024) == "1024 " @test Printf.@sprintf("%-20i", -1024) == "-1024 " @test Printf.@sprintf("%-20u", 1024) == "1024 " @test Printf.@sprintf("%-20u", UInt(4294966272)) == "4294966272 " @test Printf.@sprintf("%-20o", 511) == "777 " @test Printf.@sprintf("%-20o", UInt(4294966785)) == "37777777001 " @test Printf.@sprintf("%-20x", 305441741) == "1234abcd " @test Printf.@sprintf("%-20x", UInt(3989525555)) == "edcb5433 " @test Printf.@sprintf("%-20X", 305441741) == "1234ABCD " @test Printf.@sprintf("%-20X", UInt(3989525555)) == "EDCB5433 " @test Printf.@sprintf("%020d", 1024) == "00000000000000001024" @test Printf.@sprintf("%020d", -1024) == "-0000000000000001024" @test Printf.@sprintf("%020i", 1024) == "00000000000000001024" @test Printf.@sprintf("%020i", -1024) == "-0000000000000001024" @test Printf.@sprintf("%020u", 1024) == "00000000000000001024" @test Printf.@sprintf("%020u", UInt(4294966272)) == "00000000004294966272" @test Printf.@sprintf("%020o", 511) == "00000000000000000777" @test Printf.@sprintf("%020o", UInt(4294966785)) == "00000000037777777001" @test Printf.@sprintf("%020x", 305441741) == "0000000000001234abcd" @test Printf.@sprintf("%020x", UInt(3989525555)) == "000000000000edcb5433" @test Printf.@sprintf("%020X", 305441741) == "0000000000001234ABCD" @test Printf.@sprintf("%020X", UInt(3989525555)) == "000000000000EDCB5433" @test Printf.@sprintf("%#20o", 511) == " 0777" @test Printf.@sprintf("%#20o", UInt(4294966785)) == " 037777777001" @test Printf.@sprintf("%#20x", 305441741) == " 0x1234abcd" @test Printf.@sprintf("%#20x", UInt(3989525555)) == " 0xedcb5433" @test Printf.@sprintf("%#20X", 305441741) == " 0X1234ABCD" @test Printf.@sprintf("%#20X", UInt(3989525555)) == " 0XEDCB5433" @test Printf.@sprintf("%#020o", 511) == "00000000000000000777" @test Printf.@sprintf("%#020o", UInt(4294966785)) == "00000000037777777001" @test Printf.@sprintf("%#020x", 305441741) == "0x00000000001234abcd" @test Printf.@sprintf("%#020x", UInt(3989525555)) == "0x0000000000edcb5433" @test Printf.@sprintf("%#020X", 305441741) == "0X00000000001234ABCD" @test Printf.@sprintf("%#020X", UInt(3989525555)) == "0X0000000000EDCB5433" @test Printf.@sprintf("%0-20d", 1024) == "1024 " @test Printf.@sprintf("%0-20d", -1024) == "-1024 " @test Printf.@sprintf("%0-20i", 1024) == "1024 " @test Printf.@sprintf("%0-20i", -1024) == "-1024 " @test Printf.@sprintf("%0-20u", 1024) == "1024 " @test Printf.@sprintf("%0-20u", UInt(4294966272)) == "4294966272 " @test Printf.@sprintf("%-020o", 511) == "777 " @test Printf.@sprintf("%-020o", UInt(4294966785)) == "37777777001 " @test Printf.@sprintf("%-020x", 305441741) == "1234abcd " @test Printf.@sprintf("%-020x", UInt(3989525555)) == "edcb5433 " @test Printf.@sprintf("%-020X", 305441741) == "1234ABCD " @test Printf.@sprintf("%-020X", UInt(3989525555)) == "EDCB5433 " @test Printf.@sprintf("%.20d", 1024) == "00000000000000001024" @test Printf.@sprintf("%.20d", -1024) == "-00000000000000001024" @test Printf.@sprintf("%.20i", 1024) == "00000000000000001024" @test Printf.@sprintf("%.20i", -1024) == "-00000000000000001024" @test Printf.@sprintf("%.20u", 1024) == "00000000000000001024" @test Printf.@sprintf("%.20u", UInt(4294966272)) == "00000000004294966272" @test Printf.@sprintf("%.20o", 511) == "00000000000000000777" @test Printf.@sprintf("%.20o", UInt(4294966785)) == "00000000037777777001" @test Printf.@sprintf("%.20x", 305441741) == "0000000000001234abcd" @test Printf.@sprintf("%.20x", UInt(3989525555)) == "000000000000edcb5433" @test Printf.@sprintf("%.20X", 305441741) == "0000000000001234ABCD" @test Printf.@sprintf("%.20X", UInt(3989525555)) == "000000000000EDCB5433" @test Printf.@sprintf("%20.5d", 1024) == " 01024" @test Printf.@sprintf("%20.5d", -1024) == " -01024" @test Printf.@sprintf("%20.5i", 1024) == " 01024" @test Printf.@sprintf("%20.5i", -1024) == " -01024" @test Printf.@sprintf("%20.5u", 1024) == " 01024" @test Printf.@sprintf("%20.5u", UInt(4294966272)) == " 4294966272" @test Printf.@sprintf("%20.5o", 511) == " 00777" @test Printf.@sprintf("%20.5o", UInt(4294966785)) == " 37777777001" @test Printf.@sprintf("%20.5x", 305441741) == " 1234abcd" @test Printf.@sprintf("%20.10x", UInt(3989525555)) == " 00edcb5433" @test Printf.@sprintf("%20.5X", 305441741) == " 1234ABCD" @test Printf.@sprintf("%20.10X", UInt(3989525555)) == " 00EDCB5433" @test Printf.@sprintf("%020.5d", 1024) == " 01024" @test Printf.@sprintf("%020.5d", -1024) == " -01024" @test Printf.@sprintf("%020.5i", 1024) == " 01024" @test Printf.@sprintf("%020.5i", -1024) == " -01024" @test Printf.@sprintf("%020.5u", 1024) == " 01024" @test Printf.@sprintf("%020.5u", UInt(4294966272)) == " 4294966272" @test Printf.@sprintf("%020.5o", 511) == " 00777" @test Printf.@sprintf("%020.5o", UInt(4294966785)) == " 37777777001" @test Printf.@sprintf("%020.5x", 305441741) == " 1234abcd" @test Printf.@sprintf("%020.10x", UInt(3989525555)) == " 00edcb5433" @test Printf.@sprintf("%020.5X", 305441741) == " 1234ABCD" @test Printf.@sprintf("%020.10X", UInt(3989525555)) == " 00EDCB5433" @test Printf.@sprintf("%20.0d", 1024) == " 1024" @test Printf.@sprintf("%20.d", -1024) == " -1024" @test Printf.@sprintf("%20.d", 0) == " 0" @test Printf.@sprintf("%20.0i", 1024) == " 1024" @test Printf.@sprintf("%20.i", -1024) == " -1024" @test Printf.@sprintf("%20.i", 0) == " 0" @test Printf.@sprintf("%20.u", 1024) == " 1024" @test Printf.@sprintf("%20.0u", UInt(4294966272)) == " 4294966272" @test Printf.@sprintf("%20.u", UInt(0)) == " 0" @test Printf.@sprintf("%20.o", 511) == " 777" @test Printf.@sprintf("%20.0o", UInt(4294966785)) == " 37777777001" @test Printf.@sprintf("%20.o", UInt(0)) == " 0" @test Printf.@sprintf("%20.x", 305441741) == " 1234abcd" @test Printf.@sprintf("%20.0x", UInt(3989525555)) == " edcb5433" @test Printf.@sprintf("%20.x", UInt(0)) == " 0" @test Printf.@sprintf("%20.X", 305441741) == " 1234ABCD" @test Printf.@sprintf("%20.0X", UInt(3989525555)) == " EDCB5433" @test Printf.@sprintf("%20.X", UInt(0)) == " 0" @test Printf.@sprintf("%4d", typemin(Int8)) == "-128" @test Printf.@sprintf("%4d", typemax(Int8)) == " 127" @test Printf.@sprintf("%6d", typemin(Int16)) == "-32768" @test Printf.@sprintf("%6d", typemax(Int16)) == " 32767" @test Printf.@sprintf("%11d", typemin(Int32)) == "-2147483648" @test Printf.@sprintf("%11d", typemax(Int32)) == " 2147483647" @test Printf.@sprintf("%20d", typemin(Int64)) == "-9223372036854775808" @test Printf.@sprintf("%20d", typemax(Int64)) == " 9223372036854775807" @test Printf.@sprintf("%40d", typemin(Int128)) == "-170141183460469231731687303715884105728" @test Printf.@sprintf("%40d", typemax(Int128)) == " 170141183460469231731687303715884105727" end @testset "%n" begin x = Ref{Int}() @test begin Printf.@sprintf "%d4%n" 123 x x[] == 4 end @test begin Printf.@sprintf "%s%n" "😉" x x[] == 4 end @test begin Printf.@sprintf "%s%n" "1234" x x[] == 4 end end @testset "dynamic" begin @test Printf.@sprintf("%*d", 10, 12) == " 12" @test Printf.@sprintf("%.*d", 4, 12) == "0012" @test Printf.@sprintf("%*.*d", 10, 4, 12) == " 0012" @test Printf.@sprintf("%+*.*d", 10, 4, 12) == " +0012" @test Printf.@sprintf("%0*.*d", 10, 4, 12) == " 0012" @test Printf.@sprintf("%*d%*d%*d", 4, 12, 4, 13, 4, 14) == " 12 13 14" @test Printf.@sprintf("%*d%*d%*d", 4, 12, 5, 13, 6, 14) == " 12 13 14" @test Printf.@sprintf("%*p", 20, 0) == Printf.@sprintf("%20p", 0) @test Printf.@sprintf("%-*p", 20, 0) == Printf.@sprintf("%-20p", 0) @test Printf.@sprintf("%*p", 20, C_NULL) == Printf.@sprintf("%20p", C_NULL) @test Printf.@sprintf("%-*p", 20, C_NULL) == Printf.@sprintf("%-20p", C_NULL) @test Printf.@sprintf("%.*a", 0, 3.14) == Printf.@sprintf("%.0a", 3.14) @test Printf.@sprintf("%.*a", 1, 3.14) == Printf.@sprintf("%.1a", 3.14) @test Printf.@sprintf("%.*a", 2, 3.14) == Printf.@sprintf("%.2a", 3.14) @test Printf.@sprintf("%#.*a", 0, 3.14) == Printf.@sprintf("%#.0a", 3.14) @test Printf.@sprintf("%#.*a", 1, 3.14) == Printf.@sprintf("%#.1a", 3.14) @test Printf.@sprintf("%#.*a", 2, 3.14) == Printf.@sprintf("%#.2a", 3.14) @test Printf.@sprintf("%.*a", 6, 1.5) == Printf.@sprintf("%.6a", 1.5) @test Printf.@sprintf("%*.*g", 10, 5, -123.4) == Printf.@sprintf("%10.5g", -123.4) @test Printf.@sprintf("%0*.*g", 10, 5, -123.4) == Printf.@sprintf("%010.5g", -123.4) @test Printf.@sprintf("%.*g", 6, 1.234e7) == Printf.@sprintf("%.6g", 1.234e7) @test Printf.@sprintf("%#.*g", 6, 1.234e7) == Printf.@sprintf("%#.6g", 1.234e7) @test Printf.@sprintf("%*.*g", 10, 5, -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) == Printf.@sprintf("%10.5g", -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) @test Printf.@sprintf("%0*.*g", 10, 5, -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) == Printf.@sprintf("%010.5g", -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) @test Printf.@sprintf("%.*g", 6, 1.234e7) == Printf.@sprintf("%.6g", 1.234e7) @test Printf.@sprintf("%#.*g", 6, 1.234e7) == Printf.@sprintf("%#.6g", 1.234e7) @test Printf.@sprintf("%.*g", 5, 42) == Printf.@sprintf("%.5g", 42) @test Printf.@sprintf("%#.*g", 2, 42) == Printf.@sprintf("%#.2g", 42) @test Printf.@sprintf("%#.*g", 5, 42) == Printf.@sprintf("%#.5g", 42) @test Printf.@sprintf("%.*g", 15, 0) == Printf.@sprintf("%.15g", 0) @test Printf.@sprintf("%#.*g", 15, 0) == Printf.@sprintf("%#.15g", 0) @test Printf.@sprintf("%.*f", 0, 3.0e142) == Printf.@sprintf("%.0f", 3.0e142) @test Printf.@sprintf("%.*f", 2, 1.234) == Printf.@sprintf("%.2f", 1.234) @test Printf.@sprintf("%.*f", 2, 1.235) == Printf.@sprintf("%.2f", 1.235) @test Printf.@sprintf("%.*f", 2, 0.235) == Printf.@sprintf("%.2f", 0.235) @test Printf.@sprintf("%*.*f", 4, 1, 1.234) == Printf.@sprintf("%4.1f", 1.234) @test Printf.@sprintf("%*.*f", 8, 1, 1.234) == Printf.@sprintf("%8.1f", 1.234) @test Printf.@sprintf("%+*.*f", 8, 1, 1.234) == Printf.@sprintf("%+8.1f", 1.234) @test Printf.@sprintf("% *.*f", 8, 1, 1.234) == Printf.@sprintf("% 8.1f", 1.234) @test Printf.@sprintf("% *.*f", 7, 1, 1.234) == Printf.@sprintf("% 7.1f", 1.234) @test Printf.@sprintf("% 0*.*f", 8, 1, 1.234) == Printf.@sprintf("% 08.1f", 1.234) @test Printf.@sprintf("%0*.*f", 8, 1, 1.234) == Printf.@sprintf("%08.1f", 1.234) @test Printf.@sprintf("%-0*.*f", 8, 1, 1.234) == Printf.@sprintf("%-08.1f", 1.234) @test Printf.@sprintf("%-*.*f", 8, 1, 1.234) == Printf.@sprintf("%-8.1f", 1.234) @test Printf.@sprintf("%0*.*f", 8, 1, -1.234) == Printf.@sprintf("%08.1f", -1.234) @test Printf.@sprintf("%0*.*f", 9, 1, -1.234) == Printf.@sprintf("%09.1f", -1.234) @test Printf.@sprintf("%0*.*f", 9, 1, 1.234) == Printf.@sprintf("%09.1f", 1.234) @test Printf.@sprintf("%+0*.*f", 9, 1, 1.234) == Printf.@sprintf("%+09.1f", 1.234) @test Printf.@sprintf("% 0*.*f", 9, 1, 1.234) == Printf.@sprintf("% 09.1f", 1.234) @test Printf.@sprintf("%+ 0*.*f", 9, 1, 1.234) == Printf.@sprintf("%+ 09.1f", 1.234) @test Printf.@sprintf("%+ 0*.*f", 9, 1, 1.234) == Printf.@sprintf("%+ 09.1f", 1.234) @test Printf.@sprintf("%+ 0*.*f", 9, 0, 1.234) == Printf.@sprintf("%+ 09.0f", 1.234) @test Printf.@sprintf("%+ #0*.*f", 9, 0, 1.234) == Printf.@sprintf("%+ #09.0f", 1.234) @test Printf.@sprintf("%*.*e", 10, 4, Inf) == Printf.@sprintf("%10.4e", Inf) @test Printf.@sprintf("%*.*e", 10, 4, NaN) == Printf.@sprintf("%10.4e", NaN) @test Printf.@sprintf("%*.*e", 10, 4, Inf) == Printf.@sprintf("%10.4e", Inf) @test Printf.@sprintf("%*.*e", 10, 4, NaN) == Printf.@sprintf("%10.4e", NaN) @test Printf.@sprintf("%.*e", 0, 3.0e142) == Printf.@sprintf("%.0e", 3.0e142) @test Printf.@sprintf("%#.*e", 0, 3.0e142) == Printf.@sprintf("%#.0e", 3.0e142) @test Printf.@sprintf("%.*e", 0, 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) == Printf.@sprintf("%.0e", 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) @test Printf.@sprintf("%#.*e", 0, 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) == Printf.@sprintf("%#.0e", 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) @test Printf.@sprintf("%.*e", 0, 3.000000000000000000000000000000000000000000000000000000000000000000000000000024e1042) == Printf.@sprintf("%.0e", 3.000000000000000000000000000000000000000000000000000000000000000000000000000024e1042) @test Printf.@sprintf("%.*e", 2, 1.234) == Printf.@sprintf("%.2e", 1.234) @test Printf.@sprintf("%.*e", 2, 1.235) == Printf.@sprintf("%.2e", 1.235) @test Printf.@sprintf("%.*e", 2, 0.235) == Printf.@sprintf("%.2e", 0.235) @test Printf.@sprintf("%*.*e", 4, 1, 1.234) == Printf.@sprintf("%4.1e", 1.234) @test Printf.@sprintf("%*.*e", 8, 1, 1.234) == Printf.@sprintf("%8.1e", 1.234) @test Printf.@sprintf("%+*.*e", 8, 1, 1.234) == Printf.@sprintf("%+8.1e", 1.234) @test Printf.@sprintf("% *.*e", 8, 1, 1.234) == Printf.@sprintf("% 8.1e", 1.234) @test Printf.@sprintf("% *.*e", 7, 1, 1.234) == Printf.@sprintf("% 7.1e", 1.234) @test Printf.@sprintf("% 0*.*e", 8, 1, 1.234) == Printf.@sprintf("% 08.1e", 1.234) @test Printf.@sprintf("%0*.*e", 8, 1, 1.234) == Printf.@sprintf("%08.1e", 1.234) @test Printf.@sprintf("%-0*.*e", 8, 1, 1.234) == Printf.@sprintf("%-08.1e", 1.234) @test Printf.@sprintf("%-*.*e", 8, 1, 1.234) == Printf.@sprintf("%-8.1e", 1.234) @test Printf.@sprintf("%-*.*e", 8, 1, 1.234) == Printf.@sprintf("%-8.1e", 1.234) @test Printf.@sprintf("%0*.*e", 8, 1, -1.234) == Printf.@sprintf("%08.1e", -1.234) @test Printf.@sprintf("%0*.*e", 9, 1, -1.234) == Printf.@sprintf("%09.1e", -1.234) @test Printf.@sprintf("%0*.*e", 9, 1, 1.234) == Printf.@sprintf("%09.1e", 1.234) @test Printf.@sprintf("%+0*.*e", 9, 1, 1.234) == Printf.@sprintf("%+09.1e", 1.234) @test Printf.@sprintf("% 0*.*e", 9, 1, 1.234) == Printf.@sprintf("% 09.1e", 1.234) @test Printf.@sprintf("%+ 0*.*e", 9, 1, 1.234) == Printf.@sprintf("%+ 09.1e", 1.234) @test Printf.@sprintf("%+ 0*.*e", 9, 1, 1.234) == Printf.@sprintf("%+ 09.1e", 1.234) @test Printf.@sprintf("%+ 0*.*e", 9, 0, 1.234) == Printf.@sprintf("%+ 09.0e", 1.234) @test Printf.@sprintf("%+ #0*.*e", 9, 0, 1.234) == Printf.@sprintf("%+ #09.0e", 1.234) @test Printf.@sprintf("%.*s", 1, "foo") == Printf.@sprintf("%.1s", "foo") @test Printf.@sprintf("%*s", 1, "Hallo heimur") == Printf.@sprintf("%1s", "Hallo heimur") @test Printf.@sprintf("%*s", 20, "Hallo") == Printf.@sprintf("%20s", "Hallo") @test Printf.@sprintf("%-*s", 20, "Hallo") == Printf.@sprintf("%-20s", "Hallo") @test Printf.@sprintf("%0-*s", 20, "Hallo") == Printf.@sprintf("%0-20s", "Hallo") @test Printf.@sprintf("%.*s", 20, "Hallo heimur") == Printf.@sprintf("%.20s", "Hallo heimur") @test Printf.@sprintf("%*.*s", 20, 5, "Hallo heimur") == Printf.@sprintf("%20.5s", "Hallo heimur") @test Printf.@sprintf("%.*s", 0, "Hallo heimur") == Printf.@sprintf("%.0s", "Hallo heimur") @test Printf.@sprintf("%*.*s", 20, 0, "Hallo heimur") == Printf.@sprintf("%20.0s", "Hallo heimur") @test Printf.@sprintf("%.s", "Hallo heimur") == Printf.@sprintf("%.s", "Hallo heimur") @test Printf.@sprintf("%*.s", 20, "Hallo heimur") == Printf.@sprintf("%20.s", "Hallo heimur") @test Printf.@sprintf("%*sø", 4, "ø") == Printf.@sprintf("%4sø", "ø") @test Printf.@sprintf("%-*sø", 4, "ø") == Printf.@sprintf("%-4sø", "ø") @test Printf.@sprintf("%*s", 8, "test") == Printf.@sprintf("%8s", "test") @test Printf.@sprintf("%-*s", 8, "test") == Printf.@sprintf("%-8s", "test") @test Printf.@sprintf("%#*s", 8, :test) == Printf.@sprintf("%#8s", :test) @test Printf.@sprintf("%#-*s", 8, :test) == Printf.@sprintf("%#-8s", :test) @test Printf.@sprintf("%*.*s", 8, 3, "test") == Printf.@sprintf("%8.3s", "test") @test Printf.@sprintf("%#*.*s", 8, 3, "test") == Printf.@sprintf("%#8.3s", "test") @test Printf.@sprintf("%-*.*s", 8, 3, "test") == Printf.@sprintf("%-8.3s", "test") @test Printf.@sprintf("%#-*.*s", 8, 3, "test") == Printf.@sprintf("%#-8.3s", "test") @test Printf.@sprintf("%.*s", 3, "test") == Printf.@sprintf("%.3s", "test") @test Printf.@sprintf("%#.*s", 3, "test") == Printf.@sprintf("%#.3s", "test") @test Printf.@sprintf("%-.*s", 3, "test") == Printf.@sprintf("%-.3s", "test") @test Printf.@sprintf("%#-.*s", 3, "test") == Printf.@sprintf("%#-.3s", "test") @test Printf.@sprintf("%*c", 3, 'a') == Printf.@sprintf("%3c", 'a') @test Printf.@sprintf("%*c", 1, 'x') == Printf.@sprintf("%1c", 'x') @test Printf.@sprintf("%*c", 20, 'x') == Printf.@sprintf("%20c", 'x') @test Printf.@sprintf("%-*c", 20, 'x') == Printf.@sprintf("%-20c", 'x') @test Printf.@sprintf("%-0*c", 20, 'x') == Printf.@sprintf("%-020c", 'x') @test Printf.@sprintf("%*c", 3, 'A') == Printf.@sprintf("%3c", 'A') @test Printf.@sprintf("%-*c", 3, 'A') == Printf.@sprintf("%-3c", 'A') @test Printf.@sprintf("%*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f", 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345) == Printf.@sprintf("%4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f", 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345) @test (Printf.@sprintf("%.*f", 330, BigFloat(1)))[var"end"] != '\0' @test Printf.@sprintf("%*.*s", 4, 2, "a") == Printf.@sprintf("%4.2s", "a") @test Printf.@sprintf("%*.*e", 12, 3, pi * 1.0e100) == Printf.@sprintf("%12.3e", pi * 1.0e100) @test Printf.@sprintf("%*d", 2, 3.14) == Printf.@sprintf("%*d", 2, 3.14) @test Printf.@sprintf("%*d", 2, big(3.14)) == Printf.@sprintf("%*d", 2, big(3.14)) @test Printf.@sprintf(" %.*e\n", 1, 0.999) == Printf.@sprintf(" %.1e\n", 0.999) @test Printf.@sprintf(" %.*f", 1, 9.999) == Printf.@sprintf(" %.1f", 9.999) @test Printf.@sprintf("%*d", 10, 12) == Printf.@sprintf("%10d", 12) @test Printf.@sprintf("%.*d", 4, 12) == Printf.@sprintf("%.4d", 12) @test Printf.@sprintf("%*.*d", 10, 4, 12) == Printf.@sprintf("%10.4d", 12) @test Printf.@sprintf("%+*.*d", 10, 4, 12) == Printf.@sprintf("%+10.4d", 12) @test Printf.@sprintf("%0*.*d", 10, 4, 12) == Printf.@sprintf("%010.4d", 12) @test Printf.@sprintf("% *d", 5, 42) == Printf.@sprintf("% 5d", 42) @test Printf.@sprintf("% *d", 5, -42) == Printf.@sprintf("% 5d", -42) @test Printf.@sprintf("% *d", 15, 42) == Printf.@sprintf("% 15d", 42) @test Printf.@sprintf("% *d", 15, -42) == Printf.@sprintf("% 15d", -42) @test Printf.@sprintf("%+*d", 5, 42) == Printf.@sprintf("%+5d", 42) @test Printf.@sprintf("%+*d", 5, -42) == Printf.@sprintf("%+5d", -42) @test Printf.@sprintf("%+*d", 15, 42) == Printf.@sprintf("%+15d", 42) @test Printf.@sprintf("%+*d", 15, -42) == Printf.@sprintf("%+15d", -42) @test Printf.@sprintf("%*d", 0, 42) == Printf.@sprintf("%0d", 42) @test Printf.@sprintf("%*d", 0, -42) == Printf.@sprintf("%0d", -42) @test Printf.@sprintf("%-*d", 5, 42) == Printf.@sprintf("%-5d", 42) @test Printf.@sprintf("%-*d", 5, -42) == Printf.@sprintf("%-5d", -42) @test Printf.@sprintf("%-*d", 15, 42) == Printf.@sprintf("%-15d", 42) @test Printf.@sprintf("%-*d", 15, -42) == Printf.@sprintf("%-15d", -42) @test Printf.@sprintf("%+*lld", 8, 100) == Printf.@sprintf("%+8lld", 100) @test Printf.@sprintf("%+.*lld", 8, 100) == Printf.@sprintf("%+.8lld", 100) @test Printf.@sprintf("%+*.*lld", 10, 8, 100) == Printf.@sprintf("%+10.8lld", 100) @test Printf.@sprintf("%-*.*lld", 1, 5, -100) == Printf.@sprintf("%-1.5lld", -100) @test Printf.@sprintf("%*lld", 5, 100) == Printf.@sprintf("%5lld", 100) @test Printf.@sprintf("%*lld", 5, -100) == Printf.@sprintf("%5lld", -100) @test Printf.@sprintf("%-*lld", 5, 100) == Printf.@sprintf("%-5lld", 100) @test Printf.@sprintf("%-*lld", 5, -100) == Printf.@sprintf("%-5lld", -100) @test Printf.@sprintf("%-.*lld", 5, 100) == Printf.@sprintf("%-.5lld", 100) @test Printf.@sprintf("%-.*lld", 5, -100) == Printf.@sprintf("%-.5lld", -100) @test Printf.@sprintf("%-*.*lld", 8, 5, 100) == Printf.@sprintf("%-8.5lld", 100) @test Printf.@sprintf("%-*.*lld", 8, 5, -100) == Printf.@sprintf("%-8.5lld", -100) @test Printf.@sprintf("%0*lld", 5, 100) == Printf.@sprintf("%05lld", 100) @test Printf.@sprintf("%0*lld", 5, -100) == Printf.@sprintf("%05lld", -100) @test Printf.@sprintf("% *lld", 5, 100) == Printf.@sprintf("% 5lld", 100) @test Printf.@sprintf("% *lld", 5, -100) == Printf.@sprintf("% 5lld", -100) @test Printf.@sprintf("% .*lld", 5, 100) == Printf.@sprintf("% .5lld", 100) @test Printf.@sprintf("% .*lld", 5, -100) == Printf.@sprintf("% .5lld", -100) @test Printf.@sprintf("% *.*lld", 8, 5, 100) == Printf.@sprintf("% 8.5lld", 100) @test Printf.@sprintf("% *.*lld", 8, 5, -100) == Printf.@sprintf("% 8.5lld", -100) @test Printf.@sprintf("%.*lld", 0, 0) == Printf.@sprintf("%.0lld", 0) @test Printf.@sprintf("%#+*.*llx", 21, 18, -100) == Printf.@sprintf("%#+21.18llx", -100) @test Printf.@sprintf("%#.*llo", 25, -100) == Printf.@sprintf("%#.25llo", -100) @test Printf.@sprintf("%#+*.*llo", 24, 20, -100) == Printf.@sprintf("%#+24.20llo", -100) @test Printf.@sprintf("%#+*.*llX", 18, 21, -100) == Printf.@sprintf("%#+18.21llX", -100) @test Printf.@sprintf("%#+*.*llo", 20, 24, -100) == Printf.@sprintf("%#+20.24llo", -100) @test Printf.@sprintf("%#+*.*llu", 25, 22, -1) == Printf.@sprintf("%#+25.22llu", -1) @test Printf.@sprintf("%#+*.*llu", 30, 25, -1) == Printf.@sprintf("%#+30.25llu", -1) @test Printf.@sprintf("%+#*.*lld", 25, 22, -1) == Printf.@sprintf("%+#25.22lld", -1) @test Printf.@sprintf("%#-*.*llo", 8, 5, 100) == Printf.@sprintf("%#-8.5llo", 100) @test Printf.@sprintf("%#-+ 0*.*lld", 8, 5, 100) == Printf.@sprintf("%#-+ 08.5lld", 100) @test Printf.@sprintf("%#-+ 0*.*lld", 8, 5, 100) == Printf.@sprintf("%#-+ 08.5lld", 100) @test Printf.@sprintf("%.*lld", 40, 1) == Printf.@sprintf("%.40lld", 1) @test Printf.@sprintf("% .*lld", 40, 1) == Printf.@sprintf("% .40lld", 1) @test Printf.@sprintf("% .*d", 40, 1) == Printf.@sprintf("% .40d", 1) @test Printf.@sprintf("%#0*x", 12, 1) == Printf.@sprintf("%#012x", 1) @test Printf.@sprintf("%#0*.*x", 4, 8, 1) == Printf.@sprintf("%#04.8x", 1) @test Printf.@sprintf("%#-0*.*x", 8, 2, 1) == Printf.@sprintf("%#-08.2x", 1) @test Printf.@sprintf("%#0*o", 8, 1) == Printf.@sprintf("%#08o", 1) @test Printf.@sprintf("%*d", 20, 1024) == Printf.@sprintf("%20d", 1024) @test Printf.@sprintf("%*d", 20, -1024) == Printf.@sprintf("%20d", -1024) @test Printf.@sprintf("%*i", 20, 1024) == Printf.@sprintf("%20i", 1024) @test Printf.@sprintf("%*i", 20, -1024) == Printf.@sprintf("%20i", -1024) @test Printf.@sprintf("%*u", 20, 1024) == Printf.@sprintf("%20u", 1024) @test Printf.@sprintf("%*u", 20, UInt(4294966272)) == Printf.@sprintf("%20u", UInt(4294966272)) @test Printf.@sprintf("%*o", 20, 511) == Printf.@sprintf("%20o", 511) @test Printf.@sprintf("%*o", 20, UInt(4294966785)) == Printf.@sprintf("%20o", UInt(4294966785)) @test Printf.@sprintf("%*x", 20, 305441741) == Printf.@sprintf("%20x", 305441741) @test Printf.@sprintf("%*x", 20, UInt(3989525555)) == Printf.@sprintf("%20x", UInt(3989525555)) @test Printf.@sprintf("%*X", 20, 305441741) == Printf.@sprintf("%20X", 305441741) @test Printf.@sprintf("%*X", 20, UInt(3989525555)) == Printf.@sprintf("%20X", UInt(3989525555)) @test Printf.@sprintf("%-*d", 20, 1024) == Printf.@sprintf("%-20d", 1024) @test Printf.@sprintf("%-*d", 20, -1024) == Printf.@sprintf("%-20d", -1024) @test Printf.@sprintf("%-*i", 20, 1024) == Printf.@sprintf("%-20i", 1024) @test Printf.@sprintf("%-*i", 20, -1024) == Printf.@sprintf("%-20i", -1024) @test Printf.@sprintf("%-*u", 20, 1024) == Printf.@sprintf("%-20u", 1024) @test Printf.@sprintf("%-*u", 20, UInt(4294966272)) == Printf.@sprintf("%-20u", UInt(4294966272)) @test Printf.@sprintf("%-*o", 20, 511) == Printf.@sprintf("%-20o", 511) @test Printf.@sprintf("%-*o", 20, UInt(4294966785)) == Printf.@sprintf("%-20o", UInt(4294966785)) @test Printf.@sprintf("%-*x", 20, 305441741) == Printf.@sprintf("%-20x", 305441741) @test Printf.@sprintf("%-*x", 20, UInt(3989525555)) == Printf.@sprintf("%-20x", UInt(3989525555)) @test Printf.@sprintf("%-*X", 20, 305441741) == Printf.@sprintf("%-20X", 305441741) @test Printf.@sprintf("%-*X", 20, UInt(3989525555)) == Printf.@sprintf("%-20X", UInt(3989525555)) @test Printf.@sprintf("%0*d", 20, 1024) == Printf.@sprintf("%020d", 1024) @test Printf.@sprintf("%0*d", 20, -1024) == Printf.@sprintf("%020d", -1024) @test Printf.@sprintf("%0*i", 20, 1024) == Printf.@sprintf("%020i", 1024) @test Printf.@sprintf("%0*i", 20, -1024) == Printf.@sprintf("%020i", -1024) @test Printf.@sprintf("%0*u", 20, 1024) == Printf.@sprintf("%020u", 1024) @test Printf.@sprintf("%0*u", 20, UInt(4294966272)) == Printf.@sprintf("%020u", UInt(4294966272)) @test Printf.@sprintf("%0*o", 20, 511) == Printf.@sprintf("%020o", 511) @test Printf.@sprintf("%0*o", 20, UInt(4294966785)) == Printf.@sprintf("%020o", UInt(4294966785)) @test Printf.@sprintf("%0*x", 20, 305441741) == Printf.@sprintf("%020x", 305441741) @test Printf.@sprintf("%0*x", 20, UInt(3989525555)) == Printf.@sprintf("%020x", UInt(3989525555)) @test Printf.@sprintf("%0*X", 20, 305441741) == Printf.@sprintf("%020X", 305441741) @test Printf.@sprintf("%0*X", 20, UInt(3989525555)) == Printf.@sprintf("%020X", UInt(3989525555)) @test Printf.@sprintf("%#*o", 20, 511) == Printf.@sprintf("%#20o", 511) @test Printf.@sprintf("%#*o", 20, UInt(4294966785)) == Printf.@sprintf("%#20o", UInt(4294966785)) @test Printf.@sprintf("%#*x", 20, 305441741) == Printf.@sprintf("%#20x", 305441741) @test Printf.@sprintf("%#*x", 20, UInt(3989525555)) == Printf.@sprintf("%#20x", UInt(3989525555)) @test Printf.@sprintf("%#*X", 20, 305441741) == Printf.@sprintf("%#20X", 305441741) @test Printf.@sprintf("%#*X", 20, UInt(3989525555)) == Printf.@sprintf("%#20X", UInt(3989525555)) @test Printf.@sprintf("%#0*o", 20, 511) == Printf.@sprintf("%#020o", 511) @test Printf.@sprintf("%#0*o", 20, UInt(4294966785)) == Printf.@sprintf("%#020o", UInt(4294966785)) @test Printf.@sprintf("%#0*x", 20, 305441741) == Printf.@sprintf("%#020x", 305441741) @test Printf.@sprintf("%#0*x", 20, UInt(3989525555)) == Printf.@sprintf("%#020x", UInt(3989525555)) @test Printf.@sprintf("%#0*X", 20, 305441741) == Printf.@sprintf("%#020X", 305441741) @test Printf.@sprintf("%#0*X", 20, UInt(3989525555)) == Printf.@sprintf("%#020X", UInt(3989525555)) @test Printf.@sprintf("%0-*d", 20, 1024) == Printf.@sprintf("%0-20d", 1024) @test Printf.@sprintf("%0-*d", 20, -1024) == Printf.@sprintf("%0-20d", -1024) @test Printf.@sprintf("%0-*i", 20, 1024) == Printf.@sprintf("%0-20i", 1024) @test Printf.@sprintf("%0-*i", 20, -1024) == Printf.@sprintf("%0-20i", -1024) @test Printf.@sprintf("%0-*u", 20, 1024) == Printf.@sprintf("%0-20u", 1024) @test Printf.@sprintf("%0-*u", 20, UInt(4294966272)) == Printf.@sprintf("%0-20u", UInt(4294966272)) @test Printf.@sprintf("%-0*o", 20, 511) == Printf.@sprintf("%-020o", 511) @test Printf.@sprintf("%-0*o", 20, UInt(4294966785)) == Printf.@sprintf("%-020o", UInt(4294966785)) @test Printf.@sprintf("%-0*x", 20, 305441741) == Printf.@sprintf("%-020x", 305441741) @test Printf.@sprintf("%-0*x", 20, UInt(3989525555)) == Printf.@sprintf("%-020x", UInt(3989525555)) @test Printf.@sprintf("%-0*X", 20, 305441741) == Printf.@sprintf("%-020X", 305441741) @test Printf.@sprintf("%-0*X", 20, UInt(3989525555)) == Printf.@sprintf("%-020X", UInt(3989525555)) @test Printf.@sprintf("%.*d", 20, 1024) == Printf.@sprintf("%.20d", 1024) @test Printf.@sprintf("%.*d", 20, -1024) == Printf.@sprintf("%.20d", -1024) @test Printf.@sprintf("%.*i", 20, 1024) == Printf.@sprintf("%.20i", 1024) @test Printf.@sprintf("%.*i", 20, -1024) == Printf.@sprintf("%.20i", -1024) @test Printf.@sprintf("%.*u", 20, 1024) == Printf.@sprintf("%.20u", 1024) @test Printf.@sprintf("%.*u", 20, UInt(4294966272)) == Printf.@sprintf("%.20u", UInt(4294966272)) @test Printf.@sprintf("%.*o", 20, 511) == Printf.@sprintf("%.20o", 511) @test Printf.@sprintf("%.*o", 20, UInt(4294966785)) == Printf.@sprintf("%.20o", UInt(4294966785)) @test Printf.@sprintf("%.*x", 20, 305441741) == Printf.@sprintf("%.20x", 305441741) @test Printf.@sprintf("%.*x", 20, UInt(3989525555)) == Printf.@sprintf("%.20x", UInt(3989525555)) @test Printf.@sprintf("%.*X", 20, 305441741) == Printf.@sprintf("%.20X", 305441741) @test Printf.@sprintf("%.*X", 20, UInt(3989525555)) == Printf.@sprintf("%.20X", UInt(3989525555)) @test Printf.@sprintf("%*.*d", 20, 5, 1024) == Printf.@sprintf("%20.5d", 1024) @test Printf.@sprintf("%*.*d", 20, 5, -1024) == Printf.@sprintf("%20.5d", -1024) @test Printf.@sprintf("%*.*i", 20, 5, 1024) == Printf.@sprintf("%20.5i", 1024) @test Printf.@sprintf("%*.*i", 20, 5, -1024) == Printf.@sprintf("%20.5i", -1024) @test Printf.@sprintf("%*.*u", 20, 5, 1024) == Printf.@sprintf("%20.5u", 1024) @test Printf.@sprintf("%*.*u", 20, 5, UInt(4294966272)) == Printf.@sprintf("%20.5u", UInt(4294966272)) @test Printf.@sprintf("%*.*o", 20, 5, 511) == Printf.@sprintf("%20.5o", 511) @test Printf.@sprintf("%*.*o", 20, 5, UInt(4294966785)) == Printf.@sprintf("%20.5o", UInt(4294966785)) @test Printf.@sprintf("%*.*x", 20, 5, 305441741) == Printf.@sprintf("%20.5x", 305441741) @test Printf.@sprintf("%*.*x", 20, 10, UInt(3989525555)) == Printf.@sprintf("%20.10x", UInt(3989525555)) @test Printf.@sprintf("%*.*X", 20, 5, 305441741) == Printf.@sprintf("%20.5X", 305441741) @test Printf.@sprintf("%*.*X", 20, 10, UInt(3989525555)) == Printf.@sprintf("%20.10X", UInt(3989525555)) @test Printf.@sprintf("%0*.*d", 20, 5, 1024) == Printf.@sprintf("%020.5d", 1024) @test Printf.@sprintf("%0*.*d", 20, 5, -1024) == Printf.@sprintf("%020.5d", -1024) @test Printf.@sprintf("%0*.*i", 20, 5, 1024) == Printf.@sprintf("%020.5i", 1024) @test Printf.@sprintf("%0*.*i", 20, 5, -1024) == Printf.@sprintf("%020.5i", -1024) @test Printf.@sprintf("%0*.*u", 20, 5, 1024) == Printf.@sprintf("%020.5u", 1024) @test Printf.@sprintf("%0*.*u", 20, 5, UInt(4294966272)) == Printf.@sprintf("%020.5u", UInt(4294966272)) @test Printf.@sprintf("%0*.*o", 20, 5, 511) == Printf.@sprintf("%020.5o", 511) @test Printf.@sprintf("%0*.*o", 20, 5, UInt(4294966785)) == Printf.@sprintf("%020.5o", UInt(4294966785)) @test Printf.@sprintf("%0*.*x", 20, 5, 305441741) == Printf.@sprintf("%020.5x", 305441741) @test Printf.@sprintf("%0*.*x", 20, 10, UInt(3989525555)) == Printf.@sprintf("%020.10x", UInt(3989525555)) @test Printf.@sprintf("%0*.*X", 20, 5, 305441741) == Printf.@sprintf("%020.5X", 305441741) @test Printf.@sprintf("%0*.*X", 20, 10, UInt(3989525555)) == Printf.@sprintf("%020.10X", UInt(3989525555)) @test Printf.@sprintf("%*.0d", 20, 1024) == Printf.@sprintf("%20.0d", 1024) @test Printf.@sprintf("%*.d", 20, -1024) == Printf.@sprintf("%20.d", -1024) @test Printf.@sprintf("%*.d", 20, 0) == Printf.@sprintf("%20.d", 0) @test Printf.@sprintf("%*.0i", 20, 1024) == Printf.@sprintf("%20.0i", 1024) @test Printf.@sprintf("%*.i", 20, -1024) == Printf.@sprintf("%20.i", -1024) @test Printf.@sprintf("%*.i", 20, 0) == Printf.@sprintf("%20.i", 0) @test Printf.@sprintf("%*.u", 20, 1024) == Printf.@sprintf("%20.u", 1024) @test Printf.@sprintf("%*.0u", 20, UInt(4294966272)) == Printf.@sprintf("%20.0u", UInt(4294966272)) @test Printf.@sprintf("%*.u", 20, UInt(0)) == Printf.@sprintf("%20.u", UInt(0)) @test Printf.@sprintf("%*.o", 20, 511) == Printf.@sprintf("%20.o", 511) @test Printf.@sprintf("%*.0o", 20, UInt(4294966785)) == Printf.@sprintf("%20.0o", UInt(4294966785)) @test Printf.@sprintf("%*.o", 20, UInt(0)) == Printf.@sprintf("%20.o", UInt(0)) @test Printf.@sprintf("%*.x", 20, 305441741) == Printf.@sprintf("%20.x", 305441741) @test Printf.@sprintf("%*.0x", 20, UInt(3989525555)) == Printf.@sprintf("%20.0x", UInt(3989525555)) @test Printf.@sprintf("%*.x", 20, UInt(0)) == Printf.@sprintf("%20.x", UInt(0)) @test Printf.@sprintf("%*.X", 20, 305441741) == Printf.@sprintf("%20.X", 305441741) @test Printf.@sprintf("%*.0X", 20, UInt(3989525555)) == Printf.@sprintf("%20.0X", UInt(3989525555)) @test Printf.@sprintf("%*.X", 20, UInt(0)) == Printf.@sprintf("%20.X", UInt(0)) x = Ref{Int}() y = Ref{Int}() @test begin Printf.@sprintf "%10s%n" "😉" x Printf.@sprintf "%*s%n" 10 "😉" y x[] == y[] end @test begin Printf.@sprintf "%10s%n" "1234" x Printf.@sprintf "%*s%n" 10 "1234" y x[] == y[] end end @testset "length modifiers" begin @test_throws Printf.InvalidFormatStringError Printf.Format("%h") @test_throws Printf.InvalidFormatStringError Printf.Format("%hh") @test_throws Printf.InvalidFormatStringError Printf.Format("%z") end @testset "Docstrings" begin @test isempty(Docs.undocumented_names(Printf)) end @test @sprintf("%.160g", 1.38e-23) == "1.380000000000000060010582465734078799297660966782642624395399644741944111814291318296454846858978271484375e-23" end @testset "Printf" begin @testset "%p" begin if Sys.WORD_SIZE == 64 @test Printf.@sprintf("%20p", 0) == " 0x0000000000000000" @test Printf.@sprintf("%-20p", 0) == "0x0000000000000000 " @test Printf.@sprintf("%20p", C_NULL) == " 0x0000000000000000" @test @sprintf("%-20p", C_NULL) == "0x0000000000000000 " elseif Sys.WORD_SIZE == 32 @test Printf.@sprintf("%20p", 0) == " 0x00000000" @test Printf.@sprintf("%-20p", 0) == "0x00000000 " @test @sprintf("%20p", C_NULL) == " 0x00000000" @test @sprintf("%-20p", C_NULL) == "0x00000000 " end @test @sprintf("%p", 0xfffffffffffe0000) == "0xfffffffffffe0000" end @testset "%a" begin @test Printf.@sprintf("%a", 0.0) == "0x0p+0" @test Printf.@sprintf("%a", -0.0) == "-0x0p+0" @test Printf.@sprintf("%.3a", 0.0) == "0x0.000p+0" @test Printf.@sprintf("%a", 1.5) == "0x1.8p+0" @test Printf.@sprintf("%a", 1.5f0) == "0x1.8p+0" @test Printf.@sprintf("%a", 1.5) == "0x1.8p+0" @test Printf.@sprintf("%#.0a", 1.5) == "0x2.p+0" @test Printf.@sprintf("%+30a", 1 / 3) == " +0x1.5555555555555p-2" @test Printf.@sprintf("%a", 1.5) == "0x1.8p+0" @test Printf.@sprintf("%a", 3.14) == "0x1.91eb851eb851fp+1" @test Printf.@sprintf("%.0a", 3.14) == "0x2p+1" @test Printf.@sprintf("%.1a", 3.14) == "0x1.9p+1" @test Printf.@sprintf("%.2a", 3.14) == "0x1.92p+1" @test Printf.@sprintf("%#a", 3.14) == "0x1.91eb851eb851fp+1" @test Printf.@sprintf("%#.0a", 3.14) == "0x2.p+1" @test Printf.@sprintf("%#.1a", 3.14) == "0x1.9p+1" @test Printf.@sprintf("%#.2a", 3.14) == "0x1.92p+1" @test Printf.@sprintf("%.6a", 1.5) == "0x1.800000p+0" end @testset "%g" begin for (val, res) = ((1.2345678e7, "1.23457e+07"), (1.2345678e6, "1.23457e+06"), (123456.78, "123457"), (12345.678, "12345.7"), (1.234e7, "1.234e+07")) @test Printf.@sprintf("%.6g", val) == res end for (val, res) = ((1.2345678e7, "1.23457e+07"), (1.234567799999999999999999999999999999999999999999999999999999999999999999999993e6, "1.23457e+06"), (123456.7800000000000000000000000000000000000000000000000000000000000000000000004, "123457"), (12345.67800000000000000000000000000000000000000000000000000000000000000000000007, "12345.7")) @test Printf.@sprintf("%.6g", val) == res end for (fmt, val) = (("%10.5g", " 123.4"), ("%+10.5g", " +123.4"), ("% 10.5g", " 123.4"), ("%#10.5g", " 123.40"), ("%-10.5g", "123.4 "), ("%-+10.5g", "+123.4 "), ("%010.5g", "00000123.4")), num = (123.4, 123.4000000000000000000000000000000000000000000000000000000000000000000000000002) @test Printf.format(Printf.Format(fmt), num) == val end @test Printf.@sprintf("%10.5g", -123.4) == " -123.4" @test Printf.@sprintf("%010.5g", -123.4) == "-0000123.4" @test Printf.@sprintf("%.6g", 1.234e7) == "1.234e+07" @test Printf.@sprintf("%#.6g", 1.234e7) == "1.23400e+07" @test Printf.@sprintf("%10.5g", -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) == " -123.4" @test Printf.@sprintf("%010.5g", -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) == "-0000123.4" @test Printf.@sprintf("%.6g", 1.234e7) == "1.234e+07" @test Printf.@sprintf("%#.6g", 1.234e7) == "1.23400e+07" @test Printf.@sprintf("%.5g", 42) == "42" @test Printf.@sprintf("%#.2g", 42) == "42." @test Printf.@sprintf("%#.5g", 42) == "42.000" @test Printf.@sprintf("%g", 0.00012) == "0.00012" @test Printf.@sprintf("%g", 1.2e-5) == "1.2e-05" @test Printf.@sprintf("%g", 123456.7) == "123457" @test Printf.@sprintf("%g", 1.2345678e6) == "1.23457e+06" for (val, res) = ((Inf, "Inf"), (-Inf, "-Inf"), (NaN, "NaN"), (-NaN, "NaN")) @test Printf.@sprintf("%g", val) == res @test Printf.@sprintf("%G", val) == res end @test Printf.@sprintf("%.15g", 0) == "0" @test Printf.@sprintf("%#.15g", 0) == "0.00000000000000" end @testset "%f" begin @test Printf.@sprintf("%f", Inf) == "Inf" @test Printf.@sprintf("%+f", Inf) == "+Inf" @test Printf.@sprintf("% f", Inf) == " Inf" @test Printf.@sprintf("% #f", Inf) == " Inf" @test Printf.@sprintf("%07f", Inf) == " Inf" @test Printf.@sprintf("%f", -Inf) == "-Inf" @test Printf.@sprintf("%+f", -Inf) == "-Inf" @test Printf.@sprintf("%07f", -Inf) == " -Inf" @test Printf.@sprintf("%f", NaN) == "NaN" @test Printf.@sprintf("%+f", NaN) == "+NaN" @test Printf.@sprintf("% f", NaN) == " NaN" @test Printf.@sprintf("% #f", NaN) == " NaN" @test Printf.@sprintf("%07f", NaN) == " NaN" @test Printf.@sprintf("%e", Inf) == "Inf" @test Printf.@sprintf("%e", NaN) == "NaN" @test Printf.@sprintf("%.0f", 3.0e142) == "29999999999999997463140672961703247153805615792184250659629251954072073858354858644285983761764971823910371920726635399393477049701891710124032" @test Printf.@sprintf("%f", 1.234) == "1.234000" @test Printf.@sprintf("%F", 1.234) == "1.234000" @test Printf.@sprintf("%+f", 1.234) == "+1.234000" @test Printf.@sprintf("% f", 1.234) == " 1.234000" @test Printf.@sprintf("%f", -1.234) == "-1.234000" @test Printf.@sprintf("%+f", -1.234) == "-1.234000" @test Printf.@sprintf("% f", -1.234) == "-1.234000" @test Printf.@sprintf("%#f", 1.234) == "1.234000" @test Printf.@sprintf("%.2f", 1.234) == "1.23" @test Printf.@sprintf("%.2f", 1.235) == "1.24" @test Printf.@sprintf("%.2f", 0.235) == "0.23" @test Printf.@sprintf("%4.1f", 1.234) == " 1.2" @test Printf.@sprintf("%8.1f", 1.234) == " 1.2" @test Printf.@sprintf("%+8.1f", 1.234) == " +1.2" @test Printf.@sprintf("% 8.1f", 1.234) == " 1.2" @test Printf.@sprintf("% 7.1f", 1.234) == " 1.2" @test Printf.@sprintf("% 08.1f", 1.234) == " 00001.2" @test Printf.@sprintf("%08.1f", 1.234) == "000001.2" @test Printf.@sprintf("%-08.1f", 1.234) == "1.2 " @test Printf.@sprintf("%-8.1f", 1.234) == "1.2 " @test Printf.@sprintf("%08.1f", -1.234) == "-00001.2" @test Printf.@sprintf("%09.1f", -1.234) == "-000001.2" @test Printf.@sprintf("%09.1f", 1.234) == "0000001.2" @test Printf.@sprintf("%+09.1f", 1.234) == "+000001.2" @test Printf.@sprintf("% 09.1f", 1.234) == " 000001.2" @test Printf.@sprintf("%+ 09.1f", 1.234) == "+000001.2" @test Printf.@sprintf("%+ 09.1f", 1.234) == "+000001.2" @test Printf.@sprintf("%+ 09.0f", 1.234) == "+00000001" @test Printf.@sprintf("%+ #09.0f", 1.234) == "+0000001." @test Printf.@sprintf("%+7.1f", 9.96) == " +10.0" @test Printf.@sprintf("% 7.1f", 9.96) == " 10.0" end @testset "%e" begin @test Printf.@sprintf("%e", Inf) == "Inf" @test Printf.@sprintf("%+e", Inf) == "+Inf" @test Printf.@sprintf("% e", Inf) == " Inf" @test Printf.@sprintf("% #e", Inf) == " Inf" @test Printf.@sprintf("%07e", Inf) == " Inf" @test Printf.@sprintf("%e", -Inf) == "-Inf" @test Printf.@sprintf("%+e", -Inf) == "-Inf" @test Printf.@sprintf("%07e", -Inf) == " -Inf" @test Printf.@sprintf("%e", NaN) == "NaN" @test Printf.@sprintf("%+e", NaN) == "+NaN" @test Printf.@sprintf("% e", NaN) == " NaN" @test Printf.@sprintf("% #e", NaN) == " NaN" @test Printf.@sprintf("%07e", NaN) == " NaN" @test Printf.@sprintf("%e", Inf) == "Inf" @test Printf.@sprintf("%e", NaN) == "NaN" @test Printf.@sprintf("%.0e", 3.0e142) == "3e+142" @test Printf.@sprintf("%#.0e", 3.0e142) == "3.e+142" @test Printf.@sprintf("%.0e", 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) == "3e+142" @test Printf.@sprintf("%#.0e", 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) == "3.e+142" @test Printf.@sprintf("%.0e", 3.000000000000000000000000000000000000000000000000000000000000000000000000000024e1042) == "3e+1042" @test Printf.@sprintf("%e", 3.0e42) == "3.000000e+42" @test Printf.@sprintf("%E", 3.0e42) == "3.000000E+42" @test Printf.@sprintf("%e", 3.0e-42) == "3.000000e-42" @test Printf.@sprintf("%E", 3.0e-42) == "3.000000E-42" @test Printf.@sprintf("%e", 1.234) == "1.234000e+00" @test Printf.@sprintf("%E", 1.234) == "1.234000E+00" @test Printf.@sprintf("%+e", 1.234) == "+1.234000e+00" @test Printf.@sprintf("% e", 1.234) == " 1.234000e+00" @test Printf.@sprintf("%e", -1.234) == "-1.234000e+00" @test Printf.@sprintf("%+e", -1.234) == "-1.234000e+00" @test Printf.@sprintf("% e", -1.234) == "-1.234000e+00" @test Printf.@sprintf("%#e", 1.234) == "1.234000e+00" @test Printf.@sprintf("%.2e", 1.234) == "1.23e+00" @test Printf.@sprintf("%.2e", 1.235) == "1.24e+00" @test Printf.@sprintf("%.2e", 0.235) == "2.35e-01" @test Printf.@sprintf("%4.1e", 1.234) == "1.2e+00" @test Printf.@sprintf("%8.1e", 1.234) == " 1.2e+00" @test Printf.@sprintf("%+8.1e", 1.234) == "+1.2e+00" @test Printf.@sprintf("% 8.1e", 1.234) == " 1.2e+00" @test Printf.@sprintf("% 7.1e", 1.234) == " 1.2e+00" @test Printf.@sprintf("% 08.1e", 1.234) == " 1.2e+00" @test Printf.@sprintf("%08.1e", 1.234) == "01.2e+00" @test Printf.@sprintf("%-08.1e", 1.234) == "1.2e+00 " @test Printf.@sprintf("%-8.1e", 1.234) == "1.2e+00 " @test Printf.@sprintf("%-8.1e", 1.234) == "1.2e+00 " @test Printf.@sprintf("%08.1e", -1.234) == "-1.2e+00" @test Printf.@sprintf("%09.1e", -1.234) == "-01.2e+00" @test Printf.@sprintf("%09.1e", 1.234) == "001.2e+00" @test Printf.@sprintf("%+09.1e", 1.234) == "+01.2e+00" @test Printf.@sprintf("% 09.1e", 1.234) == " 01.2e+00" @test Printf.@sprintf("%+ 09.1e", 1.234) == "+01.2e+00" @test Printf.@sprintf("%+ 09.1e", 1.234) == "+01.2e+00" @test Printf.@sprintf("%+ 09.0e", 1.234) == "+0001e+00" @test Printf.@sprintf("%+ #09.0e", 1.234) == "+001.e+00" @test Printf.@sprintf("%+9.1e", 9.96) == " +1.0e+01" @test Printf.@sprintf("% 9.1e", 9.96) == " 1.0e+01" end @testset "strings" begin @test Printf.@sprintf("Hallo heimur") == "Hallo heimur" @test Printf.@sprintf("+%s+", "hello") == "+hello+" @test Printf.@sprintf("%.1s", "foo") == "f" @test Printf.@sprintf("%s", "%%%%") == "%%%%" @test Printf.@sprintf("%s", "Hallo heimur") == "Hallo heimur" @test Printf.@sprintf("%+s", "Hallo heimur") == "Hallo heimur" @test Printf.@sprintf("% s", "Hallo heimur") == "Hallo heimur" @test Printf.@sprintf("%+ s", "Hallo heimur") == "Hallo heimur" @test Printf.@sprintf("%1s", "Hallo heimur") == "Hallo heimur" @test Printf.@sprintf("%20s", "Hallo") == " Hallo" @test Printf.@sprintf("%-20s", "Hallo") == "Hallo " @test Printf.@sprintf("%0-20s", "Hallo") == "Hallo " @test Printf.@sprintf("%.20s", "Hallo heimur") == "Hallo heimur" @test Printf.@sprintf("%20.5s", "Hallo heimur") == " Hallo" @test Printf.@sprintf("%.0s", "Hallo heimur") == "" @test Printf.@sprintf("%20.0s", "Hallo heimur") == " " @test Printf.@sprintf("%.s", "Hallo heimur") == "" @test Printf.@sprintf("%20.s", "Hallo heimur") == " " @test Printf.@sprintf("%s", "test") == "test" @test Printf.@sprintf("%s", "tést") == "tést" @test Printf.@sprintf("ø%sø", "hey") == "øheyø" @test Printf.@sprintf("%4sø", "ø") == " øø" @test Printf.@sprintf("%-4sø", "ø") == "ø ø" @test Printf.@sprintf("%8s", "test") == " test" @test Printf.@sprintf("%-8s", "test") == "test " @test Printf.@sprintf("%s", :test) == "test" @test Printf.@sprintf("%#s", :test) == ":test" @test Printf.@sprintf("%#8s", :test) == " :test" @test Printf.@sprintf("%#-8s", :test) == ":test " @test Printf.@sprintf("%8.3s", "test") == " tes" @test Printf.@sprintf("%#8.3s", "test") == " \"te" @test Printf.@sprintf("%-8.3s", "test") == "tes " @test Printf.@sprintf("%#-8.3s", "test") == "\"te " @test Printf.@sprintf("%.3s", "test") == "tes" @test Printf.@sprintf("%#.3s", "test") == "\"te" @test Printf.@sprintf("%-.3s", "test") == "tes" @test Printf.@sprintf("%#-.3s", "test") == "\"te" @test Printf.@sprintf("%.2s", "föó") == "fö" @test Printf.@sprintf("%5s", "föó") == " föó" @test Printf.@sprintf("%6s", "😍🍕") == " 😍🍕" @test Printf.@sprintf("%2c", '🍕') == "🍕" @test Printf.@sprintf("%3c", '🍕') == " 🍕" end @testset "chars" begin @test Printf.@sprintf("%c", 'a') == "a" @test Printf.@sprintf("%c", 32) == " " @test Printf.@sprintf("%c", 36) == "\$" @test Printf.@sprintf("%3c", 'a') == " a" @test Printf.@sprintf("%c", 'x') == "x" @test Printf.@sprintf("%+c", 'x') == "x" @test Printf.@sprintf("% c", 'x') == "x" @test Printf.@sprintf("%+ c", 'x') == "x" @test Printf.@sprintf("%1c", 'x') == "x" @test Printf.@sprintf("%20c", 'x') == " x" @test Printf.@sprintf("%-20c", 'x') == "x " @test Printf.@sprintf("%-020c", 'x') == "x " @test Printf.@sprintf("%c", 65) == "A" @test Printf.@sprintf("%c", 'A') == "A" @test Printf.@sprintf("%3c", 'A') == " A" @test Printf.@sprintf("%-3c", 'A') == "A " @test Printf.@sprintf("%c", 248) == "ø" @test Printf.@sprintf("%c", 'ø') == "ø" @test Printf.@sprintf("%c", "ø") == "ø" @test Printf.@sprintf("%c", '𐀀') == "𐀀" end function _test_flags(val, vflag::AbstractString, fmt::AbstractString, res::AbstractString, prefix::AbstractString) vflag = string("%", vflag) space_fmt = string(length(res) + length(prefix) + 3, fmt) fsign = string(if val < 0 "-" else "+" end, prefix) nsign = string(if val < 0 "-" else " " end, prefix) osign = if val < 0 string("-", prefix) else string(prefix, "0") end esign = string(if val < 0 "-" else "" end, prefix) esignend = if val < 0 "" else " " end for (flag::AbstractString, ans::AbstractString) = (("", string(" ", nsign, res)), ("+", string(" ", fsign, res)), (" ", string(" ", nsign, res)), ("0", string(osign, "00", res)), ("-", string(esign, res, " ", esignend)), ("0+", string(fsign, "00", res)), ("0 ", string(nsign, "00", res)), ("-+", string(fsign, res, " ")), ("- ", string(nsign, res, " "))) fmt_string = string(vflag, flag, space_fmt) fmtd = Printf.format(Printf.Format(fmt_string), val) @test fmtd == ans end end @testset "basics" begin @test Printf.@sprintf("%%") == "%" @test Printf.@sprintf("1%%") == "1%" @test Printf.@sprintf("%%1") == "%1" @test Printf.@sprintf("1%%2") == "1%2" @test Printf.@sprintf("1%%%d", 2) == "1%2" @test Printf.@sprintf("1%%2%%3") == "1%2%3" @test Printf.@sprintf("GAP[%%]") == "GAP[%]" @test Printf.@sprintf("hey there") == "hey there" @test_throws Printf.InvalidFormatStringError Printf.Format("%+") @test_throws Printf.InvalidFormatStringError Printf.Format("%.") @test_throws Printf.InvalidFormatStringError Printf.Format("%.0") @test isempty((Printf.Format("%%")).formats) @test Printf.@sprintf("%d%d", 1, 2) == "12" @test Printf.@sprintf("%d%d", [1 2]...) == "12" @test Printf.@sprintf("X%d", 2) == "X2" @test Printf.@sprintf("Ð%d", 2) == "Ð2" @test Printf.@sprintf("ༀ%d", 2) == "ༀ2" @test Printf.@sprintf("\U1ffff%d", 2) == "\U0001ffff2" @test Printf.@sprintf("%dX%d", 1, 2) == "1X2" @test Printf.@sprintf("%dÐ%d", 1, 2) == "1Ð2" @test Printf.@sprintf("%dༀ%d", 1, 2) == "1ༀ2" @test Printf.@sprintf("%d\U1ffff%d", 1, 2) == "1\U0001ffff2" @test Printf.@sprintf("%d∃%dȃ", 1, 2) == "1∃2ȃ" @test_throws Printf.InvalidFormatStringError Printf.Format("%y%d") @test_throws Printf.InvalidFormatStringError Printf.Format("%Ð%d") @test_throws Printf.InvalidFormatStringError Printf.Format("%ༀ%d") @test_throws Printf.InvalidFormatStringError Printf.Format("%\U1ffff%d") @test Printf.@sprintf("%10.5d", 4) == " 00004" @test Printf.@sprintf("%d", typemax(Int64)) == "9223372036854775807" for (fmt, val) = (("%7.2f", " 1.23"), ("%-7.2f", "1.23 "), ("%07.2f", "0001.23"), ("%.0f", "1"), ("%#.0f", "1."), ("%.4e", "1.2345e+00"), ("%.4E", "1.2345E+00"), ("%.2a", "0x1.3cp+0"), ("%.2A", "0X1.3CP+0")), num = (1.2345, 1.234499999999999999999999999999999999999999999999999999999999999999999999999991) @test Printf.format(Printf.Format(fmt), num) == val end for (fmt, val) = (("%i", "42"), ("%u", "42"), ("Test: %i", "Test: 42"), ("%#x", "0x2a"), ("%x", "2a"), ("%X", "2A"), ("% i", " 42"), ("%+i", "+42"), ("%4i", " 42"), ("%-4i", "42 "), ("%f", "42.000000"), ("%g", "42"), ("%e", "4.200000e+01")), num = (UInt16(42), UInt32(42), UInt64(42), UInt128(42), Int16(42), Int32(42), Int64(42), Int128(42), 42) @test Printf.format(Printf.Format(fmt), num) == val end for i = ((42, "", "i", "42", ""), (42, "", "d", "42", ""), (42, "", "u", "42", ""), (42, "", "x", "2a", ""), (42, "", "X", "2A", ""), (42, "", "o", "52", ""), (42, "#", "x", "2a", "0x"), (42, "#", "X", "2A", "0X"), (42, "#", "o", "052", ""), (1.2345, "", ".2f", "1.23", ""), (1.2345, "", ".2e", "1.23e+00", ""), (1.2345, "", ".2E", "1.23E+00", ""), (1.2345, "#", ".0f", "1.", ""), (1.2345, "#", ".0e", "1.e+00", ""), (1.2345, "#", ".0E", "1.E+00", ""), (1.2345, "", ".2a", "1.3cp+0", "0x"), (1.2345, "", ".2A", "1.3CP+0", "0X")) _test_flags(i...) _test_flags(-(i[1]), i[2:5]...) end @test Printf.@sprintf("Test: %s%c%C%c%#-.0f.", "t", 65, 66, 67, -42) == "Test: tABC-42.." @test Printf.@sprintf("%f %d %d %f", 1.0, [3 4]..., 5) == "1.000000 3 4 5.000000" @test Printf.@sprintf("%s %f %9.5f %d %d %d %d%d%d%d", [1:6;]..., [7, 8, 9, 10]...) == "1 2.000000 3.00000 4 5 6 78910" @test Printf.@sprintf("%s %s %s %d %d %d %f %f %f", Any[10 ^ x + y for x = 1:3, y = 1:3]...) == "11 101 1001 12 102 1002 13.000000 103.000000 1003.000000" @test Printf.@sprintf("%s %s %s %d %d %d %f %f %f %s %s %s %d %d %d %f %f %f", Any[10x + (x + 1) for x = 1:18]...) == "12 23 34 45 56 67 78.000000 89.000000 100.000000 111 122 133 144 155 166 177.000000 188.000000 199.000000" @test (Printf.@sprintf("%.330f", BigFloat(1)))[var"end"] != '\0' @test Printf.@sprintf("%f", parse(BigFloat, "1e400")) == "10000000000000000000000000000000000000000000000000000000000000000000000000000025262527574416492004687051900140830217136998040684679611623086405387447100385714565637522507383770691831689647535911648520404034824470543643098638520633064715221151920028135130764414460468236314621044034960475540018328999334468948008954289495190631358190153259681118693204411689043999084305348398480210026863210192871358464.000000" @test_throws ArgumentError Printf.@sprintf("%f", parse(BigFloat, "1e99999")) @test Printf.@sprintf("%4.2s", "a") == " a" @test Printf.@sprintf("%12.3e", pi * 1.0e100) == " 3.142e+100" @test string((Printf.Format("%a")).formats[1]) == "%a" @test string((Printf.Format("%a")).formats[1]; modifier = "R") == "%Ra" @test Printf.@sprintf("%d", 3.14) == "3" @test Printf.@sprintf("%2d", 3.14) == " 3" @test Printf.@sprintf("%2d", big(3.14)) == " 3" @test Printf.@sprintf("%s", 1) == "1" @test Printf.@sprintf("%f", 1) == "1.000000" @test Printf.@sprintf("%e", 1) == "1.000000e+00" @test Printf.@sprintf("%g", 1) == "1" @test Printf.@sprintf("%.16g", 194.4778127560983) == "194.4778127560983" @test Printf.@sprintf("%.17g", 194.4778127560983) == "194.4778127560983" @test Printf.@sprintf("%.18g", 194.4778127560983) == "194.477812756098302" @test Printf.@sprintf("%.1g", 1.7976931348623157e308) == "2e+308" @test Printf.@sprintf("%.2g", 1.7976931348623157e308) == "1.8e+308" @test Printf.@sprintf("%.3g", 1.7976931348623157e308) == "1.8e+308" @test_throws ArgumentError @sprintf("%s%%%s", "a") @test @sprintf("%s%%%s", "a", "b") == "a%b" @test @sprintf("%d", 25.5) == "26" @test @sprintf(" %.1e\n", 0.999) == " 1.0e+00\n" @test @sprintf(" %.1f", 9.999) == " 10.0" @test @sprintf("%d", 1.0e100) == "10000000000000000159028911097599180468360808563945281389781327557747838772170381060813469985856815104" @test @sprintf("%d", 3 // 1) == "3" @test @sprintf("%d", Inf) == "Inf" @test @sprintf(" %d", NaN) == " NaN" @test Printf.@sprintf("") == "" @test Printf.format(Printf.Format("")) == "" end @testset "integers" begin @test Printf.@sprintf("% d", 42) == " 42" @test Printf.@sprintf("% d", -42) == "-42" @test Printf.@sprintf("% 5d", 42) == " 42" @test Printf.@sprintf("% 5d", -42) == " -42" @test Printf.@sprintf("% 15d", 42) == " 42" @test Printf.@sprintf("% 15d", -42) == " -42" @test Printf.@sprintf("%+d", 42) == "+42" @test Printf.@sprintf("%+d", -42) == "-42" @test Printf.@sprintf("%+5d", 42) == " +42" @test Printf.@sprintf("%+5d", -42) == " -42" @test Printf.@sprintf("%+15d", 42) == " +42" @test Printf.@sprintf("%+15d", -42) == " -42" @test Printf.@sprintf("%0d", 42) == "42" @test Printf.@sprintf("%0d", -42) == "-42" @test Printf.@sprintf("%05d", 42) == "00042" @test Printf.@sprintf("%05d", -42) == "-0042" @test Printf.@sprintf("%015d", 42) == "000000000000042" @test Printf.@sprintf("%015d", -42) == "-00000000000042" @test Printf.@sprintf("%-d", 42) == "42" @test Printf.@sprintf("%-d", -42) == "-42" @test Printf.@sprintf("%-5d", 42) == "42 " @test Printf.@sprintf("%-5d", -42) == "-42 " @test Printf.@sprintf("%-15d", 42) == "42 " @test Printf.@sprintf("%-15d", -42) == "-42 " @test Printf.@sprintf("%-0d", 42) == "42" @test Printf.@sprintf("%-0d", -42) == "-42" @test Printf.@sprintf("%-05d", 42) == "42 " @test Printf.@sprintf("%-05d", -42) == "-42 " @test Printf.@sprintf("%-015d", 42) == "42 " @test Printf.@sprintf("%-015d", -42) == "-42 " @test Printf.@sprintf("%0-d", 42) == "42" @test Printf.@sprintf("%0-d", -42) == "-42" @test Printf.@sprintf("%0-5d", 42) == "42 " @test Printf.@sprintf("%0-5d", -42) == "-42 " @test Printf.@sprintf("%0-15d", 42) == "42 " @test Printf.@sprintf("%0-15d", -42) == "-42 " @test_throws Printf.InvalidFormatStringError Printf.Format("%d %") @test Printf.@sprintf("%lld", 18446744065119617025) == "18446744065119617025" @test Printf.@sprintf("%+8lld", 100) == " +100" @test Printf.@sprintf("%+.8lld", 100) == "+00000100" @test Printf.@sprintf("%+10.8lld", 100) == " +00000100" @test_throws Printf.InvalidFormatStringError Printf.Format("%_1lld") @test Printf.@sprintf("%-1.5lld", -100) == "-00100" @test Printf.@sprintf("%5lld", 100) == " 100" @test Printf.@sprintf("%5lld", -100) == " -100" @test Printf.@sprintf("%-5lld", 100) == "100 " @test Printf.@sprintf("%-5lld", -100) == "-100 " @test Printf.@sprintf("%-.5lld", 100) == "00100" @test Printf.@sprintf("%-.5lld", -100) == "-00100" @test Printf.@sprintf("%-8.5lld", 100) == "00100 " @test Printf.@sprintf("%-8.5lld", -100) == "-00100 " @test Printf.@sprintf("%05lld", 100) == "00100" @test Printf.@sprintf("%05lld", -100) == "-0100" @test Printf.@sprintf("% lld", 100) == " 100" @test Printf.@sprintf("% lld", -100) == "-100" @test Printf.@sprintf("% 5lld", 100) == " 100" @test Printf.@sprintf("% 5lld", -100) == " -100" @test Printf.@sprintf("% .5lld", 100) == " 00100" @test Printf.@sprintf("% .5lld", -100) == "-00100" @test Printf.@sprintf("% 8.5lld", 100) == " 00100" @test Printf.@sprintf("% 8.5lld", -100) == " -00100" @test Printf.@sprintf("%.0lld", 0) == "0" @test Printf.@sprintf("%#+21.18llx", -100) == "-0x000000000000000064" @test Printf.@sprintf("%#.25llo", -100) == "-00000000000000000000000144" @test Printf.@sprintf("%#+24.20llo", -100) == " -000000000000000000144" @test Printf.@sprintf("%#+18.21llX", -100) == "-0X000000000000000000064" @test Printf.@sprintf("%#+20.24llo", -100) == "-0000000000000000000000144" @test Printf.@sprintf("%#+25.22llu", -1) == " -0000000000000000000001" @test Printf.@sprintf("%#+25.22llu", -1) == " -0000000000000000000001" @test Printf.@sprintf("%#+30.25llu", -1) == " -0000000000000000000000001" @test Printf.@sprintf("%+#25.22lld", -1) == " -0000000000000000000001" @test Printf.@sprintf("%#-8.5llo", 100) == "000144 " @test Printf.@sprintf("%#-+ 08.5lld", 100) == "+00100 " @test Printf.@sprintf("%#-+ 08.5lld", 100) == "+00100 " @test Printf.@sprintf("%.40lld", 1) == "0000000000000000000000000000000000000001" @test Printf.@sprintf("% .40lld", 1) == " 0000000000000000000000000000000000000001" @test Printf.@sprintf("% .40d", 1) == " 0000000000000000000000000000000000000001" @test Printf.@sprintf("%lld", 18446744065119617025) == "18446744065119617025" @test Printf.@sprintf("+%d+", 10) == "+10+" @test Printf.@sprintf("%#012x", 1) == "0x0000000001" @test Printf.@sprintf("%#04.8x", 1) == "0x00000001" @test Printf.@sprintf("%#-08.2x", 1) == "0x01 " @test Printf.@sprintf("%#08o", 1) == "00000001" @test Printf.@sprintf("%d", 1024) == "1024" @test Printf.@sprintf("%d", -1024) == "-1024" @test Printf.@sprintf("%i", 1024) == "1024" @test Printf.@sprintf("%i", -1024) == "-1024" @test Printf.@sprintf("%u", 1024) == "1024" @test Printf.@sprintf("%u", UInt(4294966272)) == "4294966272" @test Printf.@sprintf("%o", 511) == "777" @test Printf.@sprintf("%o", UInt(4294966785)) == "37777777001" @test Printf.@sprintf("%x", 305441741) == "1234abcd" @test Printf.@sprintf("%x", UInt(3989525555)) == "edcb5433" @test Printf.@sprintf("%X", 305441741) == "1234ABCD" @test Printf.@sprintf("%X", UInt(3989525555)) == "EDCB5433" @test Printf.@sprintf("%+d", 1024) == "+1024" @test Printf.@sprintf("%+d", -1024) == "-1024" @test Printf.@sprintf("%+i", 1024) == "+1024" @test Printf.@sprintf("%+i", -1024) == "-1024" @test Printf.@sprintf("%+u", 1024) == "+1024" @test Printf.@sprintf("%+u", UInt(4294966272)) == "+4294966272" @test Printf.@sprintf("%+o", 511) == "+777" @test Printf.@sprintf("%+o", UInt(4294966785)) == "+37777777001" @test Printf.@sprintf("%+x", 305441741) == "+1234abcd" @test Printf.@sprintf("%+x", UInt(3989525555)) == "+edcb5433" @test Printf.@sprintf("%+X", 305441741) == "+1234ABCD" @test Printf.@sprintf("%+X", UInt(3989525555)) == "+EDCB5433" @test Printf.@sprintf("% d", 1024) == " 1024" @test Printf.@sprintf("% d", -1024) == "-1024" @test Printf.@sprintf("% i", 1024) == " 1024" @test Printf.@sprintf("% i", -1024) == "-1024" @test Printf.@sprintf("% u", 1024) == " 1024" @test Printf.@sprintf("% u", UInt(4294966272)) == " 4294966272" @test Printf.@sprintf("% o", 511) == " 777" @test Printf.@sprintf("% o", UInt(4294966785)) == " 37777777001" @test Printf.@sprintf("% x", 305441741) == " 1234abcd" @test Printf.@sprintf("% x", UInt(3989525555)) == " edcb5433" @test Printf.@sprintf("% X", 305441741) == " 1234ABCD" @test Printf.@sprintf("% X", UInt(3989525555)) == " EDCB5433" @test Printf.@sprintf("%+ d", 1024) == "+1024" @test Printf.@sprintf("%+ d", -1024) == "-1024" @test Printf.@sprintf("%+ i", 1024) == "+1024" @test Printf.@sprintf("%+ i", -1024) == "-1024" @test Printf.@sprintf("%+ u", 1024) == "+1024" @test Printf.@sprintf("%+ u", UInt(4294966272)) == "+4294966272" @test Printf.@sprintf("%+ o", 511) == "+777" @test Printf.@sprintf("%+ o", UInt(4294966785)) == "+37777777001" @test Printf.@sprintf("%+ x", 305441741) == "+1234abcd" @test Printf.@sprintf("%+ x", UInt(3989525555)) == "+edcb5433" @test Printf.@sprintf("%+ X", 305441741) == "+1234ABCD" @test Printf.@sprintf("%+ X", UInt(3989525555)) == "+EDCB5433" @test Printf.@sprintf("%#o", 511) == "0777" @test Printf.@sprintf("%#o", UInt(4294966785)) == "037777777001" @test Printf.@sprintf("%#x", 305441741) == "0x1234abcd" @test Printf.@sprintf("%#x", UInt(3989525555)) == "0xedcb5433" @test Printf.@sprintf("%#X", 305441741) == "0X1234ABCD" @test Printf.@sprintf("%#X", UInt(3989525555)) == "0XEDCB5433" @test Printf.@sprintf("%#o", UInt(0)) == "00" @test Printf.@sprintf("%#x", UInt(0)) == "0x0" @test Printf.@sprintf("%#X", UInt(0)) == "0X0" @test Printf.@sprintf("%1d", 1024) == "1024" @test Printf.@sprintf("%1d", -1024) == "-1024" @test Printf.@sprintf("%1i", 1024) == "1024" @test Printf.@sprintf("%1i", -1024) == "-1024" @test Printf.@sprintf("%1u", 1024) == "1024" @test Printf.@sprintf("%1u", UInt(4294966272)) == "4294966272" @test Printf.@sprintf("%1o", 511) == "777" @test Printf.@sprintf("%1o", UInt(4294966785)) == "37777777001" @test Printf.@sprintf("%1x", 305441741) == "1234abcd" @test Printf.@sprintf("%1x", UInt(3989525555)) == "edcb5433" @test Printf.@sprintf("%1X", 305441741) == "1234ABCD" @test Printf.@sprintf("%1X", UInt(3989525555)) == "EDCB5433" @test Printf.@sprintf("%20d", 1024) == " 1024" @test Printf.@sprintf("%20d", -1024) == " -1024" @test Printf.@sprintf("%20i", 1024) == " 1024" @test Printf.@sprintf("%20i", -1024) == " -1024" @test Printf.@sprintf("%20u", 1024) == " 1024" @test Printf.@sprintf("%20u", UInt(4294966272)) == " 4294966272" @test Printf.@sprintf("%20o", 511) == " 777" @test Printf.@sprintf("%20o", UInt(4294966785)) == " 37777777001" @test Printf.@sprintf("%20x", 305441741) == " 1234abcd" @test Printf.@sprintf("%20x", UInt(3989525555)) == " edcb5433" @test Printf.@sprintf("%20X", 305441741) == " 1234ABCD" @test Printf.@sprintf("%20X", UInt(3989525555)) == " EDCB5433" @test Printf.@sprintf("%-20d", 1024) == "1024 " @test Printf.@sprintf("%-20d", -1024) == "-1024 " @test Printf.@sprintf("%-20i", 1024) == "1024 " @test Printf.@sprintf("%-20i", -1024) == "-1024 " @test Printf.@sprintf("%-20u", 1024) == "1024 " @test Printf.@sprintf("%-20u", UInt(4294966272)) == "4294966272 " @test Printf.@sprintf("%-20o", 511) == "777 " @test Printf.@sprintf("%-20o", UInt(4294966785)) == "37777777001 " @test Printf.@sprintf("%-20x", 305441741) == "1234abcd " @test Printf.@sprintf("%-20x", UInt(3989525555)) == "edcb5433 " @test Printf.@sprintf("%-20X", 305441741) == "1234ABCD " @test Printf.@sprintf("%-20X", UInt(3989525555)) == "EDCB5433 " @test Printf.@sprintf("%020d", 1024) == "00000000000000001024" @test Printf.@sprintf("%020d", -1024) == "-0000000000000001024" @test Printf.@sprintf("%020i", 1024) == "00000000000000001024" @test Printf.@sprintf("%020i", -1024) == "-0000000000000001024" @test Printf.@sprintf("%020u", 1024) == "00000000000000001024" @test Printf.@sprintf("%020u", UInt(4294966272)) == "00000000004294966272" @test Printf.@sprintf("%020o", 511) == "00000000000000000777" @test Printf.@sprintf("%020o", UInt(4294966785)) == "00000000037777777001" @test Printf.@sprintf("%020x", 305441741) == "0000000000001234abcd" @test Printf.@sprintf("%020x", UInt(3989525555)) == "000000000000edcb5433" @test Printf.@sprintf("%020X", 305441741) == "0000000000001234ABCD" @test Printf.@sprintf("%020X", UInt(3989525555)) == "000000000000EDCB5433" @test Printf.@sprintf("%#20o", 511) == " 0777" @test Printf.@sprintf("%#20o", UInt(4294966785)) == " 037777777001" @test Printf.@sprintf("%#20x", 305441741) == " 0x1234abcd" @test Printf.@sprintf("%#20x", UInt(3989525555)) == " 0xedcb5433" @test Printf.@sprintf("%#20X", 305441741) == " 0X1234ABCD" @test Printf.@sprintf("%#20X", UInt(3989525555)) == " 0XEDCB5433" @test Printf.@sprintf("%#020o", 511) == "00000000000000000777" @test Printf.@sprintf("%#020o", UInt(4294966785)) == "00000000037777777001" @test Printf.@sprintf("%#020x", 305441741) == "0x00000000001234abcd" @test Printf.@sprintf("%#020x", UInt(3989525555)) == "0x0000000000edcb5433" @test Printf.@sprintf("%#020X", 305441741) == "0X00000000001234ABCD" @test Printf.@sprintf("%#020X", UInt(3989525555)) == "0X0000000000EDCB5433" @test Printf.@sprintf("%0-20d", 1024) == "1024 " @test Printf.@sprintf("%0-20d", -1024) == "-1024 " @test Printf.@sprintf("%0-20i", 1024) == "1024 " @test Printf.@sprintf("%0-20i", -1024) == "-1024 " @test Printf.@sprintf("%0-20u", 1024) == "1024 " @test Printf.@sprintf("%0-20u", UInt(4294966272)) == "4294966272 " @test Printf.@sprintf("%-020o", 511) == "777 " @test Printf.@sprintf("%-020o", UInt(4294966785)) == "37777777001 " @test Printf.@sprintf("%-020x", 305441741) == "1234abcd " @test Printf.@sprintf("%-020x", UInt(3989525555)) == "edcb5433 " @test Printf.@sprintf("%-020X", 305441741) == "1234ABCD " @test Printf.@sprintf("%-020X", UInt(3989525555)) == "EDCB5433 " @test Printf.@sprintf("%.20d", 1024) == "00000000000000001024" @test Printf.@sprintf("%.20d", -1024) == "-00000000000000001024" @test Printf.@sprintf("%.20i", 1024) == "00000000000000001024" @test Printf.@sprintf("%.20i", -1024) == "-00000000000000001024" @test Printf.@sprintf("%.20u", 1024) == "00000000000000001024" @test Printf.@sprintf("%.20u", UInt(4294966272)) == "00000000004294966272" @test Printf.@sprintf("%.20o", 511) == "00000000000000000777" @test Printf.@sprintf("%.20o", UInt(4294966785)) == "00000000037777777001" @test Printf.@sprintf("%.20x", 305441741) == "0000000000001234abcd" @test Printf.@sprintf("%.20x", UInt(3989525555)) == "000000000000edcb5433" @test Printf.@sprintf("%.20X", 305441741) == "0000000000001234ABCD" @test Printf.@sprintf("%.20X", UInt(3989525555)) == "000000000000EDCB5433" @test Printf.@sprintf("%20.5d", 1024) == " 01024" @test Printf.@sprintf("%20.5d", -1024) == " -01024" @test Printf.@sprintf("%20.5i", 1024) == " 01024" @test Printf.@sprintf("%20.5i", -1024) == " -01024" @test Printf.@sprintf("%20.5u", 1024) == " 01024" @test Printf.@sprintf("%20.5u", UInt(4294966272)) == " 4294966272" @test Printf.@sprintf("%20.5o", 511) == " 00777" @test Printf.@sprintf("%20.5o", UInt(4294966785)) == " 37777777001" @test Printf.@sprintf("%20.5x", 305441741) == " 1234abcd" @test Printf.@sprintf("%20.10x", UInt(3989525555)) == " 00edcb5433" @test Printf.@sprintf("%20.5X", 305441741) == " 1234ABCD" @test Printf.@sprintf("%20.10X", UInt(3989525555)) == " 00EDCB5433" @test Printf.@sprintf("%020.5d", 1024) == " 01024" @test Printf.@sprintf("%020.5d", -1024) == " -01024" @test Printf.@sprintf("%020.5i", 1024) == " 01024" @test Printf.@sprintf("%020.5i", -1024) == " -01024" @test Printf.@sprintf("%020.5u", 1024) == " 01024" @test Printf.@sprintf("%020.5u", UInt(4294966272)) == " 4294966272" @test Printf.@sprintf("%020.5o", 511) == " 00777" @test Printf.@sprintf("%020.5o", UInt(4294966785)) == " 37777777001" @test Printf.@sprintf("%020.5x", 305441741) == " 1234abcd" @test Printf.@sprintf("%020.10x", UInt(3989525555)) == " 00edcb5433" @test Printf.@sprintf("%020.5X", 305441741) == " 1234ABCD" @test Printf.@sprintf("%020.10X", UInt(3989525555)) == " 00EDCB5433" @test Printf.@sprintf("%20.0d", 1024) == " 1024" @test Printf.@sprintf("%20.d", -1024) == " -1024" @test Printf.@sprintf("%20.d", 0) == " 0" @test Printf.@sprintf("%20.0i", 1024) == " 1024" @test Printf.@sprintf("%20.i", -1024) == " -1024" @test Printf.@sprintf("%20.i", 0) == " 0" @test Printf.@sprintf("%20.u", 1024) == " 1024" @test Printf.@sprintf("%20.0u", UInt(4294966272)) == " 4294966272" @test Printf.@sprintf("%20.u", UInt(0)) == " 0" @test Printf.@sprintf("%20.o", 511) == " 777" @test Printf.@sprintf("%20.0o", UInt(4294966785)) == " 37777777001" @test Printf.@sprintf("%20.o", UInt(0)) == " 0" @test Printf.@sprintf("%20.x", 305441741) == " 1234abcd" @test Printf.@sprintf("%20.0x", UInt(3989525555)) == " edcb5433" @test Printf.@sprintf("%20.x", UInt(0)) == " 0" @test Printf.@sprintf("%20.X", 305441741) == " 1234ABCD" @test Printf.@sprintf("%20.0X", UInt(3989525555)) == " EDCB5433" @test Printf.@sprintf("%20.X", UInt(0)) == " 0" @test Printf.@sprintf("%4d", typemin(Int8)) == "-128" @test Printf.@sprintf("%4d", typemax(Int8)) == " 127" @test Printf.@sprintf("%6d", typemin(Int16)) == "-32768" @test Printf.@sprintf("%6d", typemax(Int16)) == " 32767" @test Printf.@sprintf("%11d", typemin(Int32)) == "-2147483648" @test Printf.@sprintf("%11d", typemax(Int32)) == " 2147483647" @test Printf.@sprintf("%20d", typemin(Int64)) == "-9223372036854775808" @test Printf.@sprintf("%20d", typemax(Int64)) == " 9223372036854775807" @test Printf.@sprintf("%40d", typemin(Int128)) == "-170141183460469231731687303715884105728" @test Printf.@sprintf("%40d", typemax(Int128)) == " 170141183460469231731687303715884105727" end @testset "%n" begin x = Ref{Int}() @test begin Printf.@sprintf "%d4%n" 123 x x[] == 4 end @test begin Printf.@sprintf "%s%n" "😉" x x[] == 4 end @test begin Printf.@sprintf "%s%n" "1234" x x[] == 4 end end @testset "dynamic" begin @test Printf.@sprintf("%*d", 10, 12) == " 12" @test Printf.@sprintf("%.*d", 4, 12) == "0012" @test Printf.@sprintf("%*.*d", 10, 4, 12) == " 0012" @test Printf.@sprintf("%+*.*d", 10, 4, 12) == " +0012" @test Printf.@sprintf("%0*.*d", 10, 4, 12) == " 0012" @test Printf.@sprintf("%*d%*d%*d", 4, 12, 4, 13, 4, 14) == " 12 13 14" @test Printf.@sprintf("%*d%*d%*d", 4, 12, 5, 13, 6, 14) == " 12 13 14" @test Printf.@sprintf("%*p", 20, 0) == Printf.@sprintf("%20p", 0) @test Printf.@sprintf("%-*p", 20, 0) == Printf.@sprintf("%-20p", 0) @test Printf.@sprintf("%*p", 20, C_NULL) == Printf.@sprintf("%20p", C_NULL) @test Printf.@sprintf("%-*p", 20, C_NULL) == Printf.@sprintf("%-20p", C_NULL) @test Printf.@sprintf("%.*a", 0, 3.14) == Printf.@sprintf("%.0a", 3.14) @test Printf.@sprintf("%.*a", 1, 3.14) == Printf.@sprintf("%.1a", 3.14) @test Printf.@sprintf("%.*a", 2, 3.14) == Printf.@sprintf("%.2a", 3.14) @test Printf.@sprintf("%#.*a", 0, 3.14) == Printf.@sprintf("%#.0a", 3.14) @test Printf.@sprintf("%#.*a", 1, 3.14) == Printf.@sprintf("%#.1a", 3.14) @test Printf.@sprintf("%#.*a", 2, 3.14) == Printf.@sprintf("%#.2a", 3.14) @test Printf.@sprintf("%.*a", 6, 1.5) == Printf.@sprintf("%.6a", 1.5) @test Printf.@sprintf("%*.*g", 10, 5, -123.4) == Printf.@sprintf("%10.5g", -123.4) @test Printf.@sprintf("%0*.*g", 10, 5, -123.4) == Printf.@sprintf("%010.5g", -123.4) @test Printf.@sprintf("%.*g", 6, 1.234e7) == Printf.@sprintf("%.6g", 1.234e7) @test Printf.@sprintf("%#.*g", 6, 1.234e7) == Printf.@sprintf("%#.6g", 1.234e7) @test Printf.@sprintf("%*.*g", 10, 5, -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) == Printf.@sprintf("%10.5g", -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) @test Printf.@sprintf("%0*.*g", 10, 5, -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) == Printf.@sprintf("%010.5g", -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) @test Printf.@sprintf("%.*g", 6, 1.234e7) == Printf.@sprintf("%.6g", 1.234e7) @test Printf.@sprintf("%#.*g", 6, 1.234e7) == Printf.@sprintf("%#.6g", 1.234e7) @test Printf.@sprintf("%.*g", 5, 42) == Printf.@sprintf("%.5g", 42) @test Printf.@sprintf("%#.*g", 2, 42) == Printf.@sprintf("%#.2g", 42) @test Printf.@sprintf("%#.*g", 5, 42) == Printf.@sprintf("%#.5g", 42) @test Printf.@sprintf("%.*g", 15, 0) == Printf.@sprintf("%.15g", 0) @test Printf.@sprintf("%#.*g", 15, 0) == Printf.@sprintf("%#.15g", 0) @test Printf.@sprintf("%.*f", 0, 3.0e142) == Printf.@sprintf("%.0f", 3.0e142) @test Printf.@sprintf("%.*f", 2, 1.234) == Printf.@sprintf("%.2f", 1.234) @test Printf.@sprintf("%.*f", 2, 1.235) == Printf.@sprintf("%.2f", 1.235) @test Printf.@sprintf("%.*f", 2, 0.235) == Printf.@sprintf("%.2f", 0.235) @test Printf.@sprintf("%*.*f", 4, 1, 1.234) == Printf.@sprintf("%4.1f", 1.234) @test Printf.@sprintf("%*.*f", 8, 1, 1.234) == Printf.@sprintf("%8.1f", 1.234) @test Printf.@sprintf("%+*.*f", 8, 1, 1.234) == Printf.@sprintf("%+8.1f", 1.234) @test Printf.@sprintf("% *.*f", 8, 1, 1.234) == Printf.@sprintf("% 8.1f", 1.234) @test Printf.@sprintf("% *.*f", 7, 1, 1.234) == Printf.@sprintf("% 7.1f", 1.234) @test Printf.@sprintf("% 0*.*f", 8, 1, 1.234) == Printf.@sprintf("% 08.1f", 1.234) @test Printf.@sprintf("%0*.*f", 8, 1, 1.234) == Printf.@sprintf("%08.1f", 1.234) @test Printf.@sprintf("%-0*.*f", 8, 1, 1.234) == Printf.@sprintf("%-08.1f", 1.234) @test Printf.@sprintf("%-*.*f", 8, 1, 1.234) == Printf.@sprintf("%-8.1f", 1.234) @test Printf.@sprintf("%0*.*f", 8, 1, -1.234) == Printf.@sprintf("%08.1f", -1.234) @test Printf.@sprintf("%0*.*f", 9, 1, -1.234) == Printf.@sprintf("%09.1f", -1.234) @test Printf.@sprintf("%0*.*f", 9, 1, 1.234) == Printf.@sprintf("%09.1f", 1.234) @test Printf.@sprintf("%+0*.*f", 9, 1, 1.234) == Printf.@sprintf("%+09.1f", 1.234) @test Printf.@sprintf("% 0*.*f", 9, 1, 1.234) == Printf.@sprintf("% 09.1f", 1.234) @test Printf.@sprintf("%+ 0*.*f", 9, 1, 1.234) == Printf.@sprintf("%+ 09.1f", 1.234) @test Printf.@sprintf("%+ 0*.*f", 9, 1, 1.234) == Printf.@sprintf("%+ 09.1f", 1.234) @test Printf.@sprintf("%+ 0*.*f", 9, 0, 1.234) == Printf.@sprintf("%+ 09.0f", 1.234) @test Printf.@sprintf("%+ #0*.*f", 9, 0, 1.234) == Printf.@sprintf("%+ #09.0f", 1.234) @test Printf.@sprintf("%*.*e", 10, 4, Inf) == Printf.@sprintf("%10.4e", Inf) @test Printf.@sprintf("%*.*e", 10, 4, NaN) == Printf.@sprintf("%10.4e", NaN) @test Printf.@sprintf("%*.*e", 10, 4, Inf) == Printf.@sprintf("%10.4e", Inf) @test Printf.@sprintf("%*.*e", 10, 4, NaN) == Printf.@sprintf("%10.4e", NaN) @test Printf.@sprintf("%.*e", 0, 3.0e142) == Printf.@sprintf("%.0e", 3.0e142) @test Printf.@sprintf("%#.*e", 0, 3.0e142) == Printf.@sprintf("%#.0e", 3.0e142) @test Printf.@sprintf("%.*e", 0, 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) == Printf.@sprintf("%.0e", 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) @test Printf.@sprintf("%#.*e", 0, 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) == Printf.@sprintf("%#.0e", 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) @test Printf.@sprintf("%.*e", 0, 3.000000000000000000000000000000000000000000000000000000000000000000000000000024e1042) == Printf.@sprintf("%.0e", 3.000000000000000000000000000000000000000000000000000000000000000000000000000024e1042) @test Printf.@sprintf("%.*e", 2, 1.234) == Printf.@sprintf("%.2e", 1.234) @test Printf.@sprintf("%.*e", 2, 1.235) == Printf.@sprintf("%.2e", 1.235) @test Printf.@sprintf("%.*e", 2, 0.235) == Printf.@sprintf("%.2e", 0.235) @test Printf.@sprintf("%*.*e", 4, 1, 1.234) == Printf.@sprintf("%4.1e", 1.234) @test Printf.@sprintf("%*.*e", 8, 1, 1.234) == Printf.@sprintf("%8.1e", 1.234) @test Printf.@sprintf("%+*.*e", 8, 1, 1.234) == Printf.@sprintf("%+8.1e", 1.234) @test Printf.@sprintf("% *.*e", 8, 1, 1.234) == Printf.@sprintf("% 8.1e", 1.234) @test Printf.@sprintf("% *.*e", 7, 1, 1.234) == Printf.@sprintf("% 7.1e", 1.234) @test Printf.@sprintf("% 0*.*e", 8, 1, 1.234) == Printf.@sprintf("% 08.1e", 1.234) @test Printf.@sprintf("%0*.*e", 8, 1, 1.234) == Printf.@sprintf("%08.1e", 1.234) @test Printf.@sprintf("%-0*.*e", 8, 1, 1.234) == Printf.@sprintf("%-08.1e", 1.234) @test Printf.@sprintf("%-*.*e", 8, 1, 1.234) == Printf.@sprintf("%-8.1e", 1.234) @test Printf.@sprintf("%-*.*e", 8, 1, 1.234) == Printf.@sprintf("%-8.1e", 1.234) @test Printf.@sprintf("%0*.*e", 8, 1, -1.234) == Printf.@sprintf("%08.1e", -1.234) @test Printf.@sprintf("%0*.*e", 9, 1, -1.234) == Printf.@sprintf("%09.1e", -1.234) @test Printf.@sprintf("%0*.*e", 9, 1, 1.234) == Printf.@sprintf("%09.1e", 1.234) @test Printf.@sprintf("%+0*.*e", 9, 1, 1.234) == Printf.@sprintf("%+09.1e", 1.234) @test Printf.@sprintf("% 0*.*e", 9, 1, 1.234) == Printf.@sprintf("% 09.1e", 1.234) @test Printf.@sprintf("%+ 0*.*e", 9, 1, 1.234) == Printf.@sprintf("%+ 09.1e", 1.234) @test Printf.@sprintf("%+ 0*.*e", 9, 1, 1.234) == Printf.@sprintf("%+ 09.1e", 1.234) @test Printf.@sprintf("%+ 0*.*e", 9, 0, 1.234) == Printf.@sprintf("%+ 09.0e", 1.234) @test Printf.@sprintf("%+ #0*.*e", 9, 0, 1.234) == Printf.@sprintf("%+ #09.0e", 1.234) @test Printf.@sprintf("%.*s", 1, "foo") == Printf.@sprintf("%.1s", "foo") @test Printf.@sprintf("%*s", 1, "Hallo heimur") == Printf.@sprintf("%1s", "Hallo heimur") @test Printf.@sprintf("%*s", 20, "Hallo") == Printf.@sprintf("%20s", "Hallo") @test Printf.@sprintf("%-*s", 20, "Hallo") == Printf.@sprintf("%-20s", "Hallo") @test Printf.@sprintf("%0-*s", 20, "Hallo") == Printf.@sprintf("%0-20s", "Hallo") @test Printf.@sprintf("%.*s", 20, "Hallo heimur") == Printf.@sprintf("%.20s", "Hallo heimur") @test Printf.@sprintf("%*.*s", 20, 5, "Hallo heimur") == Printf.@sprintf("%20.5s", "Hallo heimur") @test Printf.@sprintf("%.*s", 0, "Hallo heimur") == Printf.@sprintf("%.0s", "Hallo heimur") @test Printf.@sprintf("%*.*s", 20, 0, "Hallo heimur") == Printf.@sprintf("%20.0s", "Hallo heimur") @test Printf.@sprintf("%.s", "Hallo heimur") == Printf.@sprintf("%.s", "Hallo heimur") @test Printf.@sprintf("%*.s", 20, "Hallo heimur") == Printf.@sprintf("%20.s", "Hallo heimur") @test Printf.@sprintf("%*sø", 4, "ø") == Printf.@sprintf("%4sø", "ø") @test Printf.@sprintf("%-*sø", 4, "ø") == Printf.@sprintf("%-4sø", "ø") @test Printf.@sprintf("%*s", 8, "test") == Printf.@sprintf("%8s", "test") @test Printf.@sprintf("%-*s", 8, "test") == Printf.@sprintf("%-8s", "test") @test Printf.@sprintf("%#*s", 8, :test) == Printf.@sprintf("%#8s", :test) @test Printf.@sprintf("%#-*s", 8, :test) == Printf.@sprintf("%#-8s", :test) @test Printf.@sprintf("%*.*s", 8, 3, "test") == Printf.@sprintf("%8.3s", "test") @test Printf.@sprintf("%#*.*s", 8, 3, "test") == Printf.@sprintf("%#8.3s", "test") @test Printf.@sprintf("%-*.*s", 8, 3, "test") == Printf.@sprintf("%-8.3s", "test") @test Printf.@sprintf("%#-*.*s", 8, 3, "test") == Printf.@sprintf("%#-8.3s", "test") @test Printf.@sprintf("%.*s", 3, "test") == Printf.@sprintf("%.3s", "test") @test Printf.@sprintf("%#.*s", 3, "test") == Printf.@sprintf("%#.3s", "test") @test Printf.@sprintf("%-.*s", 3, "test") == Printf.@sprintf("%-.3s", "test") @test Printf.@sprintf("%#-.*s", 3, "test") == Printf.@sprintf("%#-.3s", "test") @test Printf.@sprintf("%*c", 3, 'a') == Printf.@sprintf("%3c", 'a') @test Printf.@sprintf("%*c", 1, 'x') == Printf.@sprintf("%1c", 'x') @test Printf.@sprintf("%*c", 20, 'x') == Printf.@sprintf("%20c", 'x') @test Printf.@sprintf("%-*c", 20, 'x') == Printf.@sprintf("%-20c", 'x') @test Printf.@sprintf("%-0*c", 20, 'x') == Printf.@sprintf("%-020c", 'x') @test Printf.@sprintf("%*c", 3, 'A') == Printf.@sprintf("%3c", 'A') @test Printf.@sprintf("%-*c", 3, 'A') == Printf.@sprintf("%-3c", 'A') @test Printf.@sprintf("%*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f", 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345) == Printf.@sprintf("%4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f", 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345) @test (Printf.@sprintf("%.*f", 330, BigFloat(1)))[var"end"] != '\0' @test Printf.@sprintf("%*.*s", 4, 2, "a") == Printf.@sprintf("%4.2s", "a") @test Printf.@sprintf("%*.*e", 12, 3, pi * 1.0e100) == Printf.@sprintf("%12.3e", pi * 1.0e100) @test Printf.@sprintf("%*d", 2, 3.14) == Printf.@sprintf("%*d", 2, 3.14) @test Printf.@sprintf("%*d", 2, big(3.14)) == Printf.@sprintf("%*d", 2, big(3.14)) @test Printf.@sprintf(" %.*e\n", 1, 0.999) == Printf.@sprintf(" %.1e\n", 0.999) @test Printf.@sprintf(" %.*f", 1, 9.999) == Printf.@sprintf(" %.1f", 9.999) @test Printf.@sprintf("%*d", 10, 12) == Printf.@sprintf("%10d", 12) @test Printf.@sprintf("%.*d", 4, 12) == Printf.@sprintf("%.4d", 12) @test Printf.@sprintf("%*.*d", 10, 4, 12) == Printf.@sprintf("%10.4d", 12) @test Printf.@sprintf("%+*.*d", 10, 4, 12) == Printf.@sprintf("%+10.4d", 12) @test Printf.@sprintf("%0*.*d", 10, 4, 12) == Printf.@sprintf("%010.4d", 12) @test Printf.@sprintf("% *d", 5, 42) == Printf.@sprintf("% 5d", 42) @test Printf.@sprintf("% *d", 5, -42) == Printf.@sprintf("% 5d", -42) @test Printf.@sprintf("% *d", 15, 42) == Printf.@sprintf("% 15d", 42) @test Printf.@sprintf("% *d", 15, -42) == Printf.@sprintf("% 15d", -42) @test Printf.@sprintf("%+*d", 5, 42) == Printf.@sprintf("%+5d", 42) @test Printf.@sprintf("%+*d", 5, -42) == Printf.@sprintf("%+5d", -42) @test Printf.@sprintf("%+*d", 15, 42) == Printf.@sprintf("%+15d", 42) @test Printf.@sprintf("%+*d", 15, -42) == Printf.@sprintf("%+15d", -42) @test Printf.@sprintf("%*d", 0, 42) == Printf.@sprintf("%0d", 42) @test Printf.@sprintf("%*d", 0, -42) == Printf.@sprintf("%0d", -42) @test Printf.@sprintf("%-*d", 5, 42) == Printf.@sprintf("%-5d", 42) @test Printf.@sprintf("%-*d", 5, -42) == Printf.@sprintf("%-5d", -42) @test Printf.@sprintf("%-*d", 15, 42) == Printf.@sprintf("%-15d", 42) @test Printf.@sprintf("%-*d", 15, -42) == Printf.@sprintf("%-15d", -42) @test Printf.@sprintf("%+*lld", 8, 100) == Printf.@sprintf("%+8lld", 100) @test Printf.@sprintf("%+.*lld", 8, 100) == Printf.@sprintf("%+.8lld", 100) @test Printf.@sprintf("%+*.*lld", 10, 8, 100) == Printf.@sprintf("%+10.8lld", 100) @test Printf.@sprintf("%-*.*lld", 1, 5, -100) == Printf.@sprintf("%-1.5lld", -100) @test Printf.@sprintf("%*lld", 5, 100) == Printf.@sprintf("%5lld", 100) @test Printf.@sprintf("%*lld", 5, -100) == Printf.@sprintf("%5lld", -100) @test Printf.@sprintf("%-*lld", 5, 100) == Printf.@sprintf("%-5lld", 100) @test Printf.@sprintf("%-*lld", 5, -100) == Printf.@sprintf("%-5lld", -100) @test Printf.@sprintf("%-.*lld", 5, 100) == Printf.@sprintf("%-.5lld", 100) @test Printf.@sprintf("%-.*lld", 5, -100) == Printf.@sprintf("%-.5lld", -100) @test Printf.@sprintf("%-*.*lld", 8, 5, 100) == Printf.@sprintf("%-8.5lld", 100) @test Printf.@sprintf("%-*.*lld", 8, 5, -100) == Printf.@sprintf("%-8.5lld", -100) @test Printf.@sprintf("%0*lld", 5, 100) == Printf.@sprintf("%05lld", 100) @test Printf.@sprintf("%0*lld", 5, -100) == Printf.@sprintf("%05lld", -100) @test Printf.@sprintf("% *lld", 5, 100) == Printf.@sprintf("% 5lld", 100) @test Printf.@sprintf("% *lld", 5, -100) == Printf.@sprintf("% 5lld", -100) @test Printf.@sprintf("% .*lld", 5, 100) == Printf.@sprintf("% .5lld", 100) @test Printf.@sprintf("% .*lld", 5, -100) == Printf.@sprintf("% .5lld", -100) @test Printf.@sprintf("% *.*lld", 8, 5, 100) == Printf.@sprintf("% 8.5lld", 100) @test Printf.@sprintf("% *.*lld", 8, 5, -100) == Printf.@sprintf("% 8.5lld", -100) @test Printf.@sprintf("%.*lld", 0, 0) == Printf.@sprintf("%.0lld", 0) @test Printf.@sprintf("%#+*.*llx", 21, 18, -100) == Printf.@sprintf("%#+21.18llx", -100) @test Printf.@sprintf("%#.*llo", 25, -100) == Printf.@sprintf("%#.25llo", -100) @test Printf.@sprintf("%#+*.*llo", 24, 20, -100) == Printf.@sprintf("%#+24.20llo", -100) @test Printf.@sprintf("%#+*.*llX", 18, 21, -100) == Printf.@sprintf("%#+18.21llX", -100) @test Printf.@sprintf("%#+*.*llo", 20, 24, -100) == Printf.@sprintf("%#+20.24llo", -100) @test Printf.@sprintf("%#+*.*llu", 25, 22, -1) == Printf.@sprintf("%#+25.22llu", -1) @test Printf.@sprintf("%#+*.*llu", 30, 25, -1) == Printf.@sprintf("%#+30.25llu", -1) @test Printf.@sprintf("%+#*.*lld", 25, 22, -1) == Printf.@sprintf("%+#25.22lld", -1) @test Printf.@sprintf("%#-*.*llo", 8, 5, 100) == Printf.@sprintf("%#-8.5llo", 100) @test Printf.@sprintf("%#-+ 0*.*lld", 8, 5, 100) == Printf.@sprintf("%#-+ 08.5lld", 100) @test Printf.@sprintf("%#-+ 0*.*lld", 8, 5, 100) == Printf.@sprintf("%#-+ 08.5lld", 100) @test Printf.@sprintf("%.*lld", 40, 1) == Printf.@sprintf("%.40lld", 1) @test Printf.@sprintf("% .*lld", 40, 1) == Printf.@sprintf("% .40lld", 1) @test Printf.@sprintf("% .*d", 40, 1) == Printf.@sprintf("% .40d", 1) @test Printf.@sprintf("%#0*x", 12, 1) == Printf.@sprintf("%#012x", 1) @test Printf.@sprintf("%#0*.*x", 4, 8, 1) == Printf.@sprintf("%#04.8x", 1) @test Printf.@sprintf("%#-0*.*x", 8, 2, 1) == Printf.@sprintf("%#-08.2x", 1) @test Printf.@sprintf("%#0*o", 8, 1) == Printf.@sprintf("%#08o", 1) @test Printf.@sprintf("%*d", 20, 1024) == Printf.@sprintf("%20d", 1024) @test Printf.@sprintf("%*d", 20, -1024) == Printf.@sprintf("%20d", -1024) @test Printf.@sprintf("%*i", 20, 1024) == Printf.@sprintf("%20i", 1024) @test Printf.@sprintf("%*i", 20, -1024) == Printf.@sprintf("%20i", -1024) @test Printf.@sprintf("%*u", 20, 1024) == Printf.@sprintf("%20u", 1024) @test Printf.@sprintf("%*u", 20, UInt(4294966272)) == Printf.@sprintf("%20u", UInt(4294966272)) @test Printf.@sprintf("%*o", 20, 511) == Printf.@sprintf("%20o", 511) @test Printf.@sprintf("%*o", 20, UInt(4294966785)) == Printf.@sprintf("%20o", UInt(4294966785)) @test Printf.@sprintf("%*x", 20, 305441741) == Printf.@sprintf("%20x", 305441741) @test Printf.@sprintf("%*x", 20, UInt(3989525555)) == Printf.@sprintf("%20x", UInt(3989525555)) @test Printf.@sprintf("%*X", 20, 305441741) == Printf.@sprintf("%20X", 305441741) @test Printf.@sprintf("%*X", 20, UInt(3989525555)) == Printf.@sprintf("%20X", UInt(3989525555)) @test Printf.@sprintf("%-*d", 20, 1024) == Printf.@sprintf("%-20d", 1024) @test Printf.@sprintf("%-*d", 20, -1024) == Printf.@sprintf("%-20d", -1024) @test Printf.@sprintf("%-*i", 20, 1024) == Printf.@sprintf("%-20i", 1024) @test Printf.@sprintf("%-*i", 20, -1024) == Printf.@sprintf("%-20i", -1024) @test Printf.@sprintf("%-*u", 20, 1024) == Printf.@sprintf("%-20u", 1024) @test Printf.@sprintf("%-*u", 20, UInt(4294966272)) == Printf.@sprintf("%-20u", UInt(4294966272)) @test Printf.@sprintf("%-*o", 20, 511) == Printf.@sprintf("%-20o", 511) @test Printf.@sprintf("%-*o", 20, UInt(4294966785)) == Printf.@sprintf("%-20o", UInt(4294966785)) @test Printf.@sprintf("%-*x", 20, 305441741) == Printf.@sprintf("%-20x", 305441741) @test Printf.@sprintf("%-*x", 20, UInt(3989525555)) == Printf.@sprintf("%-20x", UInt(3989525555)) @test Printf.@sprintf("%-*X", 20, 305441741) == Printf.@sprintf("%-20X", 305441741) @test Printf.@sprintf("%-*X", 20, UInt(3989525555)) == Printf.@sprintf("%-20X", UInt(3989525555)) @test Printf.@sprintf("%0*d", 20, 1024) == Printf.@sprintf("%020d", 1024) @test Printf.@sprintf("%0*d", 20, -1024) == Printf.@sprintf("%020d", -1024) @test Printf.@sprintf("%0*i", 20, 1024) == Printf.@sprintf("%020i", 1024) @test Printf.@sprintf("%0*i", 20, -1024) == Printf.@sprintf("%020i", -1024) @test Printf.@sprintf("%0*u", 20, 1024) == Printf.@sprintf("%020u", 1024) @test Printf.@sprintf("%0*u", 20, UInt(4294966272)) == Printf.@sprintf("%020u", UInt(4294966272)) @test Printf.@sprintf("%0*o", 20, 511) == Printf.@sprintf("%020o", 511) @test Printf.@sprintf("%0*o", 20, UInt(4294966785)) == Printf.@sprintf("%020o", UInt(4294966785)) @test Printf.@sprintf("%0*x", 20, 305441741) == Printf.@sprintf("%020x", 305441741) @test Printf.@sprintf("%0*x", 20, UInt(3989525555)) == Printf.@sprintf("%020x", UInt(3989525555)) @test Printf.@sprintf("%0*X", 20, 305441741) == Printf.@sprintf("%020X", 305441741) @test Printf.@sprintf("%0*X", 20, UInt(3989525555)) == Printf.@sprintf("%020X", UInt(3989525555)) @test Printf.@sprintf("%#*o", 20, 511) == Printf.@sprintf("%#20o", 511) @test Printf.@sprintf("%#*o", 20, UInt(4294966785)) == Printf.@sprintf("%#20o", UInt(4294966785)) @test Printf.@sprintf("%#*x", 20, 305441741) == Printf.@sprintf("%#20x", 305441741) @test Printf.@sprintf("%#*x", 20, UInt(3989525555)) == Printf.@sprintf("%#20x", UInt(3989525555)) @test Printf.@sprintf("%#*X", 20, 305441741) == Printf.@sprintf("%#20X", 305441741) @test Printf.@sprintf("%#*X", 20, UInt(3989525555)) == Printf.@sprintf("%#20X", UInt(3989525555)) @test Printf.@sprintf("%#0*o", 20, 511) == Printf.@sprintf("%#020o", 511) @test Printf.@sprintf("%#0*o", 20, UInt(4294966785)) == Printf.@sprintf("%#020o", UInt(4294966785)) @test Printf.@sprintf("%#0*x", 20, 305441741) == Printf.@sprintf("%#020x", 305441741) @test Printf.@sprintf("%#0*x", 20, UInt(3989525555)) == Printf.@sprintf("%#020x", UInt(3989525555)) @test Printf.@sprintf("%#0*X", 20, 305441741) == Printf.@sprintf("%#020X", 305441741) @test Printf.@sprintf("%#0*X", 20, UInt(3989525555)) == Printf.@sprintf("%#020X", UInt(3989525555)) @test Printf.@sprintf("%0-*d", 20, 1024) == Printf.@sprintf("%0-20d", 1024) @test Printf.@sprintf("%0-*d", 20, -1024) == Printf.@sprintf("%0-20d", -1024) @test Printf.@sprintf("%0-*i", 20, 1024) == Printf.@sprintf("%0-20i", 1024) @test Printf.@sprintf("%0-*i", 20, -1024) == Printf.@sprintf("%0-20i", -1024) @test Printf.@sprintf("%0-*u", 20, 1024) == Printf.@sprintf("%0-20u", 1024) @test Printf.@sprintf("%0-*u", 20, UInt(4294966272)) == Printf.@sprintf("%0-20u", UInt(4294966272)) @test Printf.@sprintf("%-0*o", 20, 511) == Printf.@sprintf("%-020o", 511) @test Printf.@sprintf("%-0*o", 20, UInt(4294966785)) == Printf.@sprintf("%-020o", UInt(4294966785)) @test Printf.@sprintf("%-0*x", 20, 305441741) == Printf.@sprintf("%-020x", 305441741) @test Printf.@sprintf("%-0*x", 20, UInt(3989525555)) == Printf.@sprintf("%-020x", UInt(3989525555)) @test Printf.@sprintf("%-0*X", 20, 305441741) == Printf.@sprintf("%-020X", 305441741) @test Printf.@sprintf("%-0*X", 20, UInt(3989525555)) == Printf.@sprintf("%-020X", UInt(3989525555)) @test Printf.@sprintf("%.*d", 20, 1024) == Printf.@sprintf("%.20d", 1024) @test Printf.@sprintf("%.*d", 20, -1024) == Printf.@sprintf("%.20d", -1024) @test Printf.@sprintf("%.*i", 20, 1024) == Printf.@sprintf("%.20i", 1024) @test Printf.@sprintf("%.*i", 20, -1024) == Printf.@sprintf("%.20i", -1024) @test Printf.@sprintf("%.*u", 20, 1024) == Printf.@sprintf("%.20u", 1024) @test Printf.@sprintf("%.*u", 20, UInt(4294966272)) == Printf.@sprintf("%.20u", UInt(4294966272)) @test Printf.@sprintf("%.*o", 20, 511) == Printf.@sprintf("%.20o", 511) @test Printf.@sprintf("%.*o", 20, UInt(4294966785)) == Printf.@sprintf("%.20o", UInt(4294966785)) @test Printf.@sprintf("%.*x", 20, 305441741) == Printf.@sprintf("%.20x", 305441741) @test Printf.@sprintf("%.*x", 20, UInt(3989525555)) == Printf.@sprintf("%.20x", UInt(3989525555)) @test Printf.@sprintf("%.*X", 20, 305441741) == Printf.@sprintf("%.20X", 305441741) @test Printf.@sprintf("%.*X", 20, UInt(3989525555)) == Printf.@sprintf("%.20X", UInt(3989525555)) @test Printf.@sprintf("%*.*d", 20, 5, 1024) == Printf.@sprintf("%20.5d", 1024) @test Printf.@sprintf("%*.*d", 20, 5, -1024) == Printf.@sprintf("%20.5d", -1024) @test Printf.@sprintf("%*.*i", 20, 5, 1024) == Printf.@sprintf("%20.5i", 1024) @test Printf.@sprintf("%*.*i", 20, 5, -1024) == Printf.@sprintf("%20.5i", -1024) @test Printf.@sprintf("%*.*u", 20, 5, 1024) == Printf.@sprintf("%20.5u", 1024) @test Printf.@sprintf("%*.*u", 20, 5, UInt(4294966272)) == Printf.@sprintf("%20.5u", UInt(4294966272)) @test Printf.@sprintf("%*.*o", 20, 5, 511) == Printf.@sprintf("%20.5o", 511) @test Printf.@sprintf("%*.*o", 20, 5, UInt(4294966785)) == Printf.@sprintf("%20.5o", UInt(4294966785)) @test Printf.@sprintf("%*.*x", 20, 5, 305441741) == Printf.@sprintf("%20.5x", 305441741) @test Printf.@sprintf("%*.*x", 20, 10, UInt(3989525555)) == Printf.@sprintf("%20.10x", UInt(3989525555)) @test Printf.@sprintf("%*.*X", 20, 5, 305441741) == Printf.@sprintf("%20.5X", 305441741) @test Printf.@sprintf("%*.*X", 20, 10, UInt(3989525555)) == Printf.@sprintf("%20.10X", UInt(3989525555)) @test Printf.@sprintf("%0*.*d", 20, 5, 1024) == Printf.@sprintf("%020.5d", 1024) @test Printf.@sprintf("%0*.*d", 20, 5, -1024) == Printf.@sprintf("%020.5d", -1024) @test Printf.@sprintf("%0*.*i", 20, 5, 1024) == Printf.@sprintf("%020.5i", 1024) @test Printf.@sprintf("%0*.*i", 20, 5, -1024) == Printf.@sprintf("%020.5i", -1024) @test Printf.@sprintf("%0*.*u", 20, 5, 1024) == Printf.@sprintf("%020.5u", 1024) @test Printf.@sprintf("%0*.*u", 20, 5, UInt(4294966272)) == Printf.@sprintf("%020.5u", UInt(4294966272)) @test Printf.@sprintf("%0*.*o", 20, 5, 511) == Printf.@sprintf("%020.5o", 511) @test Printf.@sprintf("%0*.*o", 20, 5, UInt(4294966785)) == Printf.@sprintf("%020.5o", UInt(4294966785)) @test Printf.@sprintf("%0*.*x", 20, 5, 305441741) == Printf.@sprintf("%020.5x", 305441741) @test Printf.@sprintf("%0*.*x", 20, 10, UInt(3989525555)) == Printf.@sprintf("%020.10x", UInt(3989525555)) @test Printf.@sprintf("%0*.*X", 20, 5, 305441741) == Printf.@sprintf("%020.5X", 305441741) @test Printf.@sprintf("%0*.*X", 20, 10, UInt(3989525555)) == Printf.@sprintf("%020.10X", UInt(3989525555)) @test Printf.@sprintf("%*.0d", 20, 1024) == Printf.@sprintf("%20.0d", 1024) @test Printf.@sprintf("%*.d", 20, -1024) == Printf.@sprintf("%20.d", -1024) @test Printf.@sprintf("%*.d", 20, 0) == Printf.@sprintf("%20.d", 0) @test Printf.@sprintf("%*.0i", 20, 1024) == Printf.@sprintf("%20.0i", 1024) @test Printf.@sprintf("%*.i", 20, -1024) == Printf.@sprintf("%20.i", -1024) @test Printf.@sprintf("%*.i", 20, 0) == Printf.@sprintf("%20.i", 0) @test Printf.@sprintf("%*.u", 20, 1024) == Printf.@sprintf("%20.u", 1024) @test Printf.@sprintf("%*.0u", 20, UInt(4294966272)) == Printf.@sprintf("%20.0u", UInt(4294966272)) @test Printf.@sprintf("%*.u", 20, UInt(0)) == Printf.@sprintf("%20.u", UInt(0)) @test Printf.@sprintf("%*.o", 20, 511) == Printf.@sprintf("%20.o", 511) @test Printf.@sprintf("%*.0o", 20, UInt(4294966785)) == Printf.@sprintf("%20.0o", UInt(4294966785)) @test Printf.@sprintf("%*.o", 20, UInt(0)) == Printf.@sprintf("%20.o", UInt(0)) @test Printf.@sprintf("%*.x", 20, 305441741) == Printf.@sprintf("%20.x", 305441741) @test Printf.@sprintf("%*.0x", 20, UInt(3989525555)) == Printf.@sprintf("%20.0x", UInt(3989525555)) @test Printf.@sprintf("%*.x", 20, UInt(0)) == Printf.@sprintf("%20.x", UInt(0)) @test Printf.@sprintf("%*.X", 20, 305441741) == Printf.@sprintf("%20.X", 305441741) @test Printf.@sprintf("%*.0X", 20, UInt(3989525555)) == Printf.@sprintf("%20.0X", UInt(3989525555)) @test Printf.@sprintf("%*.X", 20, UInt(0)) == Printf.@sprintf("%20.X", UInt(0)) x = Ref{Int}() y = Ref{Int}() @test begin Printf.@sprintf "%10s%n" "😉" x Printf.@sprintf "%*s%n" 10 "😉" y x[] == y[] end @test begin Printf.@sprintf "%10s%n" "1234" x Printf.@sprintf "%*s%n" 10 "1234" y x[] == y[] end end @testset "length modifiers" begin @test_throws Printf.InvalidFormatStringError Printf.Format("%h") @test_throws Printf.InvalidFormatStringError Printf.Format("%hh") @test_throws Printf.InvalidFormatStringError Printf.Format("%z") end @testset "Docstrings" begin @test isempty(Docs.undocumented_names(Printf)) end @test @sprintf("%.160g", 1.38e-23) == "1.380000000000000060010582465734078799297660966782642624395399644741944111814291318296454846858978271484375e-23" end @testset "Printf" begin @testset "%p" begin if Sys.WORD_SIZE == 64 @test Printf.@sprintf("%20p", 0) == " 0x0000000000000000" @test Printf.@sprintf("%-20p", 0) == "0x0000000000000000 " @test Printf.@sprintf("%20p", C_NULL) == " 0x0000000000000000" @test @sprintf("%-20p", C_NULL) == "0x0000000000000000 " elseif Sys.WORD_SIZE == 32 @test Printf.@sprintf("%20p", 0) == " 0x00000000" @test Printf.@sprintf("%-20p", 0) == "0x00000000 " @test @sprintf("%20p", C_NULL) == " 0x00000000" @test @sprintf("%-20p", C_NULL) == "0x00000000 " end @test @sprintf("%p", 0xfffffffffffe0000) == "0xfffffffffffe0000" end @testset "%a" begin @test Printf.@sprintf("%a", 0.0) == "0x0p+0" @test Printf.@sprintf("%a", -0.0) == "-0x0p+0" @test Printf.@sprintf("%.3a", 0.0) == "0x0.000p+0" @test Printf.@sprintf("%a", 1.5) == "0x1.8p+0" @test Printf.@sprintf("%a", 1.5f0) == "0x1.8p+0" @test Printf.@sprintf("%a", 1.5) == "0x1.8p+0" @test Printf.@sprintf("%#.0a", 1.5) == "0x2.p+0" @test Printf.@sprintf("%+30a", 1 / 3) == " +0x1.5555555555555p-2" @test Printf.@sprintf("%a", 1.5) == "0x1.8p+0" @test Printf.@sprintf("%a", 3.14) == "0x1.91eb851eb851fp+1" @test Printf.@sprintf("%.0a", 3.14) == "0x2p+1" @test Printf.@sprintf("%.1a", 3.14) == "0x1.9p+1" @test Printf.@sprintf("%.2a", 3.14) == "0x1.92p+1" @test Printf.@sprintf("%#a", 3.14) == "0x1.91eb851eb851fp+1" @test Printf.@sprintf("%#.0a", 3.14) == "0x2.p+1" @test Printf.@sprintf("%#.1a", 3.14) == "0x1.9p+1" @test Printf.@sprintf("%#.2a", 3.14) == "0x1.92p+1" @test Printf.@sprintf("%.6a", 1.5) == "0x1.800000p+0" end @testset "%g" begin for (val, res) = ((1.2345678e7, "1.23457e+07"), (1.2345678e6, "1.23457e+06"), (123456.78, "123457"), (12345.678, "12345.7"), (1.234e7, "1.234e+07")) @test Printf.@sprintf("%.6g", val) == res end for (val, res) = ((1.2345678e7, "1.23457e+07"), (1.234567799999999999999999999999999999999999999999999999999999999999999999999993e6, "1.23457e+06"), (123456.7800000000000000000000000000000000000000000000000000000000000000000000004, "123457"), (12345.67800000000000000000000000000000000000000000000000000000000000000000000007, "12345.7")) @test Printf.@sprintf("%.6g", val) == res end for (fmt, val) = (("%10.5g", " 123.4"), ("%+10.5g", " +123.4"), ("% 10.5g", " 123.4"), ("%#10.5g", " 123.40"), ("%-10.5g", "123.4 "), ("%-+10.5g", "+123.4 "), ("%010.5g", "00000123.4")), num = (123.4, 123.4000000000000000000000000000000000000000000000000000000000000000000000000002) @test Printf.format(Printf.Format(fmt), num) == val end @test Printf.@sprintf("%10.5g", -123.4) == " -123.4" @test Printf.@sprintf("%010.5g", -123.4) == "-0000123.4" @test Printf.@sprintf("%.6g", 1.234e7) == "1.234e+07" @test Printf.@sprintf("%#.6g", 1.234e7) == "1.23400e+07" @test Printf.@sprintf("%10.5g", -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) == " -123.4" @test Printf.@sprintf("%010.5g", -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) == "-0000123.4" @test Printf.@sprintf("%.6g", 1.234e7) == "1.234e+07" @test Printf.@sprintf("%#.6g", 1.234e7) == "1.23400e+07" @test Printf.@sprintf("%.5g", 42) == "42" @test Printf.@sprintf("%#.2g", 42) == "42." @test Printf.@sprintf("%#.5g", 42) == "42.000" @test Printf.@sprintf("%g", 0.00012) == "0.00012" @test Printf.@sprintf("%g", 1.2e-5) == "1.2e-05" @test Printf.@sprintf("%g", 123456.7) == "123457" @test Printf.@sprintf("%g", 1.2345678e6) == "1.23457e+06" for (val, res) = ((Inf, "Inf"), (-Inf, "-Inf"), (NaN, "NaN"), (-NaN, "NaN")) @test Printf.@sprintf("%g", val) == res @test Printf.@sprintf("%G", val) == res end @test Printf.@sprintf("%.15g", 0) == "0" @test Printf.@sprintf("%#.15g", 0) == "0.00000000000000" end @testset "%f" begin @test Printf.@sprintf("%f", Inf) == "Inf" @test Printf.@sprintf("%+f", Inf) == "+Inf" @test Printf.@sprintf("% f", Inf) == " Inf" @test Printf.@sprintf("% #f", Inf) == " Inf" @test Printf.@sprintf("%07f", Inf) == " Inf" @test Printf.@sprintf("%f", -Inf) == "-Inf" @test Printf.@sprintf("%+f", -Inf) == "-Inf" @test Printf.@sprintf("%07f", -Inf) == " -Inf" @test Printf.@sprintf("%f", NaN) == "NaN" @test Printf.@sprintf("%+f", NaN) == "+NaN" @test Printf.@sprintf("% f", NaN) == " NaN" @test Printf.@sprintf("% #f", NaN) == " NaN" @test Printf.@sprintf("%07f", NaN) == " NaN" @test Printf.@sprintf("%e", Inf) == "Inf" @test Printf.@sprintf("%e", NaN) == "NaN" @test Printf.@sprintf("%.0f", 3.0e142) == "29999999999999997463140672961703247153805615792184250659629251954072073858354858644285983761764971823910371920726635399393477049701891710124032" @test Printf.@sprintf("%f", 1.234) == "1.234000" @test Printf.@sprintf("%F", 1.234) == "1.234000" @test Printf.@sprintf("%+f", 1.234) == "+1.234000" @test Printf.@sprintf("% f", 1.234) == " 1.234000" @test Printf.@sprintf("%f", -1.234) == "-1.234000" @test Printf.@sprintf("%+f", -1.234) == "-1.234000" @test Printf.@sprintf("% f", -1.234) == "-1.234000" @test Printf.@sprintf("%#f", 1.234) == "1.234000" @test Printf.@sprintf("%.2f", 1.234) == "1.23" @test Printf.@sprintf("%.2f", 1.235) == "1.24" @test Printf.@sprintf("%.2f", 0.235) == "0.23" @test Printf.@sprintf("%4.1f", 1.234) == " 1.2" @test Printf.@sprintf("%8.1f", 1.234) == " 1.2" @test Printf.@sprintf("%+8.1f", 1.234) == " +1.2" @test Printf.@sprintf("% 8.1f", 1.234) == " 1.2" @test Printf.@sprintf("% 7.1f", 1.234) == " 1.2" @test Printf.@sprintf("% 08.1f", 1.234) == " 00001.2" @test Printf.@sprintf("%08.1f", 1.234) == "000001.2" @test Printf.@sprintf("%-08.1f", 1.234) == "1.2 " @test Printf.@sprintf("%-8.1f", 1.234) == "1.2 " @test Printf.@sprintf("%08.1f", -1.234) == "-00001.2" @test Printf.@sprintf("%09.1f", -1.234) == "-000001.2" @test Printf.@sprintf("%09.1f", 1.234) == "0000001.2" @test Printf.@sprintf("%+09.1f", 1.234) == "+000001.2" @test Printf.@sprintf("% 09.1f", 1.234) == " 000001.2" @test Printf.@sprintf("%+ 09.1f", 1.234) == "+000001.2" @test Printf.@sprintf("%+ 09.1f", 1.234) == "+000001.2" @test Printf.@sprintf("%+ 09.0f", 1.234) == "+00000001" @test Printf.@sprintf("%+ #09.0f", 1.234) == "+0000001." @test Printf.@sprintf("%+7.1f", 9.96) == " +10.0" @test Printf.@sprintf("% 7.1f", 9.96) == " 10.0" end @testset "%e" begin @test Printf.@sprintf("%e", Inf) == "Inf" @test Printf.@sprintf("%+e", Inf) == "+Inf" @test Printf.@sprintf("% e", Inf) == " Inf" @test Printf.@sprintf("% #e", Inf) == " Inf" @test Printf.@sprintf("%07e", Inf) == " Inf" @test Printf.@sprintf("%e", -Inf) == "-Inf" @test Printf.@sprintf("%+e", -Inf) == "-Inf" @test Printf.@sprintf("%07e", -Inf) == " -Inf" @test Printf.@sprintf("%e", NaN) == "NaN" @test Printf.@sprintf("%+e", NaN) == "+NaN" @test Printf.@sprintf("% e", NaN) == " NaN" @test Printf.@sprintf("% #e", NaN) == " NaN" @test Printf.@sprintf("%07e", NaN) == " NaN" @test Printf.@sprintf("%e", Inf) == "Inf" @test Printf.@sprintf("%e", NaN) == "NaN" @test Printf.@sprintf("%.0e", 3.0e142) == "3e+142" @test Printf.@sprintf("%#.0e", 3.0e142) == "3.e+142" @test Printf.@sprintf("%.0e", 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) == "3e+142" @test Printf.@sprintf("%#.0e", 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) == "3.e+142" @test Printf.@sprintf("%.0e", 3.000000000000000000000000000000000000000000000000000000000000000000000000000024e1042) == "3e+1042" @test Printf.@sprintf("%e", 3.0e42) == "3.000000e+42" @test Printf.@sprintf("%E", 3.0e42) == "3.000000E+42" @test Printf.@sprintf("%e", 3.0e-42) == "3.000000e-42" @test Printf.@sprintf("%E", 3.0e-42) == "3.000000E-42" @test Printf.@sprintf("%e", 1.234) == "1.234000e+00" @test Printf.@sprintf("%E", 1.234) == "1.234000E+00" @test Printf.@sprintf("%+e", 1.234) == "+1.234000e+00" @test Printf.@sprintf("% e", 1.234) == " 1.234000e+00" @test Printf.@sprintf("%e", -1.234) == "-1.234000e+00" @test Printf.@sprintf("%+e", -1.234) == "-1.234000e+00" @test Printf.@sprintf("% e", -1.234) == "-1.234000e+00" @test Printf.@sprintf("%#e", 1.234) == "1.234000e+00" @test Printf.@sprintf("%.2e", 1.234) == "1.23e+00" @test Printf.@sprintf("%.2e", 1.235) == "1.24e+00" @test Printf.@sprintf("%.2e", 0.235) == "2.35e-01" @test Printf.@sprintf("%4.1e", 1.234) == "1.2e+00" @test Printf.@sprintf("%8.1e", 1.234) == " 1.2e+00" @test Printf.@sprintf("%+8.1e", 1.234) == "+1.2e+00" @test Printf.@sprintf("% 8.1e", 1.234) == " 1.2e+00" @test Printf.@sprintf("% 7.1e", 1.234) == " 1.2e+00" @test Printf.@sprintf("% 08.1e", 1.234) == " 1.2e+00" @test Printf.@sprintf("%08.1e", 1.234) == "01.2e+00" @test Printf.@sprintf("%-08.1e", 1.234) == "1.2e+00 " @test Printf.@sprintf("%-8.1e", 1.234) == "1.2e+00 " @test Printf.@sprintf("%-8.1e", 1.234) == "1.2e+00 " @test Printf.@sprintf("%08.1e", -1.234) == "-1.2e+00" @test Printf.@sprintf("%09.1e", -1.234) == "-01.2e+00" @test Printf.@sprintf("%09.1e", 1.234) == "001.2e+00" @test Printf.@sprintf("%+09.1e", 1.234) == "+01.2e+00" @test Printf.@sprintf("% 09.1e", 1.234) == " 01.2e+00" @test Printf.@sprintf("%+ 09.1e", 1.234) == "+01.2e+00" @test Printf.@sprintf("%+ 09.1e", 1.234) == "+01.2e+00" @test Printf.@sprintf("%+ 09.0e", 1.234) == "+0001e+00" @test Printf.@sprintf("%+ #09.0e", 1.234) == "+001.e+00" @test Printf.@sprintf("%+9.1e", 9.96) == " +1.0e+01" @test Printf.@sprintf("% 9.1e", 9.96) == " 1.0e+01" end @testset "strings" begin @test Printf.@sprintf("Hallo heimur") == "Hallo heimur" @test Printf.@sprintf("+%s+", "hello") == "+hello+" @test Printf.@sprintf("%.1s", "foo") == "f" @test Printf.@sprintf("%s", "%%%%") == "%%%%" @test Printf.@sprintf("%s", "Hallo heimur") == "Hallo heimur" @test Printf.@sprintf("%+s", "Hallo heimur") == "Hallo heimur" @test Printf.@sprintf("% s", "Hallo heimur") == "Hallo heimur" @test Printf.@sprintf("%+ s", "Hallo heimur") == "Hallo heimur" @test Printf.@sprintf("%1s", "Hallo heimur") == "Hallo heimur" @test Printf.@sprintf("%20s", "Hallo") == " Hallo" @test Printf.@sprintf("%-20s", "Hallo") == "Hallo " @test Printf.@sprintf("%0-20s", "Hallo") == "Hallo " @test Printf.@sprintf("%.20s", "Hallo heimur") == "Hallo heimur" @test Printf.@sprintf("%20.5s", "Hallo heimur") == " Hallo" @test Printf.@sprintf("%.0s", "Hallo heimur") == "" @test Printf.@sprintf("%20.0s", "Hallo heimur") == " " @test Printf.@sprintf("%.s", "Hallo heimur") == "" @test Printf.@sprintf("%20.s", "Hallo heimur") == " " @test Printf.@sprintf("%s", "test") == "test" @test Printf.@sprintf("%s", "tést") == "tést" @test Printf.@sprintf("ø%sø", "hey") == "øheyø" @test Printf.@sprintf("%4sø", "ø") == " øø" @test Printf.@sprintf("%-4sø", "ø") == "ø ø" @test Printf.@sprintf("%8s", "test") == " test" @test Printf.@sprintf("%-8s", "test") == "test " @test Printf.@sprintf("%s", :test) == "test" @test Printf.@sprintf("%#s", :test) == ":test" @test Printf.@sprintf("%#8s", :test) == " :test" @test Printf.@sprintf("%#-8s", :test) == ":test " @test Printf.@sprintf("%8.3s", "test") == " tes" @test Printf.@sprintf("%#8.3s", "test") == " \"te" @test Printf.@sprintf("%-8.3s", "test") == "tes " @test Printf.@sprintf("%#-8.3s", "test") == "\"te " @test Printf.@sprintf("%.3s", "test") == "tes" @test Printf.@sprintf("%#.3s", "test") == "\"te" @test Printf.@sprintf("%-.3s", "test") == "tes" @test Printf.@sprintf("%#-.3s", "test") == "\"te" @test Printf.@sprintf("%.2s", "föó") == "fö" @test Printf.@sprintf("%5s", "föó") == " föó" @test Printf.@sprintf("%6s", "😍🍕") == " 😍🍕" @test Printf.@sprintf("%2c", '🍕') == "🍕" @test Printf.@sprintf("%3c", '🍕') == " 🍕" end @testset "chars" begin @test Printf.@sprintf("%c", 'a') == "a" @test Printf.@sprintf("%c", 32) == " " @test Printf.@sprintf("%c", 36) == "\$" @test Printf.@sprintf("%3c", 'a') == " a" @test Printf.@sprintf("%c", 'x') == "x" @test Printf.@sprintf("%+c", 'x') == "x" @test Printf.@sprintf("% c", 'x') == "x" @test Printf.@sprintf("%+ c", 'x') == "x" @test Printf.@sprintf("%1c", 'x') == "x" @test Printf.@sprintf("%20c", 'x') == " x" @test Printf.@sprintf("%-20c", 'x') == "x " @test Printf.@sprintf("%-020c", 'x') == "x " @test Printf.@sprintf("%c", 65) == "A" @test Printf.@sprintf("%c", 'A') == "A" @test Printf.@sprintf("%3c", 'A') == " A" @test Printf.@sprintf("%-3c", 'A') == "A " @test Printf.@sprintf("%c", 248) == "ø" @test Printf.@sprintf("%c", 'ø') == "ø" @test Printf.@sprintf("%c", "ø") == "ø" @test Printf.@sprintf("%c", '𐀀') == "𐀀" end function _test_flags(val, vflag::AbstractString, fmt::AbstractString, res::AbstractString, prefix::AbstractString) vflag = string("%", vflag) space_fmt = string(length(res) + length(prefix) + 3, fmt) fsign = string(if val < 0 "-" else "+" end, prefix) nsign = string(if val < 0 "-" else " " end, prefix) osign = if val < 0 string("-", prefix) else string(prefix, "0") end esign = string(if val < 0 "-" else "" end, prefix) esignend = if val < 0 "" else " " end for (flag::AbstractString, ans::AbstractString) = (("", string(" ", nsign, res)), ("+", string(" ", fsign, res)), (" ", string(" ", nsign, res)), ("0", string(osign, "00", res)), ("-", string(esign, res, " ", esignend)), ("0+", string(fsign, "00", res)), ("0 ", string(nsign, "00", res)), ("-+", string(fsign, res, " ")), ("- ", string(nsign, res, " "))) fmt_string = string(vflag, flag, space_fmt) fmtd = Printf.format(Printf.Format(fmt_string), val) @test fmtd == ans end end @testset "basics" begin @test Printf.@sprintf("%%") == "%" @test Printf.@sprintf("1%%") == "1%" @test Printf.@sprintf("%%1") == "%1" @test Printf.@sprintf("1%%2") == "1%2" @test Printf.@sprintf("1%%%d", 2) == "1%2" @test Printf.@sprintf("1%%2%%3") == "1%2%3" @test Printf.@sprintf("GAP[%%]") == "GAP[%]" @test Printf.@sprintf("hey there") == "hey there" @test_throws Printf.InvalidFormatStringError Printf.Format("%+") @test_throws Printf.InvalidFormatStringError Printf.Format("%.") @test_throws Printf.InvalidFormatStringError Printf.Format("%.0") @test isempty((Printf.Format("%%")).formats) @test Printf.@sprintf("%d%d", 1, 2) == "12" @test Printf.@sprintf("%d%d", [1 2]...) == "12" @test Printf.@sprintf("X%d", 2) == "X2" @test Printf.@sprintf("Ð%d", 2) == "Ð2" @test Printf.@sprintf("ༀ%d", 2) == "ༀ2" @test Printf.@sprintf("\U1ffff%d", 2) == "\U0001ffff2" @test Printf.@sprintf("%dX%d", 1, 2) == "1X2" @test Printf.@sprintf("%dÐ%d", 1, 2) == "1Ð2" @test Printf.@sprintf("%dༀ%d", 1, 2) == "1ༀ2" @test Printf.@sprintf("%d\U1ffff%d", 1, 2) == "1\U0001ffff2" @test Printf.@sprintf("%d∃%dȃ", 1, 2) == "1∃2ȃ" @test_throws Printf.InvalidFormatStringError Printf.Format("%y%d") @test_throws Printf.InvalidFormatStringError Printf.Format("%Ð%d") @test_throws Printf.InvalidFormatStringError Printf.Format("%ༀ%d") @test_throws Printf.InvalidFormatStringError Printf.Format("%\U1ffff%d") @test Printf.@sprintf("%10.5d", 4) == " 00004" @test Printf.@sprintf("%d", typemax(Int64)) == "9223372036854775807" for (fmt, val) = (("%7.2f", " 1.23"), ("%-7.2f", "1.23 "), ("%07.2f", "0001.23"), ("%.0f", "1"), ("%#.0f", "1."), ("%.4e", "1.2345e+00"), ("%.4E", "1.2345E+00"), ("%.2a", "0x1.3cp+0"), ("%.2A", "0X1.3CP+0")), num = (1.2345, 1.234499999999999999999999999999999999999999999999999999999999999999999999999991) @test Printf.format(Printf.Format(fmt), num) == val end for (fmt, val) = (("%i", "42"), ("%u", "42"), ("Test: %i", "Test: 42"), ("%#x", "0x2a"), ("%x", "2a"), ("%X", "2A"), ("% i", " 42"), ("%+i", "+42"), ("%4i", " 42"), ("%-4i", "42 "), ("%f", "42.000000"), ("%g", "42"), ("%e", "4.200000e+01")), num = (UInt16(42), UInt32(42), UInt64(42), UInt128(42), Int16(42), Int32(42), Int64(42), Int128(42), 42) @test Printf.format(Printf.Format(fmt), num) == val end for i = ((42, "", "i", "42", ""), (42, "", "d", "42", ""), (42, "", "u", "42", ""), (42, "", "x", "2a", ""), (42, "", "X", "2A", ""), (42, "", "o", "52", ""), (42, "#", "x", "2a", "0x"), (42, "#", "X", "2A", "0X"), (42, "#", "o", "052", ""), (1.2345, "", ".2f", "1.23", ""), (1.2345, "", ".2e", "1.23e+00", ""), (1.2345, "", ".2E", "1.23E+00", ""), (1.2345, "#", ".0f", "1.", ""), (1.2345, "#", ".0e", "1.e+00", ""), (1.2345, "#", ".0E", "1.E+00", ""), (1.2345, "", ".2a", "1.3cp+0", "0x"), (1.2345, "", ".2A", "1.3CP+0", "0X")) _test_flags(i...) _test_flags(-(i[1]), i[2:5]...) end @test Printf.@sprintf("Test: %s%c%C%c%#-.0f.", "t", 65, 66, 67, -42) == "Test: tABC-42.." @test Printf.@sprintf("%f %d %d %f", 1.0, [3 4]..., 5) == "1.000000 3 4 5.000000" @test Printf.@sprintf("%s %f %9.5f %d %d %d %d%d%d%d", [1:6;]..., [7, 8, 9, 10]...) == "1 2.000000 3.00000 4 5 6 78910" @test Printf.@sprintf("%s %s %s %d %d %d %f %f %f", Any[10 ^ x + y for x = 1:3, y = 1:3]...) == "11 101 1001 12 102 1002 13.000000 103.000000 1003.000000" @test Printf.@sprintf("%s %s %s %d %d %d %f %f %f %s %s %s %d %d %d %f %f %f", Any[10x + (x + 1) for x = 1:18]...) == "12 23 34 45 56 67 78.000000 89.000000 100.000000 111 122 133 144 155 166 177.000000 188.000000 199.000000" @test (Printf.@sprintf("%.330f", BigFloat(1)))[var"end"] != '\0' @test Printf.@sprintf("%f", parse(BigFloat, "1e400")) == "10000000000000000000000000000000000000000000000000000000000000000000000000000025262527574416492004687051900140830217136998040684679611623086405387447100385714565637522507383770691831689647535911648520404034824470543643098638520633064715221151920028135130764414460468236314621044034960475540018328999334468948008954289495190631358190153259681118693204411689043999084305348398480210026863210192871358464.000000" @test_throws ArgumentError Printf.@sprintf("%f", parse(BigFloat, "1e99999")) @test Printf.@sprintf("%4.2s", "a") == " a" @test Printf.@sprintf("%12.3e", pi * 1.0e100) == " 3.142e+100" @test string((Printf.Format("%a")).formats[1]) == "%a" @test string((Printf.Format("%a")).formats[1]; modifier = "R") == "%Ra" @test Printf.@sprintf("%d", 3.14) == "3" @test Printf.@sprintf("%2d", 3.14) == " 3" @test Printf.@sprintf("%2d", big(3.14)) == " 3" @test Printf.@sprintf("%s", 1) == "1" @test Printf.@sprintf("%f", 1) == "1.000000" @test Printf.@sprintf("%e", 1) == "1.000000e+00" @test Printf.@sprintf("%g", 1) == "1" @test Printf.@sprintf("%.16g", 194.4778127560983) == "194.4778127560983" @test Printf.@sprintf("%.17g", 194.4778127560983) == "194.4778127560983" @test Printf.@sprintf("%.18g", 194.4778127560983) == "194.477812756098302" @test Printf.@sprintf("%.1g", 1.7976931348623157e308) == "2e+308" @test Printf.@sprintf("%.2g", 1.7976931348623157e308) == "1.8e+308" @test Printf.@sprintf("%.3g", 1.7976931348623157e308) == "1.8e+308" @test_throws ArgumentError @sprintf("%s%%%s", "a") @test @sprintf("%s%%%s", "a", "b") == "a%b" @test @sprintf("%d", 25.5) == "26" @test @sprintf(" %.1e\n", 0.999) == " 1.0e+00\n" @test @sprintf(" %.1f", 9.999) == " 10.0" @test @sprintf("%d", 1.0e100) == "10000000000000000159028911097599180468360808563945281389781327557747838772170381060813469985856815104" @test @sprintf("%d", 3 // 1) == "3" @test @sprintf("%d", Inf) == "Inf" @test @sprintf(" %d", NaN) == " NaN" @test Printf.@sprintf("") == "" @test Printf.format(Printf.Format("")) == "" end @testset "integers" begin @test Printf.@sprintf("% d", 42) == " 42" @test Printf.@sprintf("% d", -42) == "-42" @test Printf.@sprintf("% 5d", 42) == " 42" @test Printf.@sprintf("% 5d", -42) == " -42" @test Printf.@sprintf("% 15d", 42) == " 42" @test Printf.@sprintf("% 15d", -42) == " -42" @test Printf.@sprintf("%+d", 42) == "+42" @test Printf.@sprintf("%+d", -42) == "-42" @test Printf.@sprintf("%+5d", 42) == " +42" @test Printf.@sprintf("%+5d", -42) == " -42" @test Printf.@sprintf("%+15d", 42) == " +42" @test Printf.@sprintf("%+15d", -42) == " -42" @test Printf.@sprintf("%0d", 42) == "42" @test Printf.@sprintf("%0d", -42) == "-42" @test Printf.@sprintf("%05d", 42) == "00042" @test Printf.@sprintf("%05d", -42) == "-0042" @test Printf.@sprintf("%015d", 42) == "000000000000042" @test Printf.@sprintf("%015d", -42) == "-00000000000042" @test Printf.@sprintf("%-d", 42) == "42" @test Printf.@sprintf("%-d", -42) == "-42" @test Printf.@sprintf("%-5d", 42) == "42 " @test Printf.@sprintf("%-5d", -42) == "-42 " @test Printf.@sprintf("%-15d", 42) == "42 " @test Printf.@sprintf("%-15d", -42) == "-42 " @test Printf.@sprintf("%-0d", 42) == "42" @test Printf.@sprintf("%-0d", -42) == "-42" @test Printf.@sprintf("%-05d", 42) == "42 " @test Printf.@sprintf("%-05d", -42) == "-42 " @test Printf.@sprintf("%-015d", 42) == "42 " @test Printf.@sprintf("%-015d", -42) == "-42 " @test Printf.@sprintf("%0-d", 42) == "42" @test Printf.@sprintf("%0-d", -42) == "-42" @test Printf.@sprintf("%0-5d", 42) == "42 " @test Printf.@sprintf("%0-5d", -42) == "-42 " @test Printf.@sprintf("%0-15d", 42) == "42 " @test Printf.@sprintf("%0-15d", -42) == "-42 " @test_throws Printf.InvalidFormatStringError Printf.Format("%d %") @test Printf.@sprintf("%lld", 18446744065119617025) == "18446744065119617025" @test Printf.@sprintf("%+8lld", 100) == " +100" @test Printf.@sprintf("%+.8lld", 100) == "+00000100" @test Printf.@sprintf("%+10.8lld", 100) == " +00000100" @test_throws Printf.InvalidFormatStringError Printf.Format("%_1lld") @test Printf.@sprintf("%-1.5lld", -100) == "-00100" @test Printf.@sprintf("%5lld", 100) == " 100" @test Printf.@sprintf("%5lld", -100) == " -100" @test Printf.@sprintf("%-5lld", 100) == "100 " @test Printf.@sprintf("%-5lld", -100) == "-100 " @test Printf.@sprintf("%-.5lld", 100) == "00100" @test Printf.@sprintf("%-.5lld", -100) == "-00100" @test Printf.@sprintf("%-8.5lld", 100) == "00100 " @test Printf.@sprintf("%-8.5lld", -100) == "-00100 " @test Printf.@sprintf("%05lld", 100) == "00100" @test Printf.@sprintf("%05lld", -100) == "-0100" @test Printf.@sprintf("% lld", 100) == " 100" @test Printf.@sprintf("% lld", -100) == "-100" @test Printf.@sprintf("% 5lld", 100) == " 100" @test Printf.@sprintf("% 5lld", -100) == " -100" @test Printf.@sprintf("% .5lld", 100) == " 00100" @test Printf.@sprintf("% .5lld", -100) == "-00100" @test Printf.@sprintf("% 8.5lld", 100) == " 00100" @test Printf.@sprintf("% 8.5lld", -100) == " -00100" @test Printf.@sprintf("%.0lld", 0) == "0" @test Printf.@sprintf("%#+21.18llx", -100) == "-0x000000000000000064" @test Printf.@sprintf("%#.25llo", -100) == "-00000000000000000000000144" @test Printf.@sprintf("%#+24.20llo", -100) == " -000000000000000000144" @test Printf.@sprintf("%#+18.21llX", -100) == "-0X000000000000000000064" @test Printf.@sprintf("%#+20.24llo", -100) == "-0000000000000000000000144" @test Printf.@sprintf("%#+25.22llu", -1) == " -0000000000000000000001" @test Printf.@sprintf("%#+25.22llu", -1) == " -0000000000000000000001" @test Printf.@sprintf("%#+30.25llu", -1) == " -0000000000000000000000001" @test Printf.@sprintf("%+#25.22lld", -1) == " -0000000000000000000001" @test Printf.@sprintf("%#-8.5llo", 100) == "000144 " @test Printf.@sprintf("%#-+ 08.5lld", 100) == "+00100 " @test Printf.@sprintf("%#-+ 08.5lld", 100) == "+00100 " @test Printf.@sprintf("%.40lld", 1) == "0000000000000000000000000000000000000001" @test Printf.@sprintf("% .40lld", 1) == " 0000000000000000000000000000000000000001" @test Printf.@sprintf("% .40d", 1) == " 0000000000000000000000000000000000000001" @test Printf.@sprintf("%lld", 18446744065119617025) == "18446744065119617025" @test Printf.@sprintf("+%d+", 10) == "+10+" @test Printf.@sprintf("%#012x", 1) == "0x0000000001" @test Printf.@sprintf("%#04.8x", 1) == "0x00000001" @test Printf.@sprintf("%#-08.2x", 1) == "0x01 " @test Printf.@sprintf("%#08o", 1) == "00000001" @test Printf.@sprintf("%d", 1024) == "1024" @test Printf.@sprintf("%d", -1024) == "-1024" @test Printf.@sprintf("%i", 1024) == "1024" @test Printf.@sprintf("%i", -1024) == "-1024" @test Printf.@sprintf("%u", 1024) == "1024" @test Printf.@sprintf("%u", UInt(4294966272)) == "4294966272" @test Printf.@sprintf("%o", 511) == "777" @test Printf.@sprintf("%o", UInt(4294966785)) == "37777777001" @test Printf.@sprintf("%x", 305441741) == "1234abcd" @test Printf.@sprintf("%x", UInt(3989525555)) == "edcb5433" @test Printf.@sprintf("%X", 305441741) == "1234ABCD" @test Printf.@sprintf("%X", UInt(3989525555)) == "EDCB5433" @test Printf.@sprintf("%+d", 1024) == "+1024" @test Printf.@sprintf("%+d", -1024) == "-1024" @test Printf.@sprintf("%+i", 1024) == "+1024" @test Printf.@sprintf("%+i", -1024) == "-1024" @test Printf.@sprintf("%+u", 1024) == "+1024" @test Printf.@sprintf("%+u", UInt(4294966272)) == "+4294966272" @test Printf.@sprintf("%+o", 511) == "+777" @test Printf.@sprintf("%+o", UInt(4294966785)) == "+37777777001" @test Printf.@sprintf("%+x", 305441741) == "+1234abcd" @test Printf.@sprintf("%+x", UInt(3989525555)) == "+edcb5433" @test Printf.@sprintf("%+X", 305441741) == "+1234ABCD" @test Printf.@sprintf("%+X", UInt(3989525555)) == "+EDCB5433" @test Printf.@sprintf("% d", 1024) == " 1024" @test Printf.@sprintf("% d", -1024) == "-1024" @test Printf.@sprintf("% i", 1024) == " 1024" @test Printf.@sprintf("% i", -1024) == "-1024" @test Printf.@sprintf("% u", 1024) == " 1024" @test Printf.@sprintf("% u", UInt(4294966272)) == " 4294966272" @test Printf.@sprintf("% o", 511) == " 777" @test Printf.@sprintf("% o", UInt(4294966785)) == " 37777777001" @test Printf.@sprintf("% x", 305441741) == " 1234abcd" @test Printf.@sprintf("% x", UInt(3989525555)) == " edcb5433" @test Printf.@sprintf("% X", 305441741) == " 1234ABCD" @test Printf.@sprintf("% X", UInt(3989525555)) == " EDCB5433" @test Printf.@sprintf("%+ d", 1024) == "+1024" @test Printf.@sprintf("%+ d", -1024) == "-1024" @test Printf.@sprintf("%+ i", 1024) == "+1024" @test Printf.@sprintf("%+ i", -1024) == "-1024" @test Printf.@sprintf("%+ u", 1024) == "+1024" @test Printf.@sprintf("%+ u", UInt(4294966272)) == "+4294966272" @test Printf.@sprintf("%+ o", 511) == "+777" @test Printf.@sprintf("%+ o", UInt(4294966785)) == "+37777777001" @test Printf.@sprintf("%+ x", 305441741) == "+1234abcd" @test Printf.@sprintf("%+ x", UInt(3989525555)) == "+edcb5433" @test Printf.@sprintf("%+ X", 305441741) == "+1234ABCD" @test Printf.@sprintf("%+ X", UInt(3989525555)) == "+EDCB5433" @test Printf.@sprintf("%#o", 511) == "0777" @test Printf.@sprintf("%#o", UInt(4294966785)) == "037777777001" @test Printf.@sprintf("%#x", 305441741) == "0x1234abcd" @test Printf.@sprintf("%#x", UInt(3989525555)) == "0xedcb5433" @test Printf.@sprintf("%#X", 305441741) == "0X1234ABCD" @test Printf.@sprintf("%#X", UInt(3989525555)) == "0XEDCB5433" @test Printf.@sprintf("%#o", UInt(0)) == "00" @test Printf.@sprintf("%#x", UInt(0)) == "0x0" @test Printf.@sprintf("%#X", UInt(0)) == "0X0" @test Printf.@sprintf("%1d", 1024) == "1024" @test Printf.@sprintf("%1d", -1024) == "-1024" @test Printf.@sprintf("%1i", 1024) == "1024" @test Printf.@sprintf("%1i", -1024) == "-1024" @test Printf.@sprintf("%1u", 1024) == "1024" @test Printf.@sprintf("%1u", UInt(4294966272)) == "4294966272" @test Printf.@sprintf("%1o", 511) == "777" @test Printf.@sprintf("%1o", UInt(4294966785)) == "37777777001" @test Printf.@sprintf("%1x", 305441741) == "1234abcd" @test Printf.@sprintf("%1x", UInt(3989525555)) == "edcb5433" @test Printf.@sprintf("%1X", 305441741) == "1234ABCD" @test Printf.@sprintf("%1X", UInt(3989525555)) == "EDCB5433" @test Printf.@sprintf("%20d", 1024) == " 1024" @test Printf.@sprintf("%20d", -1024) == " -1024" @test Printf.@sprintf("%20i", 1024) == " 1024" @test Printf.@sprintf("%20i", -1024) == " -1024" @test Printf.@sprintf("%20u", 1024) == " 1024" @test Printf.@sprintf("%20u", UInt(4294966272)) == " 4294966272" @test Printf.@sprintf("%20o", 511) == " 777" @test Printf.@sprintf("%20o", UInt(4294966785)) == " 37777777001" @test Printf.@sprintf("%20x", 305441741) == " 1234abcd" @test Printf.@sprintf("%20x", UInt(3989525555)) == " edcb5433" @test Printf.@sprintf("%20X", 305441741) == " 1234ABCD" @test Printf.@sprintf("%20X", UInt(3989525555)) == " EDCB5433" @test Printf.@sprintf("%-20d", 1024) == "1024 " @test Printf.@sprintf("%-20d", -1024) == "-1024 " @test Printf.@sprintf("%-20i", 1024) == "1024 " @test Printf.@sprintf("%-20i", -1024) == "-1024 " @test Printf.@sprintf("%-20u", 1024) == "1024 " @test Printf.@sprintf("%-20u", UInt(4294966272)) == "4294966272 " @test Printf.@sprintf("%-20o", 511) == "777 " @test Printf.@sprintf("%-20o", UInt(4294966785)) == "37777777001 " @test Printf.@sprintf("%-20x", 305441741) == "1234abcd " @test Printf.@sprintf("%-20x", UInt(3989525555)) == "edcb5433 " @test Printf.@sprintf("%-20X", 305441741) == "1234ABCD " @test Printf.@sprintf("%-20X", UInt(3989525555)) == "EDCB5433 " @test Printf.@sprintf("%020d", 1024) == "00000000000000001024" @test Printf.@sprintf("%020d", -1024) == "-0000000000000001024" @test Printf.@sprintf("%020i", 1024) == "00000000000000001024" @test Printf.@sprintf("%020i", -1024) == "-0000000000000001024" @test Printf.@sprintf("%020u", 1024) == "00000000000000001024" @test Printf.@sprintf("%020u", UInt(4294966272)) == "00000000004294966272" @test Printf.@sprintf("%020o", 511) == "00000000000000000777" @test Printf.@sprintf("%020o", UInt(4294966785)) == "00000000037777777001" @test Printf.@sprintf("%020x", 305441741) == "0000000000001234abcd" @test Printf.@sprintf("%020x", UInt(3989525555)) == "000000000000edcb5433" @test Printf.@sprintf("%020X", 305441741) == "0000000000001234ABCD" @test Printf.@sprintf("%020X", UInt(3989525555)) == "000000000000EDCB5433" @test Printf.@sprintf("%#20o", 511) == " 0777" @test Printf.@sprintf("%#20o", UInt(4294966785)) == " 037777777001" @test Printf.@sprintf("%#20x", 305441741) == " 0x1234abcd" @test Printf.@sprintf("%#20x", UInt(3989525555)) == " 0xedcb5433" @test Printf.@sprintf("%#20X", 305441741) == " 0X1234ABCD" @test Printf.@sprintf("%#20X", UInt(3989525555)) == " 0XEDCB5433" @test Printf.@sprintf("%#020o", 511) == "00000000000000000777" @test Printf.@sprintf("%#020o", UInt(4294966785)) == "00000000037777777001" @test Printf.@sprintf("%#020x", 305441741) == "0x00000000001234abcd" @test Printf.@sprintf("%#020x", UInt(3989525555)) == "0x0000000000edcb5433" @test Printf.@sprintf("%#020X", 305441741) == "0X00000000001234ABCD" @test Printf.@sprintf("%#020X", UInt(3989525555)) == "0X0000000000EDCB5433" @test Printf.@sprintf("%0-20d", 1024) == "1024 " @test Printf.@sprintf("%0-20d", -1024) == "-1024 " @test Printf.@sprintf("%0-20i", 1024) == "1024 " @test Printf.@sprintf("%0-20i", -1024) == "-1024 " @test Printf.@sprintf("%0-20u", 1024) == "1024 " @test Printf.@sprintf("%0-20u", UInt(4294966272)) == "4294966272 " @test Printf.@sprintf("%-020o", 511) == "777 " @test Printf.@sprintf("%-020o", UInt(4294966785)) == "37777777001 " @test Printf.@sprintf("%-020x", 305441741) == "1234abcd " @test Printf.@sprintf("%-020x", UInt(3989525555)) == "edcb5433 " @test Printf.@sprintf("%-020X", 305441741) == "1234ABCD " @test Printf.@sprintf("%-020X", UInt(3989525555)) == "EDCB5433 " @test Printf.@sprintf("%.20d", 1024) == "00000000000000001024" @test Printf.@sprintf("%.20d", -1024) == "-00000000000000001024" @test Printf.@sprintf("%.20i", 1024) == "00000000000000001024" @test Printf.@sprintf("%.20i", -1024) == "-00000000000000001024" @test Printf.@sprintf("%.20u", 1024) == "00000000000000001024" @test Printf.@sprintf("%.20u", UInt(4294966272)) == "00000000004294966272" @test Printf.@sprintf("%.20o", 511) == "00000000000000000777" @test Printf.@sprintf("%.20o", UInt(4294966785)) == "00000000037777777001" @test Printf.@sprintf("%.20x", 305441741) == "0000000000001234abcd" @test Printf.@sprintf("%.20x", UInt(3989525555)) == "000000000000edcb5433" @test Printf.@sprintf("%.20X", 305441741) == "0000000000001234ABCD" @test Printf.@sprintf("%.20X", UInt(3989525555)) == "000000000000EDCB5433" @test Printf.@sprintf("%20.5d", 1024) == " 01024" @test Printf.@sprintf("%20.5d", -1024) == " -01024" @test Printf.@sprintf("%20.5i", 1024) == " 01024" @test Printf.@sprintf("%20.5i", -1024) == " -01024" @test Printf.@sprintf("%20.5u", 1024) == " 01024" @test Printf.@sprintf("%20.5u", UInt(4294966272)) == " 4294966272" @test Printf.@sprintf("%20.5o", 511) == " 00777" @test Printf.@sprintf("%20.5o", UInt(4294966785)) == " 37777777001" @test Printf.@sprintf("%20.5x", 305441741) == " 1234abcd" @test Printf.@sprintf("%20.10x", UInt(3989525555)) == " 00edcb5433" @test Printf.@sprintf("%20.5X", 305441741) == " 1234ABCD" @test Printf.@sprintf("%20.10X", UInt(3989525555)) == " 00EDCB5433" @test Printf.@sprintf("%020.5d", 1024) == " 01024" @test Printf.@sprintf("%020.5d", -1024) == " -01024" @test Printf.@sprintf("%020.5i", 1024) == " 01024" @test Printf.@sprintf("%020.5i", -1024) == " -01024" @test Printf.@sprintf("%020.5u", 1024) == " 01024" @test Printf.@sprintf("%020.5u", UInt(4294966272)) == " 4294966272" @test Printf.@sprintf("%020.5o", 511) == " 00777" @test Printf.@sprintf("%020.5o", UInt(4294966785)) == " 37777777001" @test Printf.@sprintf("%020.5x", 305441741) == " 1234abcd" @test Printf.@sprintf("%020.10x", UInt(3989525555)) == " 00edcb5433" @test Printf.@sprintf("%020.5X", 305441741) == " 1234ABCD" @test Printf.@sprintf("%020.10X", UInt(3989525555)) == " 00EDCB5433" @test Printf.@sprintf("%20.0d", 1024) == " 1024" @test Printf.@sprintf("%20.d", -1024) == " -1024" @test Printf.@sprintf("%20.d", 0) == " 0" @test Printf.@sprintf("%20.0i", 1024) == " 1024" @test Printf.@sprintf("%20.i", -1024) == " -1024" @test Printf.@sprintf("%20.i", 0) == " 0" @test Printf.@sprintf("%20.u", 1024) == " 1024" @test Printf.@sprintf("%20.0u", UInt(4294966272)) == " 4294966272" @test Printf.@sprintf("%20.u", UInt(0)) == " 0" @test Printf.@sprintf("%20.o", 511) == " 777" @test Printf.@sprintf("%20.0o", UInt(4294966785)) == " 37777777001" @test Printf.@sprintf("%20.o", UInt(0)) == " 0" @test Printf.@sprintf("%20.x", 305441741) == " 1234abcd" @test Printf.@sprintf("%20.0x", UInt(3989525555)) == " edcb5433" @test Printf.@sprintf("%20.x", UInt(0)) == " 0" @test Printf.@sprintf("%20.X", 305441741) == " 1234ABCD" @test Printf.@sprintf("%20.0X", UInt(3989525555)) == " EDCB5433" @test Printf.@sprintf("%20.X", UInt(0)) == " 0" @test Printf.@sprintf("%4d", typemin(Int8)) == "-128" @test Printf.@sprintf("%4d", typemax(Int8)) == " 127" @test Printf.@sprintf("%6d", typemin(Int16)) == "-32768" @test Printf.@sprintf("%6d", typemax(Int16)) == " 32767" @test Printf.@sprintf("%11d", typemin(Int32)) == "-2147483648" @test Printf.@sprintf("%11d", typemax(Int32)) == " 2147483647" @test Printf.@sprintf("%20d", typemin(Int64)) == "-9223372036854775808" @test Printf.@sprintf("%20d", typemax(Int64)) == " 9223372036854775807" @test Printf.@sprintf("%40d", typemin(Int128)) == "-170141183460469231731687303715884105728" @test Printf.@sprintf("%40d", typemax(Int128)) == " 170141183460469231731687303715884105727" end @testset "%n" begin x = Ref{Int}() @test begin Printf.@sprintf "%d4%n" 123 x x[] == 4 end @test begin Printf.@sprintf "%s%n" "😉" x x[] == 4 end @test begin Printf.@sprintf "%s%n" "1234" x x[] == 4 end end @testset "dynamic" begin @test Printf.@sprintf("%*d", 10, 12) == " 12" @test Printf.@sprintf("%.*d", 4, 12) == "0012" @test Printf.@sprintf("%*.*d", 10, 4, 12) == " 0012" @test Printf.@sprintf("%+*.*d", 10, 4, 12) == " +0012" @test Printf.@sprintf("%0*.*d", 10, 4, 12) == " 0012" @test Printf.@sprintf("%*d%*d%*d", 4, 12, 4, 13, 4, 14) == " 12 13 14" @test Printf.@sprintf("%*d%*d%*d", 4, 12, 5, 13, 6, 14) == " 12 13 14" @test Printf.@sprintf("%*p", 20, 0) == Printf.@sprintf("%20p", 0) @test Printf.@sprintf("%-*p", 20, 0) == Printf.@sprintf("%-20p", 0) @test Printf.@sprintf("%*p", 20, C_NULL) == Printf.@sprintf("%20p", C_NULL) @test Printf.@sprintf("%-*p", 20, C_NULL) == Printf.@sprintf("%-20p", C_NULL) @test Printf.@sprintf("%.*a", 0, 3.14) == Printf.@sprintf("%.0a", 3.14) @test Printf.@sprintf("%.*a", 1, 3.14) == Printf.@sprintf("%.1a", 3.14) @test Printf.@sprintf("%.*a", 2, 3.14) == Printf.@sprintf("%.2a", 3.14) @test Printf.@sprintf("%#.*a", 0, 3.14) == Printf.@sprintf("%#.0a", 3.14) @test Printf.@sprintf("%#.*a", 1, 3.14) == Printf.@sprintf("%#.1a", 3.14) @test Printf.@sprintf("%#.*a", 2, 3.14) == Printf.@sprintf("%#.2a", 3.14) @test Printf.@sprintf("%.*a", 6, 1.5) == Printf.@sprintf("%.6a", 1.5) @test Printf.@sprintf("%*.*g", 10, 5, -123.4) == Printf.@sprintf("%10.5g", -123.4) @test Printf.@sprintf("%0*.*g", 10, 5, -123.4) == Printf.@sprintf("%010.5g", -123.4) @test Printf.@sprintf("%.*g", 6, 1.234e7) == Printf.@sprintf("%.6g", 1.234e7) @test Printf.@sprintf("%#.*g", 6, 1.234e7) == Printf.@sprintf("%#.6g", 1.234e7) @test Printf.@sprintf("%*.*g", 10, 5, -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) == Printf.@sprintf("%10.5g", -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) @test Printf.@sprintf("%0*.*g", 10, 5, -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) == Printf.@sprintf("%010.5g", -123.4000000000000000000000000000000000000000000000000000000000000000000000000002) @test Printf.@sprintf("%.*g", 6, 1.234e7) == Printf.@sprintf("%.6g", 1.234e7) @test Printf.@sprintf("%#.*g", 6, 1.234e7) == Printf.@sprintf("%#.6g", 1.234e7) @test Printf.@sprintf("%.*g", 5, 42) == Printf.@sprintf("%.5g", 42) @test Printf.@sprintf("%#.*g", 2, 42) == Printf.@sprintf("%#.2g", 42) @test Printf.@sprintf("%#.*g", 5, 42) == Printf.@sprintf("%#.5g", 42) @test Printf.@sprintf("%.*g", 15, 0) == Printf.@sprintf("%.15g", 0) @test Printf.@sprintf("%#.*g", 15, 0) == Printf.@sprintf("%#.15g", 0) @test Printf.@sprintf("%.*f", 0, 3.0e142) == Printf.@sprintf("%.0f", 3.0e142) @test Printf.@sprintf("%.*f", 2, 1.234) == Printf.@sprintf("%.2f", 1.234) @test Printf.@sprintf("%.*f", 2, 1.235) == Printf.@sprintf("%.2f", 1.235) @test Printf.@sprintf("%.*f", 2, 0.235) == Printf.@sprintf("%.2f", 0.235) @test Printf.@sprintf("%*.*f", 4, 1, 1.234) == Printf.@sprintf("%4.1f", 1.234) @test Printf.@sprintf("%*.*f", 8, 1, 1.234) == Printf.@sprintf("%8.1f", 1.234) @test Printf.@sprintf("%+*.*f", 8, 1, 1.234) == Printf.@sprintf("%+8.1f", 1.234) @test Printf.@sprintf("% *.*f", 8, 1, 1.234) == Printf.@sprintf("% 8.1f", 1.234) @test Printf.@sprintf("% *.*f", 7, 1, 1.234) == Printf.@sprintf("% 7.1f", 1.234) @test Printf.@sprintf("% 0*.*f", 8, 1, 1.234) == Printf.@sprintf("% 08.1f", 1.234) @test Printf.@sprintf("%0*.*f", 8, 1, 1.234) == Printf.@sprintf("%08.1f", 1.234) @test Printf.@sprintf("%-0*.*f", 8, 1, 1.234) == Printf.@sprintf("%-08.1f", 1.234) @test Printf.@sprintf("%-*.*f", 8, 1, 1.234) == Printf.@sprintf("%-8.1f", 1.234) @test Printf.@sprintf("%0*.*f", 8, 1, -1.234) == Printf.@sprintf("%08.1f", -1.234) @test Printf.@sprintf("%0*.*f", 9, 1, -1.234) == Printf.@sprintf("%09.1f", -1.234) @test Printf.@sprintf("%0*.*f", 9, 1, 1.234) == Printf.@sprintf("%09.1f", 1.234) @test Printf.@sprintf("%+0*.*f", 9, 1, 1.234) == Printf.@sprintf("%+09.1f", 1.234) @test Printf.@sprintf("% 0*.*f", 9, 1, 1.234) == Printf.@sprintf("% 09.1f", 1.234) @test Printf.@sprintf("%+ 0*.*f", 9, 1, 1.234) == Printf.@sprintf("%+ 09.1f", 1.234) @test Printf.@sprintf("%+ 0*.*f", 9, 1, 1.234) == Printf.@sprintf("%+ 09.1f", 1.234) @test Printf.@sprintf("%+ 0*.*f", 9, 0, 1.234) == Printf.@sprintf("%+ 09.0f", 1.234) @test Printf.@sprintf("%+ #0*.*f", 9, 0, 1.234) == Printf.@sprintf("%+ #09.0f", 1.234) @test Printf.@sprintf("%*.*e", 10, 4, Inf) == Printf.@sprintf("%10.4e", Inf) @test Printf.@sprintf("%*.*e", 10, 4, NaN) == Printf.@sprintf("%10.4e", NaN) @test Printf.@sprintf("%*.*e", 10, 4, Inf) == Printf.@sprintf("%10.4e", Inf) @test Printf.@sprintf("%*.*e", 10, 4, NaN) == Printf.@sprintf("%10.4e", NaN) @test Printf.@sprintf("%.*e", 0, 3.0e142) == Printf.@sprintf("%.0e", 3.0e142) @test Printf.@sprintf("%#.*e", 0, 3.0e142) == Printf.@sprintf("%#.0e", 3.0e142) @test Printf.@sprintf("%.*e", 0, 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) == Printf.@sprintf("%.0e", 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) @test Printf.@sprintf("%#.*e", 0, 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) == Printf.@sprintf("%#.0e", 2.999999999999999999999999999999999999999999999999999999999999999999999999999996e142) @test Printf.@sprintf("%.*e", 0, 3.000000000000000000000000000000000000000000000000000000000000000000000000000024e1042) == Printf.@sprintf("%.0e", 3.000000000000000000000000000000000000000000000000000000000000000000000000000024e1042) @test Printf.@sprintf("%.*e", 2, 1.234) == Printf.@sprintf("%.2e", 1.234) @test Printf.@sprintf("%.*e", 2, 1.235) == Printf.@sprintf("%.2e", 1.235) @test Printf.@sprintf("%.*e", 2, 0.235) == Printf.@sprintf("%.2e", 0.235) @test Printf.@sprintf("%*.*e", 4, 1, 1.234) == Printf.@sprintf("%4.1e", 1.234) @test Printf.@sprintf("%*.*e", 8, 1, 1.234) == Printf.@sprintf("%8.1e", 1.234) @test Printf.@sprintf("%+*.*e", 8, 1, 1.234) == Printf.@sprintf("%+8.1e", 1.234) @test Printf.@sprintf("% *.*e", 8, 1, 1.234) == Printf.@sprintf("% 8.1e", 1.234) @test Printf.@sprintf("% *.*e", 7, 1, 1.234) == Printf.@sprintf("% 7.1e", 1.234) @test Printf.@sprintf("% 0*.*e", 8, 1, 1.234) == Printf.@sprintf("% 08.1e", 1.234) @test Printf.@sprintf("%0*.*e", 8, 1, 1.234) == Printf.@sprintf("%08.1e", 1.234) @test Printf.@sprintf("%-0*.*e", 8, 1, 1.234) == Printf.@sprintf("%-08.1e", 1.234) @test Printf.@sprintf("%-*.*e", 8, 1, 1.234) == Printf.@sprintf("%-8.1e", 1.234) @test Printf.@sprintf("%-*.*e", 8, 1, 1.234) == Printf.@sprintf("%-8.1e", 1.234) @test Printf.@sprintf("%0*.*e", 8, 1, -1.234) == Printf.@sprintf("%08.1e", -1.234) @test Printf.@sprintf("%0*.*e", 9, 1, -1.234) == Printf.@sprintf("%09.1e", -1.234) @test Printf.@sprintf("%0*.*e", 9, 1, 1.234) == Printf.@sprintf("%09.1e", 1.234) @test Printf.@sprintf("%+0*.*e", 9, 1, 1.234) == Printf.@sprintf("%+09.1e", 1.234) @test Printf.@sprintf("% 0*.*e", 9, 1, 1.234) == Printf.@sprintf("% 09.1e", 1.234) @test Printf.@sprintf("%+ 0*.*e", 9, 1, 1.234) == Printf.@sprintf("%+ 09.1e", 1.234) @test Printf.@sprintf("%+ 0*.*e", 9, 1, 1.234) == Printf.@sprintf("%+ 09.1e", 1.234) @test Printf.@sprintf("%+ 0*.*e", 9, 0, 1.234) == Printf.@sprintf("%+ 09.0e", 1.234) @test Printf.@sprintf("%+ #0*.*e", 9, 0, 1.234) == Printf.@sprintf("%+ #09.0e", 1.234) @test Printf.@sprintf("%.*s", 1, "foo") == Printf.@sprintf("%.1s", "foo") @test Printf.@sprintf("%*s", 1, "Hallo heimur") == Printf.@sprintf("%1s", "Hallo heimur") @test Printf.@sprintf("%*s", 20, "Hallo") == Printf.@sprintf("%20s", "Hallo") @test Printf.@sprintf("%-*s", 20, "Hallo") == Printf.@sprintf("%-20s", "Hallo") @test Printf.@sprintf("%0-*s", 20, "Hallo") == Printf.@sprintf("%0-20s", "Hallo") @test Printf.@sprintf("%.*s", 20, "Hallo heimur") == Printf.@sprintf("%.20s", "Hallo heimur") @test Printf.@sprintf("%*.*s", 20, 5, "Hallo heimur") == Printf.@sprintf("%20.5s", "Hallo heimur") @test Printf.@sprintf("%.*s", 0, "Hallo heimur") == Printf.@sprintf("%.0s", "Hallo heimur") @test Printf.@sprintf("%*.*s", 20, 0, "Hallo heimur") == Printf.@sprintf("%20.0s", "Hallo heimur") @test Printf.@sprintf("%.s", "Hallo heimur") == Printf.@sprintf("%.s", "Hallo heimur") @test Printf.@sprintf("%*.s", 20, "Hallo heimur") == Printf.@sprintf("%20.s", "Hallo heimur") @test Printf.@sprintf("%*sø", 4, "ø") == Printf.@sprintf("%4sø", "ø") @test Printf.@sprintf("%-*sø", 4, "ø") == Printf.@sprintf("%-4sø", "ø") @test Printf.@sprintf("%*s", 8, "test") == Printf.@sprintf("%8s", "test") @test Printf.@sprintf("%-*s", 8, "test") == Printf.@sprintf("%-8s", "test") @test Printf.@sprintf("%#*s", 8, :test) == Printf.@sprintf("%#8s", :test) @test Printf.@sprintf("%#-*s", 8, :test) == Printf.@sprintf("%#-8s", :test) @test Printf.@sprintf("%*.*s", 8, 3, "test") == Printf.@sprintf("%8.3s", "test") @test Printf.@sprintf("%#*.*s", 8, 3, "test") == Printf.@sprintf("%#8.3s", "test") @test Printf.@sprintf("%-*.*s", 8, 3, "test") == Printf.@sprintf("%-8.3s", "test") @test Printf.@sprintf("%#-*.*s", 8, 3, "test") == Printf.@sprintf("%#-8.3s", "test") @test Printf.@sprintf("%.*s", 3, "test") == Printf.@sprintf("%.3s", "test") @test Printf.@sprintf("%#.*s", 3, "test") == Printf.@sprintf("%#.3s", "test") @test Printf.@sprintf("%-.*s", 3, "test") == Printf.@sprintf("%-.3s", "test") @test Printf.@sprintf("%#-.*s", 3, "test") == Printf.@sprintf("%#-.3s", "test") @test Printf.@sprintf("%*c", 3, 'a') == Printf.@sprintf("%3c", 'a') @test Printf.@sprintf("%*c", 1, 'x') == Printf.@sprintf("%1c", 'x') @test Printf.@sprintf("%*c", 20, 'x') == Printf.@sprintf("%20c", 'x') @test Printf.@sprintf("%-*c", 20, 'x') == Printf.@sprintf("%-20c", 'x') @test Printf.@sprintf("%-0*c", 20, 'x') == Printf.@sprintf("%-020c", 'x') @test Printf.@sprintf("%*c", 3, 'A') == Printf.@sprintf("%3c", 'A') @test Printf.@sprintf("%-*c", 3, 'A') == Printf.@sprintf("%-3c", 'A') @test Printf.@sprintf("%*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f %*.*f", 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345, 4, 2, 1.2345) == Printf.@sprintf("%4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f", 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345, 1.2345) @test (Printf.@sprintf("%.*f", 330, BigFloat(1)))[var"end"] != '\0' @test Printf.@sprintf("%*.*s", 4, 2, "a") == Printf.@sprintf("%4.2s", "a") @test Printf.@sprintf("%*.*e", 12, 3, pi * 1.0e100) == Printf.@sprintf("%12.3e", pi * 1.0e100) @test Printf.@sprintf("%*d", 2, 3.14) == Printf.@sprintf("%*d", 2, 3.14) @test Printf.@sprintf("%*d", 2, big(3.14)) == Printf.@sprintf("%*d", 2, big(3.14)) @test Printf.@sprintf(" %.*e\n", 1, 0.999) == Printf.@sprintf(" %.1e\n", 0.999) @test Printf.@sprintf(" %.*f", 1, 9.999) == Printf.@sprintf(" %.1f", 9.999) @test Printf.@sprintf("%*d", 10, 12) == Printf.@sprintf("%10d", 12) @test Printf.@sprintf("%.*d", 4, 12) == Printf.@sprintf("%.4d", 12) @test Printf.@sprintf("%*.*d", 10, 4, 12) == Printf.@sprintf("%10.4d", 12) @test Printf.@sprintf("%+*.*d", 10, 4, 12) == Printf.@sprintf("%+10.4d", 12) @test Printf.@sprintf("%0*.*d", 10, 4, 12) == Printf.@sprintf("%010.4d", 12) @test Printf.@sprintf("% *d", 5, 42) == Printf.@sprintf("% 5d", 42) @test Printf.@sprintf("% *d", 5, -42) == Printf.@sprintf("% 5d", -42) @test Printf.@sprintf("% *d", 15, 42) == Printf.@sprintf("% 15d", 42) @test Printf.@sprintf("% *d", 15, -42) == Printf.@sprintf("% 15d", -42) @test Printf.@sprintf("%+*d", 5, 42) == Printf.@sprintf("%+5d", 42) @test Printf.@sprintf("%+*d", 5, -42) == Printf.@sprintf("%+5d", -42) @test Printf.@sprintf("%+*d", 15, 42) == Printf.@sprintf("%+15d", 42) @test Printf.@sprintf("%+*d", 15, -42) == Printf.@sprintf("%+15d", -42) @test Printf.@sprintf("%*d", 0, 42) == Printf.@sprintf("%0d", 42) @test Printf.@sprintf("%*d", 0, -42) == Printf.@sprintf("%0d", -42) @test Printf.@sprintf("%-*d", 5, 42) == Printf.@sprintf("%-5d", 42) @test Printf.@sprintf("%-*d", 5, -42) == Printf.@sprintf("%-5d", -42) @test Printf.@sprintf("%-*d", 15, 42) == Printf.@sprintf("%-15d", 42) @test Printf.@sprintf("%-*d", 15, -42) == Printf.@sprintf("%-15d", -42) @test Printf.@sprintf("%+*lld", 8, 100) == Printf.@sprintf("%+8lld", 100) @test Printf.@sprintf("%+.*lld", 8, 100) == Printf.@sprintf("%+.8lld", 100) @test Printf.@sprintf("%+*.*lld", 10, 8, 100) == Printf.@sprintf("%+10.8lld", 100) @test Printf.@sprintf("%-*.*lld", 1, 5, -100) == Printf.@sprintf("%-1.5lld", -100) @test Printf.@sprintf("%*lld", 5, 100) == Printf.@sprintf("%5lld", 100) @test Printf.@sprintf("%*lld", 5, -100) == Printf.@sprintf("%5lld", -100) @test Printf.@sprintf("%-*lld", 5, 100) == Printf.@sprintf("%-5lld", 100) @test Printf.@sprintf("%-*lld", 5, -100) == Printf.@sprintf("%-5lld", -100) @test Printf.@sprintf("%-.*lld", 5, 100) == Printf.@sprintf("%-.5lld", 100) @test Printf.@sprintf("%-.*lld", 5, -100) == Printf.@sprintf("%-.5lld", -100) @test Printf.@sprintf("%-*.*lld", 8, 5, 100) == Printf.@sprintf("%-8.5lld", 100) @test Printf.@sprintf("%-*.*lld", 8, 5, -100) == Printf.@sprintf("%-8.5lld", -100) @test Printf.@sprintf("%0*lld", 5, 100) == Printf.@sprintf("%05lld", 100) @test Printf.@sprintf("%0*lld", 5, -100) == Printf.@sprintf("%05lld", -100) @test Printf.@sprintf("% *lld", 5, 100) == Printf.@sprintf("% 5lld", 100) @test Printf.@sprintf("% *lld", 5, -100) == Printf.@sprintf("% 5lld", -100) @test Printf.@sprintf("% .*lld", 5, 100) == Printf.@sprintf("% .5lld", 100) @test Printf.@sprintf("% .*lld", 5, -100) == Printf.@sprintf("% .5lld", -100) @test Printf.@sprintf("% *.*lld", 8, 5, 100) == Printf.@sprintf("% 8.5lld", 100) @test Printf.@sprintf("% *.*lld", 8, 5, -100) == Printf.@sprintf("% 8.5lld", -100) @test Printf.@sprintf("%.*lld", 0, 0) == Printf.@sprintf("%.0lld", 0) @test Printf.@sprintf("%#+*.*llx", 21, 18, -100) == Printf.@sprintf("%#+21.18llx", -100) @test Printf.@sprintf("%#.*llo", 25, -100) == Printf.@sprintf("%#.25llo", -100) @test Printf.@sprintf("%#+*.*llo", 24, 20, -100) == Printf.@sprintf("%#+24.20llo", -100) @test Printf.@sprintf("%#+*.*llX", 18, 21, -100) == Printf.@sprintf("%#+18.21llX", -100) @test Printf.@sprintf("%#+*.*llo", 20, 24, -100) == Printf.@sprintf("%#+20.24llo", -100) @test Printf.@sprintf("%#+*.*llu", 25, 22, -1) == Printf.@sprintf("%#+25.22llu", -1) @test Printf.@sprintf("%#+*.*llu", 30, 25, -1) == Printf.@sprintf("%#+30.25llu", -1) @test Printf.@sprintf("%+#*.*lld", 25, 22, -1) == Printf.@sprintf("%+#25.22lld", -1) @test Printf.@sprintf("%#-*.*llo", 8, 5, 100) == Printf.@sprintf("%#-8.5llo", 100) @test Printf.@sprintf("%#-+ 0*.*lld", 8, 5, 100) == Printf.@sprintf("%#-+ 08.5lld", 100) @test Printf.@sprintf("%#-+ 0*.*lld", 8, 5, 100) == Printf.@sprintf("%#-+ 08.5lld", 100) @test Printf.@sprintf("%.*lld", 40, 1) == Printf.@sprintf("%.40lld", 1) @test Printf.@sprintf("% .*lld", 40, 1) == Printf.@sprintf("% .40lld", 1) @test Printf.@sprintf("% .*d", 40, 1) == Printf.@sprintf("% .40d", 1) @test Printf.@sprintf("%#0*x", 12, 1) == Printf.@sprintf("%#012x", 1) @test Printf.@sprintf("%#0*.*x", 4, 8, 1) == Printf.@sprintf("%#04.8x", 1) @test Printf.@sprintf("%#-0*.*x", 8, 2, 1) == Printf.@sprintf("%#-08.2x", 1) @test Printf.@sprintf("%#0*o", 8, 1) == Printf.@sprintf("%#08o", 1) @test Printf.@sprintf("%*d", 20, 1024) == Printf.@sprintf("%20d", 1024) @test Printf.@sprintf("%*d", 20, -1024) == Printf.@sprintf("%20d", -1024) @test Printf.@sprintf("%*i", 20, 1024) == Printf.@sprintf("%20i", 1024) @test Printf.@sprintf("%*i", 20, -1024) == Printf.@sprintf("%20i", -1024) @test Printf.@sprintf("%*u", 20, 1024) == Printf.@sprintf("%20u", 1024) @test Printf.@sprintf("%*u", 20, UInt(4294966272)) == Printf.@sprintf("%20u", UInt(4294966272)) @test Printf.@sprintf("%*o", 20, 511) == Printf.@sprintf("%20o", 511) @test Printf.@sprintf("%*o", 20, UInt(4294966785)) == Printf.@sprintf("%20o", UInt(4294966785)) @test Printf.@sprintf("%*x", 20, 305441741) == Printf.@sprintf("%20x", 305441741) @test Printf.@sprintf("%*x", 20, UInt(3989525555)) == Printf.@sprintf("%20x", UInt(3989525555)) @test Printf.@sprintf("%*X", 20, 305441741) == Printf.@sprintf("%20X", 305441741) @test Printf.@sprintf("%*X", 20, UInt(3989525555)) == Printf.@sprintf("%20X", UInt(3989525555)) @test Printf.@sprintf("%-*d", 20, 1024) == Printf.@sprintf("%-20d", 1024) @test Printf.@sprintf("%-*d", 20, -1024) == Printf.@sprintf("%-20d", -1024) @test Printf.@sprintf("%-*i", 20, 1024) == Printf.@sprintf("%-20i", 1024) @test Printf.@sprintf("%-*i", 20, -1024) == Printf.@sprintf("%-20i", -1024) @test Printf.@sprintf("%-*u", 20, 1024) == Printf.@sprintf("%-20u", 1024) @test Printf.@sprintf("%-*u", 20, UInt(4294966272)) == Printf.@sprintf("%-20u", UInt(4294966272)) @test Printf.@sprintf("%-*o", 20, 511) == Printf.@sprintf("%-20o", 511) @test Printf.@sprintf("%-*o", 20, UInt(4294966785)) == Printf.@sprintf("%-20o", UInt(4294966785)) @test Printf.@sprintf("%-*x", 20, 305441741) == Printf.@sprintf("%-20x", 305441741) @test Printf.@sprintf("%-*x", 20, UInt(3989525555)) == Printf.@sprintf("%-20x", UInt(3989525555)) @test Printf.@sprintf("%-*X", 20, 305441741) == Printf.@sprintf("%-20X", 305441741) @test Printf.@sprintf("%-*X", 20, UInt(3989525555)) == Printf.@sprintf("%-20X", UInt(3989525555)) @test Printf.@sprintf("%0*d", 20, 1024) == Printf.@sprintf("%020d", 1024) @test Printf.@sprintf("%0*d", 20, -1024) == Printf.@sprintf("%020d", -1024) @test Printf.@sprintf("%0*i", 20, 1024) == Printf.@sprintf("%020i", 1024) @test Printf.@sprintf("%0*i", 20, -1024) == Printf.@sprintf("%020i", -1024) @test Printf.@sprintf("%0*u", 20, 1024) == Printf.@sprintf("%020u", 1024) @test Printf.@sprintf("%0*u", 20, UInt(4294966272)) == Printf.@sprintf("%020u", UInt(4294966272)) @test Printf.@sprintf("%0*o", 20, 511) == Printf.@sprintf("%020o", 511) @test Printf.@sprintf("%0*o", 20, UInt(4294966785)) == Printf.@sprintf("%020o", UInt(4294966785)) @test Printf.@sprintf("%0*x", 20, 305441741) == Printf.@sprintf("%020x", 305441741) @test Printf.@sprintf("%0*x", 20, UInt(3989525555)) == Printf.@sprintf("%020x", UInt(3989525555)) @test Printf.@sprintf("%0*X", 20, 305441741) == Printf.@sprintf("%020X", 305441741) @test Printf.@sprintf("%0*X", 20, UInt(3989525555)) == Printf.@sprintf("%020X", UInt(3989525555)) @test Printf.@sprintf("%#*o", 20, 511) == Printf.@sprintf("%#20o", 511) @test Printf.@sprintf("%#*o", 20, UInt(4294966785)) == Printf.@sprintf("%#20o", UInt(4294966785)) @test Printf.@sprintf("%#*x", 20, 305441741) == Printf.@sprintf("%#20x", 305441741) @test Printf.@sprintf("%#*x", 20, UInt(3989525555)) == Printf.@sprintf("%#20x", UInt(3989525555)) @test Printf.@sprintf("%#*X", 20, 305441741) == Printf.@sprintf("%#20X", 305441741) @test Printf.@sprintf("%#*X", 20, UInt(3989525555)) == Printf.@sprintf("%#20X", UInt(3989525555)) @test Printf.@sprintf("%#0*o", 20, 511) == Printf.@sprintf("%#020o", 511) @test Printf.@sprintf("%#0*o", 20, UInt(4294966785)) == Printf.@sprintf("%#020o", UInt(4294966785)) @test Printf.@sprintf("%#0*x", 20, 305441741) == Printf.@sprintf("%#020x", 305441741) @test Printf.@sprintf("%#0*x", 20, UInt(3989525555)) == Printf.@sprintf("%#020x", UInt(3989525555)) @test Printf.@sprintf("%#0*X", 20, 305441741) == Printf.@sprintf("%#020X", 305441741) @test Printf.@sprintf("%#0*X", 20, UInt(3989525555)) == Printf.@sprintf("%#020X", UInt(3989525555)) @test Printf.@sprintf("%0-*d", 20, 1024) == Printf.@sprintf("%0-20d", 1024) @test Printf.@sprintf("%0-*d", 20, -1024) == Printf.@sprintf("%0-20d", -1024) @test Printf.@sprintf("%0-*i", 20, 1024) == Printf.@sprintf("%0-20i", 1024) @test Printf.@sprintf("%0-*i", 20, -1024) == Printf.@sprintf("%0-20i", -1024) @test Printf.@sprintf("%0-*u", 20, 1024) == Printf.@sprintf("%0-20u", 1024) @test Printf.@sprintf("%0-*u", 20, UInt(4294966272)) == Printf.@sprintf("%0-20u", UInt(4294966272)) @test Printf.@sprintf("%-0*o", 20, 511) == Printf.@sprintf("%-020o", 511) @test Printf.@sprintf("%-0*o", 20, UInt(4294966785)) == Printf.@sprintf("%-020o", UInt(4294966785)) @test Printf.@sprintf("%-0*x", 20, 305441741) == Printf.@sprintf("%-020x", 305441741) @test Printf.@sprintf("%-0*x", 20, UInt(3989525555)) == Printf.@sprintf("%-020x", UInt(3989525555)) @test Printf.@sprintf("%-0*X", 20, 305441741) == Printf.@sprintf("%-020X", 305441741) @test Printf.@sprintf("%-0*X", 20, UInt(3989525555)) == Printf.@sprintf("%-020X", UInt(3989525555)) @test Printf.@sprintf("%.*d", 20, 1024) == Printf.@sprintf("%.20d", 1024) @test Printf.@sprintf("%.*d", 20, -1024) == Printf.@sprintf("%.20d", -1024) @test Printf.@sprintf("%.*i", 20, 1024) == Printf.@sprintf("%.20i", 1024) @test Printf.@sprintf("%.*i", 20, -1024) == Printf.@sprintf("%.20i", -1024) @test Printf.@sprintf("%.*u", 20, 1024) == Printf.@sprintf("%.20u", 1024) @test Printf.@sprintf("%.*u", 20, UInt(4294966272)) == Printf.@sprintf("%.20u", UInt(4294966272)) @test Printf.@sprintf("%.*o", 20, 511) == Printf.@sprintf("%.20o", 511) @test Printf.@sprintf("%.*o", 20, UInt(4294966785)) == Printf.@sprintf("%.20o", UInt(4294966785)) @test Printf.@sprintf("%.*x", 20, 305441741) == Printf.@sprintf("%.20x", 305441741) @test Printf.@sprintf("%.*x", 20, UInt(3989525555)) == Printf.@sprintf("%.20x", UInt(3989525555)) @test Printf.@sprintf("%.*X", 20, 305441741) == Printf.@sprintf("%.20X", 305441741) @test Printf.@sprintf("%.*X", 20, UInt(3989525555)) == Printf.@sprintf("%.20X", UInt(3989525555)) @test Printf.@sprintf("%*.*d", 20, 5, 1024) == Printf.@sprintf("%20.5d", 1024) @test Printf.@sprintf("%*.*d", 20, 5, -1024) == Printf.@sprintf("%20.5d", -1024) @test Printf.@sprintf("%*.*i", 20, 5, 1024) == Printf.@sprintf("%20.5i", 1024) @test Printf.@sprintf("%*.*i", 20, 5, -1024) == Printf.@sprintf("%20.5i", -1024) @test Printf.@sprintf("%*.*u", 20, 5, 1024) == Printf.@sprintf("%20.5u", 1024) @test Printf.@sprintf("%*.*u", 20, 5, UInt(4294966272)) == Printf.@sprintf("%20.5u", UInt(4294966272)) @test Printf.@sprintf("%*.*o", 20, 5, 511) == Printf.@sprintf("%20.5o", 511) @test Printf.@sprintf("%*.*o", 20, 5, UInt(4294966785)) == Printf.@sprintf("%20.5o", UInt(4294966785)) @test Printf.@sprintf("%*.*x", 20, 5, 305441741) == Printf.@sprintf("%20.5x", 305441741) @test Printf.@sprintf("%*.*x", 20, 10, UInt(3989525555)) == Printf.@sprintf("%20.10x", UInt(3989525555)) @test Printf.@sprintf("%*.*X", 20, 5, 305441741) == Printf.@sprintf("%20.5X", 305441741) @test Printf.@sprintf("%*.*X", 20, 10, UInt(3989525555)) == Printf.@sprintf("%20.10X", UInt(3989525555)) @test Printf.@sprintf("%0*.*d", 20, 5, 1024) == Printf.@sprintf("%020.5d", 1024) @test Printf.@sprintf("%0*.*d", 20, 5, -1024) == Printf.@sprintf("%020.5d", -1024) @test Printf.@sprintf("%0*.*i", 20, 5, 1024) == Printf.@sprintf("%020.5i", 1024) @test Printf.@sprintf("%0*.*i", 20, 5, -1024) == Printf.@sprintf("%020.5i", -1024) @test Printf.@sprintf("%0*.*u", 20, 5, 1024) == Printf.@sprintf("%020.5u", 1024) @test Printf.@sprintf("%0*.*u", 20, 5, UInt(4294966272)) == Printf.@sprintf("%020.5u", UInt(4294966272)) @test Printf.@sprintf("%0*.*o", 20, 5, 511) == Printf.@sprintf("%020.5o", 511) @test Printf.@sprintf("%0*.*o", 20, 5, UInt(4294966785)) == Printf.@sprintf("%020.5o", UInt(4294966785)) @test Printf.@sprintf("%0*.*x", 20, 5, 305441741) == Printf.@sprintf("%020.5x", 305441741) @test Printf.@sprintf("%0*.*x", 20, 10, UInt(3989525555)) == Printf.@sprintf("%020.10x", UInt(3989525555)) @test Printf.@sprintf("%0*.*X", 20, 5, 305441741) == Printf.@sprintf("%020.5X", 305441741) @test Printf.@sprintf("%0*.*X", 20, 10, UInt(3989525555)) == Printf.@sprintf("%020.10X", UInt(3989525555)) @test Printf.@sprintf("%*.0d", 20, 1024) == Printf.@sprintf("%20.0d", 1024) @test Printf.@sprintf("%*.d", 20, -1024) == Printf.@sprintf("%20.d", -1024) @test Printf.@sprintf("%*.d", 20, 0) == Printf.@sprintf("%20.d", 0) @test Printf.@sprintf("%*.0i", 20, 1024) == Printf.@sprintf("%20.0i", 1024) @test Printf.@sprintf("%*.i", 20, -1024) == Printf.@sprintf("%20.i", -1024) @test Printf.@sprintf("%*.i", 20, 0) == Printf.@sprintf("%20.i", 0) @test Printf.@sprintf("%*.u", 20, 1024) == Printf.@sprintf("%20.u", 1024) @test Printf.@sprintf("%*.0u", 20, UInt(4294966272)) == Printf.@sprintf("%20.0u", UInt(4294966272)) @test Printf.@sprintf("%*.u", 20, UInt(0)) == Printf.@sprintf("%20.u", UInt(0)) @test Printf.@sprintf("%*.o", 20, 511) == Printf.@sprintf("%20.o", 511) @test Printf.@sprintf("%*.0o", 20, UInt(4294966785)) == Printf.@sprintf("%20.0o", UInt(4294966785)) @test Printf.@sprintf("%*.o", 20, UInt(0)) == Printf.@sprintf("%20.o", UInt(0)) @test Printf.@sprintf("%*.x", 20, 305441741) == Printf.@sprintf("%20.x", 305441741) @test Printf.@sprintf("%*.0x", 20, UInt(3989525555)) == Printf.@sprintf("%20.0x", UInt(3989525555)) @test Printf.@sprintf("%*.x", 20, UInt(0)) == Printf.@sprintf("%20.x", UInt(0)) @test Printf.@sprintf("%*.X", 20, 305441741) == Printf.@sprintf("%20.X", 305441741) @test Printf.@sprintf("%*.0X", 20, UInt(3989525555)) == Printf.@sprintf("%20.0X", UInt(3989525555)) @test Printf.@sprintf("%*.X", 20, UInt(0)) == Printf.@sprintf("%20.X", UInt(0)) x = Ref{Int}() y = Ref{Int}() @test begin Printf.@sprintf "%10s%n" "😉" x Printf.@sprintf "%*s%n" 10 "😉" y x[] == y[] end @test begin Printf.@sprintf "%10s%n" "1234" x Printf.@sprintf "%*s%n" 10 "1234" y x[] == y[] end end @testset "length modifiers" begin @test_throws Printf.InvalidFormatStringError Printf.Format("%h") @test_throws Printf.InvalidFormatStringError Printf.Format("%hh") @test_throws Printf.InvalidFormatStringError Printf.Format("%z") end @testset "Docstrings" begin @test isempty(Docs.undocumented_names(Printf)) end @test @sprintf("%.160g", 1.38e-23) == "1.380000000000000060010582465734078799297660966782642624395399644741944111814291318296454846858978271484375e-23" end Parsing files in Base: Test Failed at /home/pkgeval/.julia/packages/CSTParser/0hXvH/test/test_check_base.jl:166 Expression: false Stacktrace: [1] top-level scope @ ~/.julia/packages/CSTParser/0hXvH/test/test_check_base.jl:166 [2] macro expansion @ /opt/julia/share/julia/stdlib/v1.13/Test/src/Test.jl:745 [inlined] ┌ Error: parsing difference │ file = "/opt/julia/bin/../share/julia/test/complex.jl" └ @ Main.var"##439" ~/.julia/packages/CSTParser/0hXvH/test/test_check_base.jl:157 big(1) / (10 + 10im) ≈ -5 / big(100) ≈ -0.05000000000000000000000000000000000000000000000000000000000000000000000000000011 big(1) / (10 + 10im) ≈ -5 / big(100) ≈ -0.05000000000000000000000000000000000000000000000000000000000000000000000000000011 @test big(1) / (10 + 10im) ≈ -5 / big(100) ≈ -0.05000000000000000000000000000000000000000000000000000000000000000000000000000011 @test big(1) / (10 + 10im) ≈ -5 / big(100) ≈ -0.05000000000000000000000000000000000000000000000000000000000000000000000000000011 Parsing files in Base: Test Failed at /home/pkgeval/.julia/packages/CSTParser/0hXvH/test/test_check_base.jl:166 Expression: false Stacktrace: [1] top-level scope @ ~/.julia/packages/CSTParser/0hXvH/test/test_check_base.jl:166 [2] macro expansion @ /opt/julia/share/julia/stdlib/v1.13/Test/src/Test.jl:745 [inlined] ┌ Error: parsing difference │ file = "/opt/julia/bin/../share/julia/test/core.jl" └ @ Main.var"##439" ~/.julia/packages/CSTParser/0hXvH/test/test_check_base.jl:157 begin 1:3 end 1:3 1:3 : begin 1:3 end 1:3 f() = begin 1:3 end f() = 1:3 for f() = begin 1:3 end push!(a, f()) push!(fs, f) end for f() = 1:3 push!(a, f()) push!(fs, f) end begin for f() = begin 1:3 end push!(a, f()) push!(fs, f) end @test a == [1, 2, 3] @test [f() for f = fs] == [1, 2, 3] end begin for f() = 1:3 push!(a, f()) push!(fs, f) end @test a == [1, 2, 3] @test [f() for f = fs] == [1, 2, 3] end let a = [], fs = [] for f() = begin 1:3 end push!(a, f()) push!(fs, f) end @test a == [1, 2, 3] @test [f() for f = fs] == [1, 2, 3] end let a = [], fs = [] for f() = 1:3 push!(a, f()) push!(fs, f) end @test a == [1, 2, 3] @test [f() for f = fs] == [1, 2, 3] end Parsing files in Base: Test Failed at /home/pkgeval/.julia/packages/CSTParser/0hXvH/test/test_check_base.jl:166 Expression: false Stacktrace: [1] top-level scope @ ~/.julia/packages/CSTParser/0hXvH/test/test_check_base.jl:166 [2] macro expansion @ /opt/julia/share/julia/stdlib/v1.13/Test/src/Test.jl:745 [inlined] ┌ Error: parsing difference │ file = "/opt/julia/bin/../share/julia/test/dict.jl" └ @ Main.var"##439" ~/.julia/packages/CSTParser/0hXvH/test/test_check_base.jl:157 1 + 1 1 + 1 d[1 + 1] d[1 + 1] d[1 + 1] = 1 d[1 + 1] = 1 begin d[1 + 1] = 1 end begin d[1 + 1] = 1 end d->begin d[1 + 1] = 1 end d->begin d[1 + 1] = 1 end @noinline (d->begin d[1 + 1] = 1 end) @noinline (d->begin d[1 + 1] = 1 end) (@noinline((d->begin d[1 + 1] = 1 end)))(d26939) (@noinline((d->begin d[1 + 1] = 1 end)))(d26939) begin A = [1] B = [2] C = [3] wkd = WeakKeyDict() wkd[A] = 2 wkd[B] = 3 wkd[C] = 4 dd = convert(Dict{Any, Any}, wkd) @test WeakKeyDict(dd) == wkd @test convert(WeakKeyDict{Any, Any}, dd) == wkd @test WeakKeyDict(dd) isa WeakKeyDict{Any, Any} @test WeakKeyDict(A => 2, B => 3, C => 4) == wkd @test WeakKeyDict(A => 2, B => 3, C => 4) isa WeakKeyDict{Array{Int, 1}, Int} @test WeakKeyDict((a => i + 1 for (i, a) = enumerate([A, B, C]))) == wkd @test WeakKeyDict([(A, 2), (B, 3), (C, 4)]) == wkd @test WeakKeyDict{typeof(A), Int64}(Pair(A, 2), Pair(B, 3), Pair(C, 4)) == wkd @test WeakKeyDict(Pair(A, 2), Pair(B, 3), Pair(C, 4)) == wkd D = [[4.0]] @test WeakKeyDict(Pair(A, 2), Pair(B, 3), Pair(D, 4.0)) isa WeakKeyDict{Any, Any} @test WeakKeyDict(Pair(A, 2), Pair(B, 3.0), Pair(C, 4)) isa WeakKeyDict{Array{Int, 1}, Any} @test WeakKeyDict(Pair(convert(Vector{Number}, A), 2), Pair(B, 3), Pair(C, 4)) isa WeakKeyDict{Any, Int} @test copy(wkd) == wkd @test length(wkd) == 3 @test !(isempty(wkd)) res = pop!(wkd, C) @test res == 4 @test length(wkd) == 2 res = pop!(wkd, C, 3) @test res == 3 @test C ∉ keys(wkd) @test 4 ∉ values(wkd) @test length(wkd) == 2 @test !(isempty(wkd)) wkd = filter!((p->begin p.first != B end), wkd) @test B ∉ keys(wkd) @test 3 ∉ values(wkd) @test length(wkd) == 1 @test WeakKeyDict(Pair(A, 2)) == wkd @test !(isempty(wkd)) wkd = empty!(wkd) @test wkd == empty(wkd) @test typeof(wkd) == typeof(empty(wkd)) @test length(wkd) == 0 @test isempty(wkd) @test wkd isa WeakKeyDict @test_throws ArgumentError WeakKeyDict([1, 2, 3]) wkd = WeakKeyDict(A => 1) @test delete!(wkd, A) == empty(wkd) @test delete!(wkd, A) === wkd d26939 = WeakKeyDict() (@noinline((d->begin d[1 + 1] = 1 end)))(d26939) GC.gc() @test count(d26939) == 0 @test length(d26939.ht) == 1 @test length(d26939) == 0 @test isempty(d26939) empty!(d26939) for i = 1:8 (@noinline(((d, i)->begin d[big(i + 12345)] = 1 end)))(d26939, i) end lock(GC.gc, d26939) @test length(d26939.ht) == 8 @test count(d26939) == 0 @test !(haskey(d26939, nothing)) @test_throws KeyError(nothing) d26939[nothing] @test_throws KeyError(nothing) get(d26939, nothing, 1) @test_throws KeyError(nothing) get((()->begin 1 end), d26939, nothing) @test_throws KeyError(nothing) pop!(d26939, nothing) @test getkey(d26939, nothing, 321) === 321 @test pop!(d26939, nothing, 321) === 321 @test delete!(d26939, nothing) === d26939 @test length(d26939.ht) == 8 @test_throws ArgumentError d26939[nothing] = 1 @test_throws ArgumentError get!(d26939, nothing, 1) @test_throws ArgumentError get!((()->begin 1 end), d26939, nothing) @test isempty(d26939) @test length(d26939.ht) == 0 @test length(d26939) == 0 @test_throws ArgumentError WeakKeyDict{Vector{Int}, Any}([5.0] => 1) wkd = WeakKeyDict(A => 2) @test_throws ArgumentError get!(wkd, [2.0], 2) @test get!(wkd, [1.0], 2) === 2 wkd = WeakKeyDict(A => 2) @test keytype(wkd) == Vector{Int} @test wkd[[1.0]] == 2 @test haskey(wkd, [1.0]) @test pop!(wkd, [1.0]) == 2 @test get((()->begin 3 end), wkd, [2.0]) == 3 wkd = WeakKeyDict(A => 2, B => 3) map!((v->begin v - 1 end), values(wkd)) @test wkd == WeakKeyDict(A => 1, B => 2) wkd = WeakKeyDict(A => 2) @test get!(wkd, B, 3) == 3 @test wkd == WeakKeyDict(A => 2, B => 3) @test get!((()->begin 4 end), wkd, C) == 4 @test wkd == WeakKeyDict(A => 2, B => 3, C => 4) @test get!((()->begin 5 end), wkd, [1.0]) == 2 GC.@preserve A B C D nothing end begin A = [1] B = [2] C = [3] wkd = WeakKeyDict() wkd[A] = 2 wkd[B] = 3 wkd[C] = 4 dd = convert(Dict{Any, Any}, wkd) @test WeakKeyDict(dd) == wkd @test convert(WeakKeyDict{Any, Any}, dd) == wkd @test WeakKeyDict(dd) isa WeakKeyDict{Any, Any} @test WeakKeyDict(A => 2, B => 3, C => 4) == wkd @test WeakKeyDict(A => 2, B => 3, C => 4) isa WeakKeyDict{Array{Int, 1}, Int} @test WeakKeyDict((a => i + 1 for (i, a) = enumerate([A, B, C]))) == wkd @test WeakKeyDict([(A, 2), (B, 3), (C, 4)]) == wkd @test WeakKeyDict{typeof(A), Int64}(Pair(A, 2), Pair(B, 3), Pair(C, 4)) == wkd @test WeakKeyDict(Pair(A, 2), Pair(B, 3), Pair(C, 4)) == wkd D = [[4.0]] @test WeakKeyDict(Pair(A, 2), Pair(B, 3), Pair(D, 4.0)) isa WeakKeyDict{Any, Any} @test WeakKeyDict(Pair(A, 2), Pair(B, 3.0), Pair(C, 4)) isa WeakKeyDict{Array{Int, 1}, Any} @test WeakKeyDict(Pair(convert(Vector{Number}, A), 2), Pair(B, 3), Pair(C, 4)) isa WeakKeyDict{Any, Int} @test copy(wkd) == wkd @test length(wkd) == 3 @test !(isempty(wkd)) res = pop!(wkd, C) @test res == 4 @test length(wkd) == 2 res = pop!(wkd, C, 3) @test res == 3 @test C ∉ keys(wkd) @test 4 ∉ values(wkd) @test length(wkd) == 2 @test !(isempty(wkd)) wkd = filter!((p->begin p.first != B end), wkd) @test B ∉ keys(wkd) @test 3 ∉ values(wkd) @test length(wkd) == 1 @test WeakKeyDict(Pair(A, 2)) == wkd @test !(isempty(wkd)) wkd = empty!(wkd) @test wkd == empty(wkd) @test typeof(wkd) == typeof(empty(wkd)) @test length(wkd) == 0 @test isempty(wkd) @test wkd isa WeakKeyDict @test_throws ArgumentError WeakKeyDict([1, 2, 3]) wkd = WeakKeyDict(A => 1) @test delete!(wkd, A) == empty(wkd) @test delete!(wkd, A) === wkd d26939 = WeakKeyDict() (@noinline((d->begin d[1 + 1] = 1 end)))(d26939) GC.gc() @test count(d26939) == 0 @test length(d26939.ht) == 1 @test length(d26939) == 0 @test isempty(d26939) empty!(d26939) for i = 1:8 (@noinline(((d, i)->begin d[big(i + 12345)] = 1 end)))(d26939, i) end lock(GC.gc, d26939) @test length(d26939.ht) == 8 @test count(d26939) == 0 @test !(haskey(d26939, nothing)) @test_throws KeyError(nothing) d26939[nothing] @test_throws KeyError(nothing) get(d26939, nothing, 1) @test_throws KeyError(nothing) get((()->begin 1 end), d26939, nothing) @test_throws KeyError(nothing) pop!(d26939, nothing) @test getkey(d26939, nothing, 321) === 321 @test pop!(d26939, nothing, 321) === 321 @test delete!(d26939, nothing) === d26939 @test length(d26939.ht) == 8 @test_throws ArgumentError d26939[nothing] = 1 @test_throws ArgumentError get!(d26939, nothing, 1) @test_throws ArgumentError get!((()->begin 1 end), d26939, nothing) @test isempty(d26939) @test length(d26939.ht) == 0 @test length(d26939) == 0 @test_throws ArgumentError WeakKeyDict{Vector{Int}, Any}([5.0] => 1) wkd = WeakKeyDict(A => 2) @test_throws ArgumentError get!(wkd, [2.0], 2) @test get!(wkd, [1.0], 2) === 2 wkd = WeakKeyDict(A => 2) @test keytype(wkd) == Vector{Int} @test wkd[[1.0]] == 2 @test haskey(wkd, [1.0]) @test pop!(wkd, [1.0]) == 2 @test get((()->begin 3 end), wkd, [2.0]) == 3 wkd = WeakKeyDict(A => 2, B => 3) map!((v->begin v - 1 end), values(wkd)) @test wkd == WeakKeyDict(A => 1, B => 2) wkd = WeakKeyDict(A => 2) @test get!(wkd, B, 3) == 3 @test wkd == WeakKeyDict(A => 2, B => 3) @test get!((()->begin 4 end), wkd, C) == 4 @test wkd == WeakKeyDict(A => 2, B => 3, C => 4) @test get!((()->begin 5 end), wkd, [1.0]) == 2 GC.@preserve A B C D nothing end @testset "WeakKeyDict" begin A = [1] B = [2] C = [3] wkd = WeakKeyDict() wkd[A] = 2 wkd[B] = 3 wkd[C] = 4 dd = convert(Dict{Any, Any}, wkd) @test WeakKeyDict(dd) == wkd @test convert(WeakKeyDict{Any, Any}, dd) == wkd @test WeakKeyDict(dd) isa WeakKeyDict{Any, Any} @test WeakKeyDict(A => 2, B => 3, C => 4) == wkd @test WeakKeyDict(A => 2, B => 3, C => 4) isa WeakKeyDict{Array{Int, 1}, Int} @test WeakKeyDict((a => i + 1 for (i, a) = enumerate([A, B, C]))) == wkd @test WeakKeyDict([(A, 2), (B, 3), (C, 4)]) == wkd @test WeakKeyDict{typeof(A), Int64}(Pair(A, 2), Pair(B, 3), Pair(C, 4)) == wkd @test WeakKeyDict(Pair(A, 2), Pair(B, 3), Pair(C, 4)) == wkd D = [[4.0]] @test WeakKeyDict(Pair(A, 2), Pair(B, 3), Pair(D, 4.0)) isa WeakKeyDict{Any, Any} @test WeakKeyDict(Pair(A, 2), Pair(B, 3.0), Pair(C, 4)) isa WeakKeyDict{Array{Int, 1}, Any} @test WeakKeyDict(Pair(convert(Vector{Number}, A), 2), Pair(B, 3), Pair(C, 4)) isa WeakKeyDict{Any, Int} @test copy(wkd) == wkd @test length(wkd) == 3 @test !(isempty(wkd)) res = pop!(wkd, C) @test res == 4 @test length(wkd) == 2 res = pop!(wkd, C, 3) @test res == 3 @test C ∉ keys(wkd) @test 4 ∉ values(wkd) @test length(wkd) == 2 @test !(isempty(wkd)) wkd = filter!((p->begin p.first != B end), wkd) @test B ∉ keys(wkd) @test 3 ∉ values(wkd) @test length(wkd) == 1 @test WeakKeyDict(Pair(A, 2)) == wkd @test !(isempty(wkd)) wkd = empty!(wkd) @test wkd == empty(wkd) @test typeof(wkd) == typeof(empty(wkd)) @test length(wkd) == 0 @test isempty(wkd) @test wkd isa WeakKeyDict @test_throws ArgumentError WeakKeyDict([1, 2, 3]) wkd = WeakKeyDict(A => 1) @test delete!(wkd, A) == empty(wkd) @test delete!(wkd, A) === wkd d26939 = WeakKeyDict() (@noinline((d->begin d[1 + 1] = 1 end)))(d26939) GC.gc() @test count(d26939) == 0 @test length(d26939.ht) == 1 @test length(d26939) == 0 @test isempty(d26939) empty!(d26939) for i = 1:8 (@noinline(((d, i)->begin d[big(i + 12345)] = 1 end)))(d26939, i) end lock(GC.gc, d26939) @test length(d26939.ht) == 8 @test count(d26939) == 0 @test !(haskey(d26939, nothing)) @test_throws KeyError(nothing) d26939[nothing] @test_throws KeyError(nothing) get(d26939, nothing, 1) @test_throws KeyError(nothing) get((()->begin 1 end), d26939, nothing) @test_throws KeyError(nothing) pop!(d26939, nothing) @test getkey(d26939, nothing, 321) === 321 @test pop!(d26939, nothing, 321) === 321 @test delete!(d26939, nothing) === d26939 @test length(d26939.ht) == 8 @test_throws ArgumentError d26939[nothing] = 1 @test_throws ArgumentError get!(d26939, nothing, 1) @test_throws ArgumentError get!((()->begin 1 end), d26939, nothing) @test isempty(d26939) @test length(d26939.ht) == 0 @test length(d26939) == 0 @test_throws ArgumentError WeakKeyDict{Vector{Int}, Any}([5.0] => 1) wkd = WeakKeyDict(A => 2) @test_throws ArgumentError get!(wkd, [2.0], 2) @test get!(wkd, [1.0], 2) === 2 wkd = WeakKeyDict(A => 2) @test keytype(wkd) == Vector{Int} @test wkd[[1.0]] == 2 @test haskey(wkd, [1.0]) @test pop!(wkd, [1.0]) == 2 @test get((()->begin 3 end), wkd, [2.0]) == 3 wkd = WeakKeyDict(A => 2, B => 3) map!((v->begin v - 1 end), values(wkd)) @test wkd == WeakKeyDict(A => 1, B => 2) wkd = WeakKeyDict(A => 2) @test get!(wkd, B, 3) == 3 @test wkd == WeakKeyDict(A => 2, B => 3) @test get!((()->begin 4 end), wkd, C) == 4 @test wkd == WeakKeyDict(A => 2, B => 3, C => 4) @test get!((()->begin 5 end), wkd, [1.0]) == 2 GC.@preserve A B C D nothing end @testset "WeakKeyDict" begin A = [1] B = [2] C = [3] wkd = WeakKeyDict() wkd[A] = 2 wkd[B] = 3 wkd[C] = 4 dd = convert(Dict{Any, Any}, wkd) @test WeakKeyDict(dd) == wkd @test convert(WeakKeyDict{Any, Any}, dd) == wkd @test WeakKeyDict(dd) isa WeakKeyDict{Any, Any} @test WeakKeyDict(A => 2, B => 3, C => 4) == wkd @test WeakKeyDict(A => 2, B => 3, C => 4) isa WeakKeyDict{Array{Int, 1}, Int} @test WeakKeyDict((a => i + 1 for (i, a) = enumerate([A, B, C]))) == wkd @test WeakKeyDict([(A, 2), (B, 3), (C, 4)]) == wkd @test WeakKeyDict{typeof(A), Int64}(Pair(A, 2), Pair(B, 3), Pair(C, 4)) == wkd @test WeakKeyDict(Pair(A, 2), Pair(B, 3), Pair(C, 4)) == wkd D = [[4.0]] @test WeakKeyDict(Pair(A, 2), Pair(B, 3), Pair(D, 4.0)) isa WeakKeyDict{Any, Any} @test WeakKeyDict(Pair(A, 2), Pair(B, 3.0), Pair(C, 4)) isa WeakKeyDict{Array{Int, 1}, Any} @test WeakKeyDict(Pair(convert(Vector{Number}, A), 2), Pair(B, 3), Pair(C, 4)) isa WeakKeyDict{Any, Int} @test copy(wkd) == wkd @test length(wkd) == 3 @test !(isempty(wkd)) res = pop!(wkd, C) @test res == 4 @test length(wkd) == 2 res = pop!(wkd, C, 3) @test res == 3 @test C ∉ keys(wkd) @test 4 ∉ values(wkd) @test length(wkd) == 2 @test !(isempty(wkd)) wkd = filter!((p->begin p.first != B end), wkd) @test B ∉ keys(wkd) @test 3 ∉ values(wkd) @test length(wkd) == 1 @test WeakKeyDict(Pair(A, 2)) == wkd @test !(isempty(wkd)) wkd = empty!(wkd) @test wkd == empty(wkd) @test typeof(wkd) == typeof(empty(wkd)) @test length(wkd) == 0 @test isempty(wkd) @test wkd isa WeakKeyDict @test_throws ArgumentError WeakKeyDict([1, 2, 3]) wkd = WeakKeyDict(A => 1) @test delete!(wkd, A) == empty(wkd) @test delete!(wkd, A) === wkd d26939 = WeakKeyDict() (@noinline((d->begin d[1 + 1] = 1 end)))(d26939) GC.gc() @test count(d26939) == 0 @test length(d26939.ht) == 1 @test length(d26939) == 0 @test isempty(d26939) empty!(d26939) for i = 1:8 (@noinline(((d, i)->begin d[big(i + 12345)] = 1 end)))(d26939, i) end lock(GC.gc, d26939) @test length(d26939.ht) == 8 @test count(d26939) == 0 @test !(haskey(d26939, nothing)) @test_throws KeyError(nothing) d26939[nothing] @test_throws KeyError(nothing) get(d26939, nothing, 1) @test_throws KeyError(nothing) get((()->begin 1 end), d26939, nothing) @test_throws KeyError(nothing) pop!(d26939, nothing) @test getkey(d26939, nothing, 321) === 321 @test pop!(d26939, nothing, 321) === 321 @test delete!(d26939, nothing) === d26939 @test length(d26939.ht) == 8 @test_throws ArgumentError d26939[nothing] = 1 @test_throws ArgumentError get!(d26939, nothing, 1) @test_throws ArgumentError get!((()->begin 1 end), d26939, nothing) @test isempty(d26939) @test length(d26939.ht) == 0 @test length(d26939) == 0 @test_throws ArgumentError WeakKeyDict{Vector{Int}, Any}([5.0] => 1) wkd = WeakKeyDict(A => 2) @test_throws ArgumentError get!(wkd, [2.0], 2) @test get!(wkd, [1.0], 2) === 2 wkd = WeakKeyDict(A => 2) @test keytype(wkd) == Vector{Int} @test wkd[[1.0]] == 2 @test haskey(wkd, [1.0]) @test pop!(wkd, [1.0]) == 2 @test get((()->begin 3 end), wkd, [2.0]) == 3 wkd = WeakKeyDict(A => 2, B => 3) map!((v->begin v - 1 end), values(wkd)) @test wkd == WeakKeyDict(A => 1, B => 2) wkd = WeakKeyDict(A => 2) @test get!(wkd, B, 3) == 3 @test wkd == WeakKeyDict(A => 2, B => 3) @test get!((()->begin 4 end), wkd, C) == 4 @test wkd == WeakKeyDict(A => 2, B => 3, C => 4) @test get!((()->begin 5 end), wkd, [1.0]) == 2 GC.@preserve A B C D nothing end Parsing files in Base: Test Failed at /home/pkgeval/.julia/packages/CSTParser/0hXvH/test/test_check_base.jl:166 Expression: false Stacktrace: [1] top-level scope @ ~/.julia/packages/CSTParser/0hXvH/test/test_check_base.jl:166 [2] macro expansion @ /opt/julia/share/julia/stdlib/v1.13/Test/src/Test.jl:745 [inlined] ┌ Error: parsing difference │ file = "/opt/julia/bin/../share/julia/test/gmp.jl" └ @ Main.var"##439" ~/.julia/packages/CSTParser/0hXvH/test/test_check_base.jl:157 big(Int8(-128)) == -128 big(Int8(-128)) == -128 @test big(Int8(-128)) == -128 @test big(Int8(-128)) == -128 big(Int16(-32768)) == -32768 big(Int16(-32768)) == -32768 @test big(Int16(-32768)) == -32768 @test big(Int16(-32768)) == -32768 big(Int32(-2147483648)) == -2147483648 big(Int32(-2147483648)) == -2147483648 @test big(Int32(-2147483648)) == -2147483648 @test big(Int32(-2147483648)) == -2147483648 big(Int64(-9223372036854775808)) == -9223372036854775808 big(Int64(-9223372036854775808)) == -9223372036854775808 @test big(Int64(-9223372036854775808)) == -9223372036854775808 @test big(Int64(-9223372036854775808)) == -9223372036854775808 big(Int128(-170141183460469231731687303715884105728)) == -170141183460469231731687303715884105728 big(Int128(-170141183460469231731687303715884105728)) == -170141183460469231731687303715884105728 @test big(Int128(-170141183460469231731687303715884105728)) == -170141183460469231731687303715884105728 @test big(Int128(-170141183460469231731687303715884105728)) == -170141183460469231731687303715884105728 begin @test big(Int8(-128)) == -128 @test big(Int16(-32768)) == -32768 @test big(Int32(-2147483648)) == -2147483648 @test big(Int64(-9223372036854775808)) == -9223372036854775808 @test big(Int128(-170141183460469231731687303715884105728)) == -170141183460469231731687303715884105728 end begin @test big(Int8(-128)) == -128 @test big(Int16(-32768)) == -32768 @test big(Int32(-2147483648)) == -2147483648 @test big(Int64(-9223372036854775808)) == -9223372036854775808 @test big(Int128(-170141183460469231731687303715884105728)) == -170141183460469231731687303715884105728 end @testset "conversion from typemin(T)" begin @test big(Int8(-128)) == -128 @test big(Int16(-32768)) == -32768 @test big(Int32(-2147483648)) == -2147483648 @test big(Int64(-9223372036854775808)) == -9223372036854775808 @test big(Int128(-170141183460469231731687303715884105728)) == -170141183460469231731687303715884105728 end @testset "conversion from typemin(T)" begin @test big(Int8(-128)) == -128 @test big(Int16(-32768)) == -32768 @test big(Int32(-2147483648)) == -2147483648 @test big(Int64(-9223372036854775808)) == -9223372036854775808 @test big(Int128(-170141183460469231731687303715884105728)) == -170141183460469231731687303715884105728 end 2 ^ 256 2 ^ 256 2 ^ -256 2 ^ -256 2 ^ 256 + 2 ^ -256 + 1 2 ^ 256 + 2 ^ -256 + 1 x = 2 ^ 256 + 2 ^ -256 + 1 x = 2 ^ 256 + 2 ^ -256 + 1 2 ^ 64 2 ^ 64 2 ^ -64 2 ^ -64 2 ^ 64 + 2 ^ -64 + 1 2 ^ 64 + 2 ^ -64 + 1 x = 2 ^ 64 + 2 ^ -64 + 1 x = 2 ^ 64 + 2 ^ -64 + 1 2 ^ 15 2 ^ 15 2 ^ -15 2 ^ -15 2 ^ 15 + 2 ^ -15 + 1 2 ^ 15 + 2 ^ -15 + 1 x = 2 ^ 15 + 2 ^ -15 + 1 x = 2 ^ 15 + 2 ^ -15 + 1 2 ^ (n + 1) 2 ^ (n + 1) T(2 ^ (n + 1)) T(2 ^ (n + 1)) T(2 ^ (n + 1)) === T(Inf) T(2 ^ (n + 1)) === T(Inf) @test T(2 ^ (n + 1)) === T(Inf) @test T(2 ^ (n + 1)) === T(Inf) 2 ^ (n + 1) 2 ^ (n + 1) 2 ^ (n - precision(T)) 2 ^ (n - precision(T)) 2 ^ (n + 1) - 2 ^ (n - precision(T)) 2 ^ (n + 1) - 2 ^ (n - precision(T)) T(2 ^ (n + 1) - 2 ^ (n - precision(T))) T(2 ^ (n + 1) - 2 ^ (n - precision(T))) T(2 ^ (n + 1) - 2 ^ (n - precision(T))) === T(Inf) T(2 ^ (n + 1) - 2 ^ (n - precision(T))) === T(Inf) @test T(2 ^ (n + 1) - 2 ^ (n - precision(T))) === T(Inf) @test T(2 ^ (n + 1) - 2 ^ (n - precision(T))) === T(Inf) 2 ^ (n + 1) 2 ^ (n + 1) 2 ^ (n - precision(T)) 2 ^ (n - precision(T)) 2 ^ (n + 1) - 2 ^ (n - precision(T)) 2 ^ (n + 1) - 2 ^ (n - precision(T)) (2 ^ (n + 1) - 2 ^ (n - precision(T))) - 1 (2 ^ (n + 1) - 2 ^ (n - precision(T))) - 1 T((2 ^ (n + 1) - 2 ^ (n - precision(T))) - 1) T((2 ^ (n + 1) - 2 ^ (n - precision(T))) - 1) T((2 ^ (n + 1) - 2 ^ (n - precision(T))) - 1) === floatmax(T) T((2 ^ (n + 1) - 2 ^ (n - precision(T))) - 1) === floatmax(T) @test T((2 ^ (n + 1) - 2 ^ (n - precision(T))) - 1) === floatmax(T) @test T((2 ^ (n + 1) - 2 ^ (n - precision(T))) - 1) === floatmax(T) begin n = exponent(floatmax(T)) @test T(2 ^ (n + 1)) === T(Inf) @test T(2 ^ (n + 1) - 2 ^ (n - precision(T))) === T(Inf) @test T((2 ^ (n + 1) - 2 ^ (n - precision(T))) - 1) === floatmax(T) end begin n = exponent(floatmax(T)) @test T(2 ^ (n + 1)) === T(Inf) @test T(2 ^ (n + 1) - 2 ^ (n - precision(T))) === T(Inf) @test T((2 ^ (n + 1) - 2 ^ (n - precision(T))) - 1) === floatmax(T) end for T = (Float16, Float32, Float64) n = exponent(floatmax(T)) @test T(2 ^ (n + 1)) === T(Inf) @test T(2 ^ (n + 1) - 2 ^ (n - precision(T))) === T(Inf) @test T((2 ^ (n + 1) - 2 ^ (n - precision(T))) - 1) === floatmax(T) end for T = (Float16, Float32, Float64) n = exponent(floatmax(T)) @test T(2 ^ (n + 1)) === T(Inf) @test T(2 ^ (n + 1) - 2 ^ (n - precision(T))) === T(Inf) @test T((2 ^ (n + 1) - 2 ^ (n - precision(T))) - 1) === floatmax(T) end begin x = 2 ^ 256 + 2 ^ -256 + 1 @test Float64(x) == reinterpret(Float64, 0x4ff0000000000001) @test Float64(-x) == -(Float64(x)) x = x >> 1 + 1 @test Float64(x) == reinterpret(Float64, 0x4fe0000000000001) @test Float64(-x) == -(Float64(x)) x = 2 ^ 64 + 2 ^ -64 + 1 @test Float32(x) == reinterpret(Float32, 0x5f800001) @test Float32(-x) == -(Float32(x)) x = x >> 1 + 1 @test Float32(x) == reinterpret(Float32, 0x5f000001) @test Float32(-x) == -(Float32(x)) x = 2 ^ 15 + 2 ^ -15 + 1 @test Float16(x) == reinterpret(Float16, 0x7801) @test Float16(-x) == -(Float16(x)) x = x >> 1 + 1 @test Float16(x) == reinterpret(Float16, 0x7401) @test Float16(-x) == -(Float16(x)) for T = (Float16, Float32, Float64) n = exponent(floatmax(T)) @test T(2 ^ (n + 1)) === T(Inf) @test T(2 ^ (n + 1) - 2 ^ (n - precision(T))) === T(Inf) @test T((2 ^ (n + 1) - 2 ^ (n - precision(T))) - 1) === floatmax(T) end end begin x = 2 ^ 256 + 2 ^ -256 + 1 @test Float64(x) == reinterpret(Float64, 0x4ff0000000000001) @test Float64(-x) == -(Float64(x)) x = x >> 1 + 1 @test Float64(x) == reinterpret(Float64, 0x4fe0000000000001) @test Float64(-x) == -(Float64(x)) x = 2 ^ 64 + 2 ^ -64 + 1 @test Float32(x) == reinterpret(Float32, 0x5f800001) @test Float32(-x) == -(Float32(x)) x = x >> 1 + 1 @test Float32(x) == reinterpret(Float32, 0x5f000001) @test Float32(-x) == -(Float32(x)) x = 2 ^ 15 + 2 ^ -15 + 1 @test Float16(x) == reinterpret(Float16, 0x7801) @test Float16(-x) == -(Float16(x)) x = x >> 1 + 1 @test Float16(x) == reinterpret(Float16, 0x7401) @test Float16(-x) == -(Float16(x)) for T = (Float16, Float32, Float64) n = exponent(floatmax(T)) @test T(2 ^ (n + 1)) === T(Inf) @test T(2 ^ (n + 1) - 2 ^ (n - precision(T))) === T(Inf) @test T((2 ^ (n + 1) - 2 ^ (n - precision(T))) - 1) === floatmax(T) end end @testset "conversion to Float" begin x = 2 ^ 256 + 2 ^ -256 + 1 @test Float64(x) == reinterpret(Float64, 0x4ff0000000000001) @test Float64(-x) == -(Float64(x)) x = x >> 1 + 1 @test Float64(x) == reinterpret(Float64, 0x4fe0000000000001) @test Float64(-x) == -(Float64(x)) x = 2 ^ 64 + 2 ^ -64 + 1 @test Float32(x) == reinterpret(Float32, 0x5f800001) @test Float32(-x) == -(Float32(x)) x = x >> 1 + 1 @test Float32(x) == reinterpret(Float32, 0x5f000001) @test Float32(-x) == -(Float32(x)) x = 2 ^ 15 + 2 ^ -15 + 1 @test Float16(x) == reinterpret(Float16, 0x7801) @test Float16(-x) == -(Float16(x)) x = x >> 1 + 1 @test Float16(x) == reinterpret(Float16, 0x7401) @test Float16(-x) == -(Float16(x)) for T = (Float16, Float32, Float64) n = exponent(floatmax(T)) @test T(2 ^ (n + 1)) === T(Inf) @test T(2 ^ (n + 1) - 2 ^ (n - precision(T))) === T(Inf) @test T((2 ^ (n + 1) - 2 ^ (n - precision(T))) - 1) === floatmax(T) end end @testset "conversion to Float" begin x = 2 ^ 256 + 2 ^ -256 + 1 @test Float64(x) == reinterpret(Float64, 0x4ff0000000000001) @test Float64(-x) == -(Float64(x)) x = x >> 1 + 1 @test Float64(x) == reinterpret(Float64, 0x4fe0000000000001) @test Float64(-x) == -(Float64(x)) x = 2 ^ 64 + 2 ^ -64 + 1 @test Float32(x) == reinterpret(Float32, 0x5f800001) @test Float32(-x) == -(Float32(x)) x = x >> 1 + 1 @test Float32(x) == reinterpret(Float32, 0x5f000001) @test Float32(-x) == -(Float32(x)) x = 2 ^ 15 + 2 ^ -15 + 1 @test Float16(x) == reinterpret(Float16, 0x7801) @test Float16(-x) == -(Float16(x)) x = x >> 1 + 1 @test Float16(x) == reinterpret(Float16, 0x7401) @test Float16(-x) == -(Float16(x)) for T = (Float16, Float32, Float64) n = exponent(floatmax(T)) @test T(2 ^ (n + 1)) === T(Inf) @test T(2 ^ (n + 1) - 2 ^ (n - precision(T))) === T(Inf) @test T((2 ^ (n + 1) - 2 ^ (n - precision(T))) - 1) === floatmax(T) end end Parsing files in Base: Test Failed at /home/pkgeval/.julia/packages/CSTParser/0hXvH/test/test_check_base.jl:166 Expression: false Stacktrace: [1] top-level scope @ ~/.julia/packages/CSTParser/0hXvH/test/test_check_base.jl:166 [2] macro expansion @ /opt/julia/share/julia/stdlib/v1.13/Test/src/Test.jl:745 [inlined] ┌ Error: parsing difference │ file = "/opt/julia/bin/../share/julia/test/int.jl" └ @ Main.var"##439" ~/.julia/packages/CSTParser/0hXvH/test/test_check_base.jl:157 2 ^ 100 2 ^ 100 2 ^ 100 == BigInt(2) ^ 100 2 ^ 100 == BigInt(2) ^ 100 @test 2 ^ 100 == BigInt(2) ^ 100 @test 2 ^ 100 == BigInt(2) ^ 100 2 isa BigInt 2 isa BigInt @test 2 isa BigInt @test 2 isa BigInt 1.0 == BigFloat(1.0) 1.0 == BigFloat(1.0) @test 1.0 == BigFloat(1.0) @test 1.0 == BigFloat(1.0) begin @test 2 ^ 100 == BigInt(2) ^ 100 @test 2 isa BigInt @test 1.0 == BigFloat(1.0) @test_throws ArgumentError "1.0.3" @test_throws ArgumentError "pi" @test_throws ArgumentError "_æ1" @test_throws ArgumentError "æ_1" @test_throws ArgumentError "_ææ" end begin @test 2 ^ 100 == BigInt(2) ^ 100 @test 2 isa BigInt @test 1.0 == BigFloat(1.0) @test_throws ArgumentError "1.0.3" @test_throws ArgumentError "pi" @test_throws ArgumentError "_æ1" @test_throws ArgumentError "æ_1" @test_throws ArgumentError "_ææ" end @testset "big" begin @test 2 ^ 100 == BigInt(2) ^ 100 @test 2 isa BigInt @test 1.0 == BigFloat(1.0) @test_throws ArgumentError "1.0.3" @test_throws ArgumentError "pi" @test_throws ArgumentError "_æ1" @test_throws ArgumentError "æ_1" @test_throws ArgumentError "_ææ" end @testset "big" begin @test 2 ^ 100 == BigInt(2) ^ 100 @test 2 isa BigInt @test 1.0 == BigFloat(1.0) @test_throws ArgumentError "1.0.3" @test_throws ArgumentError "pi" @test_throws ArgumentError "_æ1" @test_throws ArgumentError "æ_1" @test_throws ArgumentError "_ææ" end Parsing files in Base: Test Failed at /home/pkgeval/.julia/packages/CSTParser/0hXvH/test/test_check_base.jl:166 Expression: false Stacktrace: [1] top-level scope @ ~/.julia/packages/CSTParser/0hXvH/test/test_check_base.jl:166 [2] macro expansion @ /opt/julia/share/julia/stdlib/v1.13/Test/src/Test.jl:745 [inlined] ┌ Error: parsing difference │ file = "/opt/julia/bin/../share/julia/test/math.jl" └ @ Main.var"##439" ~/.julia/packages/CSTParser/0hXvH/test/test_check_base.jl:157 cosc(0.5) cosc(0.5) cosc(0.5) ≈ -1.273239544735162686151070106980114896275677165923651589981338752471174381073817 cosc(0.5) ≈ -1.273239544735162686151070106980114896275677165923651589981338752471174381073817 @test cosc(0.5) ≈ -1.273239544735162686151070106980114896275677165923651589981338752471174381073817 rtol = 1.0e-76 @test cosc(0.5) ≈ -1.273239544735162686151070106980114896275677165923651589981338752471174381073817 rtol = 1.0e-76 cosc(0.4989999999999999999999999999999999999999999999999999999999999999999999999999994) cosc(0.4989999999999999999999999999999999999999999999999999999999999999999999999999994) cosc(0.4989999999999999999999999999999999999999999999999999999999999999999999999999994) ≈ -1.272045747741181369948389133250213864178198918667041860771078493955590574971317 cosc(0.4989999999999999999999999999999999999999999999999999999999999999999999999999994) ≈ -1.272045747741181369948389133250213864178198918667041860771078493955590574971317 @test cosc(0.4989999999999999999999999999999999999999999999999999999999999999999999999999994) ≈ -1.272045747741181369948389133250213864178198918667041860771078493955590574971317 rtol = 1.0e-76 @test cosc(0.4989999999999999999999999999999999999999999999999999999999999999999999999999994) ≈ -1.272045747741181369948389133250213864178198918667041860771078493955590574971317 rtol = 1.0e-76 begin @test cosc(0.5) ≈ -1.273239544735162686151070106980114896275677165923651589981338752471174381073817 rtol = 1.0e-76 @test cosc(0.4989999999999999999999999999999999999999999999999999999999999999999999999999994) ≈ -1.272045747741181369948389133250213864178198918667041860771078493955590574971317 rtol = 1.0e-76 end begin @test cosc(0.5) ≈ -1.273239544735162686151070106980114896275677165923651589981338752471174381073817 rtol = 1.0e-76 @test cosc(0.4989999999999999999999999999999999999999999999999999999999999999999999999999994) ≈ -1.272045747741181369948389133250213864178198918667041860771078493955590574971317 rtol = 1.0e-76 end ()->begin @test cosc(0.5) ≈ -1.273239544735162686151070106980114896275677165923651589981338752471174381073817 rtol = 1.0e-76 @test cosc(0.4989999999999999999999999999999999999999999999999999999999999999999999999999994) ≈ -1.272045747741181369948389133250213864178198918667041860771078493955590574971317 rtol = 1.0e-76 end ()->begin @test cosc(0.5) ≈ -1.273239544735162686151070106980114896275677165923651589981338752471174381073817 rtol = 1.0e-76 @test cosc(0.4989999999999999999999999999999999999999999999999999999999999999999999999999994) ≈ -1.272045747741181369948389133250213864178198918667041860771078493955590574971317 rtol = 1.0e-76 end setprecision(256) do @test cosc(0.5) ≈ -1.273239544735162686151070106980114896275677165923651589981338752471174381073817 rtol = 1.0e-76 @test cosc(0.4989999999999999999999999999999999999999999999999999999999999999999999999999994) ≈ -1.272045747741181369948389133250213864178198918667041860771078493955590574971317 rtol = 1.0e-76 end setprecision(256) do @test cosc(0.5) ≈ -1.273239544735162686151070106980114896275677165923651589981338752471174381073817 rtol = 1.0e-76 @test cosc(0.4989999999999999999999999999999999999999999999999999999999999999999999999999994) ≈ -1.272045747741181369948389133250213864178198918667041860771078493955590574971317 rtol = 1.0e-76 end begin setprecision(256) do for R = (BigFloat, Float16, Float32, Float64) for T = (R, Complex{R}) for x = (0, 1.0e-5, 1.0e-20, 1.0e-30, 1.0e-40, 1.0e-50, 1.0e-60, 1.0e-70, 5.07138898934e-313) if x < eps(R) @test sinc(T(x)) == 1 end @test cosc(T(x)) ≈ (pi * (-(R(x)) * pi)) / 3 rtol = max(eps(R) * 100, (pi * R(x)) ^ 2) end end end end @test @inferred(sinc(0 // 1)) ⩲ 1.0 @test @inferred(cosc(0 // 1)) ⩲ -0.0 @test sinc(0.001) ≈ 0.999998355066745 rtol = 1.0e-15 @test sinc(0.00099) ≈ 0.9999983878009009 rtol = 1.0e-15 @test sinc(0.05f0) ≈ 0.9958927352435614 rtol = 1.0e-7 @test sinc(0.0499f0) ≈ 0.9959091277049384 rtol = 1.0e-7 if has_fma[Float64] @test cosc(0.14) ≈ -0.4517331883801308 rtol = 1.0e-15 else @test cosc(0.14) ≈ -0.4517331883801308 rtol = 1.0e-14 end @test cosc(0.1399) ≈ -0.45142306168781854 rtol = 1.0e-14 @test cosc(0.26f0) ≈ -0.7996401373462212 rtol = 5.0e-7 @test cosc(0.2599f0) ≈ -0.7993744054401625 rtol = 5.0e-7 setprecision(256) do @test cosc(0.5) ≈ -1.273239544735162686151070106980114896275677165923651589981338752471174381073817 rtol = 1.0e-76 @test cosc(0.4989999999999999999999999999999999999999999999999999999999999999999999999999994) ≈ -1.272045747741181369948389133250213864178198918667041860771078493955590574971317 rtol = 1.0e-76 end end begin setprecision(256) do for R = (BigFloat, Float16, Float32, Float64) for T = (R, Complex{R}) for x = (0, 1.0e-5, 1.0e-20, 1.0e-30, 1.0e-40, 1.0e-50, 1.0e-60, 1.0e-70, 5.07138898934e-313) if x < eps(R) @test sinc(T(x)) == 1 end @test cosc(T(x)) ≈ (pi * (-(R(x)) * pi)) / 3 rtol = max(eps(R) * 100, (pi * R(x)) ^ 2) end end end end @test @inferred(sinc(0 // 1)) ⩲ 1.0 @test @inferred(cosc(0 // 1)) ⩲ -0.0 @test sinc(0.001) ≈ 0.999998355066745 rtol = 1.0e-15 @test sinc(0.00099) ≈ 0.9999983878009009 rtol = 1.0e-15 @test sinc(0.05f0) ≈ 0.9958927352435614 rtol = 1.0e-7 @test sinc(0.0499f0) ≈ 0.9959091277049384 rtol = 1.0e-7 if has_fma[Float64] @test cosc(0.14) ≈ -0.4517331883801308 rtol = 1.0e-15 else @test cosc(0.14) ≈ -0.4517331883801308 rtol = 1.0e-14 end @test cosc(0.1399) ≈ -0.45142306168781854 rtol = 1.0e-14 @test cosc(0.26f0) ≈ -0.7996401373462212 rtol = 5.0e-7 @test cosc(0.2599f0) ≈ -0.7993744054401625 rtol = 5.0e-7 setprecision(256) do @test cosc(0.5) ≈ -1.273239544735162686151070106980114896275677165923651589981338752471174381073817 rtol = 1.0e-76 @test cosc(0.4989999999999999999999999999999999999999999999999999999999999999999999999999994) ≈ -1.272045747741181369948389133250213864178198918667041860771078493955590574971317 rtol = 1.0e-76 end end @testset "sinc/cosc accuracy" begin setprecision(256) do for R = (BigFloat, Float16, Float32, Float64) for T = (R, Complex{R}) for x = (0, 1.0e-5, 1.0e-20, 1.0e-30, 1.0e-40, 1.0e-50, 1.0e-60, 1.0e-70, 5.07138898934e-313) if x < eps(R) @test sinc(T(x)) == 1 end @test cosc(T(x)) ≈ (pi * (-(R(x)) * pi)) / 3 rtol = max(eps(R) * 100, (pi * R(x)) ^ 2) end end end end @test @inferred(sinc(0 // 1)) ⩲ 1.0 @test @inferred(cosc(0 // 1)) ⩲ -0.0 @test sinc(0.001) ≈ 0.999998355066745 rtol = 1.0e-15 @test sinc(0.00099) ≈ 0.9999983878009009 rtol = 1.0e-15 @test sinc(0.05f0) ≈ 0.9958927352435614 rtol = 1.0e-7 @test sinc(0.0499f0) ≈ 0.9959091277049384 rtol = 1.0e-7 if has_fma[Float64] @test cosc(0.14) ≈ -0.4517331883801308 rtol = 1.0e-15 else @test cosc(0.14) ≈ -0.4517331883801308 rtol = 1.0e-14 end @test cosc(0.1399) ≈ -0.45142306168781854 rtol = 1.0e-14 @test cosc(0.26f0) ≈ -0.7996401373462212 rtol = 5.0e-7 @test cosc(0.2599f0) ≈ -0.7993744054401625 rtol = 5.0e-7 setprecision(256) do @test cosc(0.5) ≈ -1.273239544735162686151070106980114896275677165923651589981338752471174381073817 rtol = 1.0e-76 @test cosc(0.4989999999999999999999999999999999999999999999999999999999999999999999999999994) ≈ -1.272045747741181369948389133250213864178198918667041860771078493955590574971317 rtol = 1.0e-76 end end @testset "sinc/cosc accuracy" begin setprecision(256) do for R = (BigFloat, Float16, Float32, Float64) for T = (R, Complex{R}) for x = (0, 1.0e-5, 1.0e-20, 1.0e-30, 1.0e-40, 1.0e-50, 1.0e-60, 1.0e-70, 5.07138898934e-313) if x < eps(R) @test sinc(T(x)) == 1 end @test cosc(T(x)) ≈ (pi * (-(R(x)) * pi)) / 3 rtol = max(eps(R) * 100, (pi * R(x)) ^ 2) end end end end @test @inferred(sinc(0 // 1)) ⩲ 1.0 @test @inferred(cosc(0 // 1)) ⩲ -0.0 @test sinc(0.001) ≈ 0.999998355066745 rtol = 1.0e-15 @test sinc(0.00099) ≈ 0.9999983878009009 rtol = 1.0e-15 @test sinc(0.05f0) ≈ 0.9958927352435614 rtol = 1.0e-7 @test sinc(0.0499f0) ≈ 0.9959091277049384 rtol = 1.0e-7 if has_fma[Float64] @test cosc(0.14) ≈ -0.4517331883801308 rtol = 1.0e-15 else @test cosc(0.14) ≈ -0.4517331883801308 rtol = 1.0e-14 end @test cosc(0.1399) ≈ -0.45142306168781854 rtol = 1.0e-14 @test cosc(0.26f0) ≈ -0.7996401373462212 rtol = 5.0e-7 @test cosc(0.2599f0) ≈ -0.7993744054401625 rtol = 5.0e-7 setprecision(256) do @test cosc(0.5) ≈ -1.273239544735162686151070106980114896275677165923651589981338752471174381073817 rtol = 1.0e-76 @test cosc(0.4989999999999999999999999999999999999999999999999999999999999999999999999999994) ≈ -1.272045747741181369948389133250213864178198918667041860771078493955590574971317 rtol = 1.0e-76 end end prevfloat(1.0) ^ -(Int64(2)) prevfloat(1.0) ^ prevfloat prevfloat(1.0) 1.0 prevfloat(1.0) ^ -(Int64(2)) prevfloat(1.0) 62 -(Int64(2) ^ 62) (prevfloat(1.0) ^ -(Int64(2))) ^ 62 prevfloat(1.0) ^ -(Int64(2) ^ 62) (prevfloat(1.0) ^ -(Int64(2))) ^ 62 ≈ c53881 prevfloat(1.0) ^ -(Int64(2) ^ 62) ≈ c53881 @test (prevfloat(1.0) ^ -(Int64(2))) ^ 62 ≈ c53881 atol = 2 * eps(c53881) @test prevfloat(1.0) ^ -(Int64(2) ^ 62) ≈ c53881 atol = 2 * eps(c53881) begin POW_TOLS = Dict(Float16 => [0.51, 0.51, 0.51, 2.0, 1.5], Float32 => [0.51, 0.51, 0.51, 2.0, 1.5], Float64 => [0.55, 0.8, 1.5, 2.0, 1.5]) for T = (Float16, Float32, Float64) @inferred T T(1.1) ^ T(1.1) for x = (0.0, -0.0, 1.0, 10.0, 2.0, Inf, NaN, -Inf, -NaN) for y = (0.0, -0.0, 1.0, -3.0, -10.0, Inf, NaN, -Inf, -NaN) (got, expected) = (T(x) ^ T(y), T(big(x) ^ T(y))) if isnan(expected) @test isnan_type(T, got) || T.((x, y)) else @test got == expected || T.((x, y)) end end end for _ = 1:2 ^ 16 x = rand(T) * 100 y = rand(T) * 200 - 100 (got, expected) = (x ^ y, widen(x) ^ y) if isfinite(eps(T(expected))) if y == T(-2) @test abs(expected - got) <= (POW_TOLS[T])[4] * eps(T(expected)) || (x, y) elseif y == T(3) @test abs(expected - got) <= (POW_TOLS[T])[5] * eps(T(expected)) || (x, y) elseif issubnormal(got) @test abs(expected - got) <= (POW_TOLS[T])[2] * eps(T(expected)) || (x, y) else @test abs(expected - got) <= (POW_TOLS[T])[1] * eps(T(expected)) || (x, y) end end end for _ = 1:2 ^ 14 x = rand(T) * floatmin(T) y = rand(T) * 3 - T(1.2) (got, expected) = (x ^ y, widen(x) ^ y) if isfinite(eps(T(expected))) @test abs(expected - got) <= (POW_TOLS[T])[3] * eps(T(expected)) || (x, y) end end @test T(-1) ^ floatmax(T) === T(1) @test prevfloat(T(-1)) ^ floatmax(T) === T(Inf) @test nextfloat(T(-1)) ^ floatmax(T) === T(0.0) end @test 0.9999999955206014 ^ -1.0e8 == 1.565084574870928 @test 3.0e18 ^ 20 == Inf @test 0.0013653274095082324 ^ -97.60372292227069 == 4.088393948750035e279 @test 8.758520413376658e-5 ^ 70.55863059215994 == 5.052076767078296e-287 c53881 = 2.2844135865398217e222 @test (prevfloat(1.0) ^ -(Int64(2))) ^ 62 ≈ c53881 atol = 2 * eps(c53881) @test 2.0 ^ typemin(Int) == 0.0 @test (-1.0) ^ typemin(Int) == 1.0 Z = Int64(2) E = prevfloat(1.0) @test E ^ -(Z ^ 54) ≈ 7.38905609893065 @test E ^ -(Z ^ 62) ≈ 2.2844135865231613e222 @test E ^ -(Z ^ 63) == Inf @test abs(E ^ (Z ^ 62 - 1) * E ^ (-(Z ^ 62) + 1) - 1) <= eps(1.0) (n, x) = (-1065564664, 0.9999997040311492) @test abs(x ^ n - Float64(big(x) ^ n)) / eps(x ^ n) == 0 @test E ^ (big(2) ^ 100 + 1) == 0 @test E ^ 6705320061009595392 == nextfloat(0.0) n = Int64(1024 / log2(E)) @test E ^ n == Inf @test E ^ float(n) == Inf @testset "literal pow zero sign" begin @testset "T: $(T)" for T = (Float16, Float32, Float64, BigFloat) @testset "literal `-1`" begin @test -0.0 === Float64(T(-Inf) ^ -1) end @testset "`Int(-1)`" begin @test -0.0 === Float64(T(-Inf) ^ Int(-1)) end end end struct Issue55633_1 <: Number end struct Issue55633_3 <: Number end struct Issue55633_9 <: Number end Base.one(::Issue55633_3) = begin Issue55633_1() end Base.:*(::Issue55633_3, ::Issue55633_3) = begin Issue55633_9() end Base.promote_rule(::Type{Issue55633_1}, ::Type{Issue55633_3}) = begin Int end Base.promote_rule(::Type{Issue55633_3}, ::Type{Issue55633_9}) = begin Int end Base.promote_rule(::Type{Issue55633_1}, ::Type{Issue55633_9}) = begin Int end Base.promote_rule(::Type{Issue55633_1}, ::Type{Int}) = begin Int end Base.promote_rule(::Type{Issue55633_3}, ::Type{Int}) = begin Int end Base.promote_rule(::Type{Issue55633_9}, ::Type{Int}) = begin Int end Base.convert(::Type{Int}, ::Issue55633_1) = begin 1 end Base.convert(::Type{Int}, ::Issue55633_3) = begin 3 end Base.convert(::Type{Int}, ::Issue55633_9) = begin 9 end for x = (im, pi, Issue55633_3()) p = promote(one(x), x, x * x) for y = 0:2 @test all((t->begin (===)(t...) end), zip(x ^ y, p[y + 1])) end end @testset "rng exponentiation, issue #57590" begin @test EvenInteger(16) === @inferred(EvenInteger(2) ^ 4) @test EvenInteger(16) === @inferred(EvenInteger(2) ^ Int(4)) @test EvenInteger(16) === @inferred(EvenInteger(2) ^ EvenInteger(4)) end @test Float32(1.1) ^ typemin(Int) == Float32(0.0) @test Float16(1.1) ^ typemin(Int) == Float16(0.0) @test Float32(1.1) ^ unsigned(0) === Float32(1.0) @test Float32(1.1) ^ big(0) === Float32(1.0) struct Int3 <: Integer x::Int8 function Int3(x::Integer) if x < -4 || x > 3 Core.throw_inexacterror(:Int3, Int3, x) end return new(x) end end Base.typemin(::Type{Int3}) = begin Int3(-4) end (Base.promote_rule(::Type{Int3}, ::Type{T}) where T <: Integer) = begin T end (Base.convert(::Type{T}, x::Int3) where T <: Integer) = begin convert(T, x.x) end Base.:-(x::Int3) = begin if x.x == -4 x else Int3(-(x.x)) end end Base.trailing_zeros(x::Int3) = begin trailing_zeros(x.x) end Base.:>>(x::Int3, n::UInt64) = begin Int3(x.x >> n) end @test 1.001f0 ^ -3 == 1.001f0 ^ Int3(-3) @test 1.001f0 ^ -4 == 1.001f0 ^ typemin(Int3) end begin POW_TOLS = Dict(Float16 => [0.51, 0.51, 0.51, 2.0, 1.5], Float32 => [0.51, 0.51, 0.51, 2.0, 1.5], Float64 => [0.55, 0.8, 1.5, 2.0, 1.5]) for T = (Float16, Float32, Float64) @inferred T T(1.1) ^ T(1.1) for x = (0.0, -0.0, 1.0, 10.0, 2.0, Inf, NaN, -Inf, -NaN) for y = (0.0, -0.0, 1.0, -3.0, -10.0, Inf, NaN, -Inf, -NaN) (got, expected) = (T(x) ^ T(y), T(big(x) ^ T(y))) if isnan(expected) @test isnan_type(T, got) || T.((x, y)) else @test got == expected || T.((x, y)) end end end for _ = 1:2 ^ 16 x = rand(T) * 100 y = rand(T) * 200 - 100 (got, expected) = (x ^ y, widen(x) ^ y) if isfinite(eps(T(expected))) if y == T(-2) @test abs(expected - got) <= (POW_TOLS[T])[4] * eps(T(expected)) || (x, y) elseif y == T(3) @test abs(expected - got) <= (POW_TOLS[T])[5] * eps(T(expected)) || (x, y) elseif issubnormal(got) @test abs(expected - got) <= (POW_TOLS[T])[2] * eps(T(expected)) || (x, y) else @test abs(expected - got) <= (POW_TOLS[T])[1] * eps(T(expected)) || (x, y) end end end for _ = 1:2 ^ 14 x = rand(T) * floatmin(T) y = rand(T) * 3 - T(1.2) (got, expected) = (x ^ y, widen(x) ^ y) if isfinite(eps(T(expected))) @test abs(expected - got) <= (POW_TOLS[T])[3] * eps(T(expected)) || (x, y) end end @test T(-1) ^ floatmax(T) === T(1) @test prevfloat(T(-1)) ^ floatmax(T) === T(Inf) @test nextfloat(T(-1)) ^ floatmax(T) === T(0.0) end @test 0.9999999955206014 ^ -1.0e8 == 1.565084574870928 @test 3.0e18 ^ 20 == Inf @test 0.0013653274095082324 ^ -97.60372292227069 == 4.088393948750035e279 @test 8.758520413376658e-5 ^ 70.55863059215994 == 5.052076767078296e-287 c53881 = 2.2844135865398217e222 @test prevfloat(1.0) ^ -(Int64(2) ^ 62) ≈ c53881 atol = 2 * eps(c53881) @test 2.0 ^ typemin(Int) == 0.0 @test (-1.0) ^ typemin(Int) == 1.0 Z = Int64(2) E = prevfloat(1.0) @test E ^ -(Z ^ 54) ≈ 7.38905609893065 @test E ^ -(Z ^ 62) ≈ 2.2844135865231613e222 @test E ^ -(Z ^ 63) == Inf @test abs(E ^ (Z ^ 62 - 1) * E ^ (-(Z ^ 62) + 1) - 1) <= eps(1.0) (n, x) = (-1065564664, 0.9999997040311492) @test abs(x ^ n - Float64(big(x) ^ n)) / eps(x ^ n) == 0 @test E ^ (big(2) ^ 100 + 1) == 0 @test E ^ 6705320061009595392 == nextfloat(0.0) n = Int64(1024 / log2(E)) @test E ^ n == Inf @test E ^ float(n) == Inf @testset "literal pow zero sign" begin @testset "T: $(T)" for T = (Float16, Float32, Float64, BigFloat) @testset "literal `-1`" begin @test -0.0 === Float64(T(-Inf) ^ -1) end @testset "`Int(-1)`" begin @test -0.0 === Float64(T(-Inf) ^ Int(-1)) end end end struct Issue55633_1 <: Number end struct Issue55633_3 <: Number end struct Issue55633_9 <: Number end Base.one(::Issue55633_3) = begin Issue55633_1() end Base.:*(::Issue55633_3, ::Issue55633_3) = begin Issue55633_9() end Base.promote_rule(::Type{Issue55633_1}, ::Type{Issue55633_3}) = begin Int end Base.promote_rule(::Type{Issue55633_3}, ::Type{Issue55633_9}) = begin Int end Base.promote_rule(::Type{Issue55633_1}, ::Type{Issue55633_9}) = begin Int end Base.promote_rule(::Type{Issue55633_1}, ::Type{Int}) = begin Int end Base.promote_rule(::Type{Issue55633_3}, ::Type{Int}) = begin Int end Base.promote_rule(::Type{Issue55633_9}, ::Type{Int}) = begin Int end Base.convert(::Type{Int}, ::Issue55633_1) = begin 1 end Base.convert(::Type{Int}, ::Issue55633_3) = begin 3 end Base.convert(::Type{Int}, ::Issue55633_9) = begin 9 end for x = (im, pi, Issue55633_3()) p = promote(one(x), x, x * x) for y = 0:2 @test all((t->begin (===)(t...) end), zip(x ^ y, p[y + 1])) end end @testset "rng exponentiation, issue #57590" begin @test EvenInteger(16) === @inferred(EvenInteger(2) ^ 4) @test EvenInteger(16) === @inferred(EvenInteger(2) ^ Int(4)) @test EvenInteger(16) === @inferred(EvenInteger(2) ^ EvenInteger(4)) end @test Float32(1.1) ^ typemin(Int) == Float32(0.0) @test Float16(1.1) ^ typemin(Int) == Float16(0.0) @test Float32(1.1) ^ unsigned(0) === Float32(1.0) @test Float32(1.1) ^ big(0) === Float32(1.0) struct Int3 <: Integer x::Int8 function Int3(x::Integer) if x < -4 || x > 3 Core.throw_inexacterror(:Int3, Int3, x) end return new(x) end end Base.typemin(::Type{Int3}) = begin Int3(-4) end (Base.promote_rule(::Type{Int3}, ::Type{T}) where T <: Integer) = begin T end (Base.convert(::Type{T}, x::Int3) where T <: Integer) = begin convert(T, x.x) end Base.:-(x::Int3) = begin if x.x == -4 x else Int3(-(x.x)) end end Base.trailing_zeros(x::Int3) = begin trailing_zeros(x.x) end Base.:>>(x::Int3, n::UInt64) = begin Int3(x.x >> n) end @test 1.001f0 ^ -3 == 1.001f0 ^ Int3(-3) @test 1.001f0 ^ -4 == 1.001f0 ^ typemin(Int3) end @testset "pow" begin POW_TOLS = Dict(Float16 => [0.51, 0.51, 0.51, 2.0, 1.5], Float32 => [0.51, 0.51, 0.51, 2.0, 1.5], Float64 => [0.55, 0.8, 1.5, 2.0, 1.5]) for T = (Float16, Float32, Float64) @inferred T T(1.1) ^ T(1.1) for x = (0.0, -0.0, 1.0, 10.0, 2.0, Inf, NaN, -Inf, -NaN) for y = (0.0, -0.0, 1.0, -3.0, -10.0, Inf, NaN, -Inf, -NaN) (got, expected) = (T(x) ^ T(y), T(big(x) ^ T(y))) if isnan(expected) @test isnan_type(T, got) || T.((x, y)) else @test got == expected || T.((x, y)) end end end for _ = 1:2 ^ 16 x = rand(T) * 100 y = rand(T) * 200 - 100 (got, expected) = (x ^ y, widen(x) ^ y) if isfinite(eps(T(expected))) if y == T(-2) @test abs(expected - got) <= (POW_TOLS[T])[4] * eps(T(expected)) || (x, y) elseif y == T(3) @test abs(expected - got) <= (POW_TOLS[T])[5] * eps(T(expected)) || (x, y) elseif issubnormal(got) @test abs(expected - got) <= (POW_TOLS[T])[2] * eps(T(expected)) || (x, y) else @test abs(expected - got) <= (POW_TOLS[T])[1] * eps(T(expected)) || (x, y) end end end for _ = 1:2 ^ 14 x = rand(T) * floatmin(T) y = rand(T) * 3 - T(1.2) (got, expected) = (x ^ y, widen(x) ^ y) if isfinite(eps(T(expected))) @test abs(expected - got) <= (POW_TOLS[T])[3] * eps(T(expected)) || (x, y) end end @test T(-1) ^ floatmax(T) === T(1) @test prevfloat(T(-1)) ^ floatmax(T) === T(Inf) @test nextfloat(T(-1)) ^ floatmax(T) === T(0.0) end @test 0.9999999955206014 ^ -1.0e8 == 1.565084574870928 @test 3.0e18 ^ 20 == Inf @test 0.0013653274095082324 ^ -97.60372292227069 == 4.088393948750035e279 @test 8.758520413376658e-5 ^ 70.55863059215994 == 5.052076767078296e-287 c53881 = 2.2844135865398217e222 @test (prevfloat(1.0) ^ -(Int64(2))) ^ 62 ≈ c53881 atol = 2 * eps(c53881) @test 2.0 ^ typemin(Int) == 0.0 @test (-1.0) ^ typemin(Int) == 1.0 Z = Int64(2) E = prevfloat(1.0) @test E ^ -(Z ^ 54) ≈ 7.38905609893065 @test E ^ -(Z ^ 62) ≈ 2.2844135865231613e222 @test E ^ -(Z ^ 63) == Inf @test abs(E ^ (Z ^ 62 - 1) * E ^ (-(Z ^ 62) + 1) - 1) <= eps(1.0) (n, x) = (-1065564664, 0.9999997040311492) @test abs(x ^ n - Float64(big(x) ^ n)) / eps(x ^ n) == 0 @test E ^ (big(2) ^ 100 + 1) == 0 @test E ^ 6705320061009595392 == nextfloat(0.0) n = Int64(1024 / log2(E)) @test E ^ n == Inf @test E ^ float(n) == Inf @testset "literal pow zero sign" begin @testset "T: $(T)" for T = (Float16, Float32, Float64, BigFloat) @testset "literal `-1`" begin @test -0.0 === Float64(T(-Inf) ^ -1) end @testset "`Int(-1)`" begin @test -0.0 === Float64(T(-Inf) ^ Int(-1)) end end end struct Issue55633_1 <: Number end struct Issue55633_3 <: Number end struct Issue55633_9 <: Number end Base.one(::Issue55633_3) = begin Issue55633_1() end Base.:*(::Issue55633_3, ::Issue55633_3) = begin Issue55633_9() end Base.promote_rule(::Type{Issue55633_1}, ::Type{Issue55633_3}) = begin Int end Base.promote_rule(::Type{Issue55633_3}, ::Type{Issue55633_9}) = begin Int end Base.promote_rule(::Type{Issue55633_1}, ::Type{Issue55633_9}) = begin Int end Base.promote_rule(::Type{Issue55633_1}, ::Type{Int}) = begin Int end Base.promote_rule(::Type{Issue55633_3}, ::Type{Int}) = begin Int end Base.promote_rule(::Type{Issue55633_9}, ::Type{Int}) = begin Int end Base.convert(::Type{Int}, ::Issue55633_1) = begin 1 end Base.convert(::Type{Int}, ::Issue55633_3) = begin 3 end Base.convert(::Type{Int}, ::Issue55633_9) = begin 9 end for x = (im, pi, Issue55633_3()) p = promote(one(x), x, x * x) for y = 0:2 @test all((t->begin (===)(t...) end), zip(x ^ y, p[y + 1])) end end @testset "rng exponentiation, issue #57590" begin @test EvenInteger(16) === @inferred(EvenInteger(2) ^ 4) @test EvenInteger(16) === @inferred(EvenInteger(2) ^ Int(4)) @test EvenInteger(16) === @inferred(EvenInteger(2) ^ EvenInteger(4)) end @test Float32(1.1) ^ typemin(Int) == Float32(0.0) @test Float16(1.1) ^ typemin(Int) == Float16(0.0) @test Float32(1.1) ^ unsigned(0) === Float32(1.0) @test Float32(1.1) ^ big(0) === Float32(1.0) struct Int3 <: Integer x::Int8 function Int3(x::Integer) if x < -4 || x > 3 Core.throw_inexacterror(:Int3, Int3, x) end return new(x) end end Base.typemin(::Type{Int3}) = begin Int3(-4) end (Base.promote_rule(::Type{Int3}, ::Type{T}) where T <: Integer) = begin T end (Base.convert(::Type{T}, x::Int3) where T <: Integer) = begin convert(T, x.x) end Base.:-(x::Int3) = begin if x.x == -4 x else Int3(-(x.x)) end end Base.trailing_zeros(x::Int3) = begin trailing_zeros(x.x) end Base.:>>(x::Int3, n::UInt64) = begin Int3(x.x >> n) end @test 1.001f0 ^ -3 == 1.001f0 ^ Int3(-3) @test 1.001f0 ^ -4 == 1.001f0 ^ typemin(Int3) end @testset "pow" begin POW_TOLS = Dict(Float16 => [0.51, 0.51, 0.51, 2.0, 1.5], Float32 => [0.51, 0.51, 0.51, 2.0, 1.5], Float64 => [0.55, 0.8, 1.5, 2.0, 1.5]) for T = (Float16, Float32, Float64) @inferred T T(1.1) ^ T(1.1) for x = (0.0, -0.0, 1.0, 10.0, 2.0, Inf, NaN, -Inf, -NaN) for y = (0.0, -0.0, 1.0, -3.0, -10.0, Inf, NaN, -Inf, -NaN) (got, expected) = (T(x) ^ T(y), T(big(x) ^ T(y))) if isnan(expected) @test isnan_type(T, got) || T.((x, y)) else @test got == expected || T.((x, y)) end end end for _ = 1:2 ^ 16 x = rand(T) * 100 y = rand(T) * 200 - 100 (got, expected) = (x ^ y, widen(x) ^ y) if isfinite(eps(T(expected))) if y == T(-2) @test abs(expected - got) <= (POW_TOLS[T])[4] * eps(T(expected)) || (x, y) elseif y == T(3) @test abs(expected - got) <= (POW_TOLS[T])[5] * eps(T(expected)) || (x, y) elseif issubnormal(got) @test abs(expected - got) <= (POW_TOLS[T])[2] * eps(T(expected)) || (x, y) else @test abs(expected - got) <= (POW_TOLS[T])[1] * eps(T(expected)) || (x, y) end end end for _ = 1:2 ^ 14 x = rand(T) * floatmin(T) y = rand(T) * 3 - T(1.2) (got, expected) = (x ^ y, widen(x) ^ y) if isfinite(eps(T(expected))) @test abs(expected - got) <= (POW_TOLS[T])[3] * eps(T(expected)) || (x, y) end end @test T(-1) ^ floatmax(T) === T(1) @test prevfloat(T(-1)) ^ floatmax(T) === T(Inf) @test nextfloat(T(-1)) ^ floatmax(T) === T(0.0) end @test 0.9999999955206014 ^ -1.0e8 == 1.565084574870928 @test 3.0e18 ^ 20 == Inf @test 0.0013653274095082324 ^ -97.60372292227069 == 4.088393948750035e279 @test 8.758520413376658e-5 ^ 70.55863059215994 == 5.052076767078296e-287 c53881 = 2.2844135865398217e222 @test prevfloat(1.0) ^ -(Int64(2) ^ 62) ≈ c53881 atol = 2 * eps(c53881) @test 2.0 ^ typemin(Int) == 0.0 @test (-1.0) ^ typemin(Int) == 1.0 Z = Int64(2) E = prevfloat(1.0) @test E ^ -(Z ^ 54) ≈ 7.38905609893065 @test E ^ -(Z ^ 62) ≈ 2.2844135865231613e222 @test E ^ -(Z ^ 63) == Inf @test abs(E ^ (Z ^ 62 - 1) * E ^ (-(Z ^ 62) + 1) - 1) <= eps(1.0) (n, x) = (-1065564664, 0.9999997040311492) @test abs(x ^ n - Float64(big(x) ^ n)) / eps(x ^ n) == 0 @test E ^ (big(2) ^ 100 + 1) == 0 @test E ^ 6705320061009595392 == nextfloat(0.0) n = Int64(1024 / log2(E)) @test E ^ n == Inf @test E ^ float(n) == Inf @testset "literal pow zero sign" begin @testset "T: $(T)" for T = (Float16, Float32, Float64, BigFloat) @testset "literal `-1`" begin @test -0.0 === Float64(T(-Inf) ^ -1) end @testset "`Int(-1)`" begin @test -0.0 === Float64(T(-Inf) ^ Int(-1)) end end end struct Issue55633_1 <: Number end struct Issue55633_3 <: Number end struct Issue55633_9 <: Number end Base.one(::Issue55633_3) = begin Issue55633_1() end Base.:*(::Issue55633_3, ::Issue55633_3) = begin Issue55633_9() end Base.promote_rule(::Type{Issue55633_1}, ::Type{Issue55633_3}) = begin Int end Base.promote_rule(::Type{Issue55633_3}, ::Type{Issue55633_9}) = begin Int end Base.promote_rule(::Type{Issue55633_1}, ::Type{Issue55633_9}) = begin Int end Base.promote_rule(::Type{Issue55633_1}, ::Type{Int}) = begin Int end Base.promote_rule(::Type{Issue55633_3}, ::Type{Int}) = begin Int end Base.promote_rule(::Type{Issue55633_9}, ::Type{Int}) = begin Int end Base.convert(::Type{Int}, ::Issue55633_1) = begin 1 end Base.convert(::Type{Int}, ::Issue55633_3) = begin 3 end Base.convert(::Type{Int}, ::Issue55633_9) = begin 9 end for x = (im, pi, Issue55633_3()) p = promote(one(x), x, x * x) for y = 0:2 @test all((t->begin (===)(t...) end), zip(x ^ y, p[y + 1])) end end @testset "rng exponentiation, issue #57590" begin @test EvenInteger(16) === @inferred(EvenInteger(2) ^ 4) @test EvenInteger(16) === @inferred(EvenInteger(2) ^ Int(4)) @test EvenInteger(16) === @inferred(EvenInteger(2) ^ EvenInteger(4)) end @test Float32(1.1) ^ typemin(Int) == Float32(0.0) @test Float16(1.1) ^ typemin(Int) == Float16(0.0) @test Float32(1.1) ^ unsigned(0) === Float32(1.0) @test Float32(1.1) ^ big(0) === Float32(1.0) struct Int3 <: Integer x::Int8 function Int3(x::Integer) if x < -4 || x > 3 Core.throw_inexacterror(:Int3, Int3, x) end return new(x) end end Base.typemin(::Type{Int3}) = begin Int3(-4) end (Base.promote_rule(::Type{Int3}, ::Type{T}) where T <: Integer) = begin T end (Base.convert(::Type{T}, x::Int3) where T <: Integer) = begin convert(T, x.x) end Base.:-(x::Int3) = begin if x.x == -4 x else Int3(-(x.x)) end end Base.trailing_zeros(x::Int3) = begin trailing_zeros(x.x) end Base.:>>(x::Int3, n::UInt64) = begin Int3(x.x >> n) end @test 1.001f0 ^ -3 == 1.001f0 ^ Int3(-3) @test 1.001f0 ^ -4 == 1.001f0 ^ typemin(Int3) end Parsing files in Base: Test Failed at /home/pkgeval/.julia/packages/CSTParser/0hXvH/test/test_check_base.jl:166 Expression: false Stacktrace: [1] top-level scope @ ~/.julia/packages/CSTParser/0hXvH/test/test_check_base.jl:166 [2] macro expansion @ /opt/julia/share/julia/stdlib/v1.13/Test/src/Test.jl:745 [inlined] ┌ Error: parsing difference │ file = "/opt/julia/bin/../share/julia/test/mpfr.jl" └ @ Main.var"##439" ~/.julia/packages/CSTParser/0hXvH/test/test_check_base.jl:157 div(1.0, 0.1000000000000000000000000000000000000000000000000000000000000000000000000000002) div(1.0, 0.1000000000000000000000000000000000000000000000000000000000000000000000000000002) div(1.0, 0.1000000000000000000000000000000000000000000000000000000000000000000000000000002) == 9 div(1.0, 0.1000000000000000000000000000000000000000000000000000000000000000000000000000002) == 9 @test div(1.0, 0.1000000000000000000000000000000000000000000000000000000000000000000000000000002) == 9 @test div(1.0, 0.1000000000000000000000000000000000000000000000000000000000000000000000000000002) == 9 div(1, 0.1000000000000000000000000000000000000000000000000000000000000000000000000000002) div(1, 0.1000000000000000000000000000000000000000000000000000000000000000000000000000002) div(1, 0.1000000000000000000000000000000000000000000000000000000000000000000000000000002) == 9 div(1, 0.1000000000000000000000000000000000000000000000000000000000000000000000000000002) == 9 @test div(1, 0.1000000000000000000000000000000000000000000000000000000000000000000000000000002) == 9 @test div(1, 0.1000000000000000000000000000000000000000000000000000000000000000000000000000002) == 9 div(1.0, 0.1000000000000000000000000000000000000000000000000000000000000000000000000000002) div(1.0, 0.1000000000000000000000000000000000000000000000000000000000000000000000000000002) div(1.0, 0.1000000000000000000000000000000000000000000000000000000000000000000000000000002) == 9 div(1.0, 0.1000000000000000000000000000000000000000000000000000000000000000000000000000002) == 9 @test div(1.0, 0.1000000000000000000000000000000000000000000000000000000000000000000000000000002) == 9 @test div(1.0, 0.1000000000000000000000000000000000000000000000000000000000000000000000000000002) == 9 div(1.0, 0.1) div(1.0, 0.1) div(1.0, 0.1) == 9 div(1.0, 0.1) == 9 @test div(1.0, 0.1) == 9 @test div(1.0, 0.1) == 9 div(1, 0.1000000000000000000000000000000000000000000000000000000000000000000000000000002) div(1, 0.1000000000000000000000000000000000000000000000000000000000000000000000000000002) div(1, 0.1000000000000000000000000000000000000000000000000000000000000000000000000000002) == 9 div(1, 0.1000000000000000000000000000000000000000000000000000000000000000000000000000002) == 9 @test div(1, 0.1000000000000000000000000000000000000000000000000000000000000000000000000000002) == 9 @test div(1, 0.1000000000000000000000000000000000000000000000000000000000000000000000000000002) == 9 div(1, 0.1) div(1, 0.1) div(1, 0.1) == 9 div(1, 0.1) == 9 @test div(1, 0.1) == 9 @test div(1, 0.1) == 9 begin @test div(1.0, 0.1000000000000000000000000000000000000000000000000000000000000000000000000000002) == 9 @test div(1, 0.1000000000000000000000000000000000000000000000000000000000000000000000000000002) == 9 @test div(1.0, 0.1000000000000000000000000000000000000000000000000000000000000000000000000000002) == 9 @test div(1.0, 0.1) == 9 @test div(1, 0.1000000000000000000000000000000000000000000000000000000000000000000000000000002) == 9 @test div(1, 0.1) == 9 end begin @test div(1.0, 0.1000000000000000000000000000000000000000000000000000000000000000000000000000002) == 9 @test div(1, 0.1000000000000000000000000000000000000000000000000000000000000000000000000000002) == 9 @test div(1.0, 0.1000000000000000000000000000000000000000000000000000000000000000000000000000002) == 9 @test div(1.0, 0.1) == 9 @test div(1, 0.1000000000000000000000000000000000000000000000000000000000000000000000000000002) == 9 @test div(1, 0.1) == 9 end @testset "div" begin @test div(1.0, 0.1000000000000000000000000000000000000000000000000000000000000000000000000000002) == 9 @test div(1, 0.1000000000000000000000000000000000000000000000000000000000000000000000000000002) == 9 @test div(1.0, 0.1000000000000000000000000000000000000000000000000000000000000000000000000000002) == 9 @test div(1.0, 0.1) == 9 @test div(1, 0.1000000000000000000000000000000000000000000000000000000000000000000000000000002) == 9 @test div(1, 0.1) == 9 end @testset "div" begin @test div(1.0, 0.1000000000000000000000000000000000000000000000000000000000000000000000000000002) == 9 @test div(1, 0.1000000000000000000000000000000000000000000000000000000000000000000000000000002) == 9 @test div(1.0, 0.1000000000000000000000000000000000000000000000000000000000000000000000000000002) == 9 @test div(1.0, 0.1) == 9 @test div(1, 0.1000000000000000000000000000000000000000000000000000000000000000000000000000002) == 9 @test div(1, 0.1) == 9 end test_show_bigfloat(1.234567889999999999999999999999999999999999999999999999999999999999999999999998, contains_e = false, starts = "1.23") test_show_bigfloat(1.234567889999999999999999999999999999999999999999999999999999999999999999999998, contains_e = false, starts = "1.23") test_show_bigfloat(-1.234567889999999999999999999999999999999999999999999999999999999999999999999998, contains_e = false, starts = "-1.23") test_show_bigfloat(-1.234567889999999999999999999999999999999999999999999999999999999999999999999998, contains_e = false, starts = "-1.23") test_show_bigfloat(2.345764568756354326657688967895678700000000000000000000000000000000000000000002e10000, starts = "2.345", ends = "e10000") test_show_bigfloat(2.345764568756354326657688967895678700000000000000000000000000000000000000000002e10000, starts = "2.345", ends = "e10000") test_show_bigfloat(-2.345764568756354326657688967895678699999999999999999999999999999999999999999993e-10000, starts = "-2.345", ends = "e-10000") test_show_bigfloat(-2.345764568756354326657688967895678699999999999999999999999999999999999999999993e-10000, starts = "-2.345", ends = "e-10000") test_show_bigfloat(42.0, contains_e = false, starts = "42.0") test_show_bigfloat(42.0, contains_e = false, starts = "42.0") test_show_bigfloat(420.0, contains_e = false, starts = "420.0") test_show_bigfloat(420.0, contains_e = false, starts = "420.0") test_show_bigfloat(-420.0, contains_e = false, starts = "-420.0") test_show_bigfloat(-420.0, contains_e = false, starts = "-420.0") test_show_bigfloat(420000.0, contains_e = false, starts = "420000.0") test_show_bigfloat(420000.0, contains_e = false, starts = "420000.0") test_show_bigfloat(654321.0, contains_e = false, starts = "654321.0") test_show_bigfloat(654321.0, contains_e = false, starts = "654321.0") test_show_bigfloat(-654321.0, contains_e = false, starts = "-654321.0") test_show_bigfloat(-654321.0, contains_e = false, starts = "-654321.0") test_show_bigfloat(6.54321e6, contains_e = true, starts = "6.5", ends = "e6") test_show_bigfloat(6.54321e6, contains_e = true, starts = "6.5", ends = "e6") test_show_bigfloat(0.0001230000000000000000000000000000000000000000000000000000000000000000000000000003, contains_e = false, starts = "0.000123") test_show_bigfloat(0.0001230000000000000000000000000000000000000000000000000000000000000000000000000003, contains_e = false, starts = "0.000123") test_show_bigfloat(-0.0001230000000000000000000000000000000000000000000000000000000000000000000000000003, contains_e = false, starts = "-0.000123") test_show_bigfloat(-0.0001230000000000000000000000000000000000000000000000000000000000000000000000000003, contains_e = false, starts = "-0.000123") test_show_bigfloat(1.233999999999999999999999999999999999999999999999999999999999999999999999999996e-5, contains_e = true, starts = "1.23", ends = "e-5") test_show_bigfloat(1.233999999999999999999999999999999999999999999999999999999999999999999999999996e-5, contains_e = true, starts = "1.23", ends = "e-5") to_string(0.0) to_string(0.0) to_string(0.0) == "0.0" to_string(0.0) == "0.0" @test to_string(0.0) == "0.0" @test to_string(0.0) == "0.0" to_string(-0.0) to_string(-0.0) to_string(-0.0) == "-0.0" to_string(-0.0) == "-0.0" @test to_string(-0.0) == "-0.0" @test to_string(-0.0) == "-0.0" to_string(1.0) to_string(1.0) to_string(1.0) == "1.0" to_string(1.0) == "1.0" @test to_string(1.0) == "1.0" @test to_string(1.0) == "1.0" to_string(-1.0) to_string(-1.0) to_string(-1.0) == "-1.0" to_string(-1.0) == "-1.0" @test to_string(-1.0) == "-1.0" @test to_string(-1.0) == "-1.0" begin @test to_string(0.0) == "0.0" @test to_string(-0.0) == "-0.0" @test to_string(1.0) == "1.0" @test to_string(-1.0) == "-1.0" end begin @test to_string(0.0) == "0.0" @test to_string(-0.0) == "-0.0" @test to_string(1.0) == "1.0" @test to_string(-1.0) == "-1.0" end for to_string = [string, (x->begin sprint(show, x) end), (x->begin sprint(show, x, context = :compact => true) end)] @test to_string(0.0) == "0.0" @test to_string(-0.0) == "-0.0" @test to_string(1.0) == "1.0" @test to_string(-1.0) == "-1.0" end for to_string = [string, (x->begin sprint(show, x) end), (x->begin sprint(show, x, context = :compact => true) end)] @test to_string(0.0) == "0.0" @test to_string(-0.0) == "-0.0" @test to_string(1.0) == "1.0" @test to_string(-1.0) == "-1.0" end begin function test_show_bigfloat(x::BigFloat; contains_e::Bool = true, ends::String = "", starts::String = "") sx = sprint(show, x) scx = sprint(show, x, context = :compact => true) strx = string(x) @test sx == strx @test length(scx) < 20 @test length(scx) <= length(sx) @test x == parse(BigFloat, sx) @test ≈(x, parse(BigFloat, scx), rtol = 0.0001) for s = (sx, scx) @test occursin('e', s) == contains_e @test startswith(s, starts) @test endswith(s, ends) end end test_show_bigfloat(1.234567889999999999999999999999999999999999999999999999999999999999999999999998, contains_e = false, starts = "1.23") test_show_bigfloat(-1.234567889999999999999999999999999999999999999999999999999999999999999999999998, contains_e = false, starts = "-1.23") test_show_bigfloat(2.345764568756354326657688967895678700000000000000000000000000000000000000000002e10000, starts = "2.345", ends = "e10000") test_show_bigfloat(-2.345764568756354326657688967895678699999999999999999999999999999999999999999993e-10000, starts = "-2.345", ends = "e-10000") test_show_bigfloat(42.0, contains_e = false, starts = "42.0") test_show_bigfloat(420.0, contains_e = false, starts = "420.0") test_show_bigfloat(-420.0, contains_e = false, starts = "-420.0") test_show_bigfloat(420000.0, contains_e = false, starts = "420000.0") test_show_bigfloat(654321.0, contains_e = false, starts = "654321.0") test_show_bigfloat(-654321.0, contains_e = false, starts = "-654321.0") test_show_bigfloat(6.54321e6, contains_e = true, starts = "6.5", ends = "e6") test_show_bigfloat(0.0001230000000000000000000000000000000000000000000000000000000000000000000000000003, contains_e = false, starts = "0.000123") test_show_bigfloat(-0.0001230000000000000000000000000000000000000000000000000000000000000000000000000003, contains_e = false, starts = "-0.000123") test_show_bigfloat(1.233999999999999999999999999999999999999999999999999999999999999999999999999996e-5, contains_e = true, starts = "1.23", ends = "e-5") for to_string = [string, (x->begin sprint(show, x) end), (x->begin sprint(show, x, context = :compact => true) end)] @test to_string(0.0) == "0.0" @test to_string(-0.0) == "-0.0" @test to_string(1.0) == "1.0" @test to_string(-1.0) == "-1.0" end end begin function test_show_bigfloat(x::BigFloat; contains_e::Bool = true, ends::String = "", starts::String = "") sx = sprint(show, x) scx = sprint(show, x, context = :compact => true) strx = string(x) @test sx == strx @test length(scx) < 20 @test length(scx) <= length(sx) @test x == parse(BigFloat, sx) @test ≈(x, parse(BigFloat, scx), rtol = 0.0001) for s = (sx, scx) @test occursin('e', s) == contains_e @test startswith(s, starts) @test endswith(s, ends) end end test_show_bigfloat(1.234567889999999999999999999999999999999999999999999999999999999999999999999998, contains_e = false, starts = "1.23") test_show_bigfloat(-1.234567889999999999999999999999999999999999999999999999999999999999999999999998, contains_e = false, starts = "-1.23") test_show_bigfloat(2.345764568756354326657688967895678700000000000000000000000000000000000000000002e10000, starts = "2.345", ends = "e10000") test_show_bigfloat(-2.345764568756354326657688967895678699999999999999999999999999999999999999999993e-10000, starts = "-2.345", ends = "e-10000") test_show_bigfloat(42.0, contains_e = false, starts = "42.0") test_show_bigfloat(420.0, contains_e = false, starts = "420.0") test_show_bigfloat(-420.0, contains_e = false, starts = "-420.0") test_show_bigfloat(420000.0, contains_e = false, starts = "420000.0") test_show_bigfloat(654321.0, contains_e = false, starts = "654321.0") test_show_bigfloat(-654321.0, contains_e = false, starts = "-654321.0") test_show_bigfloat(6.54321e6, contains_e = true, starts = "6.5", ends = "e6") test_show_bigfloat(0.0001230000000000000000000000000000000000000000000000000000000000000000000000000003, contains_e = false, starts = "0.000123") test_show_bigfloat(-0.0001230000000000000000000000000000000000000000000000000000000000000000000000000003, contains_e = false, starts = "-0.000123") test_show_bigfloat(1.233999999999999999999999999999999999999999999999999999999999999999999999999996e-5, contains_e = true, starts = "1.23", ends = "e-5") for to_string = [string, (x->begin sprint(show, x) end), (x->begin sprint(show, x, context = :compact => true) end)] @test to_string(0.0) == "0.0" @test to_string(-0.0) == "-0.0" @test to_string(1.0) == "1.0" @test to_string(-1.0) == "-1.0" end end @testset "show BigFloat" begin function test_show_bigfloat(x::BigFloat; contains_e::Bool = true, ends::String = "", starts::String = "") sx = sprint(show, x) scx = sprint(show, x, context = :compact => true) strx = string(x) @test sx == strx @test length(scx) < 20 @test length(scx) <= length(sx) @test x == parse(BigFloat, sx) @test ≈(x, parse(BigFloat, scx), rtol = 0.0001) for s = (sx, scx) @test occursin('e', s) == contains_e @test startswith(s, starts) @test endswith(s, ends) end end test_show_bigfloat(1.234567889999999999999999999999999999999999999999999999999999999999999999999998, contains_e = false, starts = "1.23") test_show_bigfloat(-1.234567889999999999999999999999999999999999999999999999999999999999999999999998, contains_e = false, starts = "-1.23") test_show_bigfloat(2.345764568756354326657688967895678700000000000000000000000000000000000000000002e10000, starts = "2.345", ends = "e10000") test_show_bigfloat(-2.345764568756354326657688967895678699999999999999999999999999999999999999999993e-10000, starts = "-2.345", ends = "e-10000") test_show_bigfloat(42.0, contains_e = false, starts = "42.0") test_show_bigfloat(420.0, contains_e = false, starts = "420.0") test_show_bigfloat(-420.0, contains_e = false, starts = "-420.0") test_show_bigfloat(420000.0, contains_e = false, starts = "420000.0") test_show_bigfloat(654321.0, contains_e = false, starts = "654321.0") test_show_bigfloat(-654321.0, contains_e = false, starts = "-654321.0") test_show_bigfloat(6.54321e6, contains_e = true, starts = "6.5", ends = "e6") test_show_bigfloat(0.0001230000000000000000000000000000000000000000000000000000000000000000000000000003, contains_e = false, starts = "0.000123") test_show_bigfloat(-0.0001230000000000000000000000000000000000000000000000000000000000000000000000000003, contains_e = false, starts = "-0.000123") test_show_bigfloat(1.233999999999999999999999999999999999999999999999999999999999999999999999999996e-5, contains_e = true, starts = "1.23", ends = "e-5") for to_string = [string, (x->begin sprint(show, x) end), (x->begin sprint(show, x, context = :compact => true) end)] @test to_string(0.0) == "0.0" @test to_string(-0.0) == "-0.0" @test to_string(1.0) == "1.0" @test to_string(-1.0) == "-1.0" end end @testset "show BigFloat" begin function test_show_bigfloat(x::BigFloat; contains_e::Bool = true, ends::String = "", starts::String = "") sx = sprint(show, x) scx = sprint(show, x, context = :compact => true) strx = string(x) @test sx == strx @test length(scx) < 20 @test length(scx) <= length(sx) @test x == parse(BigFloat, sx) @test ≈(x, parse(BigFloat, scx), rtol = 0.0001) for s = (sx, scx) @test occursin('e', s) == contains_e @test startswith(s, starts) @test endswith(s, ends) end end test_show_bigfloat(1.234567889999999999999999999999999999999999999999999999999999999999999999999998, contains_e = false, starts = "1.23") test_show_bigfloat(-1.234567889999999999999999999999999999999999999999999999999999999999999999999998, contains_e = false, starts = "-1.23") test_show_bigfloat(2.345764568756354326657688967895678700000000000000000000000000000000000000000002e10000, starts = "2.345", ends = "e10000") test_show_bigfloat(-2.345764568756354326657688967895678699999999999999999999999999999999999999999993e-10000, starts = "-2.345", ends = "e-10000") test_show_bigfloat(42.0, contains_e = false, starts = "42.0") test_show_bigfloat(420.0, contains_e = false, starts = "420.0") test_show_bigfloat(-420.0, contains_e = false, starts = "-420.0") test_show_bigfloat(420000.0, contains_e = false, starts = "420000.0") test_show_bigfloat(654321.0, contains_e = false, starts = "654321.0") test_show_bigfloat(-654321.0, contains_e = false, starts = "-654321.0") test_show_bigfloat(6.54321e6, contains_e = true, starts = "6.5", ends = "e6") test_show_bigfloat(0.0001230000000000000000000000000000000000000000000000000000000000000000000000000003, contains_e = false, starts = "0.000123") test_show_bigfloat(-0.0001230000000000000000000000000000000000000000000000000000000000000000000000000003, contains_e = false, starts = "-0.000123") test_show_bigfloat(1.233999999999999999999999999999999999999999999999999999999999999999999999999996e-5, contains_e = true, starts = "1.23", ends = "e-5") for to_string = [string, (x->begin sprint(show, x) end), (x->begin sprint(show, x, context = :compact => true) end)] @test to_string(0.0) == "0.0" @test to_string(-0.0) == "-0.0" @test to_string(1.0) == "1.0" @test to_string(-1.0) == "-1.0" end end bf = 1.4901162082026128889687591176485489397376143775948511e-7 bf = 1.4901162082026128889687591176485489397376143775948511e-7 begin bf = 1.4901162082026128889687591176485489397376143775948511e-7 @test Float16(bf) == Float16(2.0e-7) end begin bf = 1.4901162082026128889687591176485489397376143775948511e-7 @test Float16(bf) == Float16(2.0e-7) end ()->begin bf = 1.4901162082026128889687591176485489397376143775948511e-7 @test Float16(bf) == Float16(2.0e-7) end ()->begin bf = 1.4901162082026128889687591176485489397376143775948511e-7 @test Float16(bf) == Float16(2.0e-7) end setprecision(BigFloat, 500) do bf = 1.4901162082026128889687591176485489397376143775948511e-7 @test Float16(bf) == Float16(2.0e-7) end setprecision(BigFloat, 500) do bf = 1.4901162082026128889687591176485489397376143775948511e-7 @test Float16(bf) == Float16(2.0e-7) end begin setprecision(BigFloat, 500) do bf = 1.4901162082026128889687591176485489397376143775948511e-7 @test Float16(bf) == Float16(2.0e-7) end end begin setprecision(BigFloat, 500) do bf = 1.4901162082026128889687591176485489397376143775948511e-7 @test Float16(bf) == Float16(2.0e-7) end end @testset "issue #50642" begin setprecision(BigFloat, 500) do bf = 1.4901162082026128889687591176485489397376143775948511e-7 @test Float16(bf) == Float16(2.0e-7) end end @testset "issue #50642" begin setprecision(BigFloat, 500) do bf = 1.4901162082026128889687591176485489397376143775948511e-7 @test Float16(bf) == Float16(2.0e-7) end end Ref(1.0) Ref(1.0) (1.0, 1.0, Ref(1.0)) (1.0, 1.0, Ref(1.0)) x = (1.0, 1.0, Ref(1.0)) x = (1.0, 1.0, Ref(1.0)) for x = (1.0, 1.0, Ref(1.0)) @test Base.cconvert(Ref{BigFloat}, x) isa Base.MPFR.BigFloatData end for x = (1.0, 1.0, Ref(1.0)) @test Base.cconvert(Ref{BigFloat}, x) isa Base.MPFR.BigFloatData end begin for x = (1.0, 1.0, Ref(1.0)) @test Base.cconvert(Ref{BigFloat}, x) isa Base.MPFR.BigFloatData end end begin for x = (1.0, 1.0, Ref(1.0)) @test Base.cconvert(Ref{BigFloat}, x) isa Base.MPFR.BigFloatData end end @testset "cconvert(Ref{BigFloat}, x)" begin for x = (1.0, 1.0, Ref(1.0)) @test Base.cconvert(Ref{BigFloat}, x) isa Base.MPFR.BigFloatData end end @testset "cconvert(Ref{BigFloat}, x)" begin for x = (1.0, 1.0, Ref(1.0)) @test Base.cconvert(Ref{BigFloat}, x) isa Base.MPFR.BigFloatData end end Parsing files in Base: Test Failed at /home/pkgeval/.julia/packages/CSTParser/0hXvH/test/test_check_base.jl:166 Expression: false Stacktrace: [1] top-level scope @ ~/.julia/packages/CSTParser/0hXvH/test/test_check_base.jl:166 [2] macro expansion @ /opt/julia/share/julia/stdlib/v1.13/Test/src/Test.jl:745 [inlined] ┌ Error: parsing difference │ file = "/opt/julia/bin/../share/julia/test/precompile.jl" └ @ Main.var"##439" ~/.julia/packages/CSTParser/0hXvH/test/test_check_base.jl:157 Foo.abigfloat_f()::BigFloat == 12.34000000000000000000000000000000000000000000000000000000000000000000000000005 Foo.abigfloat_f()::BigFloat == 12.34000000000000000000000000000000000000000000000000000000000000000000000000005 @test Foo.abigfloat_f()::BigFloat == 12.34000000000000000000000000000000000000000000000000000000000000000000000000005 @test Foo.abigfloat_f()::BigFloat == 12.34000000000000000000000000000000000000000000000000000000000000000000000000005 Foo.abigfloat_x::BigFloat + 21 == 64.21000000000000000000000000000000000000000000000000000000000000000000000000053 Foo.abigfloat_x::BigFloat + 21 == 64.21000000000000000000000000000000000000000000000000000000000000000000000000053 @test Foo.abigfloat_x::BigFloat + 21 == 64.21000000000000000000000000000000000000000000000000000000000000000000000000053 @test Foo.abigfloat_x::BigFloat + 21 == 64.21000000000000000000000000000000000000000000000000000000000000000000000000053 Foo.abigint_f()::BigInt == 123 Foo.abigint_f()::BigInt == 123 @test Foo.abigint_f()::BigInt == 123 @test Foo.abigint_f()::BigInt == 123 Foo.abigint_x::BigInt + 1 == 125 Foo.abigint_x::BigInt + 1 == 125 @test Foo.abigint_x::BigInt + 1 == 125 @test Foo.abigint_x::BigInt + 1 == 125 begin @test Foo.foo(17) == 18 @test Foo.Bar.bar(17) == 19 @test Foo.g() === 97.0 @test 96 < Foo.gnc() < 99 @test Foo.override(1.0) == Float64('a') @test Foo.override(1.0f0) == 'b' @test Foo.override(UInt(1)) == 2 @test 96 < Foo.overridenc(1.0) < 99 @test 99 < Foo.overridenc(1.0f0) < 102 @test 0 < Foo.overridenc(UInt(1)) < 3 @test Foo.abigfloat_f()::BigFloat == 12.34000000000000000000000000000000000000000000000000000000000000000000000000005 @test Foo.abigfloat_x::BigFloat + 21 == 64.21000000000000000000000000000000000000000000000000000000000000000000000000053 @test Foo.abigint_f()::BigInt == 123 @test Foo.abigint_x::BigInt + 1 == 125 @test Foo.abigfloat_to_f32() == 1.5f0 @test Foo.x28297.result === missing @test Foo.d29936a === Dict @test Foo.d29936b === (Dict{K, V} where {V, K}) @test Foo.x28998[var"end"] == 6 @test Foo.a31488 == fill("", 100) @test Foo.ptr1 === Ptr{UInt8}(1) @test Foo.ptr2 === Ptr{UInt8}(0) @test Foo.ptr3 === Ptr{UInt8}(-1) @test Foo.layout1::Vector{Ptr{Int8}} == Ptr{Int8}[Ptr{Int8}(0), Ptr{Int8}(0), Ptr{Int8}(-1)] @test Foo.layout2 == Any[Ptr{Int8}(0), Ptr{Int16}(0), Ptr{Int32}(-1)] @test typeof.(Foo.layout2) == [Ptr{Int8}, Ptr{Int16}, Ptr{Int32}] @test Foo.layout3 == ["ab", "cd", "ef", "gh", "ij"] @test !(isopen(Foo.ch1)) @test !(isopen(Foo.ch2)) @test !(isready(Foo.ch1)) @test isready(Foo.ch2) @test take!(Foo.ch2) === 2 @test !(isready(Foo.ch2)) @test Foo.process_state_calls === 0 @test Foo.process_state() === getpid() @test Foo.mypid !== getpid() @test Foo.FooBase_pid !== getpid() @test Foo.mypid !== Foo.FooBase_pid @test Foo.process_state_calls === 1 end begin @test Foo.foo(17) == 18 @test Foo.Bar.bar(17) == 19 @test Foo.g() === 97.0 @test 96 < Foo.gnc() < 99 @test Foo.override(1.0) == Float64('a') @test Foo.override(1.0f0) == 'b' @test Foo.override(UInt(1)) == 2 @test 96 < Foo.overridenc(1.0) < 99 @test 99 < Foo.overridenc(1.0f0) < 102 @test 0 < Foo.overridenc(UInt(1)) < 3 @test Foo.abigfloat_f()::BigFloat == 12.34000000000000000000000000000000000000000000000000000000000000000000000000005 @test Foo.abigfloat_x::BigFloat + 21 == 64.21000000000000000000000000000000000000000000000000000000000000000000000000053 @test Foo.abigint_f()::BigInt == 123 @test Foo.abigint_x::BigInt + 1 == 125 @test Foo.abigfloat_to_f32() == 1.5f0 @test Foo.x28297.result === missing @test Foo.d29936a === Dict @test Foo.d29936b === (Dict{K, V} where {V, K}) @test Foo.x28998[var"end"] == 6 @test Foo.a31488 == fill("", 100) @test Foo.ptr1 === Ptr{UInt8}(1) @test Foo.ptr2 === Ptr{UInt8}(0) @test Foo.ptr3 === Ptr{UInt8}(-1) @test Foo.layout1::Vector{Ptr{Int8}} == Ptr{Int8}[Ptr{Int8}(0), Ptr{Int8}(0), Ptr{Int8}(-1)] @test Foo.layout2 == Any[Ptr{Int8}(0), Ptr{Int16}(0), Ptr{Int32}(-1)] @test typeof.(Foo.layout2) == [Ptr{Int8}, Ptr{Int16}, Ptr{Int32}] @test Foo.layout3 == ["ab", "cd", "ef", "gh", "ij"] @test !(isopen(Foo.ch1)) @test !(isopen(Foo.ch2)) @test !(isready(Foo.ch1)) @test isready(Foo.ch2) @test take!(Foo.ch2) === 2 @test !(isready(Foo.ch2)) @test Foo.process_state_calls === 0 @test Foo.process_state() === getpid() @test Foo.mypid !== getpid() @test Foo.FooBase_pid !== getpid() @test Foo.mypid !== Foo.FooBase_pid @test Foo.process_state_calls === 1 end ()->begin @test Foo.foo(17) == 18 @test Foo.Bar.bar(17) == 19 @test Foo.g() === 97.0 @test 96 < Foo.gnc() < 99 @test Foo.override(1.0) == Float64('a') @test Foo.override(1.0f0) == 'b' @test Foo.override(UInt(1)) == 2 @test 96 < Foo.overridenc(1.0) < 99 @test 99 < Foo.overridenc(1.0f0) < 102 @test 0 < Foo.overridenc(UInt(1)) < 3 @test Foo.abigfloat_f()::BigFloat == 12.34000000000000000000000000000000000000000000000000000000000000000000000000005 @test Foo.abigfloat_x::BigFloat + 21 == 64.21000000000000000000000000000000000000000000000000000000000000000000000000053 @test Foo.abigint_f()::BigInt == 123 @test Foo.abigint_x::BigInt + 1 == 125 @test Foo.abigfloat_to_f32() == 1.5f0 @test Foo.x28297.result === missing @test Foo.d29936a === Dict @test Foo.d29936b === (Dict{K, V} where {V, K}) @test Foo.x28998[var"end"] == 6 @test Foo.a31488 == fill("", 100) @test Foo.ptr1 === Ptr{UInt8}(1) @test Foo.ptr2 === Ptr{UInt8}(0) @test Foo.ptr3 === Ptr{UInt8}(-1) @test Foo.layout1::Vector{Ptr{Int8}} == Ptr{Int8}[Ptr{Int8}(0), Ptr{Int8}(0), Ptr{Int8}(-1)] @test Foo.layout2 == Any[Ptr{Int8}(0), Ptr{Int16}(0), Ptr{Int32}(-1)] @test typeof.(Foo.layout2) == [Ptr{Int8}, Ptr{Int16}, Ptr{Int32}] @test Foo.layout3 == ["ab", "cd", "ef", "gh", "ij"] @test !(isopen(Foo.ch1)) @test !(isopen(Foo.ch2)) @test !(isready(Foo.ch1)) @test isready(Foo.ch2) @test take!(Foo.ch2) === 2 @test !(isready(Foo.ch2)) @test Foo.process_state_calls === 0 @test Foo.process_state() === getpid() @test Foo.mypid !== getpid() @test Foo.FooBase_pid !== getpid() @test Foo.mypid !== Foo.FooBase_pid @test Foo.process_state_calls === 1 end ()->begin @test Foo.foo(17) == 18 @test Foo.Bar.bar(17) == 19 @test Foo.g() === 97.0 @test 96 < Foo.gnc() < 99 @test Foo.override(1.0) == Float64('a') @test Foo.override(1.0f0) == 'b' @test Foo.override(UInt(1)) == 2 @test 96 < Foo.overridenc(1.0) < 99 @test 99 < Foo.overridenc(1.0f0) < 102 @test 0 < Foo.overridenc(UInt(1)) < 3 @test Foo.abigfloat_f()::BigFloat == 12.34000000000000000000000000000000000000000000000000000000000000000000000000005 @test Foo.abigfloat_x::BigFloat + 21 == 64.21000000000000000000000000000000000000000000000000000000000000000000000000053 @test Foo.abigint_f()::BigInt == 123 @test Foo.abigint_x::BigInt + 1 == 125 @test Foo.abigfloat_to_f32() == 1.5f0 @test Foo.x28297.result === missing @test Foo.d29936a === Dict @test Foo.d29936b === (Dict{K, V} where {V, K}) @test Foo.x28998[var"end"] == 6 @test Foo.a31488 == fill("", 100) @test Foo.ptr1 === Ptr{UInt8}(1) @test Foo.ptr2 === Ptr{UInt8}(0) @test Foo.ptr3 === Ptr{UInt8}(-1) @test Foo.layout1::Vector{Ptr{Int8}} == Ptr{Int8}[Ptr{Int8}(0), Ptr{Int8}(0), Ptr{Int8}(-1)] @test Foo.layout2 == Any[Ptr{Int8}(0), Ptr{Int16}(0), Ptr{Int32}(-1)] @test typeof.(Foo.layout2) == [Ptr{Int8}, Ptr{Int16}, Ptr{Int32}] @test Foo.layout3 == ["ab", "cd", "ef", "gh", "ij"] @test !(isopen(Foo.ch1)) @test !(isopen(Foo.ch2)) @test !(isready(Foo.ch1)) @test isready(Foo.ch2) @test take!(Foo.ch2) === 2 @test !(isready(Foo.ch2)) @test Foo.process_state_calls === 0 @test Foo.process_state() === getpid() @test Foo.mypid !== getpid() @test Foo.FooBase_pid !== getpid() @test Foo.mypid !== Foo.FooBase_pid @test Foo.process_state_calls === 1 end Base.invokelatest() do @test Foo.foo(17) == 18 @test Foo.Bar.bar(17) == 19 @test Foo.g() === 97.0 @test 96 < Foo.gnc() < 99 @test Foo.override(1.0) == Float64('a') @test Foo.override(1.0f0) == 'b' @test Foo.override(UInt(1)) == 2 @test 96 < Foo.overridenc(1.0) < 99 @test 99 < Foo.overridenc(1.0f0) < 102 @test 0 < Foo.overridenc(UInt(1)) < 3 @test Foo.abigfloat_f()::BigFloat == 12.34000000000000000000000000000000000000000000000000000000000000000000000000005 @test Foo.abigfloat_x::BigFloat + 21 == 64.21000000000000000000000000000000000000000000000000000000000000000000000000053 @test Foo.abigint_f()::BigInt == 123 @test Foo.abigint_x::BigInt + 1 == 125 @test Foo.abigfloat_to_f32() == 1.5f0 @test Foo.x28297.result === missing @test Foo.d29936a === Dict @test Foo.d29936b === (Dict{K, V} where {V, K}) @test Foo.x28998[var"end"] == 6 @test Foo.a31488 == fill("", 100) @test Foo.ptr1 === Ptr{UInt8}(1) @test Foo.ptr2 === Ptr{UInt8}(0) @test Foo.ptr3 === Ptr{UInt8}(-1) @test Foo.layout1::Vector{Ptr{Int8}} == Ptr{Int8}[Ptr{Int8}(0), Ptr{Int8}(0), Ptr{Int8}(-1)] @test Foo.layout2 == Any[Ptr{Int8}(0), Ptr{Int16}(0), Ptr{Int32}(-1)] @test typeof.(Foo.layout2) == [Ptr{Int8}, Ptr{Int16}, Ptr{Int32}] @test Foo.layout3 == ["ab", "cd", "ef", "gh", "ij"] @test !(isopen(Foo.ch1)) @test !(isopen(Foo.ch2)) @test !(isready(Foo.ch1)) @test isready(Foo.ch2) @test take!(Foo.ch2) === 2 @test !(isready(Foo.ch2)) @test Foo.process_state_calls === 0 @test Foo.process_state() === getpid() @test Foo.mypid !== getpid() @test Foo.FooBase_pid !== getpid() @test Foo.mypid !== Foo.FooBase_pid @test Foo.process_state_calls === 1 end Base.invokelatest() do @test Foo.foo(17) == 18 @test Foo.Bar.bar(17) == 19 @test Foo.g() === 97.0 @test 96 < Foo.gnc() < 99 @test Foo.override(1.0) == Float64('a') @test Foo.override(1.0f0) == 'b' @test Foo.override(UInt(1)) == 2 @test 96 < Foo.overridenc(1.0) < 99 @test 99 < Foo.overridenc(1.0f0) < 102 @test 0 < Foo.overridenc(UInt(1)) < 3 @test Foo.abigfloat_f()::BigFloat == 12.34000000000000000000000000000000000000000000000000000000000000000000000000005 @test Foo.abigfloat_x::BigFloat + 21 == 64.21000000000000000000000000000000000000000000000000000000000000000000000000053 @test Foo.abigint_f()::BigInt == 123 @test Foo.abigint_x::BigInt + 1 == 125 @test Foo.abigfloat_to_f32() == 1.5f0 @test Foo.x28297.result === missing @test Foo.d29936a === Dict @test Foo.d29936b === (Dict{K, V} where {V, K}) @test Foo.x28998[var"end"] == 6 @test Foo.a31488 == fill("", 100) @test Foo.ptr1 === Ptr{UInt8}(1) @test Foo.ptr2 === Ptr{UInt8}(0) @test Foo.ptr3 === Ptr{UInt8}(-1) @test Foo.layout1::Vector{Ptr{Int8}} == Ptr{Int8}[Ptr{Int8}(0), Ptr{Int8}(0), Ptr{Int8}(-1)] @test Foo.layout2 == Any[Ptr{Int8}(0), Ptr{Int16}(0), Ptr{Int32}(-1)] @test typeof.(Foo.layout2) == [Ptr{Int8}, Ptr{Int16}, Ptr{Int32}] @test Foo.layout3 == ["ab", "cd", "ef", "gh", "ij"] @test !(isopen(Foo.ch1)) @test !(isopen(Foo.ch2)) @test !(isready(Foo.ch1)) @test isready(Foo.ch2) @test take!(Foo.ch2) === 2 @test !(isready(Foo.ch2)) @test Foo.process_state_calls === 0 @test Foo.process_state() === getpid() @test Foo.mypid !== getpid() @test Foo.FooBase_pid !== getpid() @test Foo.mypid !== Foo.FooBase_pid @test Foo.process_state_calls === 1 end begin Foo_file = joinpath(dir, "$(Foo_module).jl") Foo2_file = joinpath(dir, "$(Foo2_module).jl") FooBase_file = joinpath(dir, "$(FooBase_module).jl") foo_file = joinpath(dir, "$(foo_incl_dep).jl") bar_file = joinpath(dir, "$(bar_incl_dep).jl") write(FooBase_file, "false && __precompile__(false)\nmodule $(FooBase_module)\n import Base: hash, >\n struct fmpz end\n struct typeA end\n >(x::fmpz, y::Int) = Base.cmp(x, y) > 0\n function hash(a::typeA, h::UInt)\n d = den(a)\n return h\n end\n abstract type AbstractAlgebraMap{A} end\n struct GAPGroupHomomorphism{A, B} <: AbstractAlgebraMap{GAPGroupHomomorphism{B, A}} end\n\n global process_state_calls::Int = 0\n const process_state = Base.OncePerProcess{typeof(getpid())}() do\n @assert (global process_state_calls += 1) == 1\n return getpid()\n end\n const mypid = process_state()\n @assert process_state_calls === 1\n process_state_calls = 0\n @assert process_state() === process_state()\n @assert process_state_calls === 0\n\n const empty_state = Base.OncePerProcess{Nothing}() do\n return nothing\n end\n @assert empty_state() === nothing\nend\n") write(Foo2_file, "module $(Foo2_module)\n export override, overridenc\n override(x::Integer) = 2\n override(x::AbstractFloat) = Float64(override(1))\n overridenc(x::Integer) = rand()+1\n overridenc(x::AbstractFloat) = Float64(overridenc(1))\nend\n") write(Foo_file, "module $(Foo_module)\n import $(FooBase_module), $(FooBase_module).typeA, $(FooBase_module).GAPGroupHomomorphism\n import $(Foo2_module): $(Foo2_module), override, overridenc\n import $(FooBase_module).hash\n import Test\n public foo, Bar\n module Inner\n import $(FooBase_module).hash\n using ..$(Foo_module)\n import ..$(Foo2_module)\n end\n\n struct typeB\n y::typeA\n end\n hash(x::typeB) = hash(x.y)\n\n # test that docs get reconnected\n @doc \"foo function\" foo(x) = x + 1\n include_dependency(\"$(foo_incl_dep).jl\")\n include_dependency(\"$(foo_incl_dep).jl\")\n module Bar\n public bar\n include_dependency(\"$(bar_incl_dep).jl\")\n end\n @doc \"Bar module\" Bar # this needs to define the META dictionary via eval\n @eval Bar @doc \"bar function\" bar(x) = x + 2\n\n # test for creation of some reasonably complicated type\n struct MyType{T} end\n const t17809s = Any[\n Tuple{\n Type{Ptr{MyType{i}}},\n Ptr{Type{MyType{i}}},\n Array{Ptr{MyType{MyType{:sym}()}}(0), 0},\n Val{Complex{Int}(1, 2)},\n Val{3},\n Val{nothing}}\n for i = 0:25]\n\n # test that types and methods get reconnected correctly\n # issue 16529 (adding a method to a type with no instances)\n (::Task)(::UInt8, ::UInt16, ::UInt32) = 2\n\n # issue 16471\n Base.sin(::UInt8, ::UInt16, ::UInt32; x = 52) = x\n const sinkw = Core.kwcall\n\n # issue 16908 (some complicated types and external method definitions)\n abstract type CategoricalPool{T, R <: Integer, V} end\n abstract type CategoricalValue{T, R <: Integer} end\n struct NominalPool{T, R <: Integer, V} <: CategoricalPool{T, R, V}\n index::Vector{T}\n invindex::Dict{T, R}\n order::Vector{R}\n ordered::Vector{T}\n valindex::Vector{V}\n end\n struct NominalValue{T, R <: Integer} <: CategoricalValue{T, R}\n level::R\n pool::NominalPool{T, R, NominalValue{T, R}}\n end\n struct OrdinalValue{T, R <: Integer} <: CategoricalValue{T, R}\n level::R\n pool::NominalPool{T, R, NominalValue{T, R}}\n end\n (::Union{Type{NominalValue}, Type{OrdinalValue}})() = 1\n (::Union{Type{NominalValue{T}}, Type{OrdinalValue{T}}})() where {T} = 2\n (::Type{Vector{NominalValue{T, R}}})() where {T, R} = 3\n (::Type{Vector{NominalValue{T, T}}})() where {T} = 4\n (::Type{Vector{NominalValue{Int, Int}}})() = 5\n\n # more tests for method signature involving a complicated type\n # issue 18343\n struct Pool18343{R, V}\n valindex::Vector{V}\n end\n struct Value18343{T, R}\n pool::Pool18343{R, Value18343{T, R}}\n end\n Base.convert(::Type{Some{S}}, ::Value18343{Some}) where {S} = 2\n Base.convert(::Type{Some{Value18343}}, ::Value18343{Some}) = 2\n Base.convert(::Type{Ref}, ::Value18343{T}) where {T} = 3\n\n const GAPType1 = GAPGroupHomomorphism{Nothing, Nothing}\n const GAPType2 = GAPGroupHomomorphism{1, 2}\n\n # issue #28297\n mutable struct Result\n result::Union{Int,Missing}\n end\n\n const x28297 = Result(missing)\n\n const d29936a = UnionAll(Dict.var, UnionAll(Dict.body.var, Dict.body.body))\n const d29936b = UnionAll(Dict.body.var, UnionAll(Dict.var, Dict.body.body))\n\n # issue #28998\n const x28998 = [missing, 2, missing, 6, missing,\n missing, missing, missing,\n missing, missing, missing,\n missing, missing, 6]\n\n let some_method = which(Base.include, (Module, String,))\n # global const some_method // FIXME: support for serializing a direct reference to an external Method not implemented\n global const some_linfo = Core.Compiler.specialize_method(some_method,\n Tuple{typeof(Base.include), Module, String}, Core.svec())\n end\n\n g() = override(1.0)\n Test.@test g() === 2.0 # compile this\n gnc() = overridenc(1.0)\n Test.@test 1 < gnc() < 5 # compile this\n\n abigfloat_f() = big\"12.34\"\n const abigfloat_x = big\"43.21\"\n abigint_f() = big\"123\"\n const abigint_x = big\"124\"\n\n # issue #51111\n abigfloat_to_f32() = Float32(big\"1.5\")\n\n # issue #31488\n _v31488 = Base.StringVector(2)\n resize!(_v31488, 0)\n const a31488 = fill(String(_v31488), 100)\n\n const ptr1 = Ptr{UInt8}(1)\n ptr2 = Ptr{UInt8}(1)\n const ptr3 = Ptr{UInt8}(-1)\n const layout1 = Ptr{Int8}[Ptr{Int8}(0), Ptr{Int8}(1), Ptr{Int8}(-1)]\n const layout2 = Any[Ptr{Int8}(0), Ptr{Int16}(1), Ptr{Int32}(-1)]\n const layout3 = collect(x.match for x in eachmatch(r\"..\", \"abcdefghijk\"))::Vector{SubString{String}}\n\n # create a backedge that includes Type{Union{}}, to ensure lookup can handle that\n call_bottom() = show(stdout, Union{})\n Core.Compiler.return_type(call_bottom, Tuple{})\n\n # check that @ccallable works from precompiled modules\n Base.@ccallable Cint f35014(x::Cint) = x+Cint(1)\n Base.@ccallable \"f35014_other\" f35014_2(x::Cint)::Cint = x+Cint(1)\n\n # check that Tasks work from serialized state\n ch1 = Channel(x -> nothing)\n ch2 = Channel(x -> (push!(x, 2); nothing), Inf)\n\n # check that Memory aliasing is respected\n a_vec_int = Int[]\n push!(a_vec_int, 1, 2)\n a_mat_int = reshape(a_vec_int, (1, 2))\n\n a_vec_any = Any[]\n push!(a_vec_any, 1, 2)\n a_mat_any = reshape(a_vec_any, (1, 2))\n\n a_vec_union = Union{Int,Nothing}[]\n push!(a_vec_union, 1, 2)\n a_mat_union = reshape(a_vec_union, (1, 2))\n\n a_vec_inline = Pair{Int,Any}[]\n push!(a_vec_inline, 1=>2, 3=>4)\n a_mat_inline = reshape(a_vec_inline, (1, 2))\n\n oid_vec_int = objectid(a_vec_int)\n oid_mat_int = objectid(a_mat_int)\n\n using $(FooBase_module): process_state, mypid as FooBase_pid, process_state_calls\n const mypid = process_state()\nend\n") touch(foo_file) touch(bar_file) @test __precompile__(false) === nothing Foo2 = Base.require(Main, Foo2_module) @eval ($Foo2).override(::Int) = begin 'a' end @eval ($Foo2).override(::Float32) = begin 'b' end @eval ($Foo2).overridenc(::Int) = begin rand() + 97.0 end @eval ($Foo2).overridenc(::Float32) = begin rand() + 100.0 end Foo = Base.require(Main, Foo_module) Base.invokelatest() do @test Foo.foo(17) == 18 @test Foo.Bar.bar(17) == 19 @test Foo.g() === 97.0 @test 96 < Foo.gnc() < 99 @test Foo.override(1.0) == Float64('a') @test Foo.override(1.0f0) == 'b' @test Foo.override(UInt(1)) == 2 @test 96 < Foo.overridenc(1.0) < 99 @test 99 < Foo.overridenc(1.0f0) < 102 @test 0 < Foo.overridenc(UInt(1)) < 3 @test Foo.abigfloat_f()::BigFloat == 12.34000000000000000000000000000000000000000000000000000000000000000000000000005 @test Foo.abigfloat_x::BigFloat + 21 == 64.21000000000000000000000000000000000000000000000000000000000000000000000000053 @test Foo.abigint_f()::BigInt == 123 @test Foo.abigint_x::BigInt + 1 == 125 @test Foo.abigfloat_to_f32() == 1.5f0 @test Foo.x28297.result === missing @test Foo.d29936a === Dict @test Foo.d29936b === (Dict{K, V} where {V, K}) @test Foo.x28998[var"end"] == 6 @test Foo.a31488 == fill("", 100) @test Foo.ptr1 === Ptr{UInt8}(1) @test Foo.ptr2 === Ptr{UInt8}(0) @test Foo.ptr3 === Ptr{UInt8}(-1) @test Foo.layout1::Vector{Ptr{Int8}} == Ptr{Int8}[Ptr{Int8}(0), Ptr{Int8}(0), Ptr{Int8}(-1)] @test Foo.layout2 == Any[Ptr{Int8}(0), Ptr{Int16}(0), Ptr{Int32}(-1)] @test typeof.(Foo.layout2) == [Ptr{Int8}, Ptr{Int16}, Ptr{Int32}] @test Foo.layout3 == ["ab", "cd", "ef", "gh", "ij"] @test !(isopen(Foo.ch1)) @test !(isopen(Foo.ch2)) @test !(isready(Foo.ch1)) @test isready(Foo.ch2) @test take!(Foo.ch2) === 2 @test !(isready(Foo.ch2)) @test Foo.process_state_calls === 0 @test Foo.process_state() === getpid() @test Foo.mypid !== getpid() @test Foo.FooBase_pid !== getpid() @test Foo.mypid !== Foo.FooBase_pid @test Foo.process_state_calls === 1 end let @test Foo.a_vec_int == Int[1, 2] @test Foo.a_mat_int == Int[1 2] Foo.a_mat_int[1, 2] = 3 @test Foo.a_vec_int[2] === 3 @test Foo.a_vec_any == Int[1, 2] @test Foo.a_mat_any == Int[1 2] Foo.a_mat_any[1, 2] = 3 @test Foo.a_vec_any[2] === 3 @test Foo.a_vec_union == Union{Int, Nothing}[1, 2] @test Foo.a_mat_union == Union{Int, Nothing}[1 2] Foo.a_mat_union[1, 2] = 3 @test Foo.a_vec_union[2] === 3 Foo.a_mat_union[1, 2] = nothing @test Foo.a_vec_union[2] === nothing @test Foo.a_vec_inline == Pair{Int, Any}[1 => 2, 3 => 4] @test Foo.a_mat_inline == Pair{Int, Any}[1 => 2 3 => 4] Foo.a_mat_inline[1, 2] = 5 => 6 @test Foo.a_vec_inline[2] === Pair{Int, Any}(5, 6) @test objectid(Foo.a_vec_int) === Foo.oid_vec_int @test objectid(Foo.a_mat_int) === Foo.oid_mat_int @test Foo.oid_vec_int !== Foo.oid_mat_int @test Base.object_build_id(Foo.a_vec_int) == Base.object_build_id(Foo.a_mat_int) @test Base.object_build_id(Foo) == Base.module_build_id(Foo) @test Base.object_build_id(Foo.a_vec_int) == Base.module_build_id(Foo) end cachedir = joinpath(dir, "compiled", "v$(VERSION.major).$(VERSION.minor)") cachedir2 = joinpath(dir2, "compiled", "v$(VERSION.major).$(VERSION.minor)") cachefile = joinpath(cachedir, "$(Foo_module).ji") @test isfile(cachefile) do_pkgimg = (Base.JLOptions()).use_pkgimages == 1 && (Base.JLOptions()).permalloc_pkgimg == 1 if do_pkgimg || (Base.JLOptions()).use_pkgimages == 0 if do_pkgimg ocachefile = Base.ocachefile_from_cachefile(cachefile)::String @test isfile(ocachefile) let foo_ptr = Libdl.dlopen(ocachefile::String, RTLD_NOLOAD) f35014_ptr = Libdl.dlsym(foo_ptr, :f35014) @test ccall(f35014_ptr, Int32, (Int32,), 3) == 4 f35014_other_ptr = Libdl.dlsym(foo_ptr, :f35014_other) @test ccall(f35014_other_ptr, Int32, (Int32,), 3) == 4 end else ocachefile = nothing end @test_logs (:warn, "Replacing module `$(Foo_module)`") begin m = Base._require_from_serialized(Base.PkgId(Foo), cachefile, ocachefile, Foo_file) @test m isa Module end end @test_throws MethodError Foo.foo(17) Base.invokelatest() do @test Foo.foo(17) == 18 @test Foo.Bar.bar(17) == 19 @test Foo.g() === 97.0 @test Foo.override(1.0) == Float64('a') @test Foo.override(1.0f0) == 'b' @test Foo.override(UInt(1)) == 2 @test string(Base.Docs.doc(Foo.foo)) == "foo function\n" @test string(Base.Docs.doc(Foo.Bar.bar)) == "bar function\n" @test string(Base.Docs.doc(Foo.Bar)) == "Bar module\n" (modules, (deps, _, requires), required_modules, _...) = Base.parse_cache_header(cachefile) discard_module = (mod_fl_mt->begin mod_fl_mt.filename end) @test modules == [Base.PkgId(Foo) => Base.module_build_id(Foo) % UInt64] @test map((x->begin x.filename end), deps) == [Foo_file, joinpath("@depot", foo_file), joinpath("@depot", bar_file)] @test requires == [Base.PkgId(Foo) => Base.PkgId(string(FooBase_module)), Base.PkgId(Foo) => Base.PkgId(Foo2), Base.PkgId(Foo) => Base.PkgId(Test), Base.PkgId(Foo) => Base.PkgId(string(FooBase_module))] srctxt = Base.read_dependency_src(cachefile, Foo_file) @test !(isempty(srctxt)) && srctxt == read(Foo_file, String) @test_throws ErrorException Base.read_dependency_src(cachefile, "/tmp/nonexistent.txt") @test_throws ErrorException Base.read_dependency_src(cachefile, joinpath(dir, foo_file)) (modules, deps1) = Base.cache_dependencies(cachefile) modules_ok = merge(Dict((let m = Base.PkgId(s) m => Base.module_build_id(Base.root_module(m)) end for s = ["Base", "Core", "Main", string(Foo2_module), string(FooBase_module)])), Dict((let m = Base.root_module(Base, s) Base.PkgId(m) => Base.module_build_id(m) end for s = [Symbol(x.name) for x = Base._sysimage_modules if !(x.name in ["Base", "Core", "Main"])])), Dict(Base.PkgId(Base.root_module(Base, :Test)) => Base.module_build_id(Base.root_module(Base, :Test))), Dict(Base.PkgId(Base.root_module(Base, :InteractiveUtils)) => Base.module_build_id(Base.root_module(Base, :InteractiveUtils))), Dict(Base.PkgId(Base.root_module(Base, :Logging)) => Base.module_build_id(Base.root_module(Base, :Logging))), Dict(Base.PkgId(Base.root_module(Base, :Random)) => Base.module_build_id(Base.root_module(Base, :Random))), Dict(Base.PkgId(Base.root_module(Base, :Serialization)) => Base.module_build_id(Base.root_module(Base, :Serialization))), Dict(Base.PkgId(Base.root_module(Base, :SHA)) => Base.module_build_id(Base.root_module(Base, :SHA))), Dict(Base.PkgId(Base.root_module(Base, :Markdown)) => Base.module_build_id(Base.root_module(Base, :Markdown))), Dict(Base.PkgId(Base.root_module(Base, :JuliaSyntaxHighlighting)) => Base.module_build_id(Base.root_module(Base, :JuliaSyntaxHighlighting))), Dict(Base.PkgId(Base.root_module(Base, :StyledStrings)) => Base.module_build_id(Base.root_module(Base, :StyledStrings))), Dict(Base.PkgId(Base.root_module(Base, :Base64)) => Base.module_build_id(Base.root_module(Base, :Base64)))) @test Dict(modules) == modules_ok @test discard_module.(deps) == deps1 (modules, (_, deps, requires), required_modules, _...) = Base.parse_cache_header(cachefile) @test map((x->begin x.filename end), deps) == [Foo_file] @test (current_task())(0x01, 0x4000, 0x30031234) == 2 @test sin(0x01, 0x4000, 0x30031234) == 52 @test sin(0x01, 0x4000, 0x30031234; x = 9142) == 9142 @test Foo.sinkw === Core.kwcall @test Foo.NominalValue() == 1 @test Foo.OrdinalValue() == 1 @test Foo.NominalValue{Int}() == 2 @test Foo.OrdinalValue{Int}() == 2 let T = Vector{Foo.NominalValue{Int}} @test T() isa T end @test Vector{Foo.NominalValue{Int32, Int64}}() == 3 @test Vector{Foo.NominalValue{UInt, UInt}}() == 4 @test Vector{Foo.NominalValue{Int, Int}}() == 5 @test all((i->begin Foo.t17809s[i + 1] === Tuple{Type{Ptr{Foo.MyType{i}}}, Ptr{Type{Foo.MyType{i}}}, Array{Ptr{Foo.MyType{Foo.MyType{:sym}()}}(0), 0}, Val{Complex{Int}(1, 2)}, Val{3}, Val{nothing}} end), 0:25) some_method = which(Base.include, (Module, String)) some_linfo = Core.Compiler.specialize_method(some_method, Tuple{typeof(Base.include), Module, String}, Core.svec()) @test Foo.some_linfo::Core.MethodInstance === some_linfo ft = Base.datatype_fieldtypes PV = (ft((Foo.Value18343{Some}).body))[1] VR = ((ft(PV))[1]).parameters[1] @test (ft(PV))[1] === Array{VR, 1} @test pointer_from_objref((ft(PV))[1]) === pointer_from_objref((ft((ft(((ft(PV))[1]).parameters[1]))[1]))[1]) @test PV === (ft(((ft(PV))[1]).parameters[1]))[1] @test pointer_from_objref(PV) === pointer_from_objref((ft(((ft(PV))[1]).parameters[1]))[1]) end Nest_module = :Nest4b3a94a1a081a8cb Nest_file = joinpath(dir, "$(Nest_module).jl") NestInner_file = joinpath(dir, "$(Nest_module)Inner.jl") NestInner2_file = joinpath(dir, "$(Nest_module)Inner2.jl") write(Nest_file, "module $(Nest_module)\ninclude(\"$(escape_string(NestInner_file))\")\nend\n") write(NestInner_file, "module NestInner\ninclude(\"$(escape_string(NestInner2_file))\")\nend\n") write(NestInner2_file, "f() = 22\n") Nest = Base.require(Main, Nest_module) cachefile = joinpath(cachedir, "$(Nest_module).ji") (modules, (deps, _, requires), required_modules, _...) = Base.parse_cache_header(cachefile) @test (last(deps)).modpath == ["NestInner"] UsesB_module = :UsesB4b3a94a1a081a8cb B_module = :UsesB4b3a94a1a081a8cb_B UsesB_file = joinpath(dir, "$(UsesB_module).jl") B_file = joinpath(dir, "$(B_module).jl") write(UsesB_file, "module $(UsesB_module)\nusing $(B_module)\nend\n") write(B_file, "module $(B_module)\nexport bfunc\nbfunc() = 33\nend\n") UsesB = Base.require(Main, UsesB_module) cachefile = joinpath(cachedir, "$(UsesB_module).ji") (modules, (deps, _, requires), required_modules, _...) = Base.parse_cache_header(cachefile) (id1, id2) = only(requires) @test (Base.pkgorigins[id1]).cachepath == cachefile @test (Base.pkgorigins[id2]).cachepath == joinpath(cachedir, "$(B_module).ji") Baz_file = joinpath(dir, "Baz.jl") write(Baz_file, "haskey(Base.loaded_modules, Base.PkgId(\"UseBaz\")) || __precompile__(false)\nmodule Baz\nbaz() = 1\nend\n") @test Base.compilecache(Base.PkgId("Baz")) == Base.PrecompilableError() OverwriteMethodError_file = joinpath(dir, "OverwriteMethodError.jl") write(OverwriteMethodError_file, "module OverwriteMethodError\n Base.:(+)(x::Bool, y::Bool) = false\nend\n") @test @test_warn("overwritten in module OverwriteMethodError", Base.compilecache(Base.PkgId("OverwriteMethodError"))) == Base.PrecompilableError() UseBaz_file = joinpath(dir, "UseBaz.jl") write(UseBaz_file, "module UseBaz\nbiz() = 1\n@assert haskey(Base.loaded_modules, Base.PkgId(\"UseBaz\"))\n@assert !haskey(Base.loaded_modules, Base.PkgId(\"Baz\"))\nusing Baz\n@assert haskey(Base.loaded_modules, Base.PkgId(\"Baz\"))\nbuz() = 2\nconst generating = ccall(:jl_generating_output, Cint, ())\nconst incremental = Base.JLOptions().incremental\nend\n") @test Base.compilecache(Base.PkgId("UseBaz")) == Base.PrecompilableError() @eval using UseBaz @test haskey(Base.loaded_modules, Base.PkgId("UseBaz")) @test haskey(Base.loaded_modules, Base.PkgId("Baz")) invokelatest() do @test UseBaz.biz() === 1 @test UseBaz.buz() === 2 @test UseBaz.generating == 0 @test UseBaz.incremental == 0 end @eval using Baz invokelatest() do @test Baz.baz() === 1 @test Baz === UseBaz.Baz end @test !(isfile("DoesNotExist.ji")) @test Base.stale_cachefile("", "DoesNotExist.ji") === true FooBar1_file = joinpath(dir, "FooBar1.jl") write(FooBar1_file, "module FooBar1\n using FooBar\nend\n") sleep(2) FooBar_file = joinpath(dir, "FooBar.jl") write(FooBar_file, "module FooBar\nend\n") (cachefile, _) = @test_logs((:debug, r"Precompiling FooBar"), min_level = Logging.Debug, match_mode = :any, Base.compilecache(Base.PkgId("FooBar"))) empty_prefs_hash = Base.get_preferences_hash(nothing, String[]) @test cachefile == Base.compilecache_path(Base.PkgId("FooBar"), empty_prefs_hash) @test isfile(joinpath(cachedir, "FooBar.ji")) Tsc = if Bool((Base.JLOptions()).use_pkgimages) Tuple{<:Vector, String, UInt128} else Tuple{<:Vector, Nothing, UInt128} end @test Base.stale_cachefile(FooBar_file, joinpath(cachedir, "FooBar.ji")) isa Tsc @test !(isdefined(Main, :FooBar)) @test !(isdefined(Main, :FooBar1)) relFooBar_file = joinpath(dir, "subfolder", "..", "FooBar.jl") @test Base.stale_cachefile(relFooBar_file, joinpath(cachedir, "FooBar.ji")) isa if Sys.iswindows() Tuple{<:Vector, String, UInt128} else Bool end mkdir(joinpath(dir, "subfolder")) @test Base.stale_cachefile(relFooBar_file, joinpath(cachedir, "FooBar.ji")) isa Tsc @eval using FooBar fb_uuid = invokelatest((()->begin Base.module_build_id(FooBar) end)) sleep(2) touch(FooBar_file) insert!(DEPOT_PATH, 1, dir2) @test Base.stale_cachefile(FooBar_file, joinpath(cachedir, "FooBar.ji")) isa Tsc @eval using FooBar1 @test !(isfile(joinpath(cachedir2, "FooBar.ji"))) @test !(isfile(joinpath(cachedir, "FooBar1.ji"))) @test isfile(joinpath(cachedir2, "FooBar1.ji")) @test Base.stale_cachefile(FooBar_file, joinpath(cachedir, "FooBar.ji")) isa Tsc @test Base.stale_cachefile(FooBar1_file, joinpath(cachedir2, "FooBar1.ji")) isa Tsc invokelatest() do @test fb_uuid == Base.module_build_id(FooBar) fb_uuid1 = Base.module_build_id(FooBar1) @test fb_uuid != fb_uuid1 end open(joinpath(cachedir2, "FooBar1.ji"), "a") do f write(f, 0x076cac96) end @test Base.stale_cachefile(FooBar1_file, joinpath(cachedir2, "FooBar1.ji")) === true FooBar2_file = joinpath(dir, "FooBar2.jl") write(FooBar2_file, "module FooBar2\nerror(\"break me\")\nend\n") try Base.require(Main, :FooBar2) error("the \"break me\" test failed") catch exc exc isa Base.Precompilation.PkgPrecompileError || rethrow() occursin("Failed to precompile FooBar2", exc.msg) || rethrow() occursin("LoadError: break me", exc.msg) || rethrow() end FooBar3_file = joinpath(dir, "FooBar3.jl") FooBar3_inc = joinpath(dir, "FooBar3_inc.jl") write(FooBar3_inc, "x=1\n") for code = ["Core.eval(Base, :(x=1))", "Base.include(Base, \"FooBar3_inc.jl\")"] write(FooBar3_file, "module FooBar3\n$(code)\nend\n") try Base.require(Main, :FooBar3) catch exc exc isa Base.Precompilation.PkgPrecompileError || rethrow() occursin("Evaluation into the closed module `Base` breaks incremental compilation", exc.msg) || rethrow() end end FooBarT_file = joinpath(dir, "FooBarT.jl") write(FooBarT_file, "module FooBarT\nend\n") FooBarT1_file = joinpath(dir, "FooBarT1.jl") write(FooBarT1_file, "module FooBarT1\n using FooBarT\nend\n") FooBarT2_file = joinpath(dir, "FooBarT2.jl") write(FooBarT2_file, "module FooBarT2\n using FooBarT1\nend\n") Base.compilecache(Base.PkgId("FooBarT2")) write(FooBarT1_file, "module FooBarT1\nend\n") rm(FooBarT_file) @test Base.stale_cachefile(FooBarT2_file, joinpath(cachedir2, "FooBarT2.ji")) === true @test Base.require(Main, :FooBarT2) isa Module end begin Foo_file = joinpath(dir, "$(Foo_module).jl") Foo2_file = joinpath(dir, "$(Foo2_module).jl") FooBase_file = joinpath(dir, "$(FooBase_module).jl") foo_file = joinpath(dir, "$(foo_incl_dep).jl") bar_file = joinpath(dir, "$(bar_incl_dep).jl") write(FooBase_file, "false && __precompile__(false)\nmodule $(FooBase_module)\n import Base: hash, >\n struct fmpz end\n struct typeA end\n >(x::fmpz, y::Int) = Base.cmp(x, y) > 0\n function hash(a::typeA, h::UInt)\n d = den(a)\n return h\n end\n abstract type AbstractAlgebraMap{A} end\n struct GAPGroupHomomorphism{A, B} <: AbstractAlgebraMap{GAPGroupHomomorphism{B, A}} end\n\n global process_state_calls::Int = 0\n const process_state = Base.OncePerProcess{typeof(getpid())}() do\n @assert (global process_state_calls += 1) == 1\n return getpid()\n end\n const mypid = process_state()\n @assert process_state_calls === 1\n process_state_calls = 0\n @assert process_state() === process_state()\n @assert process_state_calls === 0\n\n const empty_state = Base.OncePerProcess{Nothing}() do\n return nothing\n end\n @assert empty_state() === nothing\nend\n") write(Foo2_file, "module $(Foo2_module)\n export override, overridenc\n override(x::Integer) = 2\n override(x::AbstractFloat) = Float64(override(1))\n overridenc(x::Integer) = rand()+1\n overridenc(x::AbstractFloat) = Float64(overridenc(1))\nend\n") write(Foo_file, "module $(Foo_module)\n import $(FooBase_module), $(FooBase_module).typeA, $(FooBase_module).GAPGroupHomomorphism\n import $(Foo2_module): $(Foo2_module), override, overridenc\n import $(FooBase_module).hash\n import Test\n public foo, Bar\n module Inner\n import $(FooBase_module).hash\n using ..$(Foo_module)\n import ..$(Foo2_module)\n end\n\n struct typeB\n y::typeA\n end\n hash(x::typeB) = hash(x.y)\n\n # test that docs get reconnected\n @doc \"foo function\" foo(x) = x + 1\n include_dependency(\"$(foo_incl_dep).jl\")\n include_dependency(\"$(foo_incl_dep).jl\")\n module Bar\n public bar\n include_dependency(\"$(bar_incl_dep).jl\")\n end\n @doc \"Bar module\" Bar # this needs to define the META dictionary via eval\n @eval Bar @doc \"bar function\" bar(x) = x + 2\n\n # test for creation of some reasonably complicated type\n struct MyType{T} end\n const t17809s = Any[\n Tuple{\n Type{Ptr{MyType{i}}},\n Ptr{Type{MyType{i}}},\n Array{Ptr{MyType{MyType{:sym}()}}(0), 0},\n Val{Complex{Int}(1, 2)},\n Val{3},\n Val{nothing}}\n for i = 0:25]\n\n # test that types and methods get reconnected correctly\n # issue 16529 (adding a method to a type with no instances)\n (::Task)(::UInt8, ::UInt16, ::UInt32) = 2\n\n # issue 16471\n Base.sin(::UInt8, ::UInt16, ::UInt32; x = 52) = x\n const sinkw = Core.kwcall\n\n # issue 16908 (some complicated types and external method definitions)\n abstract type CategoricalPool{T, R <: Integer, V} end\n abstract type CategoricalValue{T, R <: Integer} end\n struct NominalPool{T, R <: Integer, V} <: CategoricalPool{T, R, V}\n index::Vector{T}\n invindex::Dict{T, R}\n order::Vector{R}\n ordered::Vector{T}\n valindex::Vector{V}\n end\n struct NominalValue{T, R <: Integer} <: CategoricalValue{T, R}\n level::R\n pool::NominalPool{T, R, NominalValue{T, R}}\n end\n struct OrdinalValue{T, R <: Integer} <: CategoricalValue{T, R}\n level::R\n pool::NominalPool{T, R, NominalValue{T, R}}\n end\n (::Union{Type{NominalValue}, Type{OrdinalValue}})() = 1\n (::Union{Type{NominalValue{T}}, Type{OrdinalValue{T}}})() where {T} = 2\n (::Type{Vector{NominalValue{T, R}}})() where {T, R} = 3\n (::Type{Vector{NominalValue{T, T}}})() where {T} = 4\n (::Type{Vector{NominalValue{Int, Int}}})() = 5\n\n # more tests for method signature involving a complicated type\n # issue 18343\n struct Pool18343{R, V}\n valindex::Vector{V}\n end\n struct Value18343{T, R}\n pool::Pool18343{R, Value18343{T, R}}\n end\n Base.convert(::Type{Some{S}}, ::Value18343{Some}) where {S} = 2\n Base.convert(::Type{Some{Value18343}}, ::Value18343{Some}) = 2\n Base.convert(::Type{Ref}, ::Value18343{T}) where {T} = 3\n\n const GAPType1 = GAPGroupHomomorphism{Nothing, Nothing}\n const GAPType2 = GAPGroupHomomorphism{1, 2}\n\n # issue #28297\n mutable struct Result\n result::Union{Int,Missing}\n end\n\n const x28297 = Result(missing)\n\n const d29936a = UnionAll(Dict.var, UnionAll(Dict.body.var, Dict.body.body))\n const d29936b = UnionAll(Dict.body.var, UnionAll(Dict.var, Dict.body.body))\n\n # issue #28998\n const x28998 = [missing, 2, missing, 6, missing,\n missing, missing, missing,\n missing, missing, missing,\n missing, missing, 6]\n\n let some_method = which(Base.include, (Module, String,))\n # global const some_method // FIXME: support for serializing a direct reference to an external Method not implemented\n global const some_linfo = Core.Compiler.specialize_method(some_method,\n Tuple{typeof(Base.include), Module, String}, Core.svec())\n end\n\n g() = override(1.0)\n Test.@test g() === 2.0 # compile this\n gnc() = overridenc(1.0)\n Test.@test 1 < gnc() < 5 # compile this\n\n abigfloat_f() = big\"12.34\"\n const abigfloat_x = big\"43.21\"\n abigint_f() = big\"123\"\n const abigint_x = big\"124\"\n\n # issue #51111\n abigfloat_to_f32() = Float32(big\"1.5\")\n\n # issue #31488\n _v31488 = Base.StringVector(2)\n resize!(_v31488, 0)\n const a31488 = fill(String(_v31488), 100)\n\n const ptr1 = Ptr{UInt8}(1)\n ptr2 = Ptr{UInt8}(1)\n const ptr3 = Ptr{UInt8}(-1)\n const layout1 = Ptr{Int8}[Ptr{Int8}(0), Ptr{Int8}(1), Ptr{Int8}(-1)]\n const layout2 = Any[Ptr{Int8}(0), Ptr{Int16}(1), Ptr{Int32}(-1)]\n const layout3 = collect(x.match for x in eachmatch(r\"..\", \"abcdefghijk\"))::Vector{SubString{String}}\n\n # create a backedge that includes Type{Union{}}, to ensure lookup can handle that\n call_bottom() = show(stdout, Union{})\n Core.Compiler.return_type(call_bottom, Tuple{})\n\n # check that @ccallable works from precompiled modules\n Base.@ccallable Cint f35014(x::Cint) = x+Cint(1)\n Base.@ccallable \"f35014_other\" f35014_2(x::Cint)::Cint = x+Cint(1)\n\n # check that Tasks work from serialized state\n ch1 = Channel(x -> nothing)\n ch2 = Channel(x -> (push!(x, 2); nothing), Inf)\n\n # check that Memory aliasing is respected\n a_vec_int = Int[]\n push!(a_vec_int, 1, 2)\n a_mat_int = reshape(a_vec_int, (1, 2))\n\n a_vec_any = Any[]\n push!(a_vec_any, 1, 2)\n a_mat_any = reshape(a_vec_any, (1, 2))\n\n a_vec_union = Union{Int,Nothing}[]\n push!(a_vec_union, 1, 2)\n a_mat_union = reshape(a_vec_union, (1, 2))\n\n a_vec_inline = Pair{Int,Any}[]\n push!(a_vec_inline, 1=>2, 3=>4)\n a_mat_inline = reshape(a_vec_inline, (1, 2))\n\n oid_vec_int = objectid(a_vec_int)\n oid_mat_int = objectid(a_mat_int)\n\n using $(FooBase_module): process_state, mypid as FooBase_pid, process_state_calls\n const mypid = process_state()\nend\n") touch(foo_file) touch(bar_file) @test __precompile__(false) === nothing Foo2 = Base.require(Main, Foo2_module) @eval ($Foo2).override(::Int) = begin 'a' end @eval ($Foo2).override(::Float32) = begin 'b' end @eval ($Foo2).overridenc(::Int) = begin rand() + 97.0 end @eval ($Foo2).overridenc(::Float32) = begin rand() + 100.0 end Foo = Base.require(Main, Foo_module) Base.invokelatest() do @test Foo.foo(17) == 18 @test Foo.Bar.bar(17) == 19 @test Foo.g() === 97.0 @test 96 < Foo.gnc() < 99 @test Foo.override(1.0) == Float64('a') @test Foo.override(1.0f0) == 'b' @test Foo.override(UInt(1)) == 2 @test 96 < Foo.overridenc(1.0) < 99 @test 99 < Foo.overridenc(1.0f0) < 102 @test 0 < Foo.overridenc(UInt(1)) < 3 @test Foo.abigfloat_f()::BigFloat == 12.34000000000000000000000000000000000000000000000000000000000000000000000000005 @test Foo.abigfloat_x::BigFloat + 21 == 64.21000000000000000000000000000000000000000000000000000000000000000000000000053 @test Foo.abigint_f()::BigInt == 123 @test Foo.abigint_x::BigInt + 1 == 125 @test Foo.abigfloat_to_f32() == 1.5f0 @test Foo.x28297.result === missing @test Foo.d29936a === Dict @test Foo.d29936b === (Dict{K, V} where {V, K}) @test Foo.x28998[var"end"] == 6 @test Foo.a31488 == fill("", 100) @test Foo.ptr1 === Ptr{UInt8}(1) @test Foo.ptr2 === Ptr{UInt8}(0) @test Foo.ptr3 === Ptr{UInt8}(-1) @test Foo.layout1::Vector{Ptr{Int8}} == Ptr{Int8}[Ptr{Int8}(0), Ptr{Int8}(0), Ptr{Int8}(-1)] @test Foo.layout2 == Any[Ptr{Int8}(0), Ptr{Int16}(0), Ptr{Int32}(-1)] @test typeof.(Foo.layout2) == [Ptr{Int8}, Ptr{Int16}, Ptr{Int32}] @test Foo.layout3 == ["ab", "cd", "ef", "gh", "ij"] @test !(isopen(Foo.ch1)) @test !(isopen(Foo.ch2)) @test !(isready(Foo.ch1)) @test isready(Foo.ch2) @test take!(Foo.ch2) === 2 @test !(isready(Foo.ch2)) @test Foo.process_state_calls === 0 @test Foo.process_state() === getpid() @test Foo.mypid !== getpid() @test Foo.FooBase_pid !== getpid() @test Foo.mypid !== Foo.FooBase_pid @test Foo.process_state_calls === 1 end let @test Foo.a_vec_int == Int[1, 2] @test Foo.a_mat_int == Int[1 2] Foo.a_mat_int[1, 2] = 3 @test Foo.a_vec_int[2] === 3 @test Foo.a_vec_any == Int[1, 2] @test Foo.a_mat_any == Int[1 2] Foo.a_mat_any[1, 2] = 3 @test Foo.a_vec_any[2] === 3 @test Foo.a_vec_union == Union{Int, Nothing}[1, 2] @test Foo.a_mat_union == Union{Int, Nothing}[1 2] Foo.a_mat_union[1, 2] = 3 @test Foo.a_vec_union[2] === 3 Foo.a_mat_union[1, 2] = nothing @test Foo.a_vec_union[2] === nothing @test Foo.a_vec_inline == Pair{Int, Any}[1 => 2, 3 => 4] @test Foo.a_mat_inline == Pair{Int, Any}[1 => 2 3 => 4] Foo.a_mat_inline[1, 2] = 5 => 6 @test Foo.a_vec_inline[2] === Pair{Int, Any}(5, 6) @test objectid(Foo.a_vec_int) === Foo.oid_vec_int @test objectid(Foo.a_mat_int) === Foo.oid_mat_int @test Foo.oid_vec_int !== Foo.oid_mat_int @test Base.object_build_id(Foo.a_vec_int) == Base.object_build_id(Foo.a_mat_int) @test Base.object_build_id(Foo) == Base.module_build_id(Foo) @test Base.object_build_id(Foo.a_vec_int) == Base.module_build_id(Foo) end cachedir = joinpath(dir, "compiled", "v$(VERSION.major).$(VERSION.minor)") cachedir2 = joinpath(dir2, "compiled", "v$(VERSION.major).$(VERSION.minor)") cachefile = joinpath(cachedir, "$(Foo_module).ji") @test isfile(cachefile) do_pkgimg = (Base.JLOptions()).use_pkgimages == 1 && (Base.JLOptions()).permalloc_pkgimg == 1 if do_pkgimg || (Base.JLOptions()).use_pkgimages == 0 if do_pkgimg ocachefile = Base.ocachefile_from_cachefile(cachefile)::String @test isfile(ocachefile) let foo_ptr = Libdl.dlopen(ocachefile::String, RTLD_NOLOAD) f35014_ptr = Libdl.dlsym(foo_ptr, :f35014) @test ccall(f35014_ptr, Int32, (Int32,), 3) == 4 f35014_other_ptr = Libdl.dlsym(foo_ptr, :f35014_other) @test ccall(f35014_other_ptr, Int32, (Int32,), 3) == 4 end else ocachefile = nothing end @test_logs (:warn, "Replacing module `$(Foo_module)`") begin m = Base._require_from_serialized(Base.PkgId(Foo), cachefile, ocachefile, Foo_file) @test m isa Module end end @test_throws MethodError Foo.foo(17) Base.invokelatest() do @test Foo.foo(17) == 18 @test Foo.Bar.bar(17) == 19 @test Foo.g() === 97.0 @test Foo.override(1.0) == Float64('a') @test Foo.override(1.0f0) == 'b' @test Foo.override(UInt(1)) == 2 @test string(Base.Docs.doc(Foo.foo)) == "foo function\n" @test string(Base.Docs.doc(Foo.Bar.bar)) == "bar function\n" @test string(Base.Docs.doc(Foo.Bar)) == "Bar module\n" (modules, (deps, _, requires), required_modules, _...) = Base.parse_cache_header(cachefile) discard_module = (mod_fl_mt->begin mod_fl_mt.filename end) @test modules == [Base.PkgId(Foo) => Base.module_build_id(Foo) % UInt64] @test map((x->begin x.filename end), deps) == [Foo_file, joinpath("@depot", foo_file), joinpath("@depot", bar_file)] @test requires == [Base.PkgId(Foo) => Base.PkgId(string(FooBase_module)), Base.PkgId(Foo) => Base.PkgId(Foo2), Base.PkgId(Foo) => Base.PkgId(Test), Base.PkgId(Foo) => Base.PkgId(string(FooBase_module))] srctxt = Base.read_dependency_src(cachefile, Foo_file) @test !(isempty(srctxt)) && srctxt == read(Foo_file, String) @test_throws ErrorException Base.read_dependency_src(cachefile, "/tmp/nonexistent.txt") @test_throws ErrorException Base.read_dependency_src(cachefile, joinpath(dir, foo_file)) (modules, deps1) = Base.cache_dependencies(cachefile) modules_ok = merge(Dict((let m = Base.PkgId(s) m => Base.module_build_id(Base.root_module(m)) end for s = ["Base", "Core", "Main", string(Foo2_module), string(FooBase_module)])), Dict((let m = Base.root_module(Base, s) Base.PkgId(m) => Base.module_build_id(m) end for s = [Symbol(x.name) for x = Base._sysimage_modules if !(x.name in ["Base", "Core", "Main"])])), Dict(Base.PkgId(Base.root_module(Base, :Test)) => Base.module_build_id(Base.root_module(Base, :Test))), Dict(Base.PkgId(Base.root_module(Base, :InteractiveUtils)) => Base.module_build_id(Base.root_module(Base, :InteractiveUtils))), Dict(Base.PkgId(Base.root_module(Base, :Logging)) => Base.module_build_id(Base.root_module(Base, :Logging))), Dict(Base.PkgId(Base.root_module(Base, :Random)) => Base.module_build_id(Base.root_module(Base, :Random))), Dict(Base.PkgId(Base.root_module(Base, :Serialization)) => Base.module_build_id(Base.root_module(Base, :Serialization))), Dict(Base.PkgId(Base.root_module(Base, :SHA)) => Base.module_build_id(Base.root_module(Base, :SHA))), Dict(Base.PkgId(Base.root_module(Base, :Markdown)) => Base.module_build_id(Base.root_module(Base, :Markdown))), Dict(Base.PkgId(Base.root_module(Base, :JuliaSyntaxHighlighting)) => Base.module_build_id(Base.root_module(Base, :JuliaSyntaxHighlighting))), Dict(Base.PkgId(Base.root_module(Base, :StyledStrings)) => Base.module_build_id(Base.root_module(Base, :StyledStrings))), Dict(Base.PkgId(Base.root_module(Base, :Base64)) => Base.module_build_id(Base.root_module(Base, :Base64)))) @test Dict(modules) == modules_ok @test discard_module.(deps) == deps1 (modules, (_, deps, requires), required_modules, _...) = Base.parse_cache_header(cachefile) @test map((x->begin x.filename end), deps) == [Foo_file] @test (current_task())(0x01, 0x4000, 0x30031234) == 2 @test sin(0x01, 0x4000, 0x30031234) == 52 @test sin(0x01, 0x4000, 0x30031234; x = 9142) == 9142 @test Foo.sinkw === Core.kwcall @test Foo.NominalValue() == 1 @test Foo.OrdinalValue() == 1 @test Foo.NominalValue{Int}() == 2 @test Foo.OrdinalValue{Int}() == 2 let T = Vector{Foo.NominalValue{Int}} @test T() isa T end @test Vector{Foo.NominalValue{Int32, Int64}}() == 3 @test Vector{Foo.NominalValue{UInt, UInt}}() == 4 @test Vector{Foo.NominalValue{Int, Int}}() == 5 @test all((i->begin Foo.t17809s[i + 1] === Tuple{Type{Ptr{Foo.MyType{i}}}, Ptr{Type{Foo.MyType{i}}}, Array{Ptr{Foo.MyType{Foo.MyType{:sym}()}}(0), 0}, Val{Complex{Int}(1, 2)}, Val{3}, Val{nothing}} end), 0:25) some_method = which(Base.include, (Module, String)) some_linfo = Core.Compiler.specialize_method(some_method, Tuple{typeof(Base.include), Module, String}, Core.svec()) @test Foo.some_linfo::Core.MethodInstance === some_linfo ft = Base.datatype_fieldtypes PV = (ft((Foo.Value18343{Some}).body))[1] VR = ((ft(PV))[1]).parameters[1] @test (ft(PV))[1] === Array{VR, 1} @test pointer_from_objref((ft(PV))[1]) === pointer_from_objref((ft((ft(((ft(PV))[1]).parameters[1]))[1]))[1]) @test PV === (ft(((ft(PV))[1]).parameters[1]))[1] @test pointer_from_objref(PV) === pointer_from_objref((ft(((ft(PV))[1]).parameters[1]))[1]) end Nest_module = :Nest4b3a94a1a081a8cb Nest_file = joinpath(dir, "$(Nest_module).jl") NestInner_file = joinpath(dir, "$(Nest_module)Inner.jl") NestInner2_file = joinpath(dir, "$(Nest_module)Inner2.jl") write(Nest_file, "module $(Nest_module)\ninclude(\"$(escape_string(NestInner_file))\")\nend\n") write(NestInner_file, "module NestInner\ninclude(\"$(escape_string(NestInner2_file))\")\nend\n") write(NestInner2_file, "f() = 22\n") Nest = Base.require(Main, Nest_module) cachefile = joinpath(cachedir, "$(Nest_module).ji") (modules, (deps, _, requires), required_modules, _...) = Base.parse_cache_header(cachefile) @test (last(deps)).modpath == ["NestInner"] UsesB_module = :UsesB4b3a94a1a081a8cb B_module = :UsesB4b3a94a1a081a8cb_B UsesB_file = joinpath(dir, "$(UsesB_module).jl") B_file = joinpath(dir, "$(B_module).jl") write(UsesB_file, "module $(UsesB_module)\nusing $(B_module)\nend\n") write(B_file, "module $(B_module)\nexport bfunc\nbfunc() = 33\nend\n") UsesB = Base.require(Main, UsesB_module) cachefile = joinpath(cachedir, "$(UsesB_module).ji") (modules, (deps, _, requires), required_modules, _...) = Base.parse_cache_header(cachefile) (id1, id2) = only(requires) @test (Base.pkgorigins[id1]).cachepath == cachefile @test (Base.pkgorigins[id2]).cachepath == joinpath(cachedir, "$(B_module).ji") Baz_file = joinpath(dir, "Baz.jl") write(Baz_file, "haskey(Base.loaded_modules, Base.PkgId(\"UseBaz\")) || __precompile__(false)\nmodule Baz\nbaz() = 1\nend\n") @test Base.compilecache(Base.PkgId("Baz")) == Base.PrecompilableError() OverwriteMethodError_file = joinpath(dir, "OverwriteMethodError.jl") write(OverwriteMethodError_file, "module OverwriteMethodError\n Base.:(+)(x::Bool, y::Bool) = false\nend\n") @test @test_warn("overwritten in module OverwriteMethodError", Base.compilecache(Base.PkgId("OverwriteMethodError"))) == Base.PrecompilableError() UseBaz_file = joinpath(dir, "UseBaz.jl") write(UseBaz_file, "module UseBaz\nbiz() = 1\n@assert haskey(Base.loaded_modules, Base.PkgId(\"UseBaz\"))\n@assert !haskey(Base.loaded_modules, Base.PkgId(\"Baz\"))\nusing Baz\n@assert haskey(Base.loaded_modules, Base.PkgId(\"Baz\"))\nbuz() = 2\nconst generating = ccall(:jl_generating_output, Cint, ())\nconst incremental = Base.JLOptions().incremental\nend\n") @test Base.compilecache(Base.PkgId("UseBaz")) == Base.PrecompilableError() @eval using UseBaz @test haskey(Base.loaded_modules, Base.PkgId("UseBaz")) @test haskey(Base.loaded_modules, Base.PkgId("Baz")) invokelatest() do @test UseBaz.biz() === 1 @test UseBaz.buz() === 2 @test UseBaz.generating == 0 @test UseBaz.incremental == 0 end @eval using Baz invokelatest() do @test Baz.baz() === 1 @test Baz === UseBaz.Baz end @test !(isfile("DoesNotExist.ji")) @test Base.stale_cachefile("", "DoesNotExist.ji") === true FooBar1_file = joinpath(dir, "FooBar1.jl") write(FooBar1_file, "module FooBar1\n using FooBar\nend\n") sleep(2) FooBar_file = joinpath(dir, "FooBar.jl") write(FooBar_file, "module FooBar\nend\n") (cachefile, _) = @test_logs((:debug, r"Precompiling FooBar"), min_level = Logging.Debug, match_mode = :any, Base.compilecache(Base.PkgId("FooBar"))) empty_prefs_hash = Base.get_preferences_hash(nothing, String[]) @test cachefile == Base.compilecache_path(Base.PkgId("FooBar"), empty_prefs_hash) @test isfile(joinpath(cachedir, "FooBar.ji")) Tsc = if Bool((Base.JLOptions()).use_pkgimages) Tuple{<:Vector, String, UInt128} else Tuple{<:Vector, Nothing, UInt128} end @test Base.stale_cachefile(FooBar_file, joinpath(cachedir, "FooBar.ji")) isa Tsc @test !(isdefined(Main, :FooBar)) @test !(isdefined(Main, :FooBar1)) relFooBar_file = joinpath(dir, "subfolder", "..", "FooBar.jl") @test Base.stale_cachefile(relFooBar_file, joinpath(cachedir, "FooBar.ji")) isa if Sys.iswindows() Tuple{<:Vector, String, UInt128} else Bool end mkdir(joinpath(dir, "subfolder")) @test Base.stale_cachefile(relFooBar_file, joinpath(cachedir, "FooBar.ji")) isa Tsc @eval using FooBar fb_uuid = invokelatest((()->begin Base.module_build_id(FooBar) end)) sleep(2) touch(FooBar_file) insert!(DEPOT_PATH, 1, dir2) @test Base.stale_cachefile(FooBar_file, joinpath(cachedir, "FooBar.ji")) isa Tsc @eval using FooBar1 @test !(isfile(joinpath(cachedir2, "FooBar.ji"))) @test !(isfile(joinpath(cachedir, "FooBar1.ji"))) @test isfile(joinpath(cachedir2, "FooBar1.ji")) @test Base.stale_cachefile(FooBar_file, joinpath(cachedir, "FooBar.ji")) isa Tsc @test Base.stale_cachefile(FooBar1_file, joinpath(cachedir2, "FooBar1.ji")) isa Tsc invokelatest() do @test fb_uuid == Base.module_build_id(FooBar) fb_uuid1 = Base.module_build_id(FooBar1) @test fb_uuid != fb_uuid1 end open(joinpath(cachedir2, "FooBar1.ji"), "a") do f write(f, 0x076cac96) end @test Base.stale_cachefile(FooBar1_file, joinpath(cachedir2, "FooBar1.ji")) === true FooBar2_file = joinpath(dir, "FooBar2.jl") write(FooBar2_file, "module FooBar2\nerror(\"break me\")\nend\n") try Base.require(Main, :FooBar2) error("the \"break me\" test failed") catch exc exc isa Base.Precompilation.PkgPrecompileError || rethrow() occursin("Failed to precompile FooBar2", exc.msg) || rethrow() occursin("LoadError: break me", exc.msg) || rethrow() end FooBar3_file = joinpath(dir, "FooBar3.jl") FooBar3_inc = joinpath(dir, "FooBar3_inc.jl") write(FooBar3_inc, "x=1\n") for code = ["Core.eval(Base, :(x=1))", "Base.include(Base, \"FooBar3_inc.jl\")"] write(FooBar3_file, "module FooBar3\n$(code)\nend\n") try Base.require(Main, :FooBar3) catch exc exc isa Base.Precompilation.PkgPrecompileError || rethrow() occursin("Evaluation into the closed module `Base` breaks incremental compilation", exc.msg) || rethrow() end end FooBarT_file = joinpath(dir, "FooBarT.jl") write(FooBarT_file, "module FooBarT\nend\n") FooBarT1_file = joinpath(dir, "FooBarT1.jl") write(FooBarT1_file, "module FooBarT1\n using FooBarT\nend\n") FooBarT2_file = joinpath(dir, "FooBarT2.jl") write(FooBarT2_file, "module FooBarT2\n using FooBarT1\nend\n") Base.compilecache(Base.PkgId("FooBarT2")) write(FooBarT1_file, "module FooBarT1\nend\n") rm(FooBarT_file) @test Base.stale_cachefile(FooBarT2_file, joinpath(cachedir2, "FooBarT2.ji")) === true @test Base.require(Main, :FooBarT2) isa Module end (dir,)->begin Foo_file = joinpath(dir, "$(Foo_module).jl") Foo2_file = joinpath(dir, "$(Foo2_module).jl") FooBase_file = joinpath(dir, "$(FooBase_module).jl") foo_file = joinpath(dir, "$(foo_incl_dep).jl") bar_file = joinpath(dir, "$(bar_incl_dep).jl") write(FooBase_file, "false && __precompile__(false)\nmodule $(FooBase_module)\n import Base: hash, >\n struct fmpz end\n struct typeA end\n >(x::fmpz, y::Int) = Base.cmp(x, y) > 0\n function hash(a::typeA, h::UInt)\n d = den(a)\n return h\n end\n abstract type AbstractAlgebraMap{A} end\n struct GAPGroupHomomorphism{A, B} <: AbstractAlgebraMap{GAPGroupHomomorphism{B, A}} end\n\n global process_state_calls::Int = 0\n const process_state = Base.OncePerProcess{typeof(getpid())}() do\n @assert (global process_state_calls += 1) == 1\n return getpid()\n end\n const mypid = process_state()\n @assert process_state_calls === 1\n process_state_calls = 0\n @assert process_state() === process_state()\n @assert process_state_calls === 0\n\n const empty_state = Base.OncePerProcess{Nothing}() do\n return nothing\n end\n @assert empty_state() === nothing\nend\n") write(Foo2_file, "module $(Foo2_module)\n export override, overridenc\n override(x::Integer) = 2\n override(x::AbstractFloat) = Float64(override(1))\n overridenc(x::Integer) = rand()+1\n overridenc(x::AbstractFloat) = Float64(overridenc(1))\nend\n") write(Foo_file, "module $(Foo_module)\n import $(FooBase_module), $(FooBase_module).typeA, $(FooBase_module).GAPGroupHomomorphism\n import $(Foo2_module): $(Foo2_module), override, overridenc\n import $(FooBase_module).hash\n import Test\n public foo, Bar\n module Inner\n import $(FooBase_module).hash\n using ..$(Foo_module)\n import ..$(Foo2_module)\n end\n\n struct typeB\n y::typeA\n end\n hash(x::typeB) = hash(x.y)\n\n # test that docs get reconnected\n @doc \"foo function\" foo(x) = x + 1\n include_dependency(\"$(foo_incl_dep).jl\")\n include_dependency(\"$(foo_incl_dep).jl\")\n module Bar\n public bar\n include_dependency(\"$(bar_incl_dep).jl\")\n end\n @doc \"Bar module\" Bar # this needs to define the META dictionary via eval\n @eval Bar @doc \"bar function\" bar(x) = x + 2\n\n # test for creation of some reasonably complicated type\n struct MyType{T} end\n const t17809s = Any[\n Tuple{\n Type{Ptr{MyType{i}}},\n Ptr{Type{MyType{i}}},\n Array{Ptr{MyType{MyType{:sym}()}}(0), 0},\n Val{Complex{Int}(1, 2)},\n Val{3},\n Val{nothing}}\n for i = 0:25]\n\n # test that types and methods get reconnected correctly\n # issue 16529 (adding a method to a type with no instances)\n (::Task)(::UInt8, ::UInt16, ::UInt32) = 2\n\n # issue 16471\n Base.sin(::UInt8, ::UInt16, ::UInt32; x = 52) = x\n const sinkw = Core.kwcall\n\n # issue 16908 (some complicated types and external method definitions)\n abstract type CategoricalPool{T, R <: Integer, V} end\n abstract type CategoricalValue{T, R <: Integer} end\n struct NominalPool{T, R <: Integer, V} <: CategoricalPool{T, R, V}\n index::Vector{T}\n invindex::Dict{T, R}\n order::Vector{R}\n ordered::Vector{T}\n valindex::Vector{V}\n end\n struct NominalValue{T, R <: Integer} <: CategoricalValue{T, R}\n level::R\n pool::NominalPool{T, R, NominalValue{T, R}}\n end\n struct OrdinalValue{T, R <: Integer} <: CategoricalValue{T, R}\n level::R\n pool::NominalPool{T, R, NominalValue{T, R}}\n end\n (::Union{Type{NominalValue}, Type{OrdinalValue}})() = 1\n (::Union{Type{NominalValue{T}}, Type{OrdinalValue{T}}})() where {T} = 2\n (::Type{Vector{NominalValue{T, R}}})() where {T, R} = 3\n (::Type{Vector{NominalValue{T, T}}})() where {T} = 4\n (::Type{Vector{NominalValue{Int, Int}}})() = 5\n\n # more tests for method signature involving a complicated type\n # issue 18343\n struct Pool18343{R, V}\n valindex::Vector{V}\n end\n struct Value18343{T, R}\n pool::Pool18343{R, Value18343{T, R}}\n end\n Base.convert(::Type{Some{S}}, ::Value18343{Some}) where {S} = 2\n Base.convert(::Type{Some{Value18343}}, ::Value18343{Some}) = 2\n Base.convert(::Type{Ref}, ::Value18343{T}) where {T} = 3\n\n const GAPType1 = GAPGroupHomomorphism{Nothing, Nothing}\n const GAPType2 = GAPGroupHomomorphism{1, 2}\n\n # issue #28297\n mutable struct Result\n result::Union{Int,Missing}\n end\n\n const x28297 = Result(missing)\n\n const d29936a = UnionAll(Dict.var, UnionAll(Dict.body.var, Dict.body.body))\n const d29936b = UnionAll(Dict.body.var, UnionAll(Dict.var, Dict.body.body))\n\n # issue #28998\n const x28998 = [missing, 2, missing, 6, missing,\n missing, missing, missing,\n missing, missing, missing,\n missing, missing, 6]\n\n let some_method = which(Base.include, (Module, String,))\n # global const some_method // FIXME: support for serializing a direct reference to an external Method not implemented\n global const some_linfo = Core.Compiler.specialize_method(some_method,\n Tuple{typeof(Base.include), Module, String}, Core.svec())\n end\n\n g() = override(1.0)\n Test.@test g() === 2.0 # compile this\n gnc() = overridenc(1.0)\n Test.@test 1 < gnc() < 5 # compile this\n\n abigfloat_f() = big\"12.34\"\n const abigfloat_x = big\"43.21\"\n abigint_f() = big\"123\"\n const abigint_x = big\"124\"\n\n # issue #51111\n abigfloat_to_f32() = Float32(big\"1.5\")\n\n # issue #31488\n _v31488 = Base.StringVector(2)\n resize!(_v31488, 0)\n const a31488 = fill(String(_v31488), 100)\n\n const ptr1 = Ptr{UInt8}(1)\n ptr2 = Ptr{UInt8}(1)\n const ptr3 = Ptr{UInt8}(-1)\n const layout1 = Ptr{Int8}[Ptr{Int8}(0), Ptr{Int8}(1), Ptr{Int8}(-1)]\n const layout2 = Any[Ptr{Int8}(0), Ptr{Int16}(1), Ptr{Int32}(-1)]\n const layout3 = collect(x.match for x in eachmatch(r\"..\", \"abcdefghijk\"))::Vector{SubString{String}}\n\n # create a backedge that includes Type{Union{}}, to ensure lookup can handle that\n call_bottom() = show(stdout, Union{})\n Core.Compiler.return_type(call_bottom, Tuple{})\n\n # check that @ccallable works from precompiled modules\n Base.@ccallable Cint f35014(x::Cint) = x+Cint(1)\n Base.@ccallable \"f35014_other\" f35014_2(x::Cint)::Cint = x+Cint(1)\n\n # check that Tasks work from serialized state\n ch1 = Channel(x -> nothing)\n ch2 = Channel(x -> (push!(x, 2); nothing), Inf)\n\n # check that Memory aliasing is respected\n a_vec_int = Int[]\n push!(a_vec_int, 1, 2)\n a_mat_int = reshape(a_vec_int, (1, 2))\n\n a_vec_any = Any[]\n push!(a_vec_any, 1, 2)\n a_mat_any = reshape(a_vec_any, (1, 2))\n\n a_vec_union = Union{Int,Nothing}[]\n push!(a_vec_union, 1, 2)\n a_mat_union = reshape(a_vec_union, (1, 2))\n\n a_vec_inline = Pair{Int,Any}[]\n push!(a_vec_inline, 1=>2, 3=>4)\n a_mat_inline = reshape(a_vec_inline, (1, 2))\n\n oid_vec_int = objectid(a_vec_int)\n oid_mat_int = objectid(a_mat_int)\n\n using $(FooBase_module): process_state, mypid as FooBase_pid, process_state_calls\n const mypid = process_state()\nend\n") touch(foo_file) touch(bar_file) @test __precompile__(false) === nothing Foo2 = Base.require(Main, Foo2_module) @eval ($Foo2).override(::Int) = begin 'a' end @eval ($Foo2).override(::Float32) = begin 'b' end @eval ($Foo2).overridenc(::Int) = begin rand() + 97.0 end @eval ($Foo2).overridenc(::Float32) = begin rand() + 100.0 end Foo = Base.require(Main, Foo_module) Base.invokelatest() do @test Foo.foo(17) == 18 @test Foo.Bar.bar(17) == 19 @test Foo.g() === 97.0 @test 96 < Foo.gnc() < 99 @test Foo.override(1.0) == Float64('a') @test Foo.override(1.0f0) == 'b' @test Foo.override(UInt(1)) == 2 @test 96 < Foo.overridenc(1.0) < 99 @test 99 < Foo.overridenc(1.0f0) < 102 @test 0 < Foo.overridenc(UInt(1)) < 3 @test Foo.abigfloat_f()::BigFloat == 12.34000000000000000000000000000000000000000000000000000000000000000000000000005 @test Foo.abigfloat_x::BigFloat + 21 == 64.21000000000000000000000000000000000000000000000000000000000000000000000000053 @test Foo.abigint_f()::BigInt == 123 @test Foo.abigint_x::BigInt + 1 == 125 @test Foo.abigfloat_to_f32() == 1.5f0 @test Foo.x28297.result === missing @test Foo.d29936a === Dict @test Foo.d29936b === (Dict{K, V} where {V, K}) @test Foo.x28998[var"end"] == 6 @test Foo.a31488 == fill("", 100) @test Foo.ptr1 === Ptr{UInt8}(1) @test Foo.ptr2 === Ptr{UInt8}(0) @test Foo.ptr3 === Ptr{UInt8}(-1) @test Foo.layout1::Vector{Ptr{Int8}} == Ptr{Int8}[Ptr{Int8}(0), Ptr{Int8}(0), Ptr{Int8}(-1)] @test Foo.layout2 == Any[Ptr{Int8}(0), Ptr{Int16}(0), Ptr{Int32}(-1)] @test typeof.(Foo.layout2) == [Ptr{Int8}, Ptr{Int16}, Ptr{Int32}] @test Foo.layout3 == ["ab", "cd", "ef", "gh", "ij"] @test !(isopen(Foo.ch1)) @test !(isopen(Foo.ch2)) @test !(isready(Foo.ch1)) @test isready(Foo.ch2) @test take!(Foo.ch2) === 2 @test !(isready(Foo.ch2)) @test Foo.process_state_calls === 0 @test Foo.process_state() === getpid() @test Foo.mypid !== getpid() @test Foo.FooBase_pid !== getpid() @test Foo.mypid !== Foo.FooBase_pid @test Foo.process_state_calls === 1 end let @test Foo.a_vec_int == Int[1, 2] @test Foo.a_mat_int == Int[1 2] Foo.a_mat_int[1, 2] = 3 @test Foo.a_vec_int[2] === 3 @test Foo.a_vec_any == Int[1, 2] @test Foo.a_mat_any == Int[1 2] Foo.a_mat_any[1, 2] = 3 @test Foo.a_vec_any[2] === 3 @test Foo.a_vec_union == Union{Int, Nothing}[1, 2] @test Foo.a_mat_union == Union{Int, Nothing}[1 2] Foo.a_mat_union[1, 2] = 3 @test Foo.a_vec_union[2] === 3 Foo.a_mat_union[1, 2] = nothing @test Foo.a_vec_union[2] === nothing @test Foo.a_vec_inline == Pair{Int, Any}[1 => 2, 3 => 4] @test Foo.a_mat_inline == Pair{Int, Any}[1 => 2 3 => 4] Foo.a_mat_inline[1, 2] = 5 => 6 @test Foo.a_vec_inline[2] === Pair{Int, Any}(5, 6) @test objectid(Foo.a_vec_int) === Foo.oid_vec_int @test objectid(Foo.a_mat_int) === Foo.oid_mat_int @test Foo.oid_vec_int !== Foo.oid_mat_int @test Base.object_build_id(Foo.a_vec_int) == Base.object_build_id(Foo.a_mat_int) @test Base.object_build_id(Foo) == Base.module_build_id(Foo) @test Base.object_build_id(Foo.a_vec_int) == Base.module_build_id(Foo) end cachedir = joinpath(dir, "compiled", "v$(VERSION.major).$(VERSION.minor)") cachedir2 = joinpath(dir2, "compiled", "v$(VERSION.major).$(VERSION.minor)") cachefile = joinpath(cachedir, "$(Foo_module).ji") @test isfile(cachefile) do_pkgimg = (Base.JLOptions()).use_pkgimages == 1 && (Base.JLOptions()).permalloc_pkgimg == 1 if do_pkgimg || (Base.JLOptions()).use_pkgimages == 0 if do_pkgimg ocachefile = Base.ocachefile_from_cachefile(cachefile)::String @test isfile(ocachefile) let foo_ptr = Libdl.dlopen(ocachefile::String, RTLD_NOLOAD) f35014_ptr = Libdl.dlsym(foo_ptr, :f35014) @test ccall(f35014_ptr, Int32, (Int32,), 3) == 4 f35014_other_ptr = Libdl.dlsym(foo_ptr, :f35014_other) @test ccall(f35014_other_ptr, Int32, (Int32,), 3) == 4 end else ocachefile = nothing end @test_logs (:warn, "Replacing module `$(Foo_module)`") begin m = Base._require_from_serialized(Base.PkgId(Foo), cachefile, ocachefile, Foo_file) @test m isa Module end end @test_throws MethodError Foo.foo(17) Base.invokelatest() do @test Foo.foo(17) == 18 @test Foo.Bar.bar(17) == 19 @test Foo.g() === 97.0 @test Foo.override(1.0) == Float64('a') @test Foo.override(1.0f0) == 'b' @test Foo.override(UInt(1)) == 2 @test string(Base.Docs.doc(Foo.foo)) == "foo function\n" @test string(Base.Docs.doc(Foo.Bar.bar)) == "bar function\n" @test string(Base.Docs.doc(Foo.Bar)) == "Bar module\n" (modules, (deps, _, requires), required_modules, _...) = Base.parse_cache_header(cachefile) discard_module = (mod_fl_mt->begin mod_fl_mt.filename end) @test modules == [Base.PkgId(Foo) => Base.module_build_id(Foo) % UInt64] @test map((x->begin x.filename end), deps) == [Foo_file, joinpath("@depot", foo_file), joinpath("@depot", bar_file)] @test requires == [Base.PkgId(Foo) => Base.PkgId(string(FooBase_module)), Base.PkgId(Foo) => Base.PkgId(Foo2), Base.PkgId(Foo) => Base.PkgId(Test), Base.PkgId(Foo) => Base.PkgId(string(FooBase_module))] srctxt = Base.read_dependency_src(cachefile, Foo_file) @test !(isempty(srctxt)) && srctxt == read(Foo_file, String) @test_throws ErrorException Base.read_dependency_src(cachefile, "/tmp/nonexistent.txt") @test_throws ErrorException Base.read_dependency_src(cachefile, joinpath(dir, foo_file)) (modules, deps1) = Base.cache_dependencies(cachefile) modules_ok = merge(Dict((let m = Base.PkgId(s) m => Base.module_build_id(Base.root_module(m)) end for s = ["Base", "Core", "Main", string(Foo2_module), string(FooBase_module)])), Dict((let m = Base.root_module(Base, s) Base.PkgId(m) => Base.module_build_id(m) end for s = [Symbol(x.name) for x = Base._sysimage_modules if !(x.name in ["Base", "Core", "Main"])])), Dict(Base.PkgId(Base.root_module(Base, :Test)) => Base.module_build_id(Base.root_module(Base, :Test))), Dict(Base.PkgId(Base.root_module(Base, :InteractiveUtils)) => Base.module_build_id(Base.root_module(Base, :InteractiveUtils))), Dict(Base.PkgId(Base.root_module(Base, :Logging)) => Base.module_build_id(Base.root_module(Base, :Logging))), Dict(Base.PkgId(Base.root_module(Base, :Random)) => Base.module_build_id(Base.root_module(Base, :Random))), Dict(Base.PkgId(Base.root_module(Base, :Serialization)) => Base.module_build_id(Base.root_module(Base, :Serialization))), Dict(Base.PkgId(Base.root_module(Base, :SHA)) => Base.module_build_id(Base.root_module(Base, :SHA))), Dict(Base.PkgId(Base.root_module(Base, :Markdown)) => Base.module_build_id(Base.root_module(Base, :Markdown))), Dict(Base.PkgId(Base.root_module(Base, :JuliaSyntaxHighlighting)) => Base.module_build_id(Base.root_module(Base, :JuliaSyntaxHighlighting))), Dict(Base.PkgId(Base.root_module(Base, :StyledStrings)) => Base.module_build_id(Base.root_module(Base, :StyledStrings))), Dict(Base.PkgId(Base.root_module(Base, :Base64)) => Base.module_build_id(Base.root_module(Base, :Base64)))) @test Dict(modules) == modules_ok @test discard_module.(deps) == deps1 (modules, (_, deps, requires), required_modules, _...) = Base.parse_cache_header(cachefile) @test map((x->begin x.filename end), deps) == [Foo_file] @test (current_task())(0x01, 0x4000, 0x30031234) == 2 @test sin(0x01, 0x4000, 0x30031234) == 52 @test sin(0x01, 0x4000, 0x30031234; x = 9142) == 9142 @test Foo.sinkw === Core.kwcall @test Foo.NominalValue() == 1 @test Foo.OrdinalValue() == 1 @test Foo.NominalValue{Int}() == 2 @test Foo.OrdinalValue{Int}() == 2 let T = Vector{Foo.NominalValue{Int}} @test T() isa T end @test Vector{Foo.NominalValue{Int32, Int64}}() == 3 @test Vector{Foo.NominalValue{UInt, UInt}}() == 4 @test Vector{Foo.NominalValue{Int, Int}}() == 5 @test all((i->begin Foo.t17809s[i + 1] === Tuple{Type{Ptr{Foo.MyType{i}}}, Ptr{Type{Foo.MyType{i}}}, Array{Ptr{Foo.MyType{Foo.MyType{:sym}()}}(0), 0}, Val{Complex{Int}(1, 2)}, Val{3}, Val{nothing}} end), 0:25) some_method = which(Base.include, (Module, String)) some_linfo = Core.Compiler.specialize_method(some_method, Tuple{typeof(Base.include), Module, String}, Core.svec()) @test Foo.some_linfo::Core.MethodInstance === some_linfo ft = Base.datatype_fieldtypes PV = (ft((Foo.Value18343{Some}).body))[1] VR = ((ft(PV))[1]).parameters[1] @test (ft(PV))[1] === Array{VR, 1} @test pointer_from_objref((ft(PV))[1]) === pointer_from_objref((ft((ft(((ft(PV))[1]).parameters[1]))[1]))[1]) @test PV === (ft(((ft(PV))[1]).parameters[1]))[1] @test pointer_from_objref(PV) === pointer_from_objref((ft(((ft(PV))[1]).parameters[1]))[1]) end Nest_module = :Nest4b3a94a1a081a8cb Nest_file = joinpath(dir, "$(Nest_module).jl") NestInner_file = joinpath(dir, "$(Nest_module)Inner.jl") NestInner2_file = joinpath(dir, "$(Nest_module)Inner2.jl") write(Nest_file, "module $(Nest_module)\ninclude(\"$(escape_string(NestInner_file))\")\nend\n") write(NestInner_file, "module NestInner\ninclude(\"$(escape_string(NestInner2_file))\")\nend\n") write(NestInner2_file, "f() = 22\n") Nest = Base.require(Main, Nest_module) cachefile = joinpath(cachedir, "$(Nest_module).ji") (modules, (deps, _, requires), required_modules, _...) = Base.parse_cache_header(cachefile) @test (last(deps)).modpath == ["NestInner"] UsesB_module = :UsesB4b3a94a1a081a8cb B_module = :UsesB4b3a94a1a081a8cb_B UsesB_file = joinpath(dir, "$(UsesB_module).jl") B_file = joinpath(dir, "$(B_module).jl") write(UsesB_file, "module $(UsesB_module)\nusing $(B_module)\nend\n") write(B_file, "module $(B_module)\nexport bfunc\nbfunc() = 33\nend\n") UsesB = Base.require(Main, UsesB_module) cachefile = joinpath(cachedir, "$(UsesB_module).ji") (modules, (deps, _, requires), required_modules, _...) = Base.parse_cache_header(cachefile) (id1, id2) = only(requires) @test (Base.pkgorigins[id1]).cachepath == cachefile @test (Base.pkgorigins[id2]).cachepath == joinpath(cachedir, "$(B_module).ji") Baz_file = joinpath(dir, "Baz.jl") write(Baz_file, "haskey(Base.loaded_modules, Base.PkgId(\"UseBaz\")) || __precompile__(false)\nmodule Baz\nbaz() = 1\nend\n") @test Base.compilecache(Base.PkgId("Baz")) == Base.PrecompilableError() OverwriteMethodError_file = joinpath(dir, "OverwriteMethodError.jl") write(OverwriteMethodError_file, "module OverwriteMethodError\n Base.:(+)(x::Bool, y::Bool) = false\nend\n") @test @test_warn("overwritten in module OverwriteMethodError", Base.compilecache(Base.PkgId("OverwriteMethodError"))) == Base.PrecompilableError() UseBaz_file = joinpath(dir, "UseBaz.jl") write(UseBaz_file, "module UseBaz\nbiz() = 1\n@assert haskey(Base.loaded_modules, Base.PkgId(\"UseBaz\"))\n@assert !haskey(Base.loaded_modules, Base.PkgId(\"Baz\"))\nusing Baz\n@assert haskey(Base.loaded_modules, Base.PkgId(\"Baz\"))\nbuz() = 2\nconst generating = ccall(:jl_generating_output, Cint, ())\nconst incremental = Base.JLOptions().incremental\nend\n") @test Base.compilecache(Base.PkgId("UseBaz")) == Base.PrecompilableError() @eval using UseBaz @test haskey(Base.loaded_modules, Base.PkgId("UseBaz")) @test haskey(Base.loaded_modules, Base.PkgId("Baz")) invokelatest() do @test UseBaz.biz() === 1 @test UseBaz.buz() === 2 @test UseBaz.generating == 0 @test UseBaz.incremental == 0 end @eval using Baz invokelatest() do @test Baz.baz() === 1 @test Baz === UseBaz.Baz end @test !(isfile("DoesNotExist.ji")) @test Base.stale_cachefile("", "DoesNotExist.ji") === true FooBar1_file = joinpath(dir, "FooBar1.jl") write(FooBar1_file, "module FooBar1\n using FooBar\nend\n") sleep(2) FooBar_file = joinpath(dir, "FooBar.jl") write(FooBar_file, "module FooBar\nend\n") (cachefile, _) = @test_logs((:debug, r"Precompiling FooBar"), min_level = Logging.Debug, match_mode = :any, Base.compilecache(Base.PkgId("FooBar"))) empty_prefs_hash = Base.get_preferences_hash(nothing, String[]) @test cachefile == Base.compilecache_path(Base.PkgId("FooBar"), empty_prefs_hash) @test isfile(joinpath(cachedir, "FooBar.ji")) Tsc = if Bool((Base.JLOptions()).use_pkgimages) Tuple{<:Vector, String, UInt128} else Tuple{<:Vector, Nothing, UInt128} end @test Base.stale_cachefile(FooBar_file, joinpath(cachedir, "FooBar.ji")) isa Tsc @test !(isdefined(Main, :FooBar)) @test !(isdefined(Main, :FooBar1)) relFooBar_file = joinpath(dir, "subfolder", "..", "FooBar.jl") @test Base.stale_cachefile(relFooBar_file, joinpath(cachedir, "FooBar.ji")) isa if Sys.iswindows() Tuple{<:Vector, String, UInt128} else Bool end mkdir(joinpath(dir, "subfolder")) @test Base.stale_cachefile(relFooBar_file, joinpath(cachedir, "FooBar.ji")) isa Tsc @eval using FooBar fb_uuid = invokelatest((()->begin Base.module_build_id(FooBar) end)) sleep(2) touch(FooBar_file) insert!(DEPOT_PATH, 1, dir2) @test Base.stale_cachefile(FooBar_file, joinpath(cachedir, "FooBar.ji")) isa Tsc @eval using FooBar1 @test !(isfile(joinpath(cachedir2, "FooBar.ji"))) @test !(isfile(joinpath(cachedir, "FooBar1.ji"))) @test isfile(joinpath(cachedir2, "FooBar1.ji")) @test Base.stale_cachefile(FooBar_file, joinpath(cachedir, "FooBar.ji")) isa Tsc @test Base.stale_cachefile(FooBar1_file, joinpath(cachedir2, "FooBar1.ji")) isa Tsc invokelatest() do @test fb_uuid == Base.module_build_id(FooBar) fb_uuid1 = Base.module_build_id(FooBar1) @test fb_uuid != fb_uuid1 end open(joinpath(cachedir2, "FooBar1.ji"), "a") do f write(f, 0x076cac96) end @test Base.stale_cachefile(FooBar1_file, joinpath(cachedir2, "FooBar1.ji")) === true FooBar2_file = joinpath(dir, "FooBar2.jl") write(FooBar2_file, "module FooBar2\nerror(\"break me\")\nend\n") try Base.require(Main, :FooBar2) error("the \"break me\" test failed") catch exc exc isa Base.Precompilation.PkgPrecompileError || rethrow() occursin("Failed to precompile FooBar2", exc.msg) || rethrow() occursin("LoadError: break me", exc.msg) || rethrow() end FooBar3_file = joinpath(dir, "FooBar3.jl") FooBar3_inc = joinpath(dir, "FooBar3_inc.jl") write(FooBar3_inc, "x=1\n") for code = ["Core.eval(Base, :(x=1))", "Base.include(Base, \"FooBar3_inc.jl\")"] write(FooBar3_file, "module FooBar3\n$(code)\nend\n") try Base.require(Main, :FooBar3) catch exc exc isa Base.Precompilation.PkgPrecompileError || rethrow() occursin("Evaluation into the closed module `Base` breaks incremental compilation", exc.msg) || rethrow() end end FooBarT_file = joinpath(dir, "FooBarT.jl") write(FooBarT_file, "module FooBarT\nend\n") FooBarT1_file = joinpath(dir, "FooBarT1.jl") write(FooBarT1_file, "module FooBarT1\n using FooBarT\nend\n") FooBarT2_file = joinpath(dir, "FooBarT2.jl") write(FooBarT2_file, "module FooBarT2\n using FooBarT1\nend\n") Base.compilecache(Base.PkgId("FooBarT2")) write(FooBarT1_file, "module FooBarT1\nend\n") rm(FooBarT_file) @test Base.stale_cachefile(FooBarT2_file, joinpath(cachedir2, "FooBarT2.ji")) === true @test Base.require(Main, :FooBarT2) isa Module end (dir,)->begin Foo_file = joinpath(dir, "$(Foo_module).jl") Foo2_file = joinpath(dir, "$(Foo2_module).jl") FooBase_file = joinpath(dir, "$(FooBase_module).jl") foo_file = joinpath(dir, "$(foo_incl_dep).jl") bar_file = joinpath(dir, "$(bar_incl_dep).jl") write(FooBase_file, "false && __precompile__(false)\nmodule $(FooBase_module)\n import Base: hash, >\n struct fmpz end\n struct typeA end\n >(x::fmpz, y::Int) = Base.cmp(x, y) > 0\n function hash(a::typeA, h::UInt)\n d = den(a)\n return h\n end\n abstract type AbstractAlgebraMap{A} end\n struct GAPGroupHomomorphism{A, B} <: AbstractAlgebraMap{GAPGroupHomomorphism{B, A}} end\n\n global process_state_calls::Int = 0\n const process_state = Base.OncePerProcess{typeof(getpid())}() do\n @assert (global process_state_calls += 1) == 1\n return getpid()\n end\n const mypid = process_state()\n @assert process_state_calls === 1\n process_state_calls = 0\n @assert process_state() === process_state()\n @assert process_state_calls === 0\n\n const empty_state = Base.OncePerProcess{Nothing}() do\n return nothing\n end\n @assert empty_state() === nothing\nend\n") write(Foo2_file, "module $(Foo2_module)\n export override, overridenc\n override(x::Integer) = 2\n override(x::AbstractFloat) = Float64(override(1))\n overridenc(x::Integer) = rand()+1\n overridenc(x::AbstractFloat) = Float64(overridenc(1))\nend\n") write(Foo_file, "module $(Foo_module)\n import $(FooBase_module), $(FooBase_module).typeA, $(FooBase_module).GAPGroupHomomorphism\n import $(Foo2_module): $(Foo2_module), override, overridenc\n import $(FooBase_module).hash\n import Test\n public foo, Bar\n module Inner\n import $(FooBase_module).hash\n using ..$(Foo_module)\n import ..$(Foo2_module)\n end\n\n struct typeB\n y::typeA\n end\n hash(x::typeB) = hash(x.y)\n\n # test that docs get reconnected\n @doc \"foo function\" foo(x) = x + 1\n include_dependency(\"$(foo_incl_dep).jl\")\n include_dependency(\"$(foo_incl_dep).jl\")\n module Bar\n public bar\n include_dependency(\"$(bar_incl_dep).jl\")\n end\n @doc \"Bar module\" Bar # this needs to define the META dictionary via eval\n @eval Bar @doc \"bar function\" bar(x) = x + 2\n\n # test for creation of some reasonably complicated type\n struct MyType{T} end\n const t17809s = Any[\n Tuple{\n Type{Ptr{MyType{i}}},\n Ptr{Type{MyType{i}}},\n Array{Ptr{MyType{MyType{:sym}()}}(0), 0},\n Val{Complex{Int}(1, 2)},\n Val{3},\n Val{nothing}}\n for i = 0:25]\n\n # test that types and methods get reconnected correctly\n # issue 16529 (adding a method to a type with no instances)\n (::Task)(::UInt8, ::UInt16, ::UInt32) = 2\n\n # issue 16471\n Base.sin(::UInt8, ::UInt16, ::UInt32; x = 52) = x\n const sinkw = Core.kwcall\n\n # issue 16908 (some complicated types and external method definitions)\n abstract type CategoricalPool{T, R <: Integer, V} end\n abstract type CategoricalValue{T, R <: Integer} end\n struct NominalPool{T, R <: Integer, V} <: CategoricalPool{T, R, V}\n index::Vector{T}\n invindex::Dict{T, R}\n order::Vector{R}\n ordered::Vector{T}\n valindex::Vector{V}\n end\n struct NominalValue{T, R <: Integer} <: CategoricalValue{T, R}\n level::R\n pool::NominalPool{T, R, NominalValue{T, R}}\n end\n struct OrdinalValue{T, R <: Integer} <: CategoricalValue{T, R}\n level::R\n pool::NominalPool{T, R, NominalValue{T, R}}\n end\n (::Union{Type{NominalValue}, Type{OrdinalValue}})() = 1\n (::Union{Type{NominalValue{T}}, Type{OrdinalValue{T}}})() where {T} = 2\n (::Type{Vector{NominalValue{T, R}}})() where {T, R} = 3\n (::Type{Vector{NominalValue{T, T}}})() where {T} = 4\n (::Type{Vector{NominalValue{Int, Int}}})() = 5\n\n # more tests for method signature involving a complicated type\n # issue 18343\n struct Pool18343{R, V}\n valindex::Vector{V}\n end\n struct Value18343{T, R}\n pool::Pool18343{R, Value18343{T, R}}\n end\n Base.convert(::Type{Some{S}}, ::Value18343{Some}) where {S} = 2\n Base.convert(::Type{Some{Value18343}}, ::Value18343{Some}) = 2\n Base.convert(::Type{Ref}, ::Value18343{T}) where {T} = 3\n\n const GAPType1 = GAPGroupHomomorphism{Nothing, Nothing}\n const GAPType2 = GAPGroupHomomorphism{1, 2}\n\n # issue #28297\n mutable struct Result\n result::Union{Int,Missing}\n end\n\n const x28297 = Result(missing)\n\n const d29936a = UnionAll(Dict.var, UnionAll(Dict.body.var, Dict.body.body))\n const d29936b = UnionAll(Dict.body.var, UnionAll(Dict.var, Dict.body.body))\n\n # issue #28998\n const x28998 = [missing, 2, missing, 6, missing,\n missing, missing, missing,\n missing, missing, missing,\n missing, missing, 6]\n\n let some_method = which(Base.include, (Module, String,))\n # global const some_method // FIXME: support for serializing a direct reference to an external Method not implemented\n global const some_linfo = Core.Compiler.specialize_method(some_method,\n Tuple{typeof(Base.include), Module, String}, Core.svec())\n end\n\n g() = override(1.0)\n Test.@test g() === 2.0 # compile this\n gnc() = overridenc(1.0)\n Test.@test 1 < gnc() < 5 # compile this\n\n abigfloat_f() = big\"12.34\"\n const abigfloat_x = big\"43.21\"\n abigint_f() = big\"123\"\n const abigint_x = big\"124\"\n\n # issue #51111\n abigfloat_to_f32() = Float32(big\"1.5\")\n\n # issue #31488\n _v31488 = Base.StringVector(2)\n resize!(_v31488, 0)\n const a31488 = fill(String(_v31488), 100)\n\n const ptr1 = Ptr{UInt8}(1)\n ptr2 = Ptr{UInt8}(1)\n const ptr3 = Ptr{UInt8}(-1)\n const layout1 = Ptr{Int8}[Ptr{Int8}(0), Ptr{Int8}(1), Ptr{Int8}(-1)]\n const layout2 = Any[Ptr{Int8}(0), Ptr{Int16}(1), Ptr{Int32}(-1)]\n const layout3 = collect(x.match for x in eachmatch(r\"..\", \"abcdefghijk\"))::Vector{SubString{String}}\n\n # create a backedge that includes Type{Union{}}, to ensure lookup can handle that\n call_bottom() = show(stdout, Union{})\n Core.Compiler.return_type(call_bottom, Tuple{})\n\n # check that @ccallable works from precompiled modules\n Base.@ccallable Cint f35014(x::Cint) = x+Cint(1)\n Base.@ccallable \"f35014_other\" f35014_2(x::Cint)::Cint = x+Cint(1)\n\n # check that Tasks work from serialized state\n ch1 = Channel(x -> nothing)\n ch2 = Channel(x -> (push!(x, 2); nothing), Inf)\n\n # check that Memory aliasing is respected\n a_vec_int = Int[]\n push!(a_vec_int, 1, 2)\n a_mat_int = reshape(a_vec_int, (1, 2))\n\n a_vec_any = Any[]\n push!(a_vec_any, 1, 2)\n a_mat_any = reshape(a_vec_any, (1, 2))\n\n a_vec_union = Union{Int,Nothing}[]\n push!(a_vec_union, 1, 2)\n a_mat_union = reshape(a_vec_union, (1, 2))\n\n a_vec_inline = Pair{Int,Any}[]\n push!(a_vec_inline, 1=>2, 3=>4)\n a_mat_inline = reshape(a_vec_inline, (1, 2))\n\n oid_vec_int = objectid(a_vec_int)\n oid_mat_int = objectid(a_mat_int)\n\n using $(FooBase_module): process_state, mypid as FooBase_pid, process_state_calls\n const mypid = process_state()\nend\n") touch(foo_file) touch(bar_file) @test __precompile__(false) === nothing Foo2 = Base.require(Main, Foo2_module) @eval ($Foo2).override(::Int) = begin 'a' end @eval ($Foo2).override(::Float32) = begin 'b' end @eval ($Foo2).overridenc(::Int) = begin rand() + 97.0 end @eval ($Foo2).overridenc(::Float32) = begin rand() + 100.0 end Foo = Base.require(Main, Foo_module) Base.invokelatest() do @test Foo.foo(17) == 18 @test Foo.Bar.bar(17) == 19 @test Foo.g() === 97.0 @test 96 < Foo.gnc() < 99 @test Foo.override(1.0) == Float64('a') @test Foo.override(1.0f0) == 'b' @test Foo.override(UInt(1)) == 2 @test 96 < Foo.overridenc(1.0) < 99 @test 99 < Foo.overridenc(1.0f0) < 102 @test 0 < Foo.overridenc(UInt(1)) < 3 @test Foo.abigfloat_f()::BigFloat == 12.34000000000000000000000000000000000000000000000000000000000000000000000000005 @test Foo.abigfloat_x::BigFloat + 21 == 64.21000000000000000000000000000000000000000000000000000000000000000000000000053 @test Foo.abigint_f()::BigInt == 123 @test Foo.abigint_x::BigInt + 1 == 125 @test Foo.abigfloat_to_f32() == 1.5f0 @test Foo.x28297.result === missing @test Foo.d29936a === Dict @test Foo.d29936b === (Dict{K, V} where {V, K}) @test Foo.x28998[var"end"] == 6 @test Foo.a31488 == fill("", 100) @test Foo.ptr1 === Ptr{UInt8}(1) @test Foo.ptr2 === Ptr{UInt8}(0) @test Foo.ptr3 === Ptr{UInt8}(-1) @test Foo.layout1::Vector{Ptr{Int8}} == Ptr{Int8}[Ptr{Int8}(0), Ptr{Int8}(0), Ptr{Int8}(-1)] @test Foo.layout2 == Any[Ptr{Int8}(0), Ptr{Int16}(0), Ptr{Int32}(-1)] @test typeof.(Foo.layout2) == [Ptr{Int8}, Ptr{Int16}, Ptr{Int32}] @test Foo.layout3 == ["ab", "cd", "ef", "gh", "ij"] @test !(isopen(Foo.ch1)) @test !(isopen(Foo.ch2)) @test !(isready(Foo.ch1)) @test isready(Foo.ch2) @test take!(Foo.ch2) === 2 @test !(isready(Foo.ch2)) @test Foo.process_state_calls === 0 @test Foo.process_state() === getpid() @test Foo.mypid !== getpid() @test Foo.FooBase_pid !== getpid() @test Foo.mypid !== Foo.FooBase_pid @test Foo.process_state_calls === 1 end let @test Foo.a_vec_int == Int[1, 2] @test Foo.a_mat_int == Int[1 2] Foo.a_mat_int[1, 2] = 3 @test Foo.a_vec_int[2] === 3 @test Foo.a_vec_any == Int[1, 2] @test Foo.a_mat_any == Int[1 2] Foo.a_mat_any[1, 2] = 3 @test Foo.a_vec_any[2] === 3 @test Foo.a_vec_union == Union{Int, Nothing}[1, 2] @test Foo.a_mat_union == Union{Int, Nothing}[1 2] Foo.a_mat_union[1, 2] = 3 @test Foo.a_vec_union[2] === 3 Foo.a_mat_union[1, 2] = nothing @test Foo.a_vec_union[2] === nothing @test Foo.a_vec_inline == Pair{Int, Any}[1 => 2, 3 => 4] @test Foo.a_mat_inline == Pair{Int, Any}[1 => 2 3 => 4] Foo.a_mat_inline[1, 2] = 5 => 6 @test Foo.a_vec_inline[2] === Pair{Int, Any}(5, 6) @test objectid(Foo.a_vec_int) === Foo.oid_vec_int @test objectid(Foo.a_mat_int) === Foo.oid_mat_int @test Foo.oid_vec_int !== Foo.oid_mat_int @test Base.object_build_id(Foo.a_vec_int) == Base.object_build_id(Foo.a_mat_int) @test Base.object_build_id(Foo) == Base.module_build_id(Foo) @test Base.object_build_id(Foo.a_vec_int) == Base.module_build_id(Foo) end cachedir = joinpath(dir, "compiled", "v$(VERSION.major).$(VERSION.minor)") cachedir2 = joinpath(dir2, "compiled", "v$(VERSION.major).$(VERSION.minor)") cachefile = joinpath(cachedir, "$(Foo_module).ji") @test isfile(cachefile) do_pkgimg = (Base.JLOptions()).use_pkgimages == 1 && (Base.JLOptions()).permalloc_pkgimg == 1 if do_pkgimg || (Base.JLOptions()).use_pkgimages == 0 if do_pkgimg ocachefile = Base.ocachefile_from_cachefile(cachefile)::String @test isfile(ocachefile) let foo_ptr = Libdl.dlopen(ocachefile::String, RTLD_NOLOAD) f35014_ptr = Libdl.dlsym(foo_ptr, :f35014) @test ccall(f35014_ptr, Int32, (Int32,), 3) == 4 f35014_other_ptr = Libdl.dlsym(foo_ptr, :f35014_other) @test ccall(f35014_other_ptr, Int32, (Int32,), 3) == 4 end else ocachefile = nothing end @test_logs (:warn, "Replacing module `$(Foo_module)`") begin m = Base._require_from_serialized(Base.PkgId(Foo), cachefile, ocachefile, Foo_file) @test m isa Module end end @test_throws MethodError Foo.foo(17) Base.invokelatest() do @test Foo.foo(17) == 18 @test Foo.Bar.bar(17) == 19 @test Foo.g() === 97.0 @test Foo.override(1.0) == Float64('a') @test Foo.override(1.0f0) == 'b' @test Foo.override(UInt(1)) == 2 @test string(Base.Docs.doc(Foo.foo)) == "foo function\n" @test string(Base.Docs.doc(Foo.Bar.bar)) == "bar function\n" @test string(Base.Docs.doc(Foo.Bar)) == "Bar module\n" (modules, (deps, _, requires), required_modules, _...) = Base.parse_cache_header(cachefile) discard_module = (mod_fl_mt->begin mod_fl_mt.filename end) @test modules == [Base.PkgId(Foo) => Base.module_build_id(Foo) % UInt64] @test map((x->begin x.filename end), deps) == [Foo_file, joinpath("@depot", foo_file), joinpath("@depot", bar_file)] @test requires == [Base.PkgId(Foo) => Base.PkgId(string(FooBase_module)), Base.PkgId(Foo) => Base.PkgId(Foo2), Base.PkgId(Foo) => Base.PkgId(Test), Base.PkgId(Foo) => Base.PkgId(string(FooBase_module))] srctxt = Base.read_dependency_src(cachefile, Foo_file) @test !(isempty(srctxt)) && srctxt == read(Foo_file, String) @test_throws ErrorException Base.read_dependency_src(cachefile, "/tmp/nonexistent.txt") @test_throws ErrorException Base.read_dependency_src(cachefile, joinpath(dir, foo_file)) (modules, deps1) = Base.cache_dependencies(cachefile) modules_ok = merge(Dict((let m = Base.PkgId(s) m => Base.module_build_id(Base.root_module(m)) end for s = ["Base", "Core", "Main", string(Foo2_module), string(FooBase_module)])), Dict((let m = Base.root_module(Base, s) Base.PkgId(m) => Base.module_build_id(m) end for s = [Symbol(x.name) for x = Base._sysimage_modules if !(x.name in ["Base", "Core", "Main"])])), Dict(Base.PkgId(Base.root_module(Base, :Test)) => Base.module_build_id(Base.root_module(Base, :Test))), Dict(Base.PkgId(Base.root_module(Base, :InteractiveUtils)) => Base.module_build_id(Base.root_module(Base, :InteractiveUtils))), Dict(Base.PkgId(Base.root_module(Base, :Logging)) => Base.module_build_id(Base.root_module(Base, :Logging))), Dict(Base.PkgId(Base.root_module(Base, :Random)) => Base.module_build_id(Base.root_module(Base, :Random))), Dict(Base.PkgId(Base.root_module(Base, :Serialization)) => Base.module_build_id(Base.root_module(Base, :Serialization))), Dict(Base.PkgId(Base.root_module(Base, :SHA)) => Base.module_build_id(Base.root_module(Base, :SHA))), Dict(Base.PkgId(Base.root_module(Base, :Markdown)) => Base.module_build_id(Base.root_module(Base, :Markdown))), Dict(Base.PkgId(Base.root_module(Base, :JuliaSyntaxHighlighting)) => Base.module_build_id(Base.root_module(Base, :JuliaSyntaxHighlighting))), Dict(Base.PkgId(Base.root_module(Base, :StyledStrings)) => Base.module_build_id(Base.root_module(Base, :StyledStrings))), Dict(Base.PkgId(Base.root_module(Base, :Base64)) => Base.module_build_id(Base.root_module(Base, :Base64)))) @test Dict(modules) == modules_ok @test discard_module.(deps) == deps1 (modules, (_, deps, requires), required_modules, _...) = Base.parse_cache_header(cachefile) @test map((x->begin x.filename end), deps) == [Foo_file] @test (current_task())(0x01, 0x4000, 0x30031234) == 2 @test sin(0x01, 0x4000, 0x30031234) == 52 @test sin(0x01, 0x4000, 0x30031234; x = 9142) == 9142 @test Foo.sinkw === Core.kwcall @test Foo.NominalValue() == 1 @test Foo.OrdinalValue() == 1 @test Foo.NominalValue{Int}() == 2 @test Foo.OrdinalValue{Int}() == 2 let T = Vector{Foo.NominalValue{Int}} @test T() isa T end @test Vector{Foo.NominalValue{Int32, Int64}}() == 3 @test Vector{Foo.NominalValue{UInt, UInt}}() == 4 @test Vector{Foo.NominalValue{Int, Int}}() == 5 @test all((i->begin Foo.t17809s[i + 1] === Tuple{Type{Ptr{Foo.MyType{i}}}, Ptr{Type{Foo.MyType{i}}}, Array{Ptr{Foo.MyType{Foo.MyType{:sym}()}}(0), 0}, Val{Complex{Int}(1, 2)}, Val{3}, Val{nothing}} end), 0:25) some_method = which(Base.include, (Module, String)) some_linfo = Core.Compiler.specialize_method(some_method, Tuple{typeof(Base.include), Module, String}, Core.svec()) @test Foo.some_linfo::Core.MethodInstance === some_linfo ft = Base.datatype_fieldtypes PV = (ft((Foo.Value18343{Some}).body))[1] VR = ((ft(PV))[1]).parameters[1] @test (ft(PV))[1] === Array{VR, 1} @test pointer_from_objref((ft(PV))[1]) === pointer_from_objref((ft((ft(((ft(PV))[1]).parameters[1]))[1]))[1]) @test PV === (ft(((ft(PV))[1]).parameters[1]))[1] @test pointer_from_objref(PV) === pointer_from_objref((ft(((ft(PV))[1]).parameters[1]))[1]) end Nest_module = :Nest4b3a94a1a081a8cb Nest_file = joinpath(dir, "$(Nest_module).jl") NestInner_file = joinpath(dir, "$(Nest_module)Inner.jl") NestInner2_file = joinpath(dir, "$(Nest_module)Inner2.jl") write(Nest_file, "module $(Nest_module)\ninclude(\"$(escape_string(NestInner_file))\")\nend\n") write(NestInner_file, "module NestInner\ninclude(\"$(escape_string(NestInner2_file))\")\nend\n") write(NestInner2_file, "f() = 22\n") Nest = Base.require(Main, Nest_module) cachefile = joinpath(cachedir, "$(Nest_module).ji") (modules, (deps, _, requires), required_modules, _...) = Base.parse_cache_header(cachefile) @test (last(deps)).modpath == ["NestInner"] UsesB_module = :UsesB4b3a94a1a081a8cb B_module = :UsesB4b3a94a1a081a8cb_B UsesB_file = joinpath(dir, "$(UsesB_module).jl") B_file = joinpath(dir, "$(B_module).jl") write(UsesB_file, "module $(UsesB_module)\nusing $(B_module)\nend\n") write(B_file, "module $(B_module)\nexport bfunc\nbfunc() = 33\nend\n") UsesB = Base.require(Main, UsesB_module) cachefile = joinpath(cachedir, "$(UsesB_module).ji") (modules, (deps, _, requires), required_modules, _...) = Base.parse_cache_header(cachefile) (id1, id2) = only(requires) @test (Base.pkgorigins[id1]).cachepath == cachefile @test (Base.pkgorigins[id2]).cachepath == joinpath(cachedir, "$(B_module).ji") Baz_file = joinpath(dir, "Baz.jl") write(Baz_file, "haskey(Base.loaded_modules, Base.PkgId(\"UseBaz\")) || __precompile__(false)\nmodule Baz\nbaz() = 1\nend\n") @test Base.compilecache(Base.PkgId("Baz")) == Base.PrecompilableError() OverwriteMethodError_file = joinpath(dir, "OverwriteMethodError.jl") write(OverwriteMethodError_file, "module OverwriteMethodError\n Base.:(+)(x::Bool, y::Bool) = false\nend\n") @test @test_warn("overwritten in module OverwriteMethodError", Base.compilecache(Base.PkgId("OverwriteMethodError"))) == Base.PrecompilableError() UseBaz_file = joinpath(dir, "UseBaz.jl") write(UseBaz_file, "module UseBaz\nbiz() = 1\n@assert haskey(Base.loaded_modules, Base.PkgId(\"UseBaz\"))\n@assert !haskey(Base.loaded_modules, Base.PkgId(\"Baz\"))\nusing Baz\n@assert haskey(Base.loaded_modules, Base.PkgId(\"Baz\"))\nbuz() = 2\nconst generating = ccall(:jl_generating_output, Cint, ())\nconst incremental = Base.JLOptions().incremental\nend\n") @test Base.compilecache(Base.PkgId("UseBaz")) == Base.PrecompilableError() @eval using UseBaz @test haskey(Base.loaded_modules, Base.PkgId("UseBaz")) @test haskey(Base.loaded_modules, Base.PkgId("Baz")) invokelatest() do @test UseBaz.biz() === 1 @test UseBaz.buz() === 2 @test UseBaz.generating == 0 @test UseBaz.incremental == 0 end @eval using Baz invokelatest() do @test Baz.baz() === 1 @test Baz === UseBaz.Baz end @test !(isfile("DoesNotExist.ji")) @test Base.stale_cachefile("", "DoesNotExist.ji") === true FooBar1_file = joinpath(dir, "FooBar1.jl") write(FooBar1_file, "module FooBar1\n using FooBar\nend\n") sleep(2) FooBar_file = joinpath(dir, "FooBar.jl") write(FooBar_file, "module FooBar\nend\n") (cachefile, _) = @test_logs((:debug, r"Precompiling FooBar"), min_level = Logging.Debug, match_mode = :any, Base.compilecache(Base.PkgId("FooBar"))) empty_prefs_hash = Base.get_preferences_hash(nothing, String[]) @test cachefile == Base.compilecache_path(Base.PkgId("FooBar"), empty_prefs_hash) @test isfile(joinpath(cachedir, "FooBar.ji")) Tsc = if Bool((Base.JLOptions()).use_pkgimages) Tuple{<:Vector, String, UInt128} else Tuple{<:Vector, Nothing, UInt128} end @test Base.stale_cachefile(FooBar_file, joinpath(cachedir, "FooBar.ji")) isa Tsc @test !(isdefined(Main, :FooBar)) @test !(isdefined(Main, :FooBar1)) relFooBar_file = joinpath(dir, "subfolder", "..", "FooBar.jl") @test Base.stale_cachefile(relFooBar_file, joinpath(cachedir, "FooBar.ji")) isa if Sys.iswindows() Tuple{<:Vector, String, UInt128} else Bool end mkdir(joinpath(dir, "subfolder")) @test Base.stale_cachefile(relFooBar_file, joinpath(cachedir, "FooBar.ji")) isa Tsc @eval using FooBar fb_uuid = invokelatest((()->begin Base.module_build_id(FooBar) end)) sleep(2) touch(FooBar_file) insert!(DEPOT_PATH, 1, dir2) @test Base.stale_cachefile(FooBar_file, joinpath(cachedir, "FooBar.ji")) isa Tsc @eval using FooBar1 @test !(isfile(joinpath(cachedir2, "FooBar.ji"))) @test !(isfile(joinpath(cachedir, "FooBar1.ji"))) @test isfile(joinpath(cachedir2, "FooBar1.ji")) @test Base.stale_cachefile(FooBar_file, joinpath(cachedir, "FooBar.ji")) isa Tsc @test Base.stale_cachefile(FooBar1_file, joinpath(cachedir2, "FooBar1.ji")) isa Tsc invokelatest() do @test fb_uuid == Base.module_build_id(FooBar) fb_uuid1 = Base.module_build_id(FooBar1) @test fb_uuid != fb_uuid1 end open(joinpath(cachedir2, "FooBar1.ji"), "a") do f write(f, 0x076cac96) end @test Base.stale_cachefile(FooBar1_file, joinpath(cachedir2, "FooBar1.ji")) === true FooBar2_file = joinpath(dir, "FooBar2.jl") write(FooBar2_file, "module FooBar2\nerror(\"break me\")\nend\n") try Base.require(Main, :FooBar2) error("the \"break me\" test failed") catch exc exc isa Base.Precompilation.PkgPrecompileError || rethrow() occursin("Failed to precompile FooBar2", exc.msg) || rethrow() occursin("LoadError: break me", exc.msg) || rethrow() end FooBar3_file = joinpath(dir, "FooBar3.jl") FooBar3_inc = joinpath(dir, "FooBar3_inc.jl") write(FooBar3_inc, "x=1\n") for code = ["Core.eval(Base, :(x=1))", "Base.include(Base, \"FooBar3_inc.jl\")"] write(FooBar3_file, "module FooBar3\n$(code)\nend\n") try Base.require(Main, :FooBar3) catch exc exc isa Base.Precompilation.PkgPrecompileError || rethrow() occursin("Evaluation into the closed module `Base` breaks incremental compilation", exc.msg) || rethrow() end end FooBarT_file = joinpath(dir, "FooBarT.jl") write(FooBarT_file, "module FooBarT\nend\n") FooBarT1_file = joinpath(dir, "FooBarT1.jl") write(FooBarT1_file, "module FooBarT1\n using FooBarT\nend\n") FooBarT2_file = joinpath(dir, "FooBarT2.jl") write(FooBarT2_file, "module FooBarT2\n using FooBarT1\nend\n") Base.compilecache(Base.PkgId("FooBarT2")) write(FooBarT1_file, "module FooBarT1\nend\n") rm(FooBarT_file) @test Base.stale_cachefile(FooBarT2_file, joinpath(cachedir2, "FooBarT2.ji")) === true @test Base.require(Main, :FooBarT2) isa Module end precompile_test_harness(false) do dir Foo_file = joinpath(dir, "$(Foo_module).jl") Foo2_file = joinpath(dir, "$(Foo2_module).jl") FooBase_file = joinpath(dir, "$(FooBase_module).jl") foo_file = joinpath(dir, "$(foo_incl_dep).jl") bar_file = joinpath(dir, "$(bar_incl_dep).jl") write(FooBase_file, "false && __precompile__(false)\nmodule $(FooBase_module)\n import Base: hash, >\n struct fmpz end\n struct typeA end\n >(x::fmpz, y::Int) = Base.cmp(x, y) > 0\n function hash(a::typeA, h::UInt)\n d = den(a)\n return h\n end\n abstract type AbstractAlgebraMap{A} end\n struct GAPGroupHomomorphism{A, B} <: AbstractAlgebraMap{GAPGroupHomomorphism{B, A}} end\n\n global process_state_calls::Int = 0\n const process_state = Base.OncePerProcess{typeof(getpid())}() do\n @assert (global process_state_calls += 1) == 1\n return getpid()\n end\n const mypid = process_state()\n @assert process_state_calls === 1\n process_state_calls = 0\n @assert process_state() === process_state()\n @assert process_state_calls === 0\n\n const empty_state = Base.OncePerProcess{Nothing}() do\n return nothing\n end\n @assert empty_state() === nothing\nend\n") write(Foo2_file, "module $(Foo2_module)\n export override, overridenc\n override(x::Integer) = 2\n override(x::AbstractFloat) = Float64(override(1))\n overridenc(x::Integer) = rand()+1\n overridenc(x::AbstractFloat) = Float64(overridenc(1))\nend\n") write(Foo_file, "module $(Foo_module)\n import $(FooBase_module), $(FooBase_module).typeA, $(FooBase_module).GAPGroupHomomorphism\n import $(Foo2_module): $(Foo2_module), override, overridenc\n import $(FooBase_module).hash\n import Test\n public foo, Bar\n module Inner\n import $(FooBase_module).hash\n using ..$(Foo_module)\n import ..$(Foo2_module)\n end\n\n struct typeB\n y::typeA\n end\n hash(x::typeB) = hash(x.y)\n\n # test that docs get reconnected\n @doc \"foo function\" foo(x) = x + 1\n include_dependency(\"$(foo_incl_dep).jl\")\n include_dependency(\"$(foo_incl_dep).jl\")\n module Bar\n public bar\n include_dependency(\"$(bar_incl_dep).jl\")\n end\n @doc \"Bar module\" Bar # this needs to define the META dictionary via eval\n @eval Bar @doc \"bar function\" bar(x) = x + 2\n\n # test for creation of some reasonably complicated type\n struct MyType{T} end\n const t17809s = Any[\n Tuple{\n Type{Ptr{MyType{i}}},\n Ptr{Type{MyType{i}}},\n Array{Ptr{MyType{MyType{:sym}()}}(0), 0},\n Val{Complex{Int}(1, 2)},\n Val{3},\n Val{nothing}}\n for i = 0:25]\n\n # test that types and methods get reconnected correctly\n # issue 16529 (adding a method to a type with no instances)\n (::Task)(::UInt8, ::UInt16, ::UInt32) = 2\n\n # issue 16471\n Base.sin(::UInt8, ::UInt16, ::UInt32; x = 52) = x\n const sinkw = Core.kwcall\n\n # issue 16908 (some complicated types and external method definitions)\n abstract type CategoricalPool{T, R <: Integer, V} end\n abstract type CategoricalValue{T, R <: Integer} end\n struct NominalPool{T, R <: Integer, V} <: CategoricalPool{T, R, V}\n index::Vector{T}\n invindex::Dict{T, R}\n order::Vector{R}\n ordered::Vector{T}\n valindex::Vector{V}\n end\n struct NominalValue{T, R <: Integer} <: CategoricalValue{T, R}\n level::R\n pool::NominalPool{T, R, NominalValue{T, R}}\n end\n struct OrdinalValue{T, R <: Integer} <: CategoricalValue{T, R}\n level::R\n pool::NominalPool{T, R, NominalValue{T, R}}\n end\n (::Union{Type{NominalValue}, Type{OrdinalValue}})() = 1\n (::Union{Type{NominalValue{T}}, Type{OrdinalValue{T}}})() where {T} = 2\n (::Type{Vector{NominalValue{T, R}}})() where {T, R} = 3\n (::Type{Vector{NominalValue{T, T}}})() where {T} = 4\n (::Type{Vector{NominalValue{Int, Int}}})() = 5\n\n # more tests for method signature involving a complicated type\n # issue 18343\n struct Pool18343{R, V}\n valindex::Vector{V}\n end\n struct Value18343{T, R}\n pool::Pool18343{R, Value18343{T, R}}\n end\n Base.convert(::Type{Some{S}}, ::Value18343{Some}) where {S} = 2\n Base.convert(::Type{Some{Value18343}}, ::Value18343{Some}) = 2\n Base.convert(::Type{Ref}, ::Value18343{T}) where {T} = 3\n\n const GAPType1 = GAPGroupHomomorphism{Nothing, Nothing}\n const GAPType2 = GAPGroupHomomorphism{1, 2}\n\n # issue #28297\n mutable struct Result\n result::Union{Int,Missing}\n end\n\n const x28297 = Result(missing)\n\n const d29936a = UnionAll(Dict.var, UnionAll(Dict.body.var, Dict.body.body))\n const d29936b = UnionAll(Dict.body.var, UnionAll(Dict.var, Dict.body.body))\n\n # issue #28998\n const x28998 = [missing, 2, missing, 6, missing,\n missing, missing, missing,\n missing, missing, missing,\n missing, missing, 6]\n\n let some_method = which(Base.include, (Module, String,))\n # global const some_method // FIXME: support for serializing a direct reference to an external Method not implemented\n global const some_linfo = Core.Compiler.specialize_method(some_method,\n Tuple{typeof(Base.include), Module, String}, Core.svec())\n end\n\n g() = override(1.0)\n Test.@test g() === 2.0 # compile this\n gnc() = overridenc(1.0)\n Test.@test 1 < gnc() < 5 # compile this\n\n abigfloat_f() = big\"12.34\"\n const abigfloat_x = big\"43.21\"\n abigint_f() = big\"123\"\n const abigint_x = big\"124\"\n\n # issue #51111\n abigfloat_to_f32() = Float32(big\"1.5\")\n\n # issue #31488\n _v31488 = Base.StringVector(2)\n resize!(_v31488, 0)\n const a31488 = fill(String(_v31488), 100)\n\n const ptr1 = Ptr{UInt8}(1)\n ptr2 = Ptr{UInt8}(1)\n const ptr3 = Ptr{UInt8}(-1)\n const layout1 = Ptr{Int8}[Ptr{Int8}(0), Ptr{Int8}(1), Ptr{Int8}(-1)]\n const layout2 = Any[Ptr{Int8}(0), Ptr{Int16}(1), Ptr{Int32}(-1)]\n const layout3 = collect(x.match for x in eachmatch(r\"..\", \"abcdefghijk\"))::Vector{SubString{String}}\n\n # create a backedge that includes Type{Union{}}, to ensure lookup can handle that\n call_bottom() = show(stdout, Union{})\n Core.Compiler.return_type(call_bottom, Tuple{})\n\n # check that @ccallable works from precompiled modules\n Base.@ccallable Cint f35014(x::Cint) = x+Cint(1)\n Base.@ccallable \"f35014_other\" f35014_2(x::Cint)::Cint = x+Cint(1)\n\n # check that Tasks work from serialized state\n ch1 = Channel(x -> nothing)\n ch2 = Channel(x -> (push!(x, 2); nothing), Inf)\n\n # check that Memory aliasing is respected\n a_vec_int = Int[]\n push!(a_vec_int, 1, 2)\n a_mat_int = reshape(a_vec_int, (1, 2))\n\n a_vec_any = Any[]\n push!(a_vec_any, 1, 2)\n a_mat_any = reshape(a_vec_any, (1, 2))\n\n a_vec_union = Union{Int,Nothing}[]\n push!(a_vec_union, 1, 2)\n a_mat_union = reshape(a_vec_union, (1, 2))\n\n a_vec_inline = Pair{Int,Any}[]\n push!(a_vec_inline, 1=>2, 3=>4)\n a_mat_inline = reshape(a_vec_inline, (1, 2))\n\n oid_vec_int = objectid(a_vec_int)\n oid_mat_int = objectid(a_mat_int)\n\n using $(FooBase_module): process_state, mypid as FooBase_pid, process_state_calls\n const mypid = process_state()\nend\n") touch(foo_file) touch(bar_file) @test __precompile__(false) === nothing Foo2 = Base.require(Main, Foo2_module) @eval ($Foo2).override(::Int) = begin 'a' end @eval ($Foo2).override(::Float32) = begin 'b' end @eval ($Foo2).overridenc(::Int) = begin rand() + 97.0 end @eval ($Foo2).overridenc(::Float32) = begin rand() + 100.0 end Foo = Base.require(Main, Foo_module) Base.invokelatest() do @test Foo.foo(17) == 18 @test Foo.Bar.bar(17) == 19 @test Foo.g() === 97.0 @test 96 < Foo.gnc() < 99 @test Foo.override(1.0) == Float64('a') @test Foo.override(1.0f0) == 'b' @test Foo.override(UInt(1)) == 2 @test 96 < Foo.overridenc(1.0) < 99 @test 99 < Foo.overridenc(1.0f0) < 102 @test 0 < Foo.overridenc(UInt(1)) < 3 @test Foo.abigfloat_f()::BigFloat == 12.34000000000000000000000000000000000000000000000000000000000000000000000000005 @test Foo.abigfloat_x::BigFloat + 21 == 64.21000000000000000000000000000000000000000000000000000000000000000000000000053 @test Foo.abigint_f()::BigInt == 123 @test Foo.abigint_x::BigInt + 1 == 125 @test Foo.abigfloat_to_f32() == 1.5f0 @test Foo.x28297.result === missing @test Foo.d29936a === Dict @test Foo.d29936b === (Dict{K, V} where {V, K}) @test Foo.x28998[var"end"] == 6 @test Foo.a31488 == fill("", 100) @test Foo.ptr1 === Ptr{UInt8}(1) @test Foo.ptr2 === Ptr{UInt8}(0) @test Foo.ptr3 === Ptr{UInt8}(-1) @test Foo.layout1::Vector{Ptr{Int8}} == Ptr{Int8}[Ptr{Int8}(0), Ptr{Int8}(0), Ptr{Int8}(-1)] @test Foo.layout2 == Any[Ptr{Int8}(0), Ptr{Int16}(0), Ptr{Int32}(-1)] @test typeof.(Foo.layout2) == [Ptr{Int8}, Ptr{Int16}, Ptr{Int32}] @test Foo.layout3 == ["ab", "cd", "ef", "gh", "ij"] @test !(isopen(Foo.ch1)) @test !(isopen(Foo.ch2)) @test !(isready(Foo.ch1)) @test isready(Foo.ch2) @test take!(Foo.ch2) === 2 @test !(isready(Foo.ch2)) @test Foo.process_state_calls === 0 @test Foo.process_state() === getpid() @test Foo.mypid !== getpid() @test Foo.FooBase_pid !== getpid() @test Foo.mypid !== Foo.FooBase_pid @test Foo.process_state_calls === 1 end let @test Foo.a_vec_int == Int[1, 2] @test Foo.a_mat_int == Int[1 2] Foo.a_mat_int[1, 2] = 3 @test Foo.a_vec_int[2] === 3 @test Foo.a_vec_any == Int[1, 2] @test Foo.a_mat_any == Int[1 2] Foo.a_mat_any[1, 2] = 3 @test Foo.a_vec_any[2] === 3 @test Foo.a_vec_union == Union{Int, Nothing}[1, 2] @test Foo.a_mat_union == Union{Int, Nothing}[1 2] Foo.a_mat_union[1, 2] = 3 @test Foo.a_vec_union[2] === 3 Foo.a_mat_union[1, 2] = nothing @test Foo.a_vec_union[2] === nothing @test Foo.a_vec_inline == Pair{Int, Any}[1 => 2, 3 => 4] @test Foo.a_mat_inline == Pair{Int, Any}[1 => 2 3 => 4] Foo.a_mat_inline[1, 2] = 5 => 6 @test Foo.a_vec_inline[2] === Pair{Int, Any}(5, 6) @test objectid(Foo.a_vec_int) === Foo.oid_vec_int @test objectid(Foo.a_mat_int) === Foo.oid_mat_int @test Foo.oid_vec_int !== Foo.oid_mat_int @test Base.object_build_id(Foo.a_vec_int) == Base.object_build_id(Foo.a_mat_int) @test Base.object_build_id(Foo) == Base.module_build_id(Foo) @test Base.object_build_id(Foo.a_vec_int) == Base.module_build_id(Foo) end cachedir = joinpath(dir, "compiled", "v$(VERSION.major).$(VERSION.minor)") cachedir2 = joinpath(dir2, "compiled", "v$(VERSION.major).$(VERSION.minor)") cachefile = joinpath(cachedir, "$(Foo_module).ji") @test isfile(cachefile) do_pkgimg = (Base.JLOptions()).use_pkgimages == 1 && (Base.JLOptions()).permalloc_pkgimg == 1 if do_pkgimg || (Base.JLOptions()).use_pkgimages == 0 if do_pkgimg ocachefile = Base.ocachefile_from_cachefile(cachefile)::String @test isfile(ocachefile) let foo_ptr = Libdl.dlopen(ocachefile::String, RTLD_NOLOAD) f35014_ptr = Libdl.dlsym(foo_ptr, :f35014) @test ccall(f35014_ptr, Int32, (Int32,), 3) == 4 f35014_other_ptr = Libdl.dlsym(foo_ptr, :f35014_other) @test ccall(f35014_other_ptr, Int32, (Int32,), 3) == 4 end else ocachefile = nothing end @test_logs (:warn, "Replacing module `$(Foo_module)`") begin m = Base._require_from_serialized(Base.PkgId(Foo), cachefile, ocachefile, Foo_file) @test m isa Module end end @test_throws MethodError Foo.foo(17) Base.invokelatest() do @test Foo.foo(17) == 18 @test Foo.Bar.bar(17) == 19 @test Foo.g() === 97.0 @test Foo.override(1.0) == Float64('a') @test Foo.override(1.0f0) == 'b' @test Foo.override(UInt(1)) == 2 @test string(Base.Docs.doc(Foo.foo)) == "foo function\n" @test string(Base.Docs.doc(Foo.Bar.bar)) == "bar function\n" @test string(Base.Docs.doc(Foo.Bar)) == "Bar module\n" (modules, (deps, _, requires), required_modules, _...) = Base.parse_cache_header(cachefile) discard_module = (mod_fl_mt->begin mod_fl_mt.filename end) @test modules == [Base.PkgId(Foo) => Base.module_build_id(Foo) % UInt64] @test map((x->begin x.filename end), deps) == [Foo_file, joinpath("@depot", foo_file), joinpath("@depot", bar_file)] @test requires == [Base.PkgId(Foo) => Base.PkgId(string(FooBase_module)), Base.PkgId(Foo) => Base.PkgId(Foo2), Base.PkgId(Foo) => Base.PkgId(Test), Base.PkgId(Foo) => Base.PkgId(string(FooBase_module))] srctxt = Base.read_dependency_src(cachefile, Foo_file) @test !(isempty(srctxt)) && srctxt == read(Foo_file, String) @test_throws ErrorException Base.read_dependency_src(cachefile, "/tmp/nonexistent.txt") @test_throws ErrorException Base.read_dependency_src(cachefile, joinpath(dir, foo_file)) (modules, deps1) = Base.cache_dependencies(cachefile) modules_ok = merge(Dict((let m = Base.PkgId(s) m => Base.module_build_id(Base.root_module(m)) end for s = ["Base", "Core", "Main", string(Foo2_module), string(FooBase_module)])), Dict((let m = Base.root_module(Base, s) Base.PkgId(m) => Base.module_build_id(m) end for s = [Symbol(x.name) for x = Base._sysimage_modules if !(x.name in ["Base", "Core", "Main"])])), Dict(Base.PkgId(Base.root_module(Base, :Test)) => Base.module_build_id(Base.root_module(Base, :Test))), Dict(Base.PkgId(Base.root_module(Base, :InteractiveUtils)) => Base.module_build_id(Base.root_module(Base, :InteractiveUtils))), Dict(Base.PkgId(Base.root_module(Base, :Logging)) => Base.module_build_id(Base.root_module(Base, :Logging))), Dict(Base.PkgId(Base.root_module(Base, :Random)) => Base.module_build_id(Base.root_module(Base, :Random))), Dict(Base.PkgId(Base.root_module(Base, :Serialization)) => Base.module_build_id(Base.root_module(Base, :Serialization))), Dict(Base.PkgId(Base.root_module(Base, :SHA)) => Base.module_build_id(Base.root_module(Base, :SHA))), Dict(Base.PkgId(Base.root_module(Base, :Markdown)) => Base.module_build_id(Base.root_module(Base, :Markdown))), Dict(Base.PkgId(Base.root_module(Base, :JuliaSyntaxHighlighting)) => Base.module_build_id(Base.root_module(Base, :JuliaSyntaxHighlighting))), Dict(Base.PkgId(Base.root_module(Base, :StyledStrings)) => Base.module_build_id(Base.root_module(Base, :StyledStrings))), Dict(Base.PkgId(Base.root_module(Base, :Base64)) => Base.module_build_id(Base.root_module(Base, :Base64)))) @test Dict(modules) == modules_ok @test discard_module.(deps) == deps1 (modules, (_, deps, requires), required_modules, _...) = Base.parse_cache_header(cachefile) @test map((x->begin x.filename end), deps) == [Foo_file] @test (current_task())(0x01, 0x4000, 0x30031234) == 2 @test sin(0x01, 0x4000, 0x30031234) == 52 @test sin(0x01, 0x4000, 0x30031234; x = 9142) == 9142 @test Foo.sinkw === Core.kwcall @test Foo.NominalValue() == 1 @test Foo.OrdinalValue() == 1 @test Foo.NominalValue{Int}() == 2 @test Foo.OrdinalValue{Int}() == 2 let T = Vector{Foo.NominalValue{Int}} @test T() isa T end @test Vector{Foo.NominalValue{Int32, Int64}}() == 3 @test Vector{Foo.NominalValue{UInt, UInt}}() == 4 @test Vector{Foo.NominalValue{Int, Int}}() == 5 @test all((i->begin Foo.t17809s[i + 1] === Tuple{Type{Ptr{Foo.MyType{i}}}, Ptr{Type{Foo.MyType{i}}}, Array{Ptr{Foo.MyType{Foo.MyType{:sym}()}}(0), 0}, Val{Complex{Int}(1, 2)}, Val{3}, Val{nothing}} end), 0:25) some_method = which(Base.include, (Module, String)) some_linfo = Core.Compiler.specialize_method(some_method, Tuple{typeof(Base.include), Module, String}, Core.svec()) @test Foo.some_linfo::Core.MethodInstance === some_linfo ft = Base.datatype_fieldtypes PV = (ft((Foo.Value18343{Some}).body))[1] VR = ((ft(PV))[1]).parameters[1] @test (ft(PV))[1] === Array{VR, 1} @test pointer_from_objref((ft(PV))[1]) === pointer_from_objref((ft((ft(((ft(PV))[1]).parameters[1]))[1]))[1]) @test PV === (ft(((ft(PV))[1]).parameters[1]))[1] @test pointer_from_objref(PV) === pointer_from_objref((ft(((ft(PV))[1]).parameters[1]))[1]) end Nest_module = :Nest4b3a94a1a081a8cb Nest_file = joinpath(dir, "$(Nest_module).jl") NestInner_file = joinpath(dir, "$(Nest_module)Inner.jl") NestInner2_file = joinpath(dir, "$(Nest_module)Inner2.jl") write(Nest_file, "module $(Nest_module)\ninclude(\"$(escape_string(NestInner_file))\")\nend\n") write(NestInner_file, "module NestInner\ninclude(\"$(escape_string(NestInner2_file))\")\nend\n") write(NestInner2_file, "f() = 22\n") Nest = Base.require(Main, Nest_module) cachefile = joinpath(cachedir, "$(Nest_module).ji") (modules, (deps, _, requires), required_modules, _...) = Base.parse_cache_header(cachefile) @test (last(deps)).modpath == ["NestInner"] UsesB_module = :UsesB4b3a94a1a081a8cb B_module = :UsesB4b3a94a1a081a8cb_B UsesB_file = joinpath(dir, "$(UsesB_module).jl") B_file = joinpath(dir, "$(B_module).jl") write(UsesB_file, "module $(UsesB_module)\nusing $(B_module)\nend\n") write(B_file, "module $(B_module)\nexport bfunc\nbfunc() = 33\nend\n") UsesB = Base.require(Main, UsesB_module) cachefile = joinpath(cachedir, "$(UsesB_module).ji") (modules, (deps, _, requires), required_modules, _...) = Base.parse_cache_header(cachefile) (id1, id2) = only(requires) @test (Base.pkgorigins[id1]).cachepath == cachefile @test (Base.pkgorigins[id2]).cachepath == joinpath(cachedir, "$(B_module).ji") Baz_file = joinpath(dir, "Baz.jl") write(Baz_file, "haskey(Base.loaded_modules, Base.PkgId(\"UseBaz\")) || __precompile__(false)\nmodule Baz\nbaz() = 1\nend\n") @test Base.compilecache(Base.PkgId("Baz")) == Base.PrecompilableError() OverwriteMethodError_file = joinpath(dir, "OverwriteMethodError.jl") write(OverwriteMethodError_file, "module OverwriteMethodError\n Base.:(+)(x::Bool, y::Bool) = false\nend\n") @test @test_warn("overwritten in module OverwriteMethodError", Base.compilecache(Base.PkgId("OverwriteMethodError"))) == Base.PrecompilableError() UseBaz_file = joinpath(dir, "UseBaz.jl") write(UseBaz_file, "module UseBaz\nbiz() = 1\n@assert haskey(Base.loaded_modules, Base.PkgId(\"UseBaz\"))\n@assert !haskey(Base.loaded_modules, Base.PkgId(\"Baz\"))\nusing Baz\n@assert haskey(Base.loaded_modules, Base.PkgId(\"Baz\"))\nbuz() = 2\nconst generating = ccall(:jl_generating_output, Cint, ())\nconst incremental = Base.JLOptions().incremental\nend\n") @test Base.compilecache(Base.PkgId("UseBaz")) == Base.PrecompilableError() @eval using UseBaz @test haskey(Base.loaded_modules, Base.PkgId("UseBaz")) @test haskey(Base.loaded_modules, Base.PkgId("Baz")) invokelatest() do @test UseBaz.biz() === 1 @test UseBaz.buz() === 2 @test UseBaz.generating == 0 @test UseBaz.incremental == 0 end @eval using Baz invokelatest() do @test Baz.baz() === 1 @test Baz === UseBaz.Baz end @test !(isfile("DoesNotExist.ji")) @test Base.stale_cachefile("", "DoesNotExist.ji") === true FooBar1_file = joinpath(dir, "FooBar1.jl") write(FooBar1_file, "module FooBar1\n using FooBar\nend\n") sleep(2) FooBar_file = joinpath(dir, "FooBar.jl") write(FooBar_file, "module FooBar\nend\n") (cachefile, _) = @test_logs((:debug, r"Precompiling FooBar"), min_level = Logging.Debug, match_mode = :any, Base.compilecache(Base.PkgId("FooBar"))) empty_prefs_hash = Base.get_preferences_hash(nothing, String[]) @test cachefile == Base.compilecache_path(Base.PkgId("FooBar"), empty_prefs_hash) @test isfile(joinpath(cachedir, "FooBar.ji")) Tsc = if Bool((Base.JLOptions()).use_pkgimages) Tuple{<:Vector, String, UInt128} else Tuple{<:Vector, Nothing, UInt128} end @test Base.stale_cachefile(FooBar_file, joinpath(cachedir, "FooBar.ji")) isa Tsc @test !(isdefined(Main, :FooBar)) @test !(isdefined(Main, :FooBar1)) relFooBar_file = joinpath(dir, "subfolder", "..", "FooBar.jl") @test Base.stale_cachefile(relFooBar_file, joinpath(cachedir, "FooBar.ji")) isa if Sys.iswindows() Tuple{<:Vector, String, UInt128} else Bool end mkdir(joinpath(dir, "subfolder")) @test Base.stale_cachefile(relFooBar_file, joinpath(cachedir, "FooBar.ji")) isa Tsc @eval using FooBar fb_uuid = invokelatest((()->begin Base.module_build_id(FooBar) end)) sleep(2) touch(FooBar_file) insert!(DEPOT_PATH, 1, dir2) @test Base.stale_cachefile(FooBar_file, joinpath(cachedir, "FooBar.ji")) isa Tsc @eval using FooBar1 @test !(isfile(joinpath(cachedir2, "FooBar.ji"))) @test !(isfile(joinpath(cachedir, "FooBar1.ji"))) @test isfile(joinpath(cachedir2, "FooBar1.ji")) @test Base.stale_cachefile(FooBar_file, joinpath(cachedir, "FooBar.ji")) isa Tsc @test Base.stale_cachefile(FooBar1_file, joinpath(cachedir2, "FooBar1.ji")) isa Tsc invokelatest() do @test fb_uuid == Base.module_build_id(FooBar) fb_uuid1 = Base.module_build_id(FooBar1) @test fb_uuid != fb_uuid1 end open(joinpath(cachedir2, "FooBar1.ji"), "a") do f write(f, 0x076cac96) end @test Base.stale_cachefile(FooBar1_file, joinpath(cachedir2, "FooBar1.ji")) === true FooBar2_file = joinpath(dir, "FooBar2.jl") write(FooBar2_file, "module FooBar2\nerror(\"break me\")\nend\n") try Base.require(Main, :FooBar2) error("the \"break me\" test failed") catch exc exc isa Base.Precompilation.PkgPrecompileError || rethrow() occursin("Failed to precompile FooBar2", exc.msg) || rethrow() occursin("LoadError: break me", exc.msg) || rethrow() end FooBar3_file = joinpath(dir, "FooBar3.jl") FooBar3_inc = joinpath(dir, "FooBar3_inc.jl") write(FooBar3_inc, "x=1\n") for code = ["Core.eval(Base, :(x=1))", "Base.include(Base, \"FooBar3_inc.jl\")"] write(FooBar3_file, "module FooBar3\n$(code)\nend\n") try Base.require(Main, :FooBar3) catch exc exc isa Base.Precompilation.PkgPrecompileError || rethrow() occursin("Evaluation into the closed module `Base` breaks incremental compilation", exc.msg) || rethrow() end end FooBarT_file = joinpath(dir, "FooBarT.jl") write(FooBarT_file, "module FooBarT\nend\n") FooBarT1_file = joinpath(dir, "FooBarT1.jl") write(FooBarT1_file, "module FooBarT1\n using FooBarT\nend\n") FooBarT2_file = joinpath(dir, "FooBarT2.jl") write(FooBarT2_file, "module FooBarT2\n using FooBarT1\nend\n") Base.compilecache(Base.PkgId("FooBarT2")) write(FooBarT1_file, "module FooBarT1\nend\n") rm(FooBarT_file) @test Base.stale_cachefile(FooBarT2_file, joinpath(cachedir2, "FooBarT2.ji")) === true @test Base.require(Main, :FooBarT2) isa Module end precompile_test_harness(false) do dir Foo_file = joinpath(dir, "$(Foo_module).jl") Foo2_file = joinpath(dir, "$(Foo2_module).jl") FooBase_file = joinpath(dir, "$(FooBase_module).jl") foo_file = joinpath(dir, "$(foo_incl_dep).jl") bar_file = joinpath(dir, "$(bar_incl_dep).jl") write(FooBase_file, "false && __precompile__(false)\nmodule $(FooBase_module)\n import Base: hash, >\n struct fmpz end\n struct typeA end\n >(x::fmpz, y::Int) = Base.cmp(x, y) > 0\n function hash(a::typeA, h::UInt)\n d = den(a)\n return h\n end\n abstract type AbstractAlgebraMap{A} end\n struct GAPGroupHomomorphism{A, B} <: AbstractAlgebraMap{GAPGroupHomomorphism{B, A}} end\n\n global process_state_calls::Int = 0\n const process_state = Base.OncePerProcess{typeof(getpid())}() do\n @assert (global process_state_calls += 1) == 1\n return getpid()\n end\n const mypid = process_state()\n @assert process_state_calls === 1\n process_state_calls = 0\n @assert process_state() === process_state()\n @assert process_state_calls === 0\n\n const empty_state = Base.OncePerProcess{Nothing}() do\n return nothing\n end\n @assert empty_state() === nothing\nend\n") write(Foo2_file, "module $(Foo2_module)\n export override, overridenc\n override(x::Integer) = 2\n override(x::AbstractFloat) = Float64(override(1))\n overridenc(x::Integer) = rand()+1\n overridenc(x::AbstractFloat) = Float64(overridenc(1))\nend\n") write(Foo_file, "module $(Foo_module)\n import $(FooBase_module), $(FooBase_module).typeA, $(FooBase_module).GAPGroupHomomorphism\n import $(Foo2_module): $(Foo2_module), override, overridenc\n import $(FooBase_module).hash\n import Test\n public foo, Bar\n module Inner\n import $(FooBase_module).hash\n using ..$(Foo_module)\n import ..$(Foo2_module)\n end\n\n struct typeB\n y::typeA\n end\n hash(x::typeB) = hash(x.y)\n\n # test that docs get reconnected\n @doc \"foo function\" foo(x) = x + 1\n include_dependency(\"$(foo_incl_dep).jl\")\n include_dependency(\"$(foo_incl_dep).jl\")\n module Bar\n public bar\n include_dependency(\"$(bar_incl_dep).jl\")\n end\n @doc \"Bar module\" Bar # this needs to define the META dictionary via eval\n @eval Bar @doc \"bar function\" bar(x) = x + 2\n\n # test for creation of some reasonably complicated type\n struct MyType{T} end\n const t17809s = Any[\n Tuple{\n Type{Ptr{MyType{i}}},\n Ptr{Type{MyType{i}}},\n Array{Ptr{MyType{MyType{:sym}()}}(0), 0},\n Val{Complex{Int}(1, 2)},\n Val{3},\n Val{nothing}}\n for i = 0:25]\n\n # test that types and methods get reconnected correctly\n # issue 16529 (adding a method to a type with no instances)\n (::Task)(::UInt8, ::UInt16, ::UInt32) = 2\n\n # issue 16471\n Base.sin(::UInt8, ::UInt16, ::UInt32; x = 52) = x\n const sinkw = Core.kwcall\n\n # issue 16908 (some complicated types and external method definitions)\n abstract type CategoricalPool{T, R <: Integer, V} end\n abstract type CategoricalValue{T, R <: Integer} end\n struct NominalPool{T, R <: Integer, V} <: CategoricalPool{T, R, V}\n index::Vector{T}\n invindex::Dict{T, R}\n order::Vector{R}\n ordered::Vector{T}\n valindex::Vector{V}\n end\n struct NominalValue{T, R <: Integer} <: CategoricalValue{T, R}\n level::R\n pool::NominalPool{T, R, NominalValue{T, R}}\n end\n struct OrdinalValue{T, R <: Integer} <: CategoricalValue{T, R}\n level::R\n pool::NominalPool{T, R, NominalValue{T, R}}\n end\n (::Union{Type{NominalValue}, Type{OrdinalValue}})() = 1\n (::Union{Type{NominalValue{T}}, Type{OrdinalValue{T}}})() where {T} = 2\n (::Type{Vector{NominalValue{T, R}}})() where {T, R} = 3\n (::Type{Vector{NominalValue{T, T}}})() where {T} = 4\n (::Type{Vector{NominalValue{Int, Int}}})() = 5\n\n # more tests for method signature involving a complicated type\n # issue 18343\n struct Pool18343{R, V}\n valindex::Vector{V}\n end\n struct Value18343{T, R}\n pool::Pool18343{R, Value18343{T, R}}\n end\n Base.convert(::Type{Some{S}}, ::Value18343{Some}) where {S} = 2\n Base.convert(::Type{Some{Value18343}}, ::Value18343{Some}) = 2\n Base.convert(::Type{Ref}, ::Value18343{T}) where {T} = 3\n\n const GAPType1 = GAPGroupHomomorphism{Nothing, Nothing}\n const GAPType2 = GAPGroupHomomorphism{1, 2}\n\n # issue #28297\n mutable struct Result\n result::Union{Int,Missing}\n end\n\n const x28297 = Result(missing)\n\n const d29936a = UnionAll(Dict.var, UnionAll(Dict.body.var, Dict.body.body))\n const d29936b = UnionAll(Dict.body.var, UnionAll(Dict.var, Dict.body.body))\n\n # issue #28998\n const x28998 = [missing, 2, missing, 6, missing,\n missing, missing, missing,\n missing, missing, missing,\n missing, missing, 6]\n\n let some_method = which(Base.include, (Module, String,))\n # global const some_method // FIXME: support for serializing a direct reference to an external Method not implemented\n global const some_linfo = Core.Compiler.specialize_method(some_method,\n Tuple{typeof(Base.include), Module, String}, Core.svec())\n end\n\n g() = override(1.0)\n Test.@test g() === 2.0 # compile this\n gnc() = overridenc(1.0)\n Test.@test 1 < gnc() < 5 # compile this\n\n abigfloat_f() = big\"12.34\"\n const abigfloat_x = big\"43.21\"\n abigint_f() = big\"123\"\n const abigint_x = big\"124\"\n\n # issue #51111\n abigfloat_to_f32() = Float32(big\"1.5\")\n\n # issue #31488\n _v31488 = Base.StringVector(2)\n resize!(_v31488, 0)\n const a31488 = fill(String(_v31488), 100)\n\n const ptr1 = Ptr{UInt8}(1)\n ptr2 = Ptr{UInt8}(1)\n const ptr3 = Ptr{UInt8}(-1)\n const layout1 = Ptr{Int8}[Ptr{Int8}(0), Ptr{Int8}(1), Ptr{Int8}(-1)]\n const layout2 = Any[Ptr{Int8}(0), Ptr{Int16}(1), Ptr{Int32}(-1)]\n const layout3 = collect(x.match for x in eachmatch(r\"..\", \"abcdefghijk\"))::Vector{SubString{String}}\n\n # create a backedge that includes Type{Union{}}, to ensure lookup can handle that\n call_bottom() = show(stdout, Union{})\n Core.Compiler.return_type(call_bottom, Tuple{})\n\n # check that @ccallable works from precompiled modules\n Base.@ccallable Cint f35014(x::Cint) = x+Cint(1)\n Base.@ccallable \"f35014_other\" f35014_2(x::Cint)::Cint = x+Cint(1)\n\n # check that Tasks work from serialized state\n ch1 = Channel(x -> nothing)\n ch2 = Channel(x -> (push!(x, 2); nothing), Inf)\n\n # check that Memory aliasing is respected\n a_vec_int = Int[]\n push!(a_vec_int, 1, 2)\n a_mat_int = reshape(a_vec_int, (1, 2))\n\n a_vec_any = Any[]\n push!(a_vec_any, 1, 2)\n a_mat_any = reshape(a_vec_any, (1, 2))\n\n a_vec_union = Union{Int,Nothing}[]\n push!(a_vec_union, 1, 2)\n a_mat_union = reshape(a_vec_union, (1, 2))\n\n a_vec_inline = Pair{Int,Any}[]\n push!(a_vec_inline, 1=>2, 3=>4)\n a_mat_inline = reshape(a_vec_inline, (1, 2))\n\n oid_vec_int = objectid(a_vec_int)\n oid_mat_int = objectid(a_mat_int)\n\n using $(FooBase_module): process_state, mypid as FooBase_pid, process_state_calls\n const mypid = process_state()\nend\n") touch(foo_file) touch(bar_file) @test __precompile__(false) === nothing Foo2 = Base.require(Main, Foo2_module) @eval ($Foo2).override(::Int) = begin 'a' end @eval ($Foo2).override(::Float32) = begin 'b' end @eval ($Foo2).overridenc(::Int) = begin rand() + 97.0 end @eval ($Foo2).overridenc(::Float32) = begin rand() + 100.0 end Foo = Base.require(Main, Foo_module) Base.invokelatest() do @test Foo.foo(17) == 18 @test Foo.Bar.bar(17) == 19 @test Foo.g() === 97.0 @test 96 < Foo.gnc() < 99 @test Foo.override(1.0) == Float64('a') @test Foo.override(1.0f0) == 'b' @test Foo.override(UInt(1)) == 2 @test 96 < Foo.overridenc(1.0) < 99 @test 99 < Foo.overridenc(1.0f0) < 102 @test 0 < Foo.overridenc(UInt(1)) < 3 @test Foo.abigfloat_f()::BigFloat == 12.34000000000000000000000000000000000000000000000000000000000000000000000000005 @test Foo.abigfloat_x::BigFloat + 21 == 64.21000000000000000000000000000000000000000000000000000000000000000000000000053 @test Foo.abigint_f()::BigInt == 123 @test Foo.abigint_x::BigInt + 1 == 125 @test Foo.abigfloat_to_f32() == 1.5f0 @test Foo.x28297.result === missing @test Foo.d29936a === Dict @test Foo.d29936b === (Dict{K, V} where {V, K}) @test Foo.x28998[var"end"] == 6 @test Foo.a31488 == fill("", 100) @test Foo.ptr1 === Ptr{UInt8}(1) @test Foo.ptr2 === Ptr{UInt8}(0) @test Foo.ptr3 === Ptr{UInt8}(-1) @test Foo.layout1::Vector{Ptr{Int8}} == Ptr{Int8}[Ptr{Int8}(0), Ptr{Int8}(0), Ptr{Int8}(-1)] @test Foo.layout2 == Any[Ptr{Int8}(0), Ptr{Int16}(0), Ptr{Int32}(-1)] @test typeof.(Foo.layout2) == [Ptr{Int8}, Ptr{Int16}, Ptr{Int32}] @test Foo.layout3 == ["ab", "cd", "ef", "gh", "ij"] @test !(isopen(Foo.ch1)) @test !(isopen(Foo.ch2)) @test !(isready(Foo.ch1)) @test isready(Foo.ch2) @test take!(Foo.ch2) === 2 @test !(isready(Foo.ch2)) @test Foo.process_state_calls === 0 @test Foo.process_state() === getpid() @test Foo.mypid !== getpid() @test Foo.FooBase_pid !== getpid() @test Foo.mypid !== Foo.FooBase_pid @test Foo.process_state_calls === 1 end let @test Foo.a_vec_int == Int[1, 2] @test Foo.a_mat_int == Int[1 2] Foo.a_mat_int[1, 2] = 3 @test Foo.a_vec_int[2] === 3 @test Foo.a_vec_any == Int[1, 2] @test Foo.a_mat_any == Int[1 2] Foo.a_mat_any[1, 2] = 3 @test Foo.a_vec_any[2] === 3 @test Foo.a_vec_union == Union{Int, Nothing}[1, 2] @test Foo.a_mat_union == Union{Int, Nothing}[1 2] Foo.a_mat_union[1, 2] = 3 @test Foo.a_vec_union[2] === 3 Foo.a_mat_union[1, 2] = nothing @test Foo.a_vec_union[2] === nothing @test Foo.a_vec_inline == Pair{Int, Any}[1 => 2, 3 => 4] @test Foo.a_mat_inline == Pair{Int, Any}[1 => 2 3 => 4] Foo.a_mat_inline[1, 2] = 5 => 6 @test Foo.a_vec_inline[2] === Pair{Int, Any}(5, 6) @test objectid(Foo.a_vec_int) === Foo.oid_vec_int @test objectid(Foo.a_mat_int) === Foo.oid_mat_int @test Foo.oid_vec_int !== Foo.oid_mat_int @test Base.object_build_id(Foo.a_vec_int) == Base.object_build_id(Foo.a_mat_int) @test Base.object_build_id(Foo) == Base.module_build_id(Foo) @test Base.object_build_id(Foo.a_vec_int) == Base.module_build_id(Foo) end cachedir = joinpath(dir, "compiled", "v$(VERSION.major).$(VERSION.minor)") cachedir2 = joinpath(dir2, "compiled", "v$(VERSION.major).$(VERSION.minor)") cachefile = joinpath(cachedir, "$(Foo_module).ji") @test isfile(cachefile) do_pkgimg = (Base.JLOptions()).use_pkgimages == 1 && (Base.JLOptions()).permalloc_pkgimg == 1 if do_pkgimg || (Base.JLOptions()).use_pkgimages == 0 if do_pkgimg ocachefile = Base.ocachefile_from_cachefile(cachefile)::String @test isfile(ocachefile) let foo_ptr = Libdl.dlopen(ocachefile::String, RTLD_NOLOAD) f35014_ptr = Libdl.dlsym(foo_ptr, :f35014) @test ccall(f35014_ptr, Int32, (Int32,), 3) == 4 f35014_other_ptr = Libdl.dlsym(foo_ptr, :f35014_other) @test ccall(f35014_other_ptr, Int32, (Int32,), 3) == 4 end else ocachefile = nothing end @test_logs (:warn, "Replacing module `$(Foo_module)`") begin m = Base._require_from_serialized(Base.PkgId(Foo), cachefile, ocachefile, Foo_file) @test m isa Module end end @test_throws MethodError Foo.foo(17) Base.invokelatest() do @test Foo.foo(17) == 18 @test Foo.Bar.bar(17) == 19 @test Foo.g() === 97.0 @test Foo.override(1.0) == Float64('a') @test Foo.override(1.0f0) == 'b' @test Foo.override(UInt(1)) == 2 @test string(Base.Docs.doc(Foo.foo)) == "foo function\n" @test string(Base.Docs.doc(Foo.Bar.bar)) == "bar function\n" @test string(Base.Docs.doc(Foo.Bar)) == "Bar module\n" (modules, (deps, _, requires), required_modules, _...) = Base.parse_cache_header(cachefile) discard_module = (mod_fl_mt->begin mod_fl_mt.filename end) @test modules == [Base.PkgId(Foo) => Base.module_build_id(Foo) % UInt64] @test map((x->begin x.filename end), deps) == [Foo_file, joinpath("@depot", foo_file), joinpath("@depot", bar_file)] @test requires == [Base.PkgId(Foo) => Base.PkgId(string(FooBase_module)), Base.PkgId(Foo) => Base.PkgId(Foo2), Base.PkgId(Foo) => Base.PkgId(Test), Base.PkgId(Foo) => Base.PkgId(string(FooBase_module))] srctxt = Base.read_dependency_src(cachefile, Foo_file) @test !(isempty(srctxt)) && srctxt == read(Foo_file, String) @test_throws ErrorException Base.read_dependency_src(cachefile, "/tmp/nonexistent.txt") @test_throws ErrorException Base.read_dependency_src(cachefile, joinpath(dir, foo_file)) (modules, deps1) = Base.cache_dependencies(cachefile) modules_ok = merge(Dict((let m = Base.PkgId(s) m => Base.module_build_id(Base.root_module(m)) end for s = ["Base", "Core", "Main", string(Foo2_module), string(FooBase_module)])), Dict((let m = Base.root_module(Base, s) Base.PkgId(m) => Base.module_build_id(m) end for s = [Symbol(x.name) for x = Base._sysimage_modules if !(x.name in ["Base", "Core", "Main"])])), Dict(Base.PkgId(Base.root_module(Base, :Test)) => Base.module_build_id(Base.root_module(Base, :Test))), Dict(Base.PkgId(Base.root_module(Base, :InteractiveUtils)) => Base.module_build_id(Base.root_module(Base, :InteractiveUtils))), Dict(Base.PkgId(Base.root_module(Base, :Logging)) => Base.module_build_id(Base.root_module(Base, :Logging))), Dict(Base.PkgId(Base.root_module(Base, :Random)) => Base.module_build_id(Base.root_module(Base, :Random))), Dict(Base.PkgId(Base.root_module(Base, :Serialization)) => Base.module_build_id(Base.root_module(Base, :Serialization))), Dict(Base.PkgId(Base.root_module(Base, :SHA)) => Base.module_build_id(Base.root_module(Base, :SHA))), Dict(Base.PkgId(Base.root_module(Base, :Markdown)) => Base.module_build_id(Base.root_module(Base, :Markdown))), Dict(Base.PkgId(Base.root_module(Base, :JuliaSyntaxHighlighting)) => Base.module_build_id(Base.root_module(Base, :JuliaSyntaxHighlighting))), Dict(Base.PkgId(Base.root_module(Base, :StyledStrings)) => Base.module_build_id(Base.root_module(Base, :StyledStrings))), Dict(Base.PkgId(Base.root_module(Base, :Base64)) => Base.module_build_id(Base.root_module(Base, :Base64)))) @test Dict(modules) == modules_ok @test discard_module.(deps) == deps1 (modules, (_, deps, requires), required_modules, _...) = Base.parse_cache_header(cachefile) @test map((x->begin x.filename end), deps) == [Foo_file] @test (current_task())(0x01, 0x4000, 0x30031234) == 2 @test sin(0x01, 0x4000, 0x30031234) == 52 @test sin(0x01, 0x4000, 0x30031234; x = 9142) == 9142 @test Foo.sinkw === Core.kwcall @test Foo.NominalValue() == 1 @test Foo.OrdinalValue() == 1 @test Foo.NominalValue{Int}() == 2 @test Foo.OrdinalValue{Int}() == 2 let T = Vector{Foo.NominalValue{Int}} @test T() isa T end @test Vector{Foo.NominalValue{Int32, Int64}}() == 3 @test Vector{Foo.NominalValue{UInt, UInt}}() == 4 @test Vector{Foo.NominalValue{Int, Int}}() == 5 @test all((i->begin Foo.t17809s[i + 1] === Tuple{Type{Ptr{Foo.MyType{i}}}, Ptr{Type{Foo.MyType{i}}}, Array{Ptr{Foo.MyType{Foo.MyType{:sym}()}}(0), 0}, Val{Complex{Int}(1, 2)}, Val{3}, Val{nothing}} end), 0:25) some_method = which(Base.include, (Module, String)) some_linfo = Core.Compiler.specialize_method(some_method, Tuple{typeof(Base.include), Module, String}, Core.svec()) @test Foo.some_linfo::Core.MethodInstance === some_linfo ft = Base.datatype_fieldtypes PV = (ft((Foo.Value18343{Some}).body))[1] VR = ((ft(PV))[1]).parameters[1] @test (ft(PV))[1] === Array{VR, 1} @test pointer_from_objref((ft(PV))[1]) === pointer_from_objref((ft((ft(((ft(PV))[1]).parameters[1]))[1]))[1]) @test PV === (ft(((ft(PV))[1]).parameters[1]))[1] @test pointer_from_objref(PV) === pointer_from_objref((ft(((ft(PV))[1]).parameters[1]))[1]) end Nest_module = :Nest4b3a94a1a081a8cb Nest_file = joinpath(dir, "$(Nest_module).jl") NestInner_file = joinpath(dir, "$(Nest_module)Inner.jl") NestInner2_file = joinpath(dir, "$(Nest_module)Inner2.jl") write(Nest_file, "module $(Nest_module)\ninclude(\"$(escape_string(NestInner_file))\")\nend\n") write(NestInner_file, "module NestInner\ninclude(\"$(escape_string(NestInner2_file))\")\nend\n") write(NestInner2_file, "f() = 22\n") Nest = Base.require(Main, Nest_module) cachefile = joinpath(cachedir, "$(Nest_module).ji") (modules, (deps, _, requires), required_modules, _...) = Base.parse_cache_header(cachefile) @test (last(deps)).modpath == ["NestInner"] UsesB_module = :UsesB4b3a94a1a081a8cb B_module = :UsesB4b3a94a1a081a8cb_B UsesB_file = joinpath(dir, "$(UsesB_module).jl") B_file = joinpath(dir, "$(B_module).jl") write(UsesB_file, "module $(UsesB_module)\nusing $(B_module)\nend\n") write(B_file, "module $(B_module)\nexport bfunc\nbfunc() = 33\nend\n") UsesB = Base.require(Main, UsesB_module) cachefile = joinpath(cachedir, "$(UsesB_module).ji") (modules, (deps, _, requires), required_modules, _...) = Base.parse_cache_header(cachefile) (id1, id2) = only(requires) @test (Base.pkgorigins[id1]).cachepath == cachefile @test (Base.pkgorigins[id2]).cachepath == joinpath(cachedir, "$(B_module).ji") Baz_file = joinpath(dir, "Baz.jl") write(Baz_file, "haskey(Base.loaded_modules, Base.PkgId(\"UseBaz\")) || __precompile__(false)\nmodule Baz\nbaz() = 1\nend\n") @test Base.compilecache(Base.PkgId("Baz")) == Base.PrecompilableError() OverwriteMethodError_file = joinpath(dir, "OverwriteMethodError.jl") write(OverwriteMethodError_file, "module OverwriteMethodError\n Base.:(+)(x::Bool, y::Bool) = false\nend\n") @test @test_warn("overwritten in module OverwriteMethodError", Base.compilecache(Base.PkgId("OverwriteMethodError"))) == Base.PrecompilableError() UseBaz_file = joinpath(dir, "UseBaz.jl") write(UseBaz_file, "module UseBaz\nbiz() = 1\n@assert haskey(Base.loaded_modules, Base.PkgId(\"UseBaz\"))\n@assert !haskey(Base.loaded_modules, Base.PkgId(\"Baz\"))\nusing Baz\n@assert haskey(Base.loaded_modules, Base.PkgId(\"Baz\"))\nbuz() = 2\nconst generating = ccall(:jl_generating_output, Cint, ())\nconst incremental = Base.JLOptions().incremental\nend\n") @test Base.compilecache(Base.PkgId("UseBaz")) == Base.PrecompilableError() @eval using UseBaz @test haskey(Base.loaded_modules, Base.PkgId("UseBaz")) @test haskey(Base.loaded_modules, Base.PkgId("Baz")) invokelatest() do @test UseBaz.biz() === 1 @test UseBaz.buz() === 2 @test UseBaz.generating == 0 @test UseBaz.incremental == 0 end @eval using Baz invokelatest() do @test Baz.baz() === 1 @test Baz === UseBaz.Baz end @test !(isfile("DoesNotExist.ji")) @test Base.stale_cachefile("", "DoesNotExist.ji") === true FooBar1_file = joinpath(dir, "FooBar1.jl") write(FooBar1_file, "module FooBar1\n using FooBar\nend\n") sleep(2) FooBar_file = joinpath(dir, "FooBar.jl") write(FooBar_file, "module FooBar\nend\n") (cachefile, _) = @test_logs((:debug, r"Precompiling FooBar"), min_level = Logging.Debug, match_mode = :any, Base.compilecache(Base.PkgId("FooBar"))) empty_prefs_hash = Base.get_preferences_hash(nothing, String[]) @test cachefile == Base.compilecache_path(Base.PkgId("FooBar"), empty_prefs_hash) @test isfile(joinpath(cachedir, "FooBar.ji")) Tsc = if Bool((Base.JLOptions()).use_pkgimages) Tuple{<:Vector, String, UInt128} else Tuple{<:Vector, Nothing, UInt128} end @test Base.stale_cachefile(FooBar_file, joinpath(cachedir, "FooBar.ji")) isa Tsc @test !(isdefined(Main, :FooBar)) @test !(isdefined(Main, :FooBar1)) relFooBar_file = joinpath(dir, "subfolder", "..", "FooBar.jl") @test Base.stale_cachefile(relFooBar_file, joinpath(cachedir, "FooBar.ji")) isa if Sys.iswindows() Tuple{<:Vector, String, UInt128} else Bool end mkdir(joinpath(dir, "subfolder")) @test Base.stale_cachefile(relFooBar_file, joinpath(cachedir, "FooBar.ji")) isa Tsc @eval using FooBar fb_uuid = invokelatest((()->begin Base.module_build_id(FooBar) end)) sleep(2) touch(FooBar_file) insert!(DEPOT_PATH, 1, dir2) @test Base.stale_cachefile(FooBar_file, joinpath(cachedir, "FooBar.ji")) isa Tsc @eval using FooBar1 @test !(isfile(joinpath(cachedir2, "FooBar.ji"))) @test !(isfile(joinpath(cachedir, "FooBar1.ji"))) @test isfile(joinpath(cachedir2, "FooBar1.ji")) @test Base.stale_cachefile(FooBar_file, joinpath(cachedir, "FooBar.ji")) isa Tsc @test Base.stale_cachefile(FooBar1_file, joinpath(cachedir2, "FooBar1.ji")) isa Tsc invokelatest() do @test fb_uuid == Base.module_build_id(FooBar) fb_uuid1 = Base.module_build_id(FooBar1) @test fb_uuid != fb_uuid1 end open(joinpath(cachedir2, "FooBar1.ji"), "a") do f write(f, 0x076cac96) end @test Base.stale_cachefile(FooBar1_file, joinpath(cachedir2, "FooBar1.ji")) === true FooBar2_file = joinpath(dir, "FooBar2.jl") write(FooBar2_file, "module FooBar2\nerror(\"break me\")\nend\n") try Base.require(Main, :FooBar2) error("the \"break me\" test failed") catch exc exc isa Base.Precompilation.PkgPrecompileError || rethrow() occursin("Failed to precompile FooBar2", exc.msg) || rethrow() occursin("LoadError: break me", exc.msg) || rethrow() end FooBar3_file = joinpath(dir, "FooBar3.jl") FooBar3_inc = joinpath(dir, "FooBar3_inc.jl") write(FooBar3_inc, "x=1\n") for code = ["Core.eval(Base, :(x=1))", "Base.include(Base, \"FooBar3_inc.jl\")"] write(FooBar3_file, "module FooBar3\n$(code)\nend\n") try Base.require(Main, :FooBar3) catch exc exc isa Base.Precompilation.PkgPrecompileError || rethrow() occursin("Evaluation into the closed module `Base` breaks incremental compilation", exc.msg) || rethrow() end end FooBarT_file = joinpath(dir, "FooBarT.jl") write(FooBarT_file, "module FooBarT\nend\n") FooBarT1_file = joinpath(dir, "FooBarT1.jl") write(FooBarT1_file, "module FooBarT1\n using FooBarT\nend\n") FooBarT2_file = joinpath(dir, "FooBarT2.jl") write(FooBarT2_file, "module FooBarT2\n using FooBarT1\nend\n") Base.compilecache(Base.PkgId("FooBarT2")) write(FooBarT1_file, "module FooBarT1\nend\n") rm(FooBarT_file) @test Base.stale_cachefile(FooBarT2_file, joinpath(cachedir2, "FooBarT2.ji")) === true @test Base.require(Main, :FooBarT2) isa Module end begin precompile_test_harness(false) do dir Foo_file = joinpath(dir, "$(Foo_module).jl") Foo2_file = joinpath(dir, "$(Foo2_module).jl") FooBase_file = joinpath(dir, "$(FooBase_module).jl") foo_file = joinpath(dir, "$(foo_incl_dep).jl") bar_file = joinpath(dir, "$(bar_incl_dep).jl") write(FooBase_file, "false && __precompile__(false)\nmodule $(FooBase_module)\n import Base: hash, >\n struct fmpz end\n struct typeA end\n >(x::fmpz, y::Int) = Base.cmp(x, y) > 0\n function hash(a::typeA, h::UInt)\n d = den(a)\n return h\n end\n abstract type AbstractAlgebraMap{A} end\n struct GAPGroupHomomorphism{A, B} <: AbstractAlgebraMap{GAPGroupHomomorphism{B, A}} end\n\n global process_state_calls::Int = 0\n const process_state = Base.OncePerProcess{typeof(getpid())}() do\n @assert (global process_state_calls += 1) == 1\n return getpid()\n end\n const mypid = process_state()\n @assert process_state_calls === 1\n process_state_calls = 0\n @assert process_state() === process_state()\n @assert process_state_calls === 0\n\n const empty_state = Base.OncePerProcess{Nothing}() do\n return nothing\n end\n @assert empty_state() === nothing\nend\n") write(Foo2_file, "module $(Foo2_module)\n export override, overridenc\n override(x::Integer) = 2\n override(x::AbstractFloat) = Float64(override(1))\n overridenc(x::Integer) = rand()+1\n overridenc(x::AbstractFloat) = Float64(overridenc(1))\nend\n") write(Foo_file, "module $(Foo_module)\n import $(FooBase_module), $(FooBase_module).typeA, $(FooBase_module).GAPGroupHomomorphism\n import $(Foo2_module): $(Foo2_module), override, overridenc\n import $(FooBase_module).hash\n import Test\n public foo, Bar\n module Inner\n import $(FooBase_module).hash\n using ..$(Foo_module)\n import ..$(Foo2_module)\n end\n\n struct typeB\n y::typeA\n end\n hash(x::typeB) = hash(x.y)\n\n # test that docs get reconnected\n @doc \"foo function\" foo(x) = x + 1\n include_dependency(\"$(foo_incl_dep).jl\")\n include_dependency(\"$(foo_incl_dep).jl\")\n module Bar\n public bar\n include_dependency(\"$(bar_incl_dep).jl\")\n end\n @doc \"Bar module\" Bar # this needs to define the META dictionary via eval\n @eval Bar @doc \"bar function\" bar(x) = x + 2\n\n # test for creation of some reasonably complicated type\n struct MyType{T} end\n const t17809s = Any[\n Tuple{\n Type{Ptr{MyType{i}}},\n Ptr{Type{MyType{i}}},\n Array{Ptr{MyType{MyType{:sym}()}}(0), 0},\n Val{Complex{Int}(1, 2)},\n Val{3},\n Val{nothing}}\n for i = 0:25]\n\n # test that types and methods get reconnected correctly\n # issue 16529 (adding a method to a type with no instances)\n (::Task)(::UInt8, ::UInt16, ::UInt32) = 2\n\n # issue 16471\n Base.sin(::UInt8, ::UInt16, ::UInt32; x = 52) = x\n const sinkw = Core.kwcall\n\n # issue 16908 (some complicated types and external method definitions)\n abstract type CategoricalPool{T, R <: Integer, V} end\n abstract type CategoricalValue{T, R <: Integer} end\n struct NominalPool{T, R <: Integer, V} <: CategoricalPool{T, R, V}\n index::Vector{T}\n invindex::Dict{T, R}\n order::Vector{R}\n ordered::Vector{T}\n valindex::Vector{V}\n end\n struct NominalValue{T, R <: Integer} <: CategoricalValue{T, R}\n level::R\n pool::NominalPool{T, R, NominalValue{T, R}}\n end\n struct OrdinalValue{T, R <: Integer} <: CategoricalValue{T, R}\n level::R\n pool::NominalPool{T, R, NominalValue{T, R}}\n end\n (::Union{Type{NominalValue}, Type{OrdinalValue}})() = 1\n (::Union{Type{NominalValue{T}}, Type{OrdinalValue{T}}})() where {T} = 2\n (::Type{Vector{NominalValue{T, R}}})() where {T, R} = 3\n (::Type{Vector{NominalValue{T, T}}})() where {T} = 4\n (::Type{Vector{NominalValue{Int, Int}}})() = 5\n\n # more tests for method signature involving a complicated type\n # issue 18343\n struct Pool18343{R, V}\n valindex::Vector{V}\n end\n struct Value18343{T, R}\n pool::Pool18343{R, Value18343{T, R}}\n end\n Base.convert(::Type{Some{S}}, ::Value18343{Some}) where {S} = 2\n Base.convert(::Type{Some{Value18343}}, ::Value18343{Some}) = 2\n Base.convert(::Type{Ref}, ::Value18343{T}) where {T} = 3\n\n const GAPType1 = GAPGroupHomomorphism{Nothing, Nothing}\n const GAPType2 = GAPGroupHomomorphism{1, 2}\n\n # issue #28297\n mutable struct Result\n result::Union{Int,Missing}\n end\n\n const x28297 = Result(missing)\n\n const d29936a = UnionAll(Dict.var, UnionAll(Dict.body.var, Dict.body.body))\n const d29936b = UnionAll(Dict.body.var, UnionAll(Dict.var, Dict.body.body))\n\n # issue #28998\n const x28998 = [missing, 2, missing, 6, missing,\n missing, missing, missing,\n missing, missing, missing,\n missing, missing, 6]\n\n let some_method = which(Base.include, (Module, String,))\n # global const some_method // FIXME: support for serializing a direct reference to an external Method not implemented\n global const some_linfo = Core.Compiler.specialize_method(some_method,\n Tuple{typeof(Base.include), Module, String}, Core.svec())\n end\n\n g() = override(1.0)\n Test.@test g() === 2.0 # compile this\n gnc() = overridenc(1.0)\n Test.@test 1 < gnc() < 5 # compile this\n\n abigfloat_f() = big\"12.34\"\n const abigfloat_x = big\"43.21\"\n abigint_f() = big\"123\"\n const abigint_x = big\"124\"\n\n # issue #51111\n abigfloat_to_f32() = Float32(big\"1.5\")\n\n # issue #31488\n _v31488 = Base.StringVector(2)\n resize!(_v31488, 0)\n const a31488 = fill(String(_v31488), 100)\n\n const ptr1 = Ptr{UInt8}(1)\n ptr2 = Ptr{UInt8}(1)\n const ptr3 = Ptr{UInt8}(-1)\n const layout1 = Ptr{Int8}[Ptr{Int8}(0), Ptr{Int8}(1), Ptr{Int8}(-1)]\n const layout2 = Any[Ptr{Int8}(0), Ptr{Int16}(1), Ptr{Int32}(-1)]\n const layout3 = collect(x.match for x in eachmatch(r\"..\", \"abcdefghijk\"))::Vector{SubString{String}}\n\n # create a backedge that includes Type{Union{}}, to ensure lookup can handle that\n call_bottom() = show(stdout, Union{})\n Core.Compiler.return_type(call_bottom, Tuple{})\n\n # check that @ccallable works from precompiled modules\n Base.@ccallable Cint f35014(x::Cint) = x+Cint(1)\n Base.@ccallable \"f35014_other\" f35014_2(x::Cint)::Cint = x+Cint(1)\n\n # check that Tasks work from serialized state\n ch1 = Channel(x -> nothing)\n ch2 = Channel(x -> (push!(x, 2); nothing), Inf)\n\n # check that Memory aliasing is respected\n a_vec_int = Int[]\n push!(a_vec_int, 1, 2)\n a_mat_int = reshape(a_vec_int, (1, 2))\n\n a_vec_any = Any[]\n push!(a_vec_any, 1, 2)\n a_mat_any = reshape(a_vec_any, (1, 2))\n\n a_vec_union = Union{Int,Nothing}[]\n push!(a_vec_union, 1, 2)\n a_mat_union = reshape(a_vec_union, (1, 2))\n\n a_vec_inline = Pair{Int,Any}[]\n push!(a_vec_inline, 1=>2, 3=>4)\n a_mat_inline = reshape(a_vec_inline, (1, 2))\n\n oid_vec_int = objectid(a_vec_int)\n oid_mat_int = objectid(a_mat_int)\n\n using $(FooBase_module): process_state, mypid as FooBase_pid, process_state_calls\n const mypid = process_state()\nend\n") touch(foo_file) touch(bar_file) @test __precompile__(false) === nothing Foo2 = Base.require(Main, Foo2_module) @eval ($Foo2).override(::Int) = begin 'a' end @eval ($Foo2).override(::Float32) = begin 'b' end @eval ($Foo2).overridenc(::Int) = begin rand() + 97.0 end @eval ($Foo2).overridenc(::Float32) = begin rand() + 100.0 end Foo = Base.require(Main, Foo_module) Base.invokelatest() do @test Foo.foo(17) == 18 @test Foo.Bar.bar(17) == 19 @test Foo.g() === 97.0 @test 96 < Foo.gnc() < 99 @test Foo.override(1.0) == Float64('a') @test Foo.override(1.0f0) == 'b' @test Foo.override(UInt(1)) == 2 @test 96 < Foo.overridenc(1.0) < 99 @test 99 < Foo.overridenc(1.0f0) < 102 @test 0 < Foo.overridenc(UInt(1)) < 3 @test Foo.abigfloat_f()::BigFloat == 12.34000000000000000000000000000000000000000000000000000000000000000000000000005 @test Foo.abigfloat_x::BigFloat + 21 == 64.21000000000000000000000000000000000000000000000000000000000000000000000000053 @test Foo.abigint_f()::BigInt == 123 @test Foo.abigint_x::BigInt + 1 == 125 @test Foo.abigfloat_to_f32() == 1.5f0 @test Foo.x28297.result === missing @test Foo.d29936a === Dict @test Foo.d29936b === (Dict{K, V} where {V, K}) @test Foo.x28998[var"end"] == 6 @test Foo.a31488 == fill("", 100) @test Foo.ptr1 === Ptr{UInt8}(1) @test Foo.ptr2 === Ptr{UInt8}(0) @test Foo.ptr3 === Ptr{UInt8}(-1) @test Foo.layout1::Vector{Ptr{Int8}} == Ptr{Int8}[Ptr{Int8}(0), Ptr{Int8}(0), Ptr{Int8}(-1)] @test Foo.layout2 == Any[Ptr{Int8}(0), Ptr{Int16}(0), Ptr{Int32}(-1)] @test typeof.(Foo.layout2) == [Ptr{Int8}, Ptr{Int16}, Ptr{Int32}] @test Foo.layout3 == ["ab", "cd", "ef", "gh", "ij"] @test !(isopen(Foo.ch1)) @test !(isopen(Foo.ch2)) @test !(isready(Foo.ch1)) @test isready(Foo.ch2) @test take!(Foo.ch2) === 2 @test !(isready(Foo.ch2)) @test Foo.process_state_calls === 0 @test Foo.process_state() === getpid() @test Foo.mypid !== getpid() @test Foo.FooBase_pid !== getpid() @test Foo.mypid !== Foo.FooBase_pid @test Foo.process_state_calls === 1 end let @test Foo.a_vec_int == Int[1, 2] @test Foo.a_mat_int == Int[1 2] Foo.a_mat_int[1, 2] = 3 @test Foo.a_vec_int[2] === 3 @test Foo.a_vec_any == Int[1, 2] @test Foo.a_mat_any == Int[1 2] Foo.a_mat_any[1, 2] = 3 @test Foo.a_vec_any[2] === 3 @test Foo.a_vec_union == Union{Int, Nothing}[1, 2] @test Foo.a_mat_union == Union{Int, Nothing}[1 2] Foo.a_mat_union[1, 2] = 3 @test Foo.a_vec_union[2] === 3 Foo.a_mat_union[1, 2] = nothing @test Foo.a_vec_union[2] === nothing @test Foo.a_vec_inline == Pair{Int, Any}[1 => 2, 3 => 4] @test Foo.a_mat_inline == Pair{Int, Any}[1 => 2 3 => 4] Foo.a_mat_inline[1, 2] = 5 => 6 @test Foo.a_vec_inline[2] === Pair{Int, Any}(5, 6) @test objectid(Foo.a_vec_int) === Foo.oid_vec_int @test objectid(Foo.a_mat_int) === Foo.oid_mat_int @test Foo.oid_vec_int !== Foo.oid_mat_int @test Base.object_build_id(Foo.a_vec_int) == Base.object_build_id(Foo.a_mat_int) @test Base.object_build_id(Foo) == Base.module_build_id(Foo) @test Base.object_build_id(Foo.a_vec_int) == Base.module_build_id(Foo) end cachedir = joinpath(dir, "compiled", "v$(VERSION.major).$(VERSION.minor)") cachedir2 = joinpath(dir2, "compiled", "v$(VERSION.major).$(VERSION.minor)") cachefile = joinpath(cachedir, "$(Foo_module).ji") @test isfile(cachefile) do_pkgimg = (Base.JLOptions()).use_pkgimages == 1 && (Base.JLOptions()).permalloc_pkgimg == 1 if do_pkgimg || (Base.JLOptions()).use_pkgimages == 0 if do_pkgimg ocachefile = Base.ocachefile_from_cachefile(cachefile)::String @test isfile(ocachefile) let foo_ptr = Libdl.dlopen(ocachefile::String, RTLD_NOLOAD) f35014_ptr = Libdl.dlsym(foo_ptr, :f35014) @test ccall(f35014_ptr, Int32, (Int32,), 3) == 4 f35014_other_ptr = Libdl.dlsym(foo_ptr, :f35014_other) @test ccall(f35014_other_ptr, Int32, (Int32,), 3) == 4 end else ocachefile = nothing end @test_logs (:warn, "Replacing module `$(Foo_module)`") begin m = Base._require_from_serialized(Base.PkgId(Foo), cachefile, ocachefile, Foo_file) @test m isa Module end end @test_throws MethodError Foo.foo(17) Base.invokelatest() do @test Foo.foo(17) == 18 @test Foo.Bar.bar(17) == 19 @test Foo.g() === 97.0 @test Foo.override(1.0) == Float64('a') @test Foo.override(1.0f0) == 'b' @test Foo.override(UInt(1)) == 2 @test string(Base.Docs.doc(Foo.foo)) == "foo function\n" @test string(Base.Docs.doc(Foo.Bar.bar)) == "bar function\n" @test string(Base.Docs.doc(Foo.Bar)) == "Bar module\n" (modules, (deps, _, requires), required_modules, _...) = Base.parse_cache_header(cachefile) discard_module = (mod_fl_mt->begin mod_fl_mt.filename end) @test modules == [Base.PkgId(Foo) => Base.module_build_id(Foo) % UInt64] @test map((x->begin x.filename end), deps) == [Foo_file, joinpath("@depot", foo_file), joinpath("@depot", bar_file)] @test requires == [Base.PkgId(Foo) => Base.PkgId(string(FooBase_module)), Base.PkgId(Foo) => Base.PkgId(Foo2), Base.PkgId(Foo) => Base.PkgId(Test), Base.PkgId(Foo) => Base.PkgId(string(FooBase_module))] srctxt = Base.read_dependency_src(cachefile, Foo_file) @test !(isempty(srctxt)) && srctxt == read(Foo_file, String) @test_throws ErrorException Base.read_dependency_src(cachefile, "/tmp/nonexistent.txt") @test_throws ErrorException Base.read_dependency_src(cachefile, joinpath(dir, foo_file)) (modules, deps1) = Base.cache_dependencies(cachefile) modules_ok = merge(Dict((let m = Base.PkgId(s) m => Base.module_build_id(Base.root_module(m)) end for s = ["Base", "Core", "Main", string(Foo2_module), string(FooBase_module)])), Dict((let m = Base.root_module(Base, s) Base.PkgId(m) => Base.module_build_id(m) end for s = [Symbol(x.name) for x = Base._sysimage_modules if !(x.name in ["Base", "Core", "Main"])])), Dict(Base.PkgId(Base.root_module(Base, :Test)) => Base.module_build_id(Base.root_module(Base, :Test))), Dict(Base.PkgId(Base.root_module(Base, :InteractiveUtils)) => Base.module_build_id(Base.root_module(Base, :InteractiveUtils))), Dict(Base.PkgId(Base.root_module(Base, :Logging)) => Base.module_build_id(Base.root_module(Base, :Logging))), Dict(Base.PkgId(Base.root_module(Base, :Random)) => Base.module_build_id(Base.root_module(Base, :Random))), Dict(Base.PkgId(Base.root_module(Base, :Serialization)) => Base.module_build_id(Base.root_module(Base, :Serialization))), Dict(Base.PkgId(Base.root_module(Base, :SHA)) => Base.module_build_id(Base.root_module(Base, :SHA))), Dict(Base.PkgId(Base.root_module(Base, :Markdown)) => Base.module_build_id(Base.root_module(Base, :Markdown))), Dict(Base.PkgId(Base.root_module(Base, :JuliaSyntaxHighlighting)) => Base.module_build_id(Base.root_module(Base, :JuliaSyntaxHighlighting))), Dict(Base.PkgId(Base.root_module(Base, :StyledStrings)) => Base.module_build_id(Base.root_module(Base, :StyledStrings))), Dict(Base.PkgId(Base.root_module(Base, :Base64)) => Base.module_build_id(Base.root_module(Base, :Base64)))) @test Dict(modules) == modules_ok @test discard_module.(deps) == deps1 (modules, (_, deps, requires), required_modules, _...) = Base.parse_cache_header(cachefile) @test map((x->begin x.filename end), deps) == [Foo_file] @test (current_task())(0x01, 0x4000, 0x30031234) == 2 @test sin(0x01, 0x4000, 0x30031234) == 52 @test sin(0x01, 0x4000, 0x30031234; x = 9142) == 9142 @test Foo.sinkw === Core.kwcall @test Foo.NominalValue() == 1 @test Foo.OrdinalValue() == 1 @test Foo.NominalValue{Int}() == 2 @test Foo.OrdinalValue{Int}() == 2 let T = Vector{Foo.NominalValue{Int}} @test T() isa T end @test Vector{Foo.NominalValue{Int32, Int64}}() == 3 @test Vector{Foo.NominalValue{UInt, UInt}}() == 4 @test Vector{Foo.NominalValue{Int, Int}}() == 5 @test all((i->begin Foo.t17809s[i + 1] === Tuple{Type{Ptr{Foo.MyType{i}}}, Ptr{Type{Foo.MyType{i}}}, Array{Ptr{Foo.MyType{Foo.MyType{:sym}()}}(0), 0}, Val{Complex{Int}(1, 2)}, Val{3}, Val{nothing}} end), 0:25) some_method = which(Base.include, (Module, String)) some_linfo = Core.Compiler.specialize_method(some_method, Tuple{typeof(Base.include), Module, String}, Core.svec()) @test Foo.some_linfo::Core.MethodInstance === some_linfo ft = Base.datatype_fieldtypes PV = (ft((Foo.Value18343{Some}).body))[1] VR = ((ft(PV))[1]).parameters[1] @test (ft(PV))[1] === Array{VR, 1} @test pointer_from_objref((ft(PV))[1]) === pointer_from_objref((ft((ft(((ft(PV))[1]).parameters[1]))[1]))[1]) @test PV === (ft(((ft(PV))[1]).parameters[1]))[1] @test pointer_from_objref(PV) === pointer_from_objref((ft(((ft(PV))[1]).parameters[1]))[1]) end Nest_module = :Nest4b3a94a1a081a8cb Nest_file = joinpath(dir, "$(Nest_module).jl") NestInner_file = joinpath(dir, "$(Nest_module)Inner.jl") NestInner2_file = joinpath(dir, "$(Nest_module)Inner2.jl") write(Nest_file, "module $(Nest_module)\ninclude(\"$(escape_string(NestInner_file))\")\nend\n") write(NestInner_file, "module NestInner\ninclude(\"$(escape_string(NestInner2_file))\")\nend\n") write(NestInner2_file, "f() = 22\n") Nest = Base.require(Main, Nest_module) cachefile = joinpath(cachedir, "$(Nest_module).ji") (modules, (deps, _, requires), required_modules, _...) = Base.parse_cache_header(cachefile) @test (last(deps)).modpath == ["NestInner"] UsesB_module = :UsesB4b3a94a1a081a8cb B_module = :UsesB4b3a94a1a081a8cb_B UsesB_file = joinpath(dir, "$(UsesB_module).jl") B_file = joinpath(dir, "$(B_module).jl") write(UsesB_file, "module $(UsesB_module)\nusing $(B_module)\nend\n") write(B_file, "module $(B_module)\nexport bfunc\nbfunc() = 33\nend\n") UsesB = Base.require(Main, UsesB_module) cachefile = joinpath(cachedir, "$(UsesB_module).ji") (modules, (deps, _, requires), required_modules, _...) = Base.parse_cache_header(cachefile) (id1, id2) = only(requires) @test (Base.pkgorigins[id1]).cachepath == cachefile @test (Base.pkgorigins[id2]).cachepath == joinpath(cachedir, "$(B_module).ji") Baz_file = joinpath(dir, "Baz.jl") write(Baz_file, "haskey(Base.loaded_modules, Base.PkgId(\"UseBaz\")) || __precompile__(false)\nmodule Baz\nbaz() = 1\nend\n") @test Base.compilecache(Base.PkgId("Baz")) == Base.PrecompilableError() OverwriteMethodError_file = joinpath(dir, "OverwriteMethodError.jl") write(OverwriteMethodError_file, "module OverwriteMethodError\n Base.:(+)(x::Bool, y::Bool) = false\nend\n") @test @test_warn("overwritten in module OverwriteMethodError", Base.compilecache(Base.PkgId("OverwriteMethodError"))) == Base.PrecompilableError() UseBaz_file = joinpath(dir, "UseBaz.jl") write(UseBaz_file, "module UseBaz\nbiz() = 1\n@assert haskey(Base.loaded_modules, Base.PkgId(\"UseBaz\"))\n@assert !haskey(Base.loaded_modules, Base.PkgId(\"Baz\"))\nusing Baz\n@assert haskey(Base.loaded_modules, Base.PkgId(\"Baz\"))\nbuz() = 2\nconst generating = ccall(:jl_generating_output, Cint, ())\nconst incremental = Base.JLOptions().incremental\nend\n") @test Base.compilecache(Base.PkgId("UseBaz")) == Base.PrecompilableError() @eval using UseBaz @test haskey(Base.loaded_modules, Base.PkgId("UseBaz")) @test haskey(Base.loaded_modules, Base.PkgId("Baz")) invokelatest() do @test UseBaz.biz() === 1 @test UseBaz.buz() === 2 @test UseBaz.generating == 0 @test UseBaz.incremental == 0 end @eval using Baz invokelatest() do @test Baz.baz() === 1 @test Baz === UseBaz.Baz end @test !(isfile("DoesNotExist.ji")) @test Base.stale_cachefile("", "DoesNotExist.ji") === true FooBar1_file = joinpath(dir, "FooBar1.jl") write(FooBar1_file, "module FooBar1\n using FooBar\nend\n") sleep(2) FooBar_file = joinpath(dir, "FooBar.jl") write(FooBar_file, "module FooBar\nend\n") (cachefile, _) = @test_logs((:debug, r"Precompiling FooBar"), min_level = Logging.Debug, match_mode = :any, Base.compilecache(Base.PkgId("FooBar"))) empty_prefs_hash = Base.get_preferences_hash(nothing, String[]) @test cachefile == Base.compilecache_path(Base.PkgId("FooBar"), empty_prefs_hash) @test isfile(joinpath(cachedir, "FooBar.ji")) Tsc = if Bool((Base.JLOptions()).use_pkgimages) Tuple{<:Vector, String, UInt128} else Tuple{<:Vector, Nothing, UInt128} end @test Base.stale_cachefile(FooBar_file, joinpath(cachedir, "FooBar.ji")) isa Tsc @test !(isdefined(Main, :FooBar)) @test !(isdefined(Main, :FooBar1)) relFooBar_file = joinpath(dir, "subfolder", "..", "FooBar.jl") @test Base.stale_cachefile(relFooBar_file, joinpath(cachedir, "FooBar.ji")) isa if Sys.iswindows() Tuple{<:Vector, String, UInt128} else Bool end mkdir(joinpath(dir, "subfolder")) @test Base.stale_cachefile(relFooBar_file, joinpath(cachedir, "FooBar.ji")) isa Tsc @eval using FooBar fb_uuid = invokelatest((()->begin Base.module_build_id(FooBar) end)) sleep(2) touch(FooBar_file) insert!(DEPOT_PATH, 1, dir2) @test Base.stale_cachefile(FooBar_file, joinpath(cachedir, "FooBar.ji")) isa Tsc @eval using FooBar1 @test !(isfile(joinpath(cachedir2, "FooBar.ji"))) @test !(isfile(joinpath(cachedir, "FooBar1.ji"))) @test isfile(joinpath(cachedir2, "FooBar1.ji")) @test Base.stale_cachefile(FooBar_file, joinpath(cachedir, "FooBar.ji")) isa Tsc @test Base.stale_cachefile(FooBar1_file, joinpath(cachedir2, "FooBar1.ji")) isa Tsc invokelatest() do @test fb_uuid == Base.module_build_id(FooBar) fb_uuid1 = Base.module_build_id(FooBar1) @test fb_uuid != fb_uuid1 end open(joinpath(cachedir2, "FooBar1.ji"), "a") do f write(f, 0x076cac96) end @test Base.stale_cachefile(FooBar1_file, joinpath(cachedir2, "FooBar1.ji")) === true FooBar2_file = joinpath(dir, "FooBar2.jl") write(FooBar2_file, "module FooBar2\nerror(\"break me\")\nend\n") try Base.require(Main, :FooBar2) error("the \"break me\" test failed") catch exc exc isa Base.Precompilation.PkgPrecompileError || rethrow() occursin("Failed to precompile FooBar2", exc.msg) || rethrow() occursin("LoadError: break me", exc.msg) || rethrow() end FooBar3_file = joinpath(dir, "FooBar3.jl") FooBar3_inc = joinpath(dir, "FooBar3_inc.jl") write(FooBar3_inc, "x=1\n") for code = ["Core.eval(Base, :(x=1))", "Base.include(Base, \"FooBar3_inc.jl\")"] write(FooBar3_file, "module FooBar3\n$(code)\nend\n") try Base.require(Main, :FooBar3) catch exc exc isa Base.Precompilation.PkgPrecompileError || rethrow() occursin("Evaluation into the closed module `Base` breaks incremental compilation", exc.msg) || rethrow() end end FooBarT_file = joinpath(dir, "FooBarT.jl") write(FooBarT_file, "module FooBarT\nend\n") FooBarT1_file = joinpath(dir, "FooBarT1.jl") write(FooBarT1_file, "module FooBarT1\n using FooBarT\nend\n") FooBarT2_file = joinpath(dir, "FooBarT2.jl") write(FooBarT2_file, "module FooBarT2\n using FooBarT1\nend\n") Base.compilecache(Base.PkgId("FooBarT2")) write(FooBarT1_file, "module FooBarT1\nend\n") rm(FooBarT_file) @test Base.stale_cachefile(FooBarT2_file, joinpath(cachedir2, "FooBarT2.ji")) === true @test Base.require(Main, :FooBarT2) isa Module end end begin precompile_test_harness(false) do dir Foo_file = joinpath(dir, "$(Foo_module).jl") Foo2_file = joinpath(dir, "$(Foo2_module).jl") FooBase_file = joinpath(dir, "$(FooBase_module).jl") foo_file = joinpath(dir, "$(foo_incl_dep).jl") bar_file = joinpath(dir, "$(bar_incl_dep).jl") write(FooBase_file, "false && __precompile__(false)\nmodule $(FooBase_module)\n import Base: hash, >\n struct fmpz end\n struct typeA end\n >(x::fmpz, y::Int) = Base.cmp(x, y) > 0\n function hash(a::typeA, h::UInt)\n d = den(a)\n return h\n end\n abstract type AbstractAlgebraMap{A} end\n struct GAPGroupHomomorphism{A, B} <: AbstractAlgebraMap{GAPGroupHomomorphism{B, A}} end\n\n global process_state_calls::Int = 0\n const process_state = Base.OncePerProcess{typeof(getpid())}() do\n @assert (global process_state_calls += 1) == 1\n return getpid()\n end\n const mypid = process_state()\n @assert process_state_calls === 1\n process_state_calls = 0\n @assert process_state() === process_state()\n @assert process_state_calls === 0\n\n const empty_state = Base.OncePerProcess{Nothing}() do\n return nothing\n end\n @assert empty_state() === nothing\nend\n") write(Foo2_file, "module $(Foo2_module)\n export override, overridenc\n override(x::Integer) = 2\n override(x::AbstractFloat) = Float64(override(1))\n overridenc(x::Integer) = rand()+1\n overridenc(x::AbstractFloat) = Float64(overridenc(1))\nend\n") write(Foo_file, "module $(Foo_module)\n import $(FooBase_module), $(FooBase_module).typeA, $(FooBase_module).GAPGroupHomomorphism\n import $(Foo2_module): $(Foo2_module), override, overridenc\n import $(FooBase_module).hash\n import Test\n public foo, Bar\n module Inner\n import $(FooBase_module).hash\n using ..$(Foo_module)\n import ..$(Foo2_module)\n end\n\n struct typeB\n y::typeA\n end\n hash(x::typeB) = hash(x.y)\n\n # test that docs get reconnected\n @doc \"foo function\" foo(x) = x + 1\n include_dependency(\"$(foo_incl_dep).jl\")\n include_dependency(\"$(foo_incl_dep).jl\")\n module Bar\n public bar\n include_dependency(\"$(bar_incl_dep).jl\")\n end\n @doc \"Bar module\" Bar # this needs to define the META dictionary via eval\n @eval Bar @doc \"bar function\" bar(x) = x + 2\n\n # test for creation of some reasonably complicated type\n struct MyType{T} end\n const t17809s = Any[\n Tuple{\n Type{Ptr{MyType{i}}},\n Ptr{Type{MyType{i}}},\n Array{Ptr{MyType{MyType{:sym}()}}(0), 0},\n Val{Complex{Int}(1, 2)},\n Val{3},\n Val{nothing}}\n for i = 0:25]\n\n # test that types and methods get reconnected correctly\n # issue 16529 (adding a method to a type with no instances)\n (::Task)(::UInt8, ::UInt16, ::UInt32) = 2\n\n # issue 16471\n Base.sin(::UInt8, ::UInt16, ::UInt32; x = 52) = x\n const sinkw = Core.kwcall\n\n # issue 16908 (some complicated types and external method definitions)\n abstract type CategoricalPool{T, R <: Integer, V} end\n abstract type CategoricalValue{T, R <: Integer} end\n struct NominalPool{T, R <: Integer, V} <: CategoricalPool{T, R, V}\n index::Vector{T}\n invindex::Dict{T, R}\n order::Vector{R}\n ordered::Vector{T}\n valindex::Vector{V}\n end\n struct NominalValue{T, R <: Integer} <: CategoricalValue{T, R}\n level::R\n pool::NominalPool{T, R, NominalValue{T, R}}\n end\n struct OrdinalValue{T, R <: Integer} <: CategoricalValue{T, R}\n level::R\n pool::NominalPool{T, R, NominalValue{T, R}}\n end\n (::Union{Type{NominalValue}, Type{OrdinalValue}})() = 1\n (::Union{Type{NominalValue{T}}, Type{OrdinalValue{T}}})() where {T} = 2\n (::Type{Vector{NominalValue{T, R}}})() where {T, R} = 3\n (::Type{Vector{NominalValue{T, T}}})() where {T} = 4\n (::Type{Vector{NominalValue{Int, Int}}})() = 5\n\n # more tests for method signature involving a complicated type\n # issue 18343\n struct Pool18343{R, V}\n valindex::Vector{V}\n end\n struct Value18343{T, R}\n pool::Pool18343{R, Value18343{T, R}}\n end\n Base.convert(::Type{Some{S}}, ::Value18343{Some}) where {S} = 2\n Base.convert(::Type{Some{Value18343}}, ::Value18343{Some}) = 2\n Base.convert(::Type{Ref}, ::Value18343{T}) where {T} = 3\n\n const GAPType1 = GAPGroupHomomorphism{Nothing, Nothing}\n const GAPType2 = GAPGroupHomomorphism{1, 2}\n\n # issue #28297\n mutable struct Result\n result::Union{Int,Missing}\n end\n\n const x28297 = Result(missing)\n\n const d29936a = UnionAll(Dict.var, UnionAll(Dict.body.var, Dict.body.body))\n const d29936b = UnionAll(Dict.body.var, UnionAll(Dict.var, Dict.body.body))\n\n # issue #28998\n const x28998 = [missing, 2, missing, 6, missing,\n missing, missing, missing,\n missing, missing, missing,\n missing, missing, 6]\n\n let some_method = which(Base.include, (Module, String,))\n # global const some_method // FIXME: support for serializing a direct reference to an external Method not implemented\n global const some_linfo = Core.Compiler.specialize_method(some_method,\n Tuple{typeof(Base.include), Module, String}, Core.svec())\n end\n\n g() = override(1.0)\n Test.@test g() === 2.0 # compile this\n gnc() = overridenc(1.0)\n Test.@test 1 < gnc() < 5 # compile this\n\n abigfloat_f() = big\"12.34\"\n const abigfloat_x = big\"43.21\"\n abigint_f() = big\"123\"\n const abigint_x = big\"124\"\n\n # issue #51111\n abigfloat_to_f32() = Float32(big\"1.5\")\n\n # issue #31488\n _v31488 = Base.StringVector(2)\n resize!(_v31488, 0)\n const a31488 = fill(String(_v31488), 100)\n\n const ptr1 = Ptr{UInt8}(1)\n ptr2 = Ptr{UInt8}(1)\n const ptr3 = Ptr{UInt8}(-1)\n const layout1 = Ptr{Int8}[Ptr{Int8}(0), Ptr{Int8}(1), Ptr{Int8}(-1)]\n const layout2 = Any[Ptr{Int8}(0), Ptr{Int16}(1), Ptr{Int32}(-1)]\n const layout3 = collect(x.match for x in eachmatch(r\"..\", \"abcdefghijk\"))::Vector{SubString{String}}\n\n # create a backedge that includes Type{Union{}}, to ensure lookup can handle that\n call_bottom() = show(stdout, Union{})\n Core.Compiler.return_type(call_bottom, Tuple{})\n\n # check that @ccallable works from precompiled modules\n Base.@ccallable Cint f35014(x::Cint) = x+Cint(1)\n Base.@ccallable \"f35014_other\" f35014_2(x::Cint)::Cint = x+Cint(1)\n\n # check that Tasks work from serialized state\n ch1 = Channel(x -> nothing)\n ch2 = Channel(x -> (push!(x, 2); nothing), Inf)\n\n # check that Memory aliasing is respected\n a_vec_int = Int[]\n push!(a_vec_int, 1, 2)\n a_mat_int = reshape(a_vec_int, (1, 2))\n\n a_vec_any = Any[]\n push!(a_vec_any, 1, 2)\n a_mat_any = reshape(a_vec_any, (1, 2))\n\n a_vec_union = Union{Int,Nothing}[]\n push!(a_vec_union, 1, 2)\n a_mat_union = reshape(a_vec_union, (1, 2))\n\n a_vec_inline = Pair{Int,Any}[]\n push!(a_vec_inline, 1=>2, 3=>4)\n a_mat_inline = reshape(a_vec_inline, (1, 2))\n\n oid_vec_int = objectid(a_vec_int)\n oid_mat_int = objectid(a_mat_int)\n\n using $(FooBase_module): process_state, mypid as FooBase_pid, process_state_calls\n const mypid = process_state()\nend\n") touch(foo_file) touch(bar_file) @test __precompile__(false) === nothing Foo2 = Base.require(Main, Foo2_module) @eval ($Foo2).override(::Int) = begin 'a' end @eval ($Foo2).override(::Float32) = begin 'b' end @eval ($Foo2).overridenc(::Int) = begin rand() + 97.0 end @eval ($Foo2).overridenc(::Float32) = begin rand() + 100.0 end Foo = Base.require(Main, Foo_module) Base.invokelatest() do @test Foo.foo(17) == 18 @test Foo.Bar.bar(17) == 19 @test Foo.g() === 97.0 @test 96 < Foo.gnc() < 99 @test Foo.override(1.0) == Float64('a') @test Foo.override(1.0f0) == 'b' @test Foo.override(UInt(1)) == 2 @test 96 < Foo.overridenc(1.0) < 99 @test 99 < Foo.overridenc(1.0f0) < 102 @test 0 < Foo.overridenc(UInt(1)) < 3 @test Foo.abigfloat_f()::BigFloat == 12.34000000000000000000000000000000000000000000000000000000000000000000000000005 @test Foo.abigfloat_x::BigFloat + 21 == 64.21000000000000000000000000000000000000000000000000000000000000000000000000053 @test Foo.abigint_f()::BigInt == 123 @test Foo.abigint_x::BigInt + 1 == 125 @test Foo.abigfloat_to_f32() == 1.5f0 @test Foo.x28297.result === missing @test Foo.d29936a === Dict @test Foo.d29936b === (Dict{K, V} where {V, K}) @test Foo.x28998[var"end"] == 6 @test Foo.a31488 == fill("", 100) @test Foo.ptr1 === Ptr{UInt8}(1) @test Foo.ptr2 === Ptr{UInt8}(0) @test Foo.ptr3 === Ptr{UInt8}(-1) @test Foo.layout1::Vector{Ptr{Int8}} == Ptr{Int8}[Ptr{Int8}(0), Ptr{Int8}(0), Ptr{Int8}(-1)] @test Foo.layout2 == Any[Ptr{Int8}(0), Ptr{Int16}(0), Ptr{Int32}(-1)] @test typeof.(Foo.layout2) == [Ptr{Int8}, Ptr{Int16}, Ptr{Int32}] @test Foo.layout3 == ["ab", "cd", "ef", "gh", "ij"] @test !(isopen(Foo.ch1)) @test !(isopen(Foo.ch2)) @test !(isready(Foo.ch1)) @test isready(Foo.ch2) @test take!(Foo.ch2) === 2 @test !(isready(Foo.ch2)) @test Foo.process_state_calls === 0 @test Foo.process_state() === getpid() @test Foo.mypid !== getpid() @test Foo.FooBase_pid !== getpid() @test Foo.mypid !== Foo.FooBase_pid @test Foo.process_state_calls === 1 end let @test Foo.a_vec_int == Int[1, 2] @test Foo.a_mat_int == Int[1 2] Foo.a_mat_int[1, 2] = 3 @test Foo.a_vec_int[2] === 3 @test Foo.a_vec_any == Int[1, 2] @test Foo.a_mat_any == Int[1 2] Foo.a_mat_any[1, 2] = 3 @test Foo.a_vec_any[2] === 3 @test Foo.a_vec_union == Union{Int, Nothing}[1, 2] @test Foo.a_mat_union == Union{Int, Nothing}[1 2] Foo.a_mat_union[1, 2] = 3 @test Foo.a_vec_union[2] === 3 Foo.a_mat_union[1, 2] = nothing @test Foo.a_vec_union[2] === nothing @test Foo.a_vec_inline == Pair{Int, Any}[1 => 2, 3 => 4] @test Foo.a_mat_inline == Pair{Int, Any}[1 => 2 3 => 4] Foo.a_mat_inline[1, 2] = 5 => 6 @test Foo.a_vec_inline[2] === Pair{Int, Any}(5, 6) @test objectid(Foo.a_vec_int) === Foo.oid_vec_int @test objectid(Foo.a_mat_int) === Foo.oid_mat_int @test Foo.oid_vec_int !== Foo.oid_mat_int @test Base.object_build_id(Foo.a_vec_int) == Base.object_build_id(Foo.a_mat_int) @test Base.object_build_id(Foo) == Base.module_build_id(Foo) @test Base.object_build_id(Foo.a_vec_int) == Base.module_build_id(Foo) end cachedir = joinpath(dir, "compiled", "v$(VERSION.major).$(VERSION.minor)") cachedir2 = joinpath(dir2, "compiled", "v$(VERSION.major).$(VERSION.minor)") cachefile = joinpath(cachedir, "$(Foo_module).ji") @test isfile(cachefile) do_pkgimg = (Base.JLOptions()).use_pkgimages == 1 && (Base.JLOptions()).permalloc_pkgimg == 1 if do_pkgimg || (Base.JLOptions()).use_pkgimages == 0 if do_pkgimg ocachefile = Base.ocachefile_from_cachefile(cachefile)::String @test isfile(ocachefile) let foo_ptr = Libdl.dlopen(ocachefile::String, RTLD_NOLOAD) f35014_ptr = Libdl.dlsym(foo_ptr, :f35014) @test ccall(f35014_ptr, Int32, (Int32,), 3) == 4 f35014_other_ptr = Libdl.dlsym(foo_ptr, :f35014_other) @test ccall(f35014_other_ptr, Int32, (Int32,), 3) == 4 end else ocachefile = nothing end @test_logs (:warn, "Replacing module `$(Foo_module)`") begin m = Base._require_from_serialized(Base.PkgId(Foo), cachefile, ocachefile, Foo_file) @test m isa Module end end @test_throws MethodError Foo.foo(17) Base.invokelatest() do @test Foo.foo(17) == 18 @test Foo.Bar.bar(17) == 19 @test Foo.g() === 97.0 @test Foo.override(1.0) == Float64('a') @test Foo.override(1.0f0) == 'b' @test Foo.override(UInt(1)) == 2 @test string(Base.Docs.doc(Foo.foo)) == "foo function\n" @test string(Base.Docs.doc(Foo.Bar.bar)) == "bar function\n" @test string(Base.Docs.doc(Foo.Bar)) == "Bar module\n" (modules, (deps, _, requires), required_modules, _...) = Base.parse_cache_header(cachefile) discard_module = (mod_fl_mt->begin mod_fl_mt.filename end) @test modules == [Base.PkgId(Foo) => Base.module_build_id(Foo) % UInt64] @test map((x->begin x.filename end), deps) == [Foo_file, joinpath("@depot", foo_file), joinpath("@depot", bar_file)] @test requires == [Base.PkgId(Foo) => Base.PkgId(string(FooBase_module)), Base.PkgId(Foo) => Base.PkgId(Foo2), Base.PkgId(Foo) => Base.PkgId(Test), Base.PkgId(Foo) => Base.PkgId(string(FooBase_module))] srctxt = Base.read_dependency_src(cachefile, Foo_file) @test !(isempty(srctxt)) && srctxt == read(Foo_file, String) @test_throws ErrorException Base.read_dependency_src(cachefile, "/tmp/nonexistent.txt") @test_throws ErrorException Base.read_dependency_src(cachefile, joinpath(dir, foo_file)) (modules, deps1) = Base.cache_dependencies(cachefile) modules_ok = merge(Dict((let m = Base.PkgId(s) m => Base.module_build_id(Base.root_module(m)) end for s = ["Base", "Core", "Main", string(Foo2_module), string(FooBase_module)])), Dict((let m = Base.root_module(Base, s) Base.PkgId(m) => Base.module_build_id(m) end for s = [Symbol(x.name) for x = Base._sysimage_modules if !(x.name in ["Base", "Core", "Main"])])), Dict(Base.PkgId(Base.root_module(Base, :Test)) => Base.module_build_id(Base.root_module(Base, :Test))), Dict(Base.PkgId(Base.root_module(Base, :InteractiveUtils)) => Base.module_build_id(Base.root_module(Base, :InteractiveUtils))), Dict(Base.PkgId(Base.root_module(Base, :Logging)) => Base.module_build_id(Base.root_module(Base, :Logging))), Dict(Base.PkgId(Base.root_module(Base, :Random)) => Base.module_build_id(Base.root_module(Base, :Random))), Dict(Base.PkgId(Base.root_module(Base, :Serialization)) => Base.module_build_id(Base.root_module(Base, :Serialization))), Dict(Base.PkgId(Base.root_module(Base, :SHA)) => Base.module_build_id(Base.root_module(Base, :SHA))), Dict(Base.PkgId(Base.root_module(Base, :Markdown)) => Base.module_build_id(Base.root_module(Base, :Markdown))), Dict(Base.PkgId(Base.root_module(Base, :JuliaSyntaxHighlighting)) => Base.module_build_id(Base.root_module(Base, :JuliaSyntaxHighlighting))), Dict(Base.PkgId(Base.root_module(Base, :StyledStrings)) => Base.module_build_id(Base.root_module(Base, :StyledStrings))), Dict(Base.PkgId(Base.root_module(Base, :Base64)) => Base.module_build_id(Base.root_module(Base, :Base64)))) @test Dict(modules) == modules_ok @test discard_module.(deps) == deps1 (modules, (_, deps, requires), required_modules, _...) = Base.parse_cache_header(cachefile) @test map((x->begin x.filename end), deps) == [Foo_file] @test (current_task())(0x01, 0x4000, 0x30031234) == 2 @test sin(0x01, 0x4000, 0x30031234) == 52 @test sin(0x01, 0x4000, 0x30031234; x = 9142) == 9142 @test Foo.sinkw === Core.kwcall @test Foo.NominalValue() == 1 @test Foo.OrdinalValue() == 1 @test Foo.NominalValue{Int}() == 2 @test Foo.OrdinalValue{Int}() == 2 let T = Vector{Foo.NominalValue{Int}} @test T() isa T end @test Vector{Foo.NominalValue{Int32, Int64}}() == 3 @test Vector{Foo.NominalValue{UInt, UInt}}() == 4 @test Vector{Foo.NominalValue{Int, Int}}() == 5 @test all((i->begin Foo.t17809s[i + 1] === Tuple{Type{Ptr{Foo.MyType{i}}}, Ptr{Type{Foo.MyType{i}}}, Array{Ptr{Foo.MyType{Foo.MyType{:sym}()}}(0), 0}, Val{Complex{Int}(1, 2)}, Val{3}, Val{nothing}} end), 0:25) some_method = which(Base.include, (Module, String)) some_linfo = Core.Compiler.specialize_method(some_method, Tuple{typeof(Base.include), Module, String}, Core.svec()) @test Foo.some_linfo::Core.MethodInstance === some_linfo ft = Base.datatype_fieldtypes PV = (ft((Foo.Value18343{Some}).body))[1] VR = ((ft(PV))[1]).parameters[1] @test (ft(PV))[1] === Array{VR, 1} @test pointer_from_objref((ft(PV))[1]) === pointer_from_objref((ft((ft(((ft(PV))[1]).parameters[1]))[1]))[1]) @test PV === (ft(((ft(PV))[1]).parameters[1]))[1] @test pointer_from_objref(PV) === pointer_from_objref((ft(((ft(PV))[1]).parameters[1]))[1]) end Nest_module = :Nest4b3a94a1a081a8cb Nest_file = joinpath(dir, "$(Nest_module).jl") NestInner_file = joinpath(dir, "$(Nest_module)Inner.jl") NestInner2_file = joinpath(dir, "$(Nest_module)Inner2.jl") write(Nest_file, "module $(Nest_module)\ninclude(\"$(escape_string(NestInner_file))\")\nend\n") write(NestInner_file, "module NestInner\ninclude(\"$(escape_string(NestInner2_file))\")\nend\n") write(NestInner2_file, "f() = 22\n") Nest = Base.require(Main, Nest_module) cachefile = joinpath(cachedir, "$(Nest_module).ji") (modules, (deps, _, requires), required_modules, _...) = Base.parse_cache_header(cachefile) @test (last(deps)).modpath == ["NestInner"] UsesB_module = :UsesB4b3a94a1a081a8cb B_module = :UsesB4b3a94a1a081a8cb_B UsesB_file = joinpath(dir, "$(UsesB_module).jl") B_file = joinpath(dir, "$(B_module).jl") write(UsesB_file, "module $(UsesB_module)\nusing $(B_module)\nend\n") write(B_file, "module $(B_module)\nexport bfunc\nbfunc() = 33\nend\n") UsesB = Base.require(Main, UsesB_module) cachefile = joinpath(cachedir, "$(UsesB_module).ji") (modules, (deps, _, requires), required_modules, _...) = Base.parse_cache_header(cachefile) (id1, id2) = only(requires) @test (Base.pkgorigins[id1]).cachepath == cachefile @test (Base.pkgorigins[id2]).cachepath == joinpath(cachedir, "$(B_module).ji") Baz_file = joinpath(dir, "Baz.jl") write(Baz_file, "haskey(Base.loaded_modules, Base.PkgId(\"UseBaz\")) || __precompile__(false)\nmodule Baz\nbaz() = 1\nend\n") @test Base.compilecache(Base.PkgId("Baz")) == Base.PrecompilableError() OverwriteMethodError_file = joinpath(dir, "OverwriteMethodError.jl") write(OverwriteMethodError_file, "module OverwriteMethodError\n Base.:(+)(x::Bool, y::Bool) = false\nend\n") @test @test_warn("overwritten in module OverwriteMethodError", Base.compilecache(Base.PkgId("OverwriteMethodError"))) == Base.PrecompilableError() UseBaz_file = joinpath(dir, "UseBaz.jl") write(UseBaz_file, "module UseBaz\nbiz() = 1\n@assert haskey(Base.loaded_modules, Base.PkgId(\"UseBaz\"))\n@assert !haskey(Base.loaded_modules, Base.PkgId(\"Baz\"))\nusing Baz\n@assert haskey(Base.loaded_modules, Base.PkgId(\"Baz\"))\nbuz() = 2\nconst generating = ccall(:jl_generating_output, Cint, ())\nconst incremental = Base.JLOptions().incremental\nend\n") @test Base.compilecache(Base.PkgId("UseBaz")) == Base.PrecompilableError() @eval using UseBaz @test haskey(Base.loaded_modules, Base.PkgId("UseBaz")) @test haskey(Base.loaded_modules, Base.PkgId("Baz")) invokelatest() do @test UseBaz.biz() === 1 @test UseBaz.buz() === 2 @test UseBaz.generating == 0 @test UseBaz.incremental == 0 end @eval using Baz invokelatest() do @test Baz.baz() === 1 @test Baz === UseBaz.Baz end @test !(isfile("DoesNotExist.ji")) @test Base.stale_cachefile("", "DoesNotExist.ji") === true FooBar1_file = joinpath(dir, "FooBar1.jl") write(FooBar1_file, "module FooBar1\n using FooBar\nend\n") sleep(2) FooBar_file = joinpath(dir, "FooBar.jl") write(FooBar_file, "module FooBar\nend\n") (cachefile, _) = @test_logs((:debug, r"Precompiling FooBar"), min_level = Logging.Debug, match_mode = :any, Base.compilecache(Base.PkgId("FooBar"))) empty_prefs_hash = Base.get_preferences_hash(nothing, String[]) @test cachefile == Base.compilecache_path(Base.PkgId("FooBar"), empty_prefs_hash) @test isfile(joinpath(cachedir, "FooBar.ji")) Tsc = if Bool((Base.JLOptions()).use_pkgimages) Tuple{<:Vector, String, UInt128} else Tuple{<:Vector, Nothing, UInt128} end @test Base.stale_cachefile(FooBar_file, joinpath(cachedir, "FooBar.ji")) isa Tsc @test !(isdefined(Main, :FooBar)) @test !(isdefined(Main, :FooBar1)) relFooBar_file = joinpath(dir, "subfolder", "..", "FooBar.jl") @test Base.stale_cachefile(relFooBar_file, joinpath(cachedir, "FooBar.ji")) isa if Sys.iswindows() Tuple{<:Vector, String, UInt128} else Bool end mkdir(joinpath(dir, "subfolder")) @test Base.stale_cachefile(relFooBar_file, joinpath(cachedir, "FooBar.ji")) isa Tsc @eval using FooBar fb_uuid = invokelatest((()->begin Base.module_build_id(FooBar) end)) sleep(2) touch(FooBar_file) insert!(DEPOT_PATH, 1, dir2) @test Base.stale_cachefile(FooBar_file, joinpath(cachedir, "FooBar.ji")) isa Tsc @eval using FooBar1 @test !(isfile(joinpath(cachedir2, "FooBar.ji"))) @test !(isfile(joinpath(cachedir, "FooBar1.ji"))) @test isfile(joinpath(cachedir2, "FooBar1.ji")) @test Base.stale_cachefile(FooBar_file, joinpath(cachedir, "FooBar.ji")) isa Tsc @test Base.stale_cachefile(FooBar1_file, joinpath(cachedir2, "FooBar1.ji")) isa Tsc invokelatest() do @test fb_uuid == Base.module_build_id(FooBar) fb_uuid1 = Base.module_build_id(FooBar1) @test fb_uuid != fb_uuid1 end open(joinpath(cachedir2, "FooBar1.ji"), "a") do f write(f, 0x076cac96) end @test Base.stale_cachefile(FooBar1_file, joinpath(cachedir2, "FooBar1.ji")) === true FooBar2_file = joinpath(dir, "FooBar2.jl") write(FooBar2_file, "module FooBar2\nerror(\"break me\")\nend\n") try Base.require(Main, :FooBar2) error("the \"break me\" test failed") catch exc exc isa Base.Precompilation.PkgPrecompileError || rethrow() occursin("Failed to precompile FooBar2", exc.msg) || rethrow() occursin("LoadError: break me", exc.msg) || rethrow() end FooBar3_file = joinpath(dir, "FooBar3.jl") FooBar3_inc = joinpath(dir, "FooBar3_inc.jl") write(FooBar3_inc, "x=1\n") for code = ["Core.eval(Base, :(x=1))", "Base.include(Base, \"FooBar3_inc.jl\")"] write(FooBar3_file, "module FooBar3\n$(code)\nend\n") try Base.require(Main, :FooBar3) catch exc exc isa Base.Precompilation.PkgPrecompileError || rethrow() occursin("Evaluation into the closed module `Base` breaks incremental compilation", exc.msg) || rethrow() end end FooBarT_file = joinpath(dir, "FooBarT.jl") write(FooBarT_file, "module FooBarT\nend\n") FooBarT1_file = joinpath(dir, "FooBarT1.jl") write(FooBarT1_file, "module FooBarT1\n using FooBarT\nend\n") FooBarT2_file = joinpath(dir, "FooBarT2.jl") write(FooBarT2_file, "module FooBarT2\n using FooBarT1\nend\n") Base.compilecache(Base.PkgId("FooBarT2")) write(FooBarT1_file, "module FooBarT1\nend\n") rm(FooBarT_file) @test Base.stale_cachefile(FooBarT2_file, joinpath(cachedir2, "FooBarT2.ji")) === true @test Base.require(Main, :FooBarT2) isa Module end end (dir2,)->begin precompile_test_harness(false) do dir Foo_file = joinpath(dir, "$(Foo_module).jl") Foo2_file = joinpath(dir, "$(Foo2_module).jl") FooBase_file = joinpath(dir, "$(FooBase_module).jl") foo_file = joinpath(dir, "$(foo_incl_dep).jl") bar_file = joinpath(dir, "$(bar_incl_dep).jl") write(FooBase_file, "false && __precompile__(false)\nmodule $(FooBase_module)\n import Base: hash, >\n struct fmpz end\n struct typeA end\n >(x::fmpz, y::Int) = Base.cmp(x, y) > 0\n function hash(a::typeA, h::UInt)\n d = den(a)\n return h\n end\n abstract type AbstractAlgebraMap{A} end\n struct GAPGroupHomomorphism{A, B} <: AbstractAlgebraMap{GAPGroupHomomorphism{B, A}} end\n\n global process_state_calls::Int = 0\n const process_state = Base.OncePerProcess{typeof(getpid())}() do\n @assert (g PkgEval terminated after 220.67s: test log exceeded the size limit