-
Notifications
You must be signed in to change notification settings - Fork 3
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 Serializable #6
Merged
+513
−5
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0991900
attempt to add serializable annotations
danini-the-panini e283df0
made some progress
danini-the-panini 646f627
it's working!
danini-the-panini 5fa44cc
add unwrap children and dash_vals
danini-the-panini 45dcedf
remove global monkey patches
danini-the-panini 0d1689d
add more unwrap serializable options
danini-the-panini File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
require "../spec_helper" | ||
|
||
class TestChild | ||
include KDL::Serializable | ||
|
||
@[KDL::Argument] | ||
property value : String | ||
end | ||
|
||
class TestNode | ||
include KDL::Serializable | ||
|
||
@[KDL::Argument] | ||
property first : String | ||
|
||
@[KDL::Argument] | ||
property second : Bool | ||
|
||
@[KDL::Arguments] | ||
property numbers : Array(UInt32) | ||
|
||
@[KDL::Property] | ||
property foo : String | ||
|
||
@[KDL::Property(name: "bardle")] | ||
property bar : String | ||
|
||
@[KDL::Properties] | ||
property map : Hash(String, String) | ||
|
||
@[KDL::Child(unwrap: "argument")] | ||
property arg : String | ||
|
||
@[KDL::Child(unwrap: "arguments")] | ||
property args : Array(String) | ||
|
||
@[KDL::Child(unwrap: "properties")] | ||
property props : Hash(String, String) | ||
|
||
@[KDL::Child(name: "feature", unwrap: "argument")] | ||
property feature_name : String | ||
|
||
@[KDL::Child(name: "feature", unwrap: "property", property_name: "enabled")] | ||
property feature_enabled : Bool | ||
|
||
@[KDL::Child(name: "feature", unwrap: "property", property_name: "option")] | ||
property feature_option : UInt32 | ||
|
||
@[KDL::Child(unwrap: "dash_vals")] | ||
property dashies : Array(String) | ||
|
||
@[KDL::Child] | ||
property norf : TestChild | ||
|
||
@[KDL::Children(name: "thing")] | ||
property things : Array(TestChild) | ||
|
||
@[KDL::Child(unwrap: "children")] | ||
property thangs : Array(TestChild) | ||
|
||
@[KDL::Children(name: "path", unwrap: "argument")] | ||
property paths : Array(String) | ||
end | ||
|
||
describe KDL::Serializable do | ||
it "serializes documents" do | ||
doc = KDL.parse <<-KDL | ||
TestNode "arg1" #true 1 22 333 foo="a" bardle="b" baz="c" qux="d" { | ||
norf wat | ||
thing foo | ||
thing bar | ||
thing baz | ||
path "some/path" | ||
path "some/other/path" | ||
arg arg2 | ||
args x y z | ||
props a=x b=y c=z | ||
feature florp enabled=#true option=42 | ||
dashies { | ||
- Lorem | ||
- Ipsum | ||
} | ||
thangs { | ||
- qux | ||
- norf | ||
} | ||
} | ||
KDL | ||
|
||
obj = TestNode.from_kdl(doc.nodes[0]) | ||
obj.first.should eq "arg1" | ||
obj.second.should eq true | ||
obj.numbers.should eq [1, 22, 333] | ||
obj.foo.should eq "a" | ||
obj.bar.should eq "b" | ||
obj.map.should eq({ "baz" => "c", "qux" => "d" }) | ||
obj.arg.should eq "arg2" | ||
obj.args.should eq ["x", "y", "z"] | ||
obj.props.should eq({ "a" => "x", "b" => "y", "c" => "z" }) | ||
obj.feature_name.should eq("florp") | ||
obj.feature_enabled.should eq(true) | ||
obj.feature_option.should eq(42_u64) | ||
obj.dashies.should eq(["Lorem", "Ipsum"]) | ||
obj.norf.value.should eq "wat" | ||
obj.things.size.should eq 3 | ||
obj.things[0].value.should eq "foo" | ||
obj.things[1].value.should eq "bar" | ||
obj.things[2].value.should eq "baz" | ||
obj.thangs.size.should eq 2 | ||
obj.thangs[0].value.should eq "qux" | ||
obj.thangs[1].value.should eq "norf" | ||
obj.paths.should eq ["some/path", "some/other/path"] | ||
|
||
KDL::Document.new([obj.to_kdl]).should eq doc | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This syntax is quite common, e.g.:
Having to call
#value
on it is a bit cumbersome. Directly newing upArray(String)
for such cases would be nicer. This is related to my other comment about arrays inserializable.cr
:D