From a96fc9de7f954983843390a8e29d528936f5ab84 Mon Sep 17 00:00:00 2001 From: Heptazhou Date: Sun, 7 Apr 2024 04:59:19 +0000 Subject: [PATCH] Update --- .gitattributes | 2 ++ docs/Project.toml | 1 - docs/make.jl | 2 +- docs/src/api.md | 13 +++++++++++++ docs/src/index.md | 13 +++++++++++++ src/UUID4.jl | 28 +++++++++++++++++++++------- test/Project.toml | 1 - test/runtests.jl | 4 ++-- 8 files changed, 52 insertions(+), 12 deletions(-) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..c9a53f5 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ + +/docs/src/index.md linguist-generated diff --git a/docs/Project.toml b/docs/Project.toml index d0c1130..ec71834 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -1,5 +1,4 @@ [deps] Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" -Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/docs/make.jl b/docs/make.jl index 8e37b30..30c1232 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -5,6 +5,7 @@ DocMeta.setdocmeta!(UUID4, :DocTestSetup, quote #! format: noindent using OrderedCollections using UUID4 +using UUID4: Random end) @info "doctest" @@ -12,7 +13,6 @@ Documenter.doctest(UUID4, fix = true, manual = false) @info "makedocs" Documenter.makedocs( - doctest = false, format = Documenter.HTML(), modules = [UUID4], pages = ["Manual" => "index.md"], diff --git a/docs/src/api.md b/docs/src/api.md index a10c65c..9ddb57a 100644 --- a/docs/src/api.md +++ b/docs/src/api.md @@ -1,5 +1,18 @@ ## API reference ```@autodocs Modules = [UUID4] +Order = [:module] +``` + +## Types +```@autodocs +Modules = [UUID4] +Order = [:constant, :type] +``` + +## Functions +```@autodocs +Modules = [UUID4] +Order = [:function, :macro] ``` diff --git a/docs/src/index.md b/docs/src/index.md index 8a55678..42db6e3 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -17,5 +17,18 @@ help?> uuid ## API reference ```@autodocs Modules = [UUID4] +Order = [:module] +``` + +## Types +```@autodocs +Modules = [UUID4] +Order = [:constant, :type] +``` + +## Functions +```@autodocs +Modules = [UUID4] +Order = [:function, :macro] ``` diff --git a/src/UUID4.jl b/src/UUID4.jl index 71fb360..210ee66 100644 --- a/src/UUID4.jl +++ b/src/UUID4.jl @@ -29,39 +29,53 @@ export uuid_string export uuid_tryparse export uuid_version -export AbstractRNG, MersenneTwister, RandomDevice export UUID const Maybe{T} = Union{Nothing, T} const UUID = Base.UUID -using Random: AbstractRNG, MersenneTwister, RandomDevice +using Random: Random + +@doc " Maybe{T} -> Union{Nothing, T}" Maybe +@doc " UUID -> Base.UUID" UUID """ - uuid(rng::AbstractRNG = Random.RandomDevice()) -> UUID + uuid(rng::Random.AbstractRNG = Random.RandomDevice()) -> UUID Generate a version 4 (random or pseudo-random) universally unique identifier (UUID), as specified by [RFC 4122](https://tools.ietf.org/html/rfc4122). # Examples ```jldoctest -julia> rng = MersenneTwister(42); +julia> rng = Random.MersenneTwister(42); julia> uuid(rng) UUID("bc8f8f98-a497-45c4-817b-b034d1a24a0e") ``` """ -function uuid(rng::AbstractRNG = RandomDevice())::UUID +function uuid(rng::Random.AbstractRNG = Random.RandomDevice())::UUID id = rand(rng, UInt128) id &= 0xffffffffffff0fff3fffffffffffffff id |= 0x00000000000040008000000000000000 id |> UUID end -const uuid4 = uuid +@doc " uuid4 -> uuid" const uuid4 = uuid """ uuid_formats() -> Vector{Int} -Return all supported UUID string formats. +Return all $(length(UUID4.uuid_formats())) supported UUID string formats. + +```julia +# case-sensitive +22 # (base62) 22 +24 # (base62) 7-7-8 +# case-insensitive +25 # (base36) 25 +29 # (base36) 5-5-5-5-5 +32 # (base16) 32 +36 # (base16) 8-4-4-4-12 +39 # (base16) 4-4-4-4-4-4-4-4 +``` """ function uuid_formats()::Vector{Int} [ diff --git a/test/Project.toml b/test/Project.toml index d0c1130..ec71834 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -1,5 +1,4 @@ [deps] Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" -Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/test/runtests.jl b/test/runtests.jl index 9d7bbb4..36c875e 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -14,8 +14,8 @@ # along with this program. If not, see . using OrderedCollections: LittleDict, OrderedDict -using Random: Random using Test, UUID4 +using UUID4: Random parse(Bool, get(ENV, "CI", "0")) || cd(@__DIR__) do cp("./Project.toml", "../docs/Project.toml", force = true) @@ -37,7 +37,7 @@ u4 = uuid4() @test 4 == uuid_version(u4 |> string |> s -> replace(s, "-" => "")) @test u4 == UUID(string(u4)) == UUID(GenericString(string(u4))) @test u4 == UUID(UInt128(u4)) -@test uuid4(MersenneTwister(0)) == uuid4(MersenneTwister(0)) +@test uuid4(Random.MersenneTwister(0)) == uuid4(Random.MersenneTwister(0)) @test_throws ArgumentError UUID("550e8400e29b-41d4-a716-446655440000") @test_throws ArgumentError UUID("550e8400e29b-41d4-a716-44665544000098") @test_throws ArgumentError UUID("z50e8400-e29b-41d4-a716-446655440000")