Repository: JuliaLang/julia
File: stdlib/REPL/test/replcompletions.jl (Julia)

Code before:
for i in 1:498
    @eval g54131(::Val{$i}) = i
end
g54131(::Val{499}; kwarg=true) = 499*kwarg
struct F54131; end
Base.getproperty(::F54131, ::Symbol) = Any[cos, sin, g54131][rand(1:3)]
f54131 = F54131()
@testset "performance of kwarg completion with large method tables" begin
    # The goal here is to simply ensure we aren't hitting catestrophically bad
    # behaviors when shift isn't pressed. The difference between good and bad
    # is on the order of tens of milliseconds vs tens of seconds; using 1 sec as
    # a very rough canary that is hopefully robust even in the noisy CI coalmines
    s = "g54131(kwa"
    a, b, c = completions(s, lastindex(s), @__MODULE__, #= shift =# false)
    @test REPLCompletions.KeywordArgumentCompletion("kwarg") in a
    @test (@elapsed completions(s, lastindex(s), @__MODULE__, false)) < 1

    s = "f54131.x("
    a, b, c = completions(s, lastindex(s), @__MODULE__, false)
    @test only(a) isa REPLCompletions.TextCompletion
    @test (@elapsed completions(s, lastindex(s), @__MODULE__, false)) < 1

    s = "f54131.x(kwa"
    a, b, c = completions(s, lastindex(s), @__MODULE__, false)
    @test REPLCompletions.KeywordArgumentCompletion("kwarg") in a
    @test (@elapsed completions(s, lastindex(s), @__MODULE__, false)) < 1
end

@kwdef struct T59244
    asdf = 1
    qwer = 2
end
@kwdef struct S59244{T}
    asdf::T = 1
    qwer::T = 2
end
@testset "kwarg completion of types" begin
    s = "T59244(as"
    a, b, c = completions(s, lastindex(s), @__MODULE__, #= shift =# false)
    @test REPLCompletions.KeywordArgumentCompletion("asdf") in a

    s = "T59244(; qw"
    a, b, c = completions(s, lastindex(s), @__MODULE__, #= shift =# false)
    @test REPLCompletions.KeywordArgumentCompletion("qwer") in a
    @test REPLCompletions.KeywordArgumentCompletion("qwer") == only(a)

    s = "S59244(as"
    a, b, c = completions(s, lastindex(s), @__MODULE__, #= shift =# false)
    @test REPLCompletions.KeywordArgumentCompletion("asdf") in a

    s = "S59244(; qw"

Review comment (bug):
Testing elapsed time on CI to 1 second precision is not okay (it makes CI and debugging unreliable)
```suggestion
    @test (@elapsed completions(s, lastindex(s), @__MODULE__, false)) < 100
```

Code after:
for i in 1:498
    @eval g54131(::Val{$i}) = i
end
g54131(::Val{499}; kwarg=true) = 499*kwarg
struct F54131; end
Base.getproperty(::F54131, ::Symbol) = Any[cos, sin, g54131][rand(1:3)]
f54131 = F54131()
@testset "performance of kwarg completion with large method tables" begin
    # The goal here is to simply ensure we aren't hitting catestrophically bad
    # behaviors when shift isn't pressed. The difference between good and bad
    # is on the order of tens of milliseconds vs tens of seconds; using 1 sec as
    # a very rough canary that is hopefully robust even in the noisy CI coalmines
    s = "g54131(kwa"
    a, b, c = completions(s, lastindex(s), @__MODULE__, #= shift =# false)
    @test REPLCompletions.KeywordArgumentCompletion("kwarg") in a
    @test (@elapsed completions(s, lastindex(s), @__MODULE__, false)) < 1

    s = "f54131.x("
    a, b, c = completions(s, lastindex(s), @__MODULE__, false)
    @test only(a) isa REPLCompletions.TextCompletion
    @test (@elapsed completions(s, lastindex(s), @__MODULE__, false)) < 1

    s = "f54131.x(kwa"
    a, b, c = completions(s, lastindex(s), @__MODULE__, false)
    @test REPLCompletions.KeywordArgumentCompletion("kwarg") in a
    @test (@elapsed completions(s, lastindex(s), @__MODULE__, false)) < 100
end

@kwdef struct T59244
    asdf = 1
    qwer = 2
end
@kwdef struct S59244{T}
    asdf::T = 1
    qwer::T = 2
end
@testset "kwarg completion of types" begin
    s = "T59244(as"
    a, b, c = completions(s, lastindex(s), @__MODULE__, #= shift =# false)
    @test REPLCompletions.KeywordArgumentCompletion("asdf") in a

    s = "T59244(; qw"
    a, b, c = completions(s, lastindex(s), @__MODULE__, #= shift =# false)
    @test REPLCompletions.KeywordArgumentCompletion("qwer") in a
    @test REPLCompletions.KeywordArgumentCompletion("qwer") == only(a)

    s = "S59244(as"
    a, b, c = completions(s, lastindex(s), @__MODULE__, #= shift =# false)
    @test REPLCompletions.KeywordArgumentCompletion("asdf") in a

    s = "S59244(; qw"