Skip to content

Commit

Permalink
Fixed expected output in to_csv test (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
gryumov authored Sep 24, 2024
1 parent 4914e83 commit 91d4ccd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "BoundTypes"
uuid = "ff833f9a-10fd-491c-ad5c-961b556a6c53"
version = "1.0.2"
version = "1.0.3"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Expand Down
54 changes: 27 additions & 27 deletions test/serde_usage.jl
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@
"""

@test to_csv([user]) == """
account_creation_date,age,bio,email,height_in_cm,is_email_verified,password,subscription_end_date,username,weight_in_kg
2023-01-15T14:22:00,25,Just a simple bio.,[email protected],175.5,true,Abc123!@#Def,2030-01-15T00:00:00,user123_,70.0
username,password,email,age,bio,height_in_cm,weight_in_kg,account_creation_date,subscription_end_date,is_email_verified
user123_,Abc123!@#Def,[email protected],25,Just a simple bio.,175.5,70.0,2023-01-15T14:22:00,2030-01-15T00:00:00,true
"""

@test to_query(user) == """
Expand Down Expand Up @@ -220,108 +220,108 @@
a::StringMaxLength{StringMinLength{StringLowerCase{String},10},20}
b::Float64
end

obj = StringAndFloat("1234567890a", 1)

json = "{\"a\":\"1234567890a\",\"b\":1.0}"
toml = "a = \"1234567890a\"\nb = 1.0\n"
csv = "a,b\n1234567890a,1.0\n"
query = "a=1234567890a&b=1.0"
xml = "<xml a=\"1234567890a\" b=\"1.0\"/>\n"
yaml = "a: \"1234567890a\"\nb: 1.0\n"

@test to_json(obj) == json
@test to_toml(obj) == toml
@test to_csv([obj]) == csv
@test to_query(obj) == query
@test to_xml(obj) == xml
@test to_yaml(obj) == yaml

@test Serde.deser_json(StringAndFloat, json) == obj
@test Serde.deser_toml(StringAndFloat, toml) == obj
@test Serde.deser_csv(StringAndFloat, csv)[1] == obj
@test Serde.deser_query(StringAndFloat, query) == obj
@test Serde.deser_xml(StringAndFloat, xml) == obj
@test Serde.deser_yaml(StringAndFloat, yaml) == obj

struct StringAndNumber
a::StringMaxLength{StringMinLength{StringLowerCase{String},10},20}
b::NumberPositive{Float64}
end

obj = StringAndNumber("1234567890a", 1)

json = "{\"a\":\"1234567890a\",\"b\":1.0}"
toml = "a = \"1234567890a\"\nb = 1.0\n"
csv = "a,b\n1234567890a,1.0\n"
query = "a=1234567890a&b=1.0"
xml = "<xml a=\"1234567890a\" b=\"1.0\"/>\n"
yaml = "a: \"1234567890a\"\nb: 1.0\n"

@test to_json(obj) == json
@test to_toml(obj) == toml
@test to_csv([obj]) == csv
@test to_query(obj) == query
@test to_xml(obj) == xml
@test to_yaml(obj) == yaml

@test Serde.deser_json(StringAndNumber, json) == obj
@test Serde.deser_toml(StringAndNumber, toml) == obj
@test Serde.deser_csv(StringAndNumber, csv)[1] == obj
@test Serde.deser_query(StringAndNumber, query) == obj
@test Serde.deser_xml(StringAndNumber, xml) == obj
@test Serde.deser_yaml(StringAndNumber, yaml) == obj

struct StringsAndNumber
a::StringMaxLength{StringMinLength{StringLowerCase{String},10},20}
b::StringMinLength{String,5}
c::NumberPositive{Float64}
end

obj = StringsAndNumber("1234567890a", "asdfdasf", 1.0)

json = "{\"a\":\"1234567890a\",\"b\":\"asdfdasf\",\"c\":1.0}"
toml = "a = \"1234567890a\"\nb = \"asdfdasf\"\nc = 1.0\n"
csv = "a,b,c\n1234567890a,asdfdasf,1.0\n"
query = "a=1234567890a&b=asdfdasf&c=1.0"
xml = "<xml a=\"1234567890a\" b=\"asdfdasf\" c=\"1.0\"/>\n"
yaml = "a: \"1234567890a\"\nb: \"asdfdasf\"\nc: 1.0\n"

@test to_json(obj) == json
@test to_toml(obj) == toml
@test to_csv([obj]) == csv
@test to_query(obj) == query
@test to_xml(obj) == xml
@test to_yaml(obj) == yaml

@test Serde.deser_json(StringsAndNumber, json) == obj
@test Serde.deser_toml(StringsAndNumber, toml) == obj
@test Serde.deser_csv(StringsAndNumber, csv)[1] == obj
@test Serde.deser_query(StringsAndNumber, query) == obj
@test Serde.deser_xml(StringsAndNumber, xml) == obj
@test Serde.deser_yaml(StringsAndNumber, yaml) == obj

struct TwoStrings
a::StringMaxLength{StringMinLength{StringLowerCase{String},10},20}
b::StringMinLength{String,5}
end

obj = TwoStrings("1234567890a", "asdfdasf")

json = "{\"a\":\"1234567890a\",\"b\":\"asdfdasf\"}"
toml = "a = \"1234567890a\"\nb = \"asdfdasf\"\n"
csv = "a,b\n1234567890a,asdfdasf\n"
query = "a=1234567890a&b=asdfdasf"
xml = "<xml a=\"1234567890a\" b=\"asdfdasf\"/>\n"
yaml = "a: \"1234567890a\"\nb: \"asdfdasf\"\n"

@test to_json(obj) == json
@test to_toml(obj) == toml
@test to_csv([obj]) == csv
@test to_query(obj) == query
@test to_xml(obj) == xml
@test to_yaml(obj) == yaml

@test Serde.deser_json(TwoStrings, json) == obj
@test Serde.deser_toml(TwoStrings, toml) == obj
@test Serde.deser_csv(TwoStrings, csv)[1] == obj
Expand All @@ -334,31 +334,31 @@
b::TimeBefore{TimeAfter{Date,Date(2020)},Date(2025)}
c::TimeInterval{DateTime,DateTime(2020),<,<,DateTime(2025)}
end

Serde.deser(::Type{BasicTimeTypes}, ::Type{Time}, x::String) = Time(x)
Serde.deser(::Type{BasicTimeTypes}, ::Type{Date}, x::String) = Date(x)
Serde.deser(::Type{BasicTimeTypes}, ::Type{DateTime}, x::String) = DateTime(x)

function Serde.deser(::Type{BasicTimeTypes}, ::Type{T}, x::String) where {T<:BoundTime}
return T(Serde.deser(BasicTimeTypes, bound_type(T), x))
end

obj = BasicTimeTypes(Time(15), Date(2023), DateTime(2024))

json = "{\"a\":\"15:00:00\",\"b\":\"2023-01-01\",\"c\":\"2024-01-01T00:00:00\"}"
toml = "a = \"15:00:00\"\nb = \"2023-01-01\"\nc = \"2024-01-01T00:00:00\"\n"
csv = "a,b,c\n15:00:00,2023-01-01,2024-01-01T00:00:00\n"
query = "a=15%3A00%3A00&b=2023-01-01&c=2024-01-01T00%3A00%3A00"
xml = "<xml a=\"15:00:00\" b=\"2023-01-01\" c=\"2024-01-01T00:00:00\"/>\n"
yaml = "a: \"15:00:00\"\nb: \"2023-01-01\"\nc: \"2024-01-01T00:00:00\"\n"

@test to_json(obj) == json
@test to_toml(obj) == toml
@test to_csv([obj]) == csv
@test to_query(obj) == query
@test to_xml(obj) == xml
@test to_yaml(obj) == yaml

@test Serde.deser_json(BasicTimeTypes, json) == obj
@test Serde.deser_toml(BasicTimeTypes, toml) == obj
@test Serde.deser_csv(BasicTimeTypes, csv)[1] == obj
Expand Down

2 comments on commit 91d4ccd

@gryumov
Copy link
Member Author

Choose a reason for hiding this comment

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

@JuliaRegistrator register()

Release notes:

  • Fixed expected output in to_csv test

@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/115807

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.3 -m "<description of version>" 91d4ccd154704a1466b65e2deb828a9e4442f75f
git push origin v1.0.3

Please sign in to comment.