mirror of
https://github.com/valitydev/elixir-thrift.git
synced 2024-11-07 02:35:17 +00:00
Booleans can have integer default values (#143)
Booleans can have 1 and 0 as default values. This converts them into true and false, so we can deal with them properly. Fixes #142
This commit is contained in:
parent
9cd1d502a1
commit
fd8600815d
@ -19,6 +19,9 @@ defmodule Thrift.Parser.Conversions do
|
||||
val
|
||||
end
|
||||
|
||||
def cast(:bool, 0), do: false
|
||||
def cast(:bool, 1), do: true
|
||||
|
||||
def cast(:string, val) do
|
||||
List.to_string(val)
|
||||
end
|
||||
|
@ -380,6 +380,8 @@ defmodule ParserTest do
|
||||
struct MyStruct {
|
||||
1: optional bool negative;
|
||||
2: optional bool positive = true;
|
||||
3: optional bool c_positive = 1;
|
||||
4: optional bool c_negative = 0;
|
||||
}
|
||||
"""
|
||||
|> parse([:structs, :MyStruct])
|
||||
@ -388,7 +390,9 @@ defmodule ParserTest do
|
||||
name: :MyStruct,
|
||||
fields: [
|
||||
%Field{id: 1, name: :negative, type: :bool, required: false, default: nil},
|
||||
%Field{id: 2, name: :positive, type: :bool, required: false, default: true}
|
||||
%Field{id: 2, name: :positive, type: :bool, required: false, default: true},
|
||||
%Field{id: 3, name: :c_positive, type: :bool, required: false, default: true},
|
||||
%Field{id: 4, name: :c_negative, type: :bool, required: false, default: false},
|
||||
]}
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user