Skip to content
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 test that fails test for nested union types #72

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions spec/coerce_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,18 @@ class WithFixedArray < T::Struct
const :arr, [Integer, String, Integer]
end

class Value1 < T::Struct
const :prop_1, Integer
end

class Value2 < T::Struct
const :prop_2, Integer
end

class WithUnsupportedNestedUnion < T::Struct
const :value, T.any(Value1, Value2)
end

class CustomString < String
end

Expand Down Expand Up @@ -241,6 +253,20 @@ class Param2 < T::Struct
end.to raise_error(TypeError)
end
end

context 'unsupported nested union' do
it 'keeps the values as-is' do
coerced = TypeCoerce[WithUnsupportedNestedUnion].new.from({value: { prop_1: 1 }})
expect(coerced.prop_1).to eq(1)

coerced = TypeCoerce[WithUnsupportedNestedUnion].new.from({value: { prop_2: 2 }})
expect(coerced.prop_2).to eq(1)

expect do
TypeCoerce[WithUnsupportedNestedUnion].new.from({value: { prop_3: 3 }})
end.to raise_error(TypeError)
end
end
end

context 'when dealing with arrays' do
Expand Down