Skip to content
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

Add test and followup for StyledStringsExt #302

Merged
merged 1 commit into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ StyledStringsExt = "StyledStrings"

[compat]
FixedPointNumbers = "0.5, 0.6, 0.7, 0.8"
StyledStrings = "1"
# StyledStrings = "1" # FIXME: workaround for unregistered StyledStrings
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This should be fixed in the close future, but currently StyledStrings is unregistered and it should be v1 for the time being.
We are touching the internals of StyledStrings, so we run the risk of incompatibility. And that can't be prevented by the "1" cap anyway.
(In other words, if we follow the principle, we need to specify the patch version here.)

Copy link
Contributor

Choose a reason for hiding this comment

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

We are touching the internals of StyledStrings, so we run the risk of incompatibility

Just FYI, SimpleColor is part of the public API in the 1.11 stdlib version, so the conversion implemented here shouldn't break in any 1.x version of StyledStrings.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

What constitutes a breaking change is ambiguous. If SimpleColor added a feature to have an alpha component, it would not break the code, but it would go against the user's intuition.
That is just an example. StyledStrings is community owned, although you are the lead developer. I don't believe anything bad will happen, but there is no guarantee how it will turn out.
For example, CI could cease to function effectively even though no one has done anything wrong.

julia = "1"

[extras]
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" # FIXME: workaround for unregistered StyledStrings
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Documenter", "Test"]
test = ["Documenter", "Pkg", "Test"]
1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[deps]
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" # FIXME: workaround for unregistered StyledStrings
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
24 changes: 24 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@

# FIXME: Once StyledStrings v1 is registered, remove the following and the `Pkg` dependency
if isdefined(Base, :get_extension)
import Pkg
if VERSION < v"1.11"
Pkg.add(url="https://github.com/JuliaLang/StyledStrings.jl", rev="julia1-compat")
Copy link
Collaborator Author

@kimikage kimikage Apr 25, 2024

Choose a reason for hiding this comment

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

I don't know how long julia1-compat remains in effect, but it is more practical than main for now.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't anticipate deleting the branch at any point, it will just become abandoned at some stage.

else
Pkg.add("StyledStrings")
end
end

using ColorTypes
using ColorTypes.FixedPointNumbers
using Test
Expand All @@ -7,6 +18,19 @@ using Test
using Documenter
doctest(ColorTypes, manual = false)

@testset "StyledStringsExt" begin
if isdefined(Base, :get_extension)
import StyledStrings
try
simplecolor = convert(StyledStrings.SimpleColor, ARGB(1, 0.6, 0, 0.4))
@test simplecolor === StyledStrings.SimpleColor(0xff, 0x99, 0x00)
catch
@test_broken convert(StyledStrings.SimpleColor, ARGB(1, 0.6, 0, 0.4))
end
@test_throws Exception convert(StyledStrings.SimpleColor, HSV(0, 0, 0))
end
end

# if the test below fails, please extend the list of types at the call to
# make_alpha in types.jl (this is the price of making that list explicit)
ctypes = union(setdiff(ColorTypes.parametric3, (XRGB, RGBX)), (Gray,))
Expand Down
Loading