-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
a bunch of random doctests #20608
a bunch of random doctests #20608
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -21,6 +21,23 @@ Returns a new write-only I/O stream, which converts any bytes written to it into | |||
base64-encoded ASCII bytes written to `ostream`. | ||||
Calling [`close`](@ref) on the `Base64EncodePipe` stream | ||||
is necessary to complete the encoding (but does not close `ostream`). | ||||
|
||||
```jldoctest | ||||
julia> io = IOBuffer(); | ||||
|
||||
julia> iob64_encode = Base64EncodePipe(io); | ||||
|
||||
julia> write(iob64_encode, "Hello!") | ||||
6 | ||||
|
||||
julia> close(iob64_encode); | ||||
|
||||
julia> str = String(take!(io)) | ||||
"SGVsbG8h" | ||||
|
||||
julia> String(base64decode(str)) | ||||
"Hello!" | ||||
``` | ||||
""" | ||||
mutable struct Base64EncodePipe <: IO | ||||
io::IO | ||||
|
@@ -171,6 +188,8 @@ Given a [`write`](@ref)-like function `writefunc`, which takes an I/O stream as | |||
string, and returns the string. `base64encode(args...)` is equivalent to `base64encode(write, args...)`: | ||||
it converts its arguments into bytes using the standard [`write`](@ref) functions and returns the | ||||
base64-encoded string. | ||||
|
||||
See also [`base64decode`](@ref). | ||||
""" | ||||
function base64encode(f::Function, args...) | ||||
s = IOBuffer() | ||||
|
@@ -187,6 +206,20 @@ base64encode(x...) = base64encode(write, x...) | |||
Base64DecodePipe(istream) | ||||
|
||||
Returns a new read-only I/O stream, which decodes base64-encoded data read from `istream`. | ||||
|
||||
```jldoctest | ||||
julia> io = IOBuffer(); | ||||
|
||||
julia> iob64_decode = Base64DecodePipe(io); | ||||
|
||||
julia> write(io, "SGVsbG8h") | ||||
0x0000000000000008 | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. strange that the return type is inconsistent for write There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it? Inconsistent with what? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. write on the Base64EncodePipe above returns signed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, interesting. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could make this an Line 325 in 769d37b
|
||||
|
||||
julia> seekstart(io); | ||||
|
||||
julia> String(read(iob64_decode)) | ||||
"Hello!" | ||||
``` | ||||
""" | ||||
mutable struct Base64DecodePipe <: IO | ||||
io::IO | ||||
|
@@ -225,6 +258,22 @@ close(b::Base64DecodePipe) = nothing | |||
base64decode(string) | ||||
|
||||
Decodes the base64-encoded `string` and returns a `Vector{UInt8}` of the decoded bytes. | ||||
|
||||
See also [`base64encode`](@ref) | ||||
|
||||
```jldoctest | ||||
julia> b = base64decode("SGVsbG8h") | ||||
6-element Array{UInt8,1}: | ||||
0x48 | ||||
0x65 | ||||
0x6c | ||||
0x6c | ||||
0x6f | ||||
0x21 | ||||
|
||||
julia> String(b) | ||||
"Hello!" | ||||
``` | ||||
""" | ||||
function base64decode(s) | ||||
b = IOBuffer(s) | ||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -215,6 +215,7 @@ end | |
Eliminates array bounds checking within expressions. | ||
|
||
In the example below the bound check of array A is skipped to improve performance. | ||
|
||
```julia | ||
function sum(A::AbstractArray) | ||
r = zero(eltype(A)) | ||
|
@@ -224,6 +225,7 @@ function sum(A::AbstractArray) | |
return r | ||
end | ||
``` | ||
|
||
!!! Warning | ||
|
||
Using `@inbounds` may return incorrect results/crashes/corruption | ||
|
@@ -281,6 +283,25 @@ getindex(v::SimpleVector, I::AbstractArray) = Core.svec(Any[ v[i] for i in I ].. | |
|
||
Tests whether the given array has a value associated with index `i`. Returns `false` | ||
if the index is out of bounds, or has an undefined reference. | ||
|
||
```jldoctest | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we want to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it bad style with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think |
||
julia> isassigned(rand(3, 3), 5) | ||
true | ||
|
||
julia> isassigned(rand(3, 3), 3 * 3 + 1) | ||
false | ||
|
||
julia> mutable struct Foo end | ||
|
||
julia> v = similar(rand(3), Foo) | ||
3-element Array{Foo,1}: | ||
#undef | ||
#undef | ||
#undef | ||
|
||
julia> isassigned(v, 1) | ||
false | ||
``` | ||
""" | ||
function isassigned end | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will we always get the same (tiny) numbers for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it will depend on uninitialized memory but it's a
```julia
block, not a```jldoctest