matryer / silk

Markdown based document-driven RESTful API testing.
http://silktest.org/
GNU General Public License v2.0
942 stars 69 forks source link

add a format 'len(Data): int' to count elements in a slice #29

Closed craftgear closed 6 years ago

craftgear commented 8 years ago

Add a new format to count elements in a response slice.

This would be useful when you expect an exact amount of data to retrieve.

Usage:

## Get /foo/total
Get 10 items
=== 
len(Data): 10
matryer commented 8 years ago

Great stuff.

Since we're using JavaScript notation, would it make sense to do Data.items.length?

On 4 Mar 2016, at 05:19, Shunsuke Watanabe notifications@github.com wrote:

Add a new format to count elements in a response slice.

This would be useful when you expect an exact amount of data to retrieve.

Usage:

Get /foo/total

Get 10 items

len(Data): 10 You can view, comment on, or merge this pull request online at:

https://github.com/matryer/silk/pull/29

Commit Summary

add a format 'len(Data): int' to count elements in a slice File Changes

M runner/run.go (12) Patch Links:

https://github.com/matryer/silk/pull/29.patch https://github.com/matryer/silk/pull/29.diff — Reply to this email directly or view it on GitHub.

craftgear commented 8 years ago

That makes sense.

Then how about making it as Data.length? When you get response as an array response.length is intuitive IMHO, moreover it's shorter.

craftgear commented 8 years ago

Wait, length should work with properties and strings.

Let me think about this again.

matryer commented 8 years ago

Is this ready to go now?

craftgear commented 8 years ago

Not yet. Give me a little more time.

davidbgk commented 8 years ago

Maybe Data.length(): 6 would avoid the collision with a length attribute?

matryer commented 8 years ago

Maybe it’s not a collision… you might well want to assert the length of a string?

On 11 Mar 2016, at 15:14, David Larlet notifications@github.com wrote:

Maybe Data.length(): 6 would avoid the collision with a length attribute?

— Reply to this email directly or view it on GitHub https://github.com/matryer/silk/pull/29#issuecomment-195598060.

craftgear commented 8 years ago

@matryer Yes, I try to check String.length. Do you think it's unnecessary?

matryer commented 8 years ago

I'd love to get this done and into the next pre-release if possible. @craftgear can you have a look at my comments please?