Skip to content

Commit cd9b190

Browse files
committed
Add map() tests
Proposed in: jmespath/jmespath.site#15
1 parent 1b5261b commit cd9b190

File tree

1 file changed

+73
-1
lines changed

1 file changed

+73
-1
lines changed

tests/functions.json

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,4 +750,76 @@
750750
]
751751
}
752752
]
753-
}]
753+
}, {
754+
"given":
755+
{
756+
"people": [
757+
{"a": 10, "b": 1, "c": "z"},
758+
{"a": 10, "b": 2, "c": null},
759+
{"a": 10, "b": 3},
760+
{"a": 10, "b": 4, "c": "z"},
761+
{"a": 10, "b": 5, "c": null},
762+
{"a": 10, "b": 6},
763+
{"a": 10, "b": 7, "c": "z"},
764+
{"a": 10, "b": 8, "c": null},
765+
{"a": 10, "b": 9}
766+
],
767+
"empty": []
768+
},
769+
"cases": [
770+
{
771+
"expression": "map(&a, people)",
772+
"result": [10, 10, 10, 10, 10, 10, 10, 10, 10]
773+
},
774+
{
775+
"expression": "map(&c, people)",
776+
"result": ["z", null, null, "z", null, null, "z", null, null]
777+
},
778+
{
779+
"expression": "map(&a, badkey)",
780+
"error": "invalid-type"
781+
},
782+
{
783+
"expression": "map(&foo, empty)",
784+
"result": []
785+
}
786+
]
787+
}, {
788+
"given": {
789+
"array": [
790+
{
791+
"foo": {"bar": "yes1"}
792+
},
793+
{
794+
"foo": {"bar": "yes2"}
795+
},
796+
{
797+
"foo1": {"bar": "no"}
798+
}
799+
]},
800+
"cases": [
801+
{
802+
"expression": "map(&foo.bar, array)",
803+
"result": ["yes1", "yes2", null]
804+
},
805+
{
806+
"expression": "map(&foo1.bar, array)",
807+
"result": [null, null, "no"]
808+
},
809+
{
810+
"expression": "map(&foo.bar.baz, array)",
811+
"result": [null, null, null]
812+
}
813+
]
814+
}, {
815+
"given": {
816+
"array": [[1, 2, 3, [4]], [5, 6, 7, [8, 9]]]
817+
},
818+
"cases": [
819+
{
820+
"expression": "map(&[], array)",
821+
"result": [[1, 2, 3, 4], [5, 6, 7, 8, 9]]
822+
}
823+
]
824+
}
825+
]

0 commit comments

Comments
 (0)