Skip to content

Commit

Permalink
Add README examples test suite for Chevrons
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Doris committed Jan 31, 2025
1 parent eff1ae9 commit b323e3f
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions test/integration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,59 @@ end
@map({number_of_children = __.children, __.age})() >> DataFrame()
) == Data.df1b
end

@testitem "README examples" begin
using DataFrames, TidierData, Test

@testset "Basic DataFrame example" begin
df = DataFrame(
name = ["John", "Sally", "Roger"],
age = [54, 34, 79],
children = [0, 2, 4],
)
result = @chevrons df >> @filter(age > 40) >> @select(num_children = children, age)
@test size(result) == (2, 2)
@test result.age == [54, 79]
@test result.num_children == [0, 4]
end

@testset "Basic array manipulation" begin
result = @chevrons Int[] >> push!(5, 2, 4, 3, 1) >> sort!()
@test result == [1, 2, 3, 4, 5]
end

@testset "Filter with isodd" begin
result = @chevrons [5, 2, 4, 3, 1] >> filter!(isodd, _)
@test result == [5, 3, 1]
end

@testset "Filter with expression involving _" begin
result = @chevrons [5, 2, 4, 3, 1] >> filter!(isodd, _ .+ 10)
@test result == [15, 13, 11]
end

@testset "Side effects with >>>" begin
x = 0
result = @chevrons 10 >> (_ * 2) >>> (x = _) >> (x^2 - _)
@test result == 380
@test x == 20
end

@testset "Array mutation with >>>" begin
arr = [5, 2, 4, 3, 1]
result = @chevrons arr >>> popat!(4)
@test result == arr # >>> returns the original array
@test arr == [5, 2, 4, 1] # verify mutation worked
end

@testset "Backwards piping with <<" begin
mktempdir() do dir
path = joinpath(dir, "test.txt")
write(path, "ignore this line\nkeep this line!")
result = @chevrons (
path >> open() << (io -> io >>> readline() >> read(String)) >> uppercase()
)
@test result == "KEEP THIS LINE!"
end
end
end

2 comments on commit b323e3f

@cjdoris
Copy link
Owner

Choose a reason for hiding this comment

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

@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 created: JuliaRegistries/General/124136

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

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>" b323e3febbacb29b269265aeaf1677d61685c4f2
git push origin v1.0.0

Please sign in to comment.