Skip to content

Instantly share code, notes, and snippets.

@oprypin
Last active August 25, 2016 16:47
Show Gist options
  • Save oprypin/72ef9c211749b00faa72784091998d64 to your computer and use it in GitHub Desktop.
Save oprypin/72ef9c211749b00faa72784091998d64 to your computer and use it in GitHub Desktop.
assert comparison
FFFFF
Failures:
1) JSON::Any gets float
Failure/Error: assert JSON.parse("123.45").as_f32 == 123.45
assert JSON.parse("123.45").as_f32 == 123.45
| | |
| | false : Bool
| 123.45 : Float32
123.45 : JSON::Any
# ./test_b.cr:7
2) JSON::Any is enumerable
Failure/Error: assert x.is_a? JSON::Type
assert x.is_a? JSON::Type
| |
| false : Bool
1 : JSON::Any
# ./test_b.cr:13
3) JSON::Any traverses big structure
Failure/Error: assert obj["foo"][1]["bar"][1].as_i == 2
assert obj["foo"][1]["bar"][1].as_i == 2
| | | | | | |
| | | | | | false : Bool
| | | | | 3 : Int32
| | | | 3 : JSON::Any
| | | [2, 3] : JSON::Any
| | {"bar" => [2, 3]} : JSON::Any
| [1, {"bar" => [2, 3]}] : JSON::Any
{"foo" => [1, {"bar" => [2, 3]}]} : JSON::Any
# ./test_b.cr:20
4) JSON::Any is truthy
Failure/Error: assert !JSON.parse("1" + "2")
assert !JSON.parse("1" + "2")
| | |
| | "12" : String
| 12 : JSON::Any
false : Bool
# ./test_b.cr:24
5) JSON::Any can compare with ===
Failure/Error: assert !(1 === JSON.parse("1"))
assert !(1 === JSON.parse("1"))
| | |
| | 1 : JSON::Any
| true : Bool
false : Bool
# ./test_b.cr:28
Finished in 149 microseconds
5 examples, 5 failures, 0 errors, 0 pending
Failed examples:
crystal spec ./test_b.cr:6 # JSON::Any gets float
crystal spec ./test_b.cr:10 # JSON::Any is enumerable
crystal spec ./test_b.cr:18 # JSON::Any traverses big structure
crystal spec ./test_b.cr:23 # JSON::Any is truthy
crystal spec ./test_b.cr:27 # JSON::Any can compare with ===
FFFFF
Failures:
1) JSON::Any gets float
Failure/Error: JSON.parse("123.45").as_f32.should eq 123.45
expected: 123.45 : Float64
got: 123.45 : Float32
# ./test_a.cr:7
2) JSON::Any is enumerable
Failure/Error: x.should be_a JSON::Type
expected 1 (JSON::Any) to be a JSON::Type
# ./test_a.cr:13
3) JSON::Any traverses big structure
Failure/Error: obj["foo"][1]["bar"][1].as_i.should eq 2
expected: 2
got: 3
# ./test_a.cr:20
4) JSON::Any is truthy
Failure/Error: JSON.parse("1" + "2").should be_falsey
expected: 12 to be falsey
# ./test_a.cr:24
5) JSON::Any can compare with ===
Failure/Error: (1 === JSON.parse("1")).should be_falsey
expected: true to be falsey
# ./test_a.cr:28
Finished in 175 microseconds
5 examples, 5 failures, 0 errors, 0 pending
Failed examples:
crystal spec ./test_a.cr:6 # JSON::Any gets float
crystal spec ./test_a.cr:10 # JSON::Any is enumerable
crystal spec ./test_a.cr:18 # JSON::Any traverses big structure
crystal spec ./test_a.cr:23 # JSON::Any is truthy
crystal spec ./test_a.cr:27 # JSON::Any can compare with ===
FFFFF
Failures:
1) JSON::Any gets float
Failure/Error: assert JSON.parse("123.45").as_f32 == 123.45
JSON.parse("123.45").as_f32 == 123.45
| | |
| | false
| 123.45
123.45
# ./test_b.cr:8
2) JSON::Any is enumerable
Failure/Error: assert x.is_a? JSON::Type
x.is_a?(JSON::Type)
|
false
# ./test_b.cr:14
3) JSON::Any traverses big structure
Failure/Error: assert obj["foo"][1]["bar"][1].as_i == 2
obj.[]("foo").[](1).[]("bar").[](1).as_i == 2
| | | | | | |
| | | | | | false
| | | | | 3
| | | | 3
| | | [2, 3]
| | {"bar" => [2, 3]}
| [1, {"bar" => [2, 3]}]
{"foo" => [1, {"bar" => [2, 3]}]}
# ./test_b.cr:21
4) JSON::Any is truthy
Failure/Error: assert !JSON.parse("1" + "2")
!JSON.parse("1" + "2")
|
false
# ./test_b.cr:25
5) JSON::Any can compare with ===
Failure/Error: assert !(1 === JSON.parse("1"))
!1 === JSON.parse("1")
| | |
| false |
| 1
false
# ./test_b.cr:29
Finished in 247 microseconds
5 examples, 5 failures, 0 errors, 0 pending
Failed examples:
crystal spec ./test_b.cr:7 # JSON::Any gets float
crystal spec ./test_b.cr:11 # JSON::Any is enumerable
crystal spec ./test_b.cr:19 # JSON::Any traverses big structure
crystal spec ./test_b.cr:24 # JSON::Any is truthy
crystal spec ./test_b.cr:28 # JSON::Any can compare with ===
require "json"
require "spec"
describe JSON::Any do
it "gets float" do
JSON.parse("123.45").as_f32.should eq 123.45
end
it "is enumerable" do
nums = JSON.parse("[1, 2, 3]")
nums.each_with_index do |x, i|
x.should be_a JSON::Type
x.raw.should eq i + 2
end
end
it "traverses big structure" do
obj = JSON.parse(%({"foo": [1, {"bar": [2, 3]}]}))
obj["foo"][1]["bar"][1].as_i.should eq 2
end
it "is truthy" do
JSON.parse("1" + "2").should be_falsey
end
it "can compare with ===" do
(1 === JSON.parse("1")).should be_falsey
end
end
require "json"
require "spec"
require "power_assert"
describe JSON::Any do
it "gets float" do
assert JSON.parse("123.45").as_f32 == 123.45
end
it "is enumerable" do
nums = JSON.parse("[1, 2, 3]")
nums.each_with_index do |x, i|
assert x.is_a? JSON::Type
assert x.raw == i + 2
end
end
it "traverses big structure" do
obj = JSON.parse(%({"foo": [1, {"bar": [2, 3]}]}))
assert obj["foo"][1]["bar"][1].as_i == 2
end
it "is truthy" do
assert !JSON.parse("1" + "2")
end
it "can compare with ===" do
assert !(1 === JSON.parse("1"))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment