Skip to content

Commit

Permalink
Serializable, remove version conditions (#6209)
Browse files Browse the repository at this point in the history
  • Loading branch information
kostya authored and Serdar Dogruyol committed Jun 19, 2018
1 parent 8959b54 commit 5c22fb3
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 30 deletions.
27 changes: 16 additions & 11 deletions spec/std/json/serializable_spec.cr
@@ -1,5 +1,3 @@
{% if Crystal::VERSION.includes?("0.24.2+") || Crystal::VERSION == "0.25.0" %}

require "spec"
require "json"
require "big"
Expand All @@ -14,12 +12,14 @@ end

class JSONAttrEmptyClass
include JSON::Serializable

def initialize; end
end

class JSONAttrEmptyClassWithUnmapped
include JSON::Serializable
include JSON::Serializable::Unmapped

def initialize; end
end

Expand Down Expand Up @@ -271,13 +271,20 @@ class JSONAttrModuleTest
property foo = 15

def initialize; end
def to_tuple; {@moo, @foo}; end

def to_tuple
{@moo, @foo}
end
end

class JSONAttrModuleTest2 < JSONAttrModuleTest
property bar : Int32

def initialize(@bar : Int32); end
def to_tuple; {@moo, @foo, @bar}; end

def to_tuple
{@moo, @foo, @bar}
end
end

struct JSONAttrPersonWithYAML
Expand Down Expand Up @@ -705,11 +712,11 @@ describe "JSON mapping" do
end

it "defines query getter with class restriction" do
\{% begin %}
\{% methods = JSONAttrWithQueryAttributes.methods \%}
\{{ methods.find(&.name.==("foo?")).return_type }}.should eq(Bool)
\{{ methods.find(&.name.==("bar?")).return_type }}.should eq(Bool)
\{% end \%}
{% begin %}
{% methods = JSONAttrWithQueryAttributes.methods %}
{{ methods.find(&.name.==("foo?")).return_type }}.should eq(Bool)
{{ methods.find(&.name.==("bar?")).return_type }}.should eq(Bool)
{% end %}
end

it "defines non-query setter and presence methods" do
Expand Down Expand Up @@ -788,5 +795,3 @@ describe "JSON mapping" do
JSONAttrPersonWithYAMLInitializeHook.from_yaml(person.to_yaml).msg.should eq "Hello Vasya"
end
end

{% end %}
16 changes: 7 additions & 9 deletions spec/std/yaml/serializable_spec.cr
@@ -1,5 +1,3 @@
{% if Crystal::VERSION.includes?("0.24.2+") || Crystal::VERSION == "0.25.0" %}

require "spec"
require "yaml"
require "../../support/finalize"
Expand All @@ -10,12 +8,14 @@ end

class YAMLAttrEmptyClass
include YAML::Serializable

def initialize; end
end

class YAMLAttrEmptyClassWithUnmapped
include YAML::Serializable
include YAML::Serializable::Unmapped

def initialize; end
end

Expand Down Expand Up @@ -730,11 +730,11 @@ describe "YAML::Serializable" do
end

it "defines query getter with class restriction" do
\{% begin \%}
\{% methods = YAMLAttrWithQueryAttributes.methods \%}
\{{ methods.find(&.name.==("foo?")).return_type }}.should eq(Bool)
\{{ methods.find(&.name.==("bar?")).return_type }}.should eq(Bool)
\{% end \%}
{% begin %}
{% methods = YAMLAttrWithQueryAttributes.methods %}
{{ methods.find(&.name.==("foo?")).return_type }}.should eq(Bool)
{{ methods.find(&.name.==("bar?")).return_type }}.should eq(Bool)
{% end %}
end

it "defines non-query setter and presence methods" do
Expand Down Expand Up @@ -772,5 +772,3 @@ describe "YAML::Serializable" do
it { YAMLAttrModuleTest2.from_yaml(%({"bar": 30, "moo": 40})).to_tuple.should eq({40, 15, 30}) }
end
end

{% end %}
5 changes: 0 additions & 5 deletions src/json.cr
Expand Up @@ -93,8 +93,3 @@ module JSON
end

require "./json/*"

# TODO: remove conditions after 0.25
{% if Crystal::VERSION.includes?("0.24.2+") || Crystal::VERSION == "0.25.0" %}
require "./json/next/serialization"
{% end %}
File renamed without changes.
5 changes: 0 additions & 5 deletions src/yaml.cr
Expand Up @@ -3,11 +3,6 @@ require "./yaml/schema/*"
require "./yaml/schema/core/*"
require "./yaml/nodes/*"

# TODO: remove conditions after 0.25
{% if Crystal::VERSION.includes?("0.24.2+") || Crystal::VERSION == "0.25.0" %}
require "./yaml/next/serialization"
{% end %}

require "base64"

# The YAML module provides serialization and deserialization of YAML
Expand Down
File renamed without changes.

0 comments on commit 5c22fb3

Please sign in to comment.