Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F112609
array_test.exs
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
array_test.exs
View Options
defmodule
OpenApiSpec.Cast.ArrayTest
do
use
ExUnit.Case
alias
OpenApiSpex.Cast
.
{
Array
,
Error
}
alias
OpenApiSpex
.
{
Cast
,
Schema
}
defp
cast
(
map
),
do
:
Array
.
cast
(
struct
(
Cast
,
map
))
describe
"cast/4"
do
test
"array"
do
schema
=
%
Schema
{
type
:
:array
}
assert
cast
(
value
:
[],
schema
:
schema
)
==
{
:ok
,
[]}
assert
cast
(
value
:
[
1
,
2
,
3
],
schema
:
schema
)
==
{
:ok
,
[
1
,
2
,
3
]}
assert
cast
(
value
:
[
"1"
,
"2"
,
"3"
],
schema
:
schema
)
==
{
:ok
,
[
"1"
,
"2"
,
"3"
]}
assert
{
:error
,
[
error
]}
=
cast
(
value
:
%{},
schema
:
schema
)
assert
%
Error
{}
=
error
assert
error
.
reason
==
:invalid_type
assert
error
.
value
==
%{}
end
test
"with maxItems"
do
schema
=
%
Schema
{
type
:
:array
,
maxItems
:
2
}
assert
cast
(
value
:
[
1
,
2
],
schema
:
schema
)
==
{
:ok
,
[
1
,
2
]}
assert
{
:error
,
[
error
]}
=
cast
(
value
:
[
1
,
2
,
3
],
schema
:
schema
)
assert
%
Error
{}
=
error
assert
error
.
reason
==
:max_items
assert
error
.
value
==
[
1
,
2
,
3
]
end
test
"with minItems"
do
schema
=
%
Schema
{
type
:
:array
,
minItems
:
2
}
assert
cast
(
value
:
[
1
,
2
],
schema
:
schema
)
==
{
:ok
,
[
1
,
2
]}
assert
{
:error
,
[
error
]}
=
cast
(
value
:
[
1
],
schema
:
schema
)
assert
%
Error
{}
=
error
assert
error
.
reason
==
:min_items
assert
error
.
value
==
[
1
]
end
test
"with uniqueItems"
do
schema
=
%
Schema
{
type
:
:array
,
uniqueItems
:
true
}
assert
cast
(
value
:
[
1
,
2
],
schema
:
schema
)
==
{
:ok
,
[
1
,
2
]}
assert
{
:error
,
[
error
]}
=
cast
(
value
:
[
1
,
1
],
schema
:
schema
)
assert
%
Error
{}
=
error
assert
error
.
reason
==
:unique_items
assert
error
.
value
==
[
1
,
1
]
end
test
"array with items schema"
do
items_schema
=
%
Schema
{
type
:
:integer
}
schema
=
%
Schema
{
type
:
:array
,
items
:
items_schema
}
assert
cast
(
value
:
[],
schema
:
schema
)
==
{
:ok
,
[]}
assert
cast
(
value
:
[
1
,
2
,
3
],
schema
:
schema
)
==
{
:ok
,
[
1
,
2
,
3
]}
assert
cast
(
value
:
[
"1"
,
"2"
,
"3"
],
schema
:
schema
)
==
{
:ok
,
[
1
,
2
,
3
]}
assert
{
:error
,
[
error
]}
=
cast
(
value
:
[
1
,
"two"
],
schema
:
schema
)
assert
%
Error
{}
=
error
assert
error
.
reason
==
:invalid_type
assert
error
.
value
==
"two"
assert
error
.
path
==
[
1
]
end
end
end
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 23, 9:10 PM (23 h, 51 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
38786
Default Alt Text
array_test.exs (2 KB)
Attached To
Mode
R22 open_api_spex
Attached
Detach File
Event Timeline
Log In to Comment