Skip to content

Commit

Permalink
Merge branch 'main' into release-1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
lmiq committed Dec 18, 2024
2 parents 0954f86 + 1ae3e8d commit ec8e6ee
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ to other `ParsedShow` objects or to strings.
- `vector_simplify`: if `true`, only the first and last elements of arrays are kept
- `repl`: dictionary with custom replacements to be made before parsing

### Comparison arguments
### Comparison arguments for `isapprox`

The `isapprox` function comparing two `TestShowString` objects has the following keyword arguments:
The `isapprox` function comparing `ParsedShow` objects (between each other, or to strings) has the following keyword arguments:

- `f64`: function to compare two floats
- `i64`: function to compare two integers
- `path`: function to compare two paths
- `float_match`: function to compare two floats
- `int_match`: function to compare two integers
- `path_match`: function to compare two paths
- `assertion_error`: if `true`, throws an `AssertionError` if the comparison fails

### Example
Expand All @@ -60,7 +60,7 @@ Object with Int(1), /usr/bin/bash and [1.0, 3.141592653589793, 7.5, 1.4142135623
julia> parse_show(a) ≈ "Object with Int(1), /usr/bin/bash and [1.0, 3.1415, 7.5, 1.4142]"
true
julia> isapprox(parse_show(a), "Object with Int(1), /usr/bin/bash and [1.0, 3.1415, 7.5, 1.4142]"; f64 = (x,y) -> x == y, assertion_error=false)
julia> isapprox(parse_show(a), "Object with Int(1), /usr/bin/bash and [1.0, 3.1415, 7.5, 1.4142]"; float_match = (x,y) -> x == y, assertion_error=false)
false
```

Expand Down
26 changes: 13 additions & 13 deletions src/ShowMethodTesting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Object with Int(1), /usr/bin/bash and [1.0, 3.141592653589793, 7.5, 1.4142135623
julia> parse_show(a) ≈ "Object with Int(1), /usr/bin/bash and [1.0, 3.1415, 7.5, 1.4142]"
true
julia> isapprox(parse_show(a), "Object with Int(1), /usr/bin/bash and [1.0, 3.1415, 7.5, 1.4142]"; f64 = (x,y) -> x == y, assertion_error=false)
julia> isapprox(parse_show(a), "Object with Int(1), /usr/bin/bash and [1.0, 3.1415, 7.5, 1.4142]"; float_match = (x,y) -> x == y, assertion_error=false)
false
```
Expand All @@ -67,9 +67,9 @@ end

"""
isapprox(x::ParsedShow, y::ParsedShow
f64=(x1, x2) -> isapprox(x1, x2, rtol=1e-3),
i64=(x1, x2) -> x1 == x2,
path=(x1, x2) -> last(splitpath(x1)) == last(splitpath(x2)),
float_match=(x1, x2) -> isapprox(x1, x2, rtol=1e-3),
int_match=(x1, x2) -> x1 == x2,
path_match=(x1, x2) -> last(splitpath(x1)) == last(splitpath(x2)),
assertion_error=true,
)
isapprox(x::ParsedShow, y::String; kargs...) = isapprox(x, parse_show(y); kargs...)
Expand All @@ -81,18 +81,18 @@ Compare two `ParsedShow` objects, with custom comparison functions for floats, i
- `x`: first object to compare
- `y`: second object to compare
- `f64`: function to compare two floats
- `i64`: function to compare two integers
- `path`: function to compare two paths
- `float_match`: function to compare two floats
- `int_match`: function to compare two integers
- `path_match`: function to compare two paths
- `assertion_error`: if `true`, throws an `AssertionError` if the comparison fails
"""
function Base.isapprox(
x::ParsedShow,
y::ParsedShow;
f64=(x1, x2) -> isapprox(x1, x2, rtol=1e-3),
i64=(x1, x2) -> x1 == x2,
path=(x1, x2) -> last(splitpath(x1)) == last(splitpath(x2)),
float_match=(x1, x2) -> isapprox(x1, x2, rtol=1e-3),
int_match=(x1, x2) -> x1 == x2,
path_match=(x1, x2) -> last(splitpath(x1)) == last(splitpath(x2)),
assertion_error=true,
)
match(f, x1, x2) = begin
Expand All @@ -116,18 +116,18 @@ function Base.isapprox(
!all_match && break
value = tryparse(Int, xf) # test if xf can be interpreted as an integer
if !isnothing(value)
all_match = match(i64, value, tryparse(Int, yf))
all_match = match(int_match, value, tryparse(Int, yf))
continue
end
value = tryparse(Float64, xf) # test if xf can be interpreted as a float
if !isnothing(value)
all_match = match(f64, value, tryparse(Float64, yf))
all_match = match(float_match, value, tryparse(Float64, yf))
continue
end
xf = strip(xf, ',')
yf = strip(yf, ',')
if ispath(yf) || ispath(xf) # only compares the last entry for paths
all_match = match(path, last(splitpath(xf)), last(splitpath(yf)))
all_match = match(path_match, last(splitpath(xf)), last(splitpath(yf)))
continue
end
all_match = match(isequal, xf, yf)
Expand Down

2 comments on commit ec8e6ee

@lmiq
Copy link
Member Author

@lmiq lmiq commented on ec8e6ee Dec 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register

Release notes:

Update release.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request updated: JuliaRegistries/General/121621

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.0.0 -m "<description of version>" ec8e6ee41686a21354715b8c072c0af19814dfb4
git push origin v1.0.0

Please sign in to comment.