Skip to content

Commit

Permalink
Merge pull request #10 from woolfred/fix-boolean-parsing
Browse files Browse the repository at this point in the history
Fix boolean parsing
  • Loading branch information
boudra committed Jan 18, 2019
2 parents 91f97e9 + 0b21079 commit 82990b5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion c_src/decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ void decode(decoder_t* d, json_event_t* e) {
if(d->cursor + 5 <= limit) {
if(memcmp(d->cursor, "false", 5) == 0) {
e->type = BOOLEAN;
e->value.boolean = 1;
e->value.boolean = 0;
d->cursor = d->cursor + 5;
} else {
syntax_error(d, e);
Expand Down
5 changes: 5 additions & 0 deletions test/jaxon_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ defmodule JaxonTest do
assert decode!("-99.99e99 ") == -99.99e99
end

test "booleans" do
assert decode!(~s(true)) == true
assert decode!(~s(false)) == false
end

test "objects" do
assert decode!(~s({})) == %{}
assert decode!(~s({"number": 2})) == %{"number" => 2}
Expand Down
4 changes: 2 additions & 2 deletions test/parser_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule ParseTest do
doctest Parser

@tests [
{~s({ "name": "john", "test": {"number": 5.1}, "tags":[null,true,true,1]}),
{~s({ "name": "john", "test": {"number": 5.1}, "tags":[null,true,false,1]}),
[
:start_object,
{:string, "name"},
Expand All @@ -26,7 +26,7 @@ defmodule ParseTest do
:comma,
{:boolean, true},
:comma,
{:boolean, true},
{:boolean, false},
:comma,
{:integer, 1},
:end_array,
Expand Down

0 comments on commit 82990b5

Please sign in to comment.