Discussion:
[Cucumber] Turnip expressions in Cucumber
aslak hellesoy
2014-06-26 20:49:52 UTC
Permalink
Regular expressions are powerful. They are also ugly and many people
struggle with them.

I'd like to introduce an alternative to regular expressions for step
definitions: Turnip expressions [3]. (We'd still support regular
expressions).

The source code is here [4]. They are also supported in Behat, source here
[5].

What do people think? Welcome addition?

[3] https://github.com/jnicklas/turnip#placeholders
[4] https://github.com/jnicklas/turnip/blob/master/lib/turnip/placeholder.rb
[5]
https://github.com/Behat/Behat/blob/master/src/Behat/Behat/Definition/Pattern/Policy/TurnipPatternPolicy.php
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/d/optout.
Rob Park
2014-06-27 01:00:47 UTC
Permalink
Post by aslak hellesoy
Regular expressions are powerful. They are also ugly and many people
struggle with them.
I'd like to introduce an alternative to regular expressions for step
definitions: Turnip expressions [3]. (We'd still support regular
expressions).
The source code is here [4]. They are also supported in Behat, source here
[5].
What do people think? Welcome addition?
Yeah, I think that looks really nice and readable.
Post by aslak hellesoy
[3] https://github.com/jnicklas/turnip#placeholders
[4]
https://github.com/jnicklas/turnip/blob/master/lib/turnip/placeholder.rb
[5]
https://github.com/Behat/Behat/blob/master/src/Behat/Behat/Definition/Pattern/Policy/TurnipPatternPolicy.php
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/d/optout.
Tom Dunstan
2014-06-27 02:56:32 UTC
Permalink
Post by aslak hellesoy
What do people think? Welcome addition?
Looks much nicer than regexps, and deals with a number of cases where I've
had to do horrible things in a regexp to handle optional plurals etc.

Can you stick parens around the placeholder name, or somehow makr where a
word ends? Can be useful for e.g.: "I go through the (:n)st/nd/rd/th door".
Or maybe it would be "I go through the :n(st/nd/rd/th) door".

Cheers

Tom
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/d/optout.
Paolo Ambrosio
2014-06-27 06:51:22 UTC
Permalink
Post by aslak hellesoy
Regular expressions are powerful. They are also ugly
Yes, they are ugly, especially in languages where backslashes need to be
escaped.
Post by aslak hellesoy
and many people struggle with them.
Very sad but true.
Post by aslak hellesoy
I'd like to introduce an alternative to regular expressions for step
definitions: Turnip expressions [3]. (We'd still support regular
expressions).
Post by aslak hellesoy
The source code is here [4]. They are also supported in Behat, source
here [5].
Post by aslak hellesoy
What do people think? Welcome addition?
I like it.

How would someone specify the expression type in step definitions?
Post by aslak hellesoy
[3] https://github.com/jnicklas/turnip#placeholders
[4]
https://github.com/jnicklas/turnip/blob/master/lib/turnip/placeholder.rb
Post by aslak hellesoy
[5]
https://github.com/Behat/Behat/blob/master/src/Behat/Behat/Definition/Pattern/Policy/TurnipPatternPolicy.php
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/d/optout.
Steve Tooke
2014-06-27 10:50:45 UTC
Permalink
Post by Paolo Ambrosio
Post by aslak hellesoy
What do people think? Welcome addition?
I like it.
+1
Post by Paolo Ambrosio
How would someone specify the expression type in step definitions?
Could we not make that decision based on the argument passed to the
step?

e.g. in Ruby

We would either be given a string

Given("a step def with a :placeholder") do; end

or a regex

Given(/a regexp? step def/ do; end

Currently you can do either with ruby, but it will just match the exact
string - I believe.

Another option, we could have a way to configure the default expression
type for a project, and a way to override that on individual steps.

e..g in Ruby

Given("a step def with a :placeholder", type: "turnip") do |placeholder|
# ..
end

or

Given(/a step def with a (regex)/, type: "regexp") do |placeholder|
# ...
end

But I'm not sure it's needed.

Steve

--
E: steve-***@public.gmane.org
T: +44 7919 337 463
http://tooky.co.uk | http://kickstartacademy.io |
https://twitter.com/tooky
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/d/optout.
aslak hellesoy
2014-06-27 11:28:36 UTC
Permalink
Post by Paolo Ambrosio
Post by aslak hellesoy
Regular expressions are powerful. They are also ugly
Yes, they are ugly, especially in languages where backslashes need to be
escaped.
Post by aslak hellesoy
and many people struggle with them.
Very sad but true.
Post by aslak hellesoy
I'd like to introduce an alternative to regular expressions for step
definitions: Turnip expressions [3]. (We'd still support regular
expressions).
Post by aslak hellesoy
The source code is here [4]. They are also supported in Behat, source
here [5].
Post by aslak hellesoy
What do people think? Welcome addition?
I like it.
How would someone specify the expression type in step definitions?
For languages that have a literal syntax for regular expressions it's a
non-issue. I think the only languages that don't have this are Java, C# and
C.

For those languages, it would be nice if we could use // as a convention:

"/something/" => Regexp
"something" => Turnip

However, that will cause a lot of backwards incompatibility problems, so we
can't do that.

Do you think we could use a heuristic based on what's in the string?

"I have (.*) cukes in my belly" => Regexp, because of '('
"I have :n cukes in my belly" => Turnip, because of ':'

If we detect ambiguity, we could force the user to give hints, for example
an extra @Turnip annotation, or we could say that // is a way to hint it's
RegExp (slowly easing people toward that convention).

WDYT?

Who wants to take a stab at implementing this? I think it's simple enough
that it can live alongside the cucumber codebase - we don't need a separate
lib.

Aslak
Post by Paolo Ambrosio
Post by aslak hellesoy
[3] https://github.com/jnicklas/turnip#placeholders
[4]
https://github.com/jnicklas/turnip/blob/master/lib/turnip/placeholder.rb
Post by aslak hellesoy
[5]
https://github.com/Behat/Behat/blob/master/src/Behat/Behat/Definition/Pattern/Policy/TurnipPatternPolicy.php
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/d/optout.
Rob Park
2014-06-27 13:03:44 UTC
Permalink
Post by aslak hellesoy
Post by Paolo Ambrosio
Post by aslak hellesoy
Regular expressions are powerful. They are also ugly
Yes, they are ugly, especially in languages where backslashes need to be
escaped.
Post by aslak hellesoy
and many people struggle with them.
Very sad but true.
Post by aslak hellesoy
I'd like to introduce an alternative to regular expressions for step
definitions: Turnip expressions [3]. (We'd still support regular
expressions).
Post by aslak hellesoy
The source code is here [4]. They are also supported in Behat, source
here [5].
Post by aslak hellesoy
What do people think? Welcome addition?
I like it.
How would someone specify the expression type in step definitions?
For languages that have a literal syntax for regular expressions it's a
non-issue. I think the only languages that don't have this are Java, C# and
C.
"/something/" => Regexp
"something" => Turnip
However, that will cause a lot of backwards incompatibility problems, so
we can't do that.
Do you think we could use a heuristic based on what's in the string?
"I have (.*) cukes in my belly" => Regexp, because of '('
"I have :n cukes in my belly" => Turnip, because of ':'
Would we need to be able to escape the '(' and the ':', respectively? i.e.
Post by aslak hellesoy
If we detect ambiguity, we could force the user to give hints, for example
RegExp (slowly easing people toward that convention).
WDYT?
Who wants to take a stab at implementing this? I think it's simple enough
that it can live alongside the cucumber codebase - we don't need a separate
lib.
Aslak
Post by Paolo Ambrosio
Post by aslak hellesoy
[3] https://github.com/jnicklas/turnip#placeholders
[4]
https://github.com/jnicklas/turnip/blob/master/lib/turnip/placeholder.rb
Post by aslak hellesoy
[5]
https://github.com/Behat/Behat/blob/master/src/Behat/Behat/Definition/Pattern/Policy/TurnipPatternPolicy.php
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/d/optout.
aslak hellesoy
2014-06-27 14:19:40 UTC
Permalink
Post by Rob Park
Post by aslak hellesoy
Post by Paolo Ambrosio
Post by aslak hellesoy
Regular expressions are powerful. They are also ugly
Yes, they are ugly, especially in languages where backslashes need to be
escaped.
Post by aslak hellesoy
and many people struggle with them.
Very sad but true.
Post by aslak hellesoy
I'd like to introduce an alternative to regular expressions for step
definitions: Turnip expressions [3]. (We'd still support regular
expressions).
Post by aslak hellesoy
The source code is here [4]. They are also supported in Behat, source
here [5].
Post by aslak hellesoy
What do people think? Welcome addition?
I like it.
How would someone specify the expression type in step definitions?
For languages that have a literal syntax for regular expressions it's a
non-issue. I think the only languages that don't have this are Java, C# and
C.
"/something/" => Regexp
"something" => Turnip
However, that will cause a lot of backwards incompatibility problems, so
we can't do that.
Do you think we could use a heuristic based on what's in the string?
"I have (.*) cukes in my belly" => Regexp, because of '('
"I have :n cukes in my belly" => Turnip, because of ':'
Would we need to be able to escape the '(' and the ':', respectively? i.e.
You mean if you want to use '(' and ':' literally? For example:

Then /I should see \:-\)/ do
end

I suppose we'd have to escape them, yes, but it sounds like a pretty
contrived case.
I haven't studied the existing Turnip Expression implementations in detail.
We should probably come up with a spec and document it.

I have started a page here:

*
https://github.com/cucumber/cucumber.github.com/blob/master/turnip-expressions.md
* http://cukes.info/turnip-expressions.html

Although it's not linked from anywhere on the cukes.info website yet it's a
good starting point for us.
Post by Rob Park
Post by aslak hellesoy
If we detect ambiguity, we could force the user to give hints, for
hint it's RegExp (slowly easing people toward that convention).
WDYT?
Who wants to take a stab at implementing this? I think it's simple enough
that it can live alongside the cucumber codebase - we don't need a separate
lib.
Aslak
Post by Paolo Ambrosio
Post by aslak hellesoy
[3] https://github.com/jnicklas/turnip#placeholders
[4]
https://github.com/jnicklas/turnip/blob/master/lib/turnip/placeholder.rb
Post by aslak hellesoy
[5]
https://github.com/Behat/Behat/blob/master/src/Behat/Behat/Definition/Pattern/Policy/TurnipPatternPolicy.php
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/d/optout.
Rob Park
2014-06-27 14:46:29 UTC
Permalink
Post by aslak hellesoy
Post by Rob Park
Post by aslak hellesoy
Post by Paolo Ambrosio
Post by aslak hellesoy
Regular expressions are powerful. They are also ugly
Yes, they are ugly, especially in languages where backslashes need to
be escaped.
Post by aslak hellesoy
and many people struggle with them.
Very sad but true.
Post by aslak hellesoy
I'd like to introduce an alternative to regular expressions for step
definitions: Turnip expressions [3]. (We'd still support regular
expressions).
Post by aslak hellesoy
The source code is here [4]. They are also supported in Behat, source
here [5].
Post by aslak hellesoy
What do people think? Welcome addition?
I like it.
How would someone specify the expression type in step definitions?
For languages that have a literal syntax for regular expressions it's a
non-issue. I think the only languages that don't have this are Java, C# and
C.
"/something/" => Regexp
"something" => Turnip
However, that will cause a lot of backwards incompatibility problems, so
we can't do that.
Do you think we could use a heuristic based on what's in the string?
"I have (.*) cukes in my belly" => Regexp, because of '('
"I have :n cukes in my belly" => Turnip, because of ':'
Would we need to be able to escape the '(' and the ':', respectively?
Then /I should see \:-\)/ do
end
I suppose we'd have to escape them, yes, but it sounds like a pretty
contrived case.
So, I'm not saying these are good things to do or even that I want to do
them. But I do think we should know how it will be handled, because I have
these things in client code bases.

My recollection would be most often seeing ':' (hard to grep for ':'
though) before a table (similar to your example actually)... and to me, it
would be valid enough to say don't do that, but that would be a breaking
change still.

As for '(' ...
Then I submitted the form (XYZ) ...
Then /^I submitted the form \(XYZ\)$/ do ...
where they're already escaped.
Post by aslak hellesoy
I haven't studied the existing Turnip Expression implementations in
detail. We should probably come up with a spec and document it.
*
https://github.com/cucumber/cucumber.github.com/blob/master/turnip-expressions.md
* http://cukes.info/turnip-expressions.html
Although it's not linked from anywhere on the cukes.info website yet it's
a good starting point for us.
Post by Rob Park
Post by aslak hellesoy
If we detect ambiguity, we could force the user to give hints, for
hint it's RegExp (slowly easing people toward that convention).
WDYT?
Who wants to take a stab at implementing this? I think it's simple
enough that it can live alongside the cucumber codebase - we don't need a
separate lib.
Aslak
Post by Paolo Ambrosio
Post by aslak hellesoy
[3] https://github.com/jnicklas/turnip#placeholders
[4]
https://github.com/jnicklas/turnip/blob/master/lib/turnip/placeholder.rb
Post by aslak hellesoy
[5]
https://github.com/Behat/Behat/blob/master/src/Behat/Behat/Definition/Pattern/Policy/TurnipPatternPolicy.php
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/d/optout.
aslak hellesoy
2014-06-27 15:30:07 UTC
Permalink
Post by Rob Park
Post by aslak hellesoy
On Fri, Jun 27, 2014 at 7:28 AM, aslak hellesoy <
Post by aslak hellesoy
Post by Paolo Ambrosio
Post by aslak hellesoy
Regular expressions are powerful. They are also ugly
Yes, they are ugly, especially in languages where backslashes need to
be escaped.
Post by aslak hellesoy
and many people struggle with them.
Very sad but true.
Post by aslak hellesoy
I'd like to introduce an alternative to regular expressions for step
definitions: Turnip expressions [3]. (We'd still support regular
expressions).
Post by aslak hellesoy
The source code is here [4]. They are also supported in Behat,
source here [5].
Post by aslak hellesoy
What do people think? Welcome addition?
I like it.
How would someone specify the expression type in step definitions?
For languages that have a literal syntax for regular expressions it's a
non-issue. I think the only languages that don't have this are Java, C# and
C.
"/something/" => Regexp
"something" => Turnip
However, that will cause a lot of backwards incompatibility problems,
so we can't do that.
Do you think we could use a heuristic based on what's in the string?
"I have (.*) cukes in my belly" => Regexp, because of '('
"I have :n cukes in my belly" => Turnip, because of ':'
Would we need to be able to escape the '(' and the ':', respectively?
Then /I should see \:-\)/ do
end
I suppose we'd have to escape them, yes, but it sounds like a pretty
contrived case.
So, I'm not saying these are good things to do or even that I want to do
them. But I do think we should know how it will be handled, because I have
these things in client code bases.
My recollection would be most often seeing ':' (hard to grep for ':'
though) before a table (similar to your example actually)...
That's a good point. I hadn't thought about that. Maybe we could interpret
: as : if it's not immediately followed by \w+ if you see what I mean.
Post by Rob Park
and to me, it would be valid enough to say don't do that, but that would
be a breaking change still.
As for '(' ...
Then I submitted the form (XYZ) ...
Then /^I submitted the form \(XYZ\)$/ do ...
where they're already escaped.
I say let's give it a stab and handle all the corner cases as they show up.
Post by Rob Park
Post by aslak hellesoy
I haven't studied the existing Turnip Expression implementations in
detail. We should probably come up with a spec and document it.
*
https://github.com/cucumber/cucumber.github.com/blob/master/turnip-expressions.md
* http://cukes.info/turnip-expressions.html
Although it's not linked from anywhere on the cukes.info website yet
it's a good starting point for us.
Post by aslak hellesoy
If we detect ambiguity, we could force the user to give hints, for
hint it's RegExp (slowly easing people toward that convention).
WDYT?
Who wants to take a stab at implementing this? I think it's simple
enough that it can live alongside the cucumber codebase - we don't need a
separate lib.
Aslak
Post by Paolo Ambrosio
Post by aslak hellesoy
[3] https://github.com/jnicklas/turnip#placeholders
[4]
https://github.com/jnicklas/turnip/blob/master/lib/turnip/placeholder.rb
Post by aslak hellesoy
[5]
https://github.com/Behat/Behat/blob/master/src/Behat/Behat/Definition/Pattern/Policy/TurnipPatternPolicy.php
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/d/optout.
Steve Tooke
2014-07-16 09:42:50 UTC
Permalink
--
E: [1]steve-***@public.gmane.org
T: +44 7919 337 463
[2]http://tooky.co.uk | [3]http://kickstartacademy.io |
[4]https://twitter.com/tooky





On Fri, 27 Jun 2014, at 03:19 PM, aslak hellesoy wrote:




On Fri, Jun 27, 2014 at 2:03 PM, Rob Park
<[5]robert.d.park-***@public.gmane.org> wrote:




On Fri, Jun 27, 2014 at 7:28 AM, aslak hellesoy
<[6]aslak.hellesoy-***@public.gmane.org> wrote:




On Fri, Jun 27, 2014 at 7:51 AM, Paolo Ambrosio
<[7]paolo-***@public.gmane.org> wrote:

On 26 Jun 2014 21:50, "aslak hellesoy"
Post by aslak hellesoy
Regular expressions are powerful. They are also ugly
Yes, they are ugly, especially in languages where
backslashes need to be escaped.
Post by aslak hellesoy
and many people struggle with them.
Very sad but true.
Post by aslak hellesoy
I'd like to introduce an alternative to regular expressions
for step definitions: Turnip expressions [3]. (We'd still
support regular expressions).
Post by aslak hellesoy
The source code is here [4]. They are also supported in
Behat, source here [5].
Post by aslak hellesoy
What do people think? Welcome addition?
I like it.

How would someone specify the expression type in step
definitions?

For languages that have a literal syntax for regular
expressions it's a non-issue. I think the only languages that
don't have this are Java, C# and C.

For those languages, it would be nice if we could use // as a
convention:

"/something/" => Regexp
"something" => Turnip

However, that will cause a lot of backwards incompatibility
problems, so we can't do that.

Do you think we could use a heuristic based on what's in the
string?

"I have (.*) cukes in my belly" => Regexp, because of '('
"I have :n cukes in my belly" => Turnip, because of ':'


Would we need to be able to escape the '(' and the ':',
respectively? i.e. \( \:


You mean if you want to use '(' and ':' literally? For example:

Then /I should see \:-\)/ do
end

I suppose we'd have to escape them, yes, but it sounds like a
pretty contrived case.
I haven't studied the existing Turnip Expression
implementations in detail. We should probably come up with a
spec and document it.

I have started a page here:

* [9]https://github.com/cucumber/cucumber.github.com/blob/maste
r/turnip-expressions.md
* [10]http://cukes.info/turnip-expressions.html



I've taken a first-stab at implementing this for Cucumber-Ruby.



[11]https://github.com/cucumber/cucumber/pull/708



It follows the style that Jonas uses in Turnip.



Cucumber-Ruby already has $placeholders - which are quite
permissive. So I haven't changed that behaviour, and I don't
think we will remove that behaviour in Cucumber-Ruby 2.0 as
we're trying to minimize the number of _deliberate_ breaking
changes :)



I'm not sure we should have $placeholders for numbers and
:placeholders for strings, I think it would be better to use
custom placeholders[1].



WDYT?



[1]:
[12]https://github.com/jnicklas/turnip#custom-step-placeholders




Although it's not linked from anywhere on the [13]cukes.info
website yet it's a good starting point for us.


If we detect ambiguity, we could force the user to give hints,
for example an extra @Turnip annotation, or we could say that
// is a way to hint it's RegExp (slowly easing people toward
that convention).

WDYT?

Who wants to take a stab at implementing this? I think it's
simple enough that it can live alongside the cucumber codebase
- we don't need a separate lib.

Aslak
Post by aslak hellesoy
[3] [14]https://github.com/jnicklas/turnip#placeholders
[4] [15]https://github.com/jnicklas/turnip/blob/master/lib/turn
ip/placeholder.rb
[5] [16]https://github.com/Behat/Behat/blob/master/src/Behat/Be
hat/Definition/Pattern/Policy/TurnipPatternPolicy.php



--
Posting rules: [17]http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the
Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from
it, send an email to [18]cukes+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit [19]https://groups.google.com/d/optout.


--

Posting rules: [20]http://cukes.info/posting-rules.html

---

You received this message because you are subscribed to the
Google Groups "Cukes" group.

To unsubscribe from this group and stop receiving emails from
it, send an email to [21]cukes+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org

For more options, visit [22]https://groups.google.com/d/optout.

References

1. mailto:steve-***@public.gmane.org
2. http://tooky.co.uk/
3. http://kickstartacademy.io/
4. https://twitter.com/tooky
5. mailto:robert.d.park-***@public.gmane.org
6. mailto:aslak.hellesoy-***@public.gmane.org
7. mailto:paolo-***@public.gmane.org
8. mailto:aslak.hellesoy-***@public.gmane.org
9. https://github.com/cucumber/cucumber.github.com/blob/master/turnip-expressions.md
10. http://cukes.info/turnip-expressions.html
11. https://github.com/cucumber/cucumber/pull/708
12. https://github.com/jnicklas/turnip#custom-step-placeholders
13. http://cukes.info/
14. https://github.com/jnicklas/turnip#placeholders
15. https://github.com/jnicklas/turnip/blob/master/lib/turnip/placeholder.rb
16. https://github.com/Behat/Behat/blob/master/src/Behat/Behat/Definition/Pattern/Policy/TurnipPatternPolicy.php
17. http://cukes.info/posting-rules.html
18. mailto:cukes+unsubscribe-/***@public.gmane.org
19. https://groups.google.com/d/optout
20. http://cukes.info/posting-rules.html
21. mailto:cukes+unsubscribe-/***@public.gmane.org
22. https://groups.google.com/d/optout
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/d/optout.
Steve Tooke
2014-06-27 13:50:36 UTC
Permalink
On Fri, 27 Jun 2014, at 12:28 PM, aslak hellesoy wrote:




On Fri, Jun 27, 2014 at 7:51 AM, Paolo Ambrosio
<[1]paolo-***@public.gmane.org> wrote:

On 26 Jun 2014 21:50, "aslak hellesoy"
Post by aslak hellesoy
Regular expressions are powerful. They are also ugly
Yes, they are ugly, especially in languages where
backslashes need to be escaped.
Post by aslak hellesoy
and many people struggle with them.
Very sad but true.
Post by aslak hellesoy
I'd like to introduce an alternative to regular expressions
for step definitions: Turnip expressions [3]. (We'd still
support regular expressions).
Post by aslak hellesoy
The source code is here [4]. They are also supported in
Behat, source here [5].
Post by aslak hellesoy
What do people think? Welcome addition?
I like it.

How would someone specify the expression type in step
definitions?

For languages that have a literal syntax for regular
expressions it's a non-issue. I think the only languages that
don't have this are Java, C# and C.

For those languages, it would be nice if we could use // as a
convention:

"/something/" => Regexp
"something" => Turnip

However, that will cause a lot of backwards incompatibility
problems, so we can't do that.

Do you think we could use a heuristic based on what's in the
string?

"I have (.*) cukes in my belly" => Regexp, because of '('
"I have :n cukes in my belly" => Turnip, because of ':'



It might be possible to come up with something... but we
couldn't use "(" I don't think.



Turnip allows



"I have :n cuke(s) in my belly"



to match



"I have 1 cuke in my belly"



or



"I have 2 cukes in my belly"




If we detect ambiguity, we could force the user to give hints,
for example an extra @Turnip annotation, or we could say that
// is a way to hint it's RegExp (slowly easing people toward
that convention).

WDYT?

Who wants to take a stab at implementing this? I think it's
simple enough that it can live alongside the cucumber codebase
- we don't need a separate lib.

Aslak
Post by aslak hellesoy
[3] [3]https://github.com/jnicklas/turnip#placeholders
[4] [4]https://github.com/jnicklas/turnip/blob/master/lib/turni
p/placeholder.rb
[5] [5]https://github.com/Behat/Behat/blob/master/src/Behat/Beh
at/Definition/Pattern/Policy/TurnipPatternPolicy.php

--
Posting rules: [6]http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the
Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from
it, send an email to [7]cukes+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit [8]https://groups.google.com/d/optout.


--

Posting rules: [9]http://cukes.info/posting-rules.html

---

You received this message because you are subscribed to the
Google Groups "Cukes" group.

To unsubscribe from this group and stop receiving emails from
it, send an email to [10]cukes+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org

For more options, visit [11]https://groups.google.com/d/optout.

References

1. mailto:paolo-***@public.gmane.org
2. mailto:aslak.hellesoy-***@public.gmane.org
3. https://github.com/jnicklas/turnip#placeholders
4. https://github.com/jnicklas/turnip/blob/master/lib/turnip/placeholder.rb
5. https://github.com/Behat/Behat/blob/master/src/Behat/Behat/Definition/Pattern/Policy/TurnipPatternPolicy.php
6. http://cukes.info/posting-rules.html
7. mailto:cukes+unsubscribe-/***@public.gmane.org
8. https://groups.google.com/d/optout
9. http://cukes.info/posting-rules.html
10. mailto:cukes+unsubscribe-/***@public.gmane.org
11. https://groups.google.com/d/optout
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/d/optout.
Seb Rose
2014-06-27 14:11:18 UTC
Permalink
On Fri, 27 Jun 2014, at 06:50 AM, Steve Tooke wrote:







On Fri, 27 Jun 2014, at 12:28 PM, aslak hellesoy wrote:




On Fri, Jun 27, 2014 at 7:51 AM, Paolo Ambrosio
<[1]paolo-***@public.gmane.org> wrote:

On 26 Jun 2014 21:50, "aslak hellesoy"
Post by aslak hellesoy
Regular expressions are powerful. They are also ugly
Yes, they are ugly, especially in languages where
backslashes need to be escaped.
Post by aslak hellesoy
and many people struggle with them.
Very sad but true.
Post by aslak hellesoy
I'd like to introduce an alternative to regular expressions
for step definitions: Turnip expressions [3]. (We'd still
support regular expressions).
Post by aslak hellesoy
The source code is here [4]. They are also supported in
Behat, source here [5].
Post by aslak hellesoy
What do people think? Welcome addition?
I like it.

How would someone specify the expression type in step
definitions?

For languages that have a literal syntax for regular
expressions it's a non-issue. I think the only languages that
don't have this are Java, C# and C.

For those languages, it would be nice if we could use // as a
convention:

"/something/" => Regexp
"something" => Turnip

However, that will cause a lot of backwards incompatibility
problems, so we can't do that.

Do you think we could use a heuristic based on what's in the
string?

"I have (.*) cukes in my belly" => Regexp, because of '('
"I have :n cukes in my belly" => Turnip, because of ':'



It might be possible to come up with something... but we
couldn't use "(" I don't think.



Turnip allows



"I have :n cuke(s) in my belly"



to match



"I have 1 cuke in my belly"



or



"I have 2 cukes in my belly"



Does anyone have a feel for how many people don't use ^ and $
anchors? Could we use them as discriminators?



Alternatively, if we didn't want Turnip & regex to coexist in a
single run, we could supply a flag to Cucumber-JVM to tell it
which pattern matching to use.



There's the snippet generator to consider, too. i.e. Turnip or
regex.






If we detect ambiguity, we could force the user to give hints,
for example an extra @Turnip annotation, or we could say that
// is a way to hint it's RegExp (slowly easing people toward
that convention).

WDYT?

Who wants to take a stab at implementing this? I think it's
simple enough that it can live alongside the cucumber codebase
- we don't need a separate lib.

Aslak
Post by aslak hellesoy
[3] [3]https://github.com/jnicklas/turnip#placeholders
[4] [4]https://github.com/jnicklas/turnip/blob/master/lib/turni
p/placeholder.rb
[5] [5]https://github.com/Behat/Behat/blob/master/src/Behat/Beh
at/Definition/Pattern/Policy/TurnipPatternPolicy.php

--
Posting rules: [6]http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the
Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from
it, send an email to [7]cukes+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit [8]https://groups.google.com/d/optout.


--

Posting rules: [9]http://cukes.info/posting-rules.html

---

You received this message because you are subscribed to the
Google Groups "Cukes" group.

To unsubscribe from this group and stop receiving emails from
it, send an email to [10]cukes+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org

For more options, visit [11]https://groups.google.com/d/optout.





--

Posting rules: [12]http://cukes.info/posting-rules.html

---

You received this message because you are subscribed to the
Google Groups "Cukes" group.

To unsubscribe from this group and stop receiving emails from
it, send an email to [13]cukes+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org

For more options, visit [14]https://groups.google.com/d/optout.

References

1. mailto:paolo-***@public.gmane.org
2. mailto:aslak.hellesoy-***@public.gmane.org
3. https://github.com/jnicklas/turnip#placeholders
4. https://github.com/jnicklas/turnip/blob/master/lib/turnip/placeholder.rb
5. https://github.com/Behat/Behat/blob/master/src/Behat/Behat/Definition/Pattern/Policy/TurnipPatternPolicy.php
6. http://cukes.info/posting-rules.html
7. mailto:cukes+unsubscribe-/***@public.gmane.org
8. https://groups.google.com/d/optout
9. http://cukes.info/posting-rules.html
10. mailto:cukes+unsubscribe-/***@public.gmane.org
11. https://groups.google.com/d/optout
12. http://cukes.info/posting-rules.html
13. mailto:cukes+unsubscribe-/***@public.gmane.org
14. https://groups.google.com/d/optout
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/d/optout.
aslak hellesoy
2014-06-27 14:15:21 UTC
Permalink
Post by Paolo Ambrosio
Post by aslak hellesoy
Regular expressions are powerful. They are also ugly
Yes, they are ugly, especially in languages where backslashes need to be
escaped.
Post by aslak hellesoy
and many people struggle with them.
Very sad but true.
Post by aslak hellesoy
I'd like to introduce an alternative to regular expressions for step
definitions: Turnip expressions [3]. (We'd still support regular
expressions).
Post by aslak hellesoy
The source code is here [4]. They are also supported in Behat, source
here [5].
Post by aslak hellesoy
What do people think? Welcome addition?
I like it.
How would someone specify the expression type in step definitions?
For languages that have a literal syntax for regular expressions it's a
non-issue. I think the only languages that don't have this are Java, C# and
C.
"/something/" => Regexp
"something" => Turnip
However, that will cause a lot of backwards incompatibility problems, so
we can't do that.
Do you think we could use a heuristic based on what's in the string?
"I have (.*) cukes in my belly" => Regexp, because of '('
"I have :n cukes in my belly" => Turnip, because of ':'
It might be possible to come up with something... but we couldn't use "("
I don't think.
Turnip allows
"I have :n cuke(s) in my belly"
to match
"I have 1 cuke in my belly"
or
"I have 2 cukes in my belly"
Does anyone have a feel for how many people don't use ^ and $ anchors?
Could we use them as discriminators?
We could definitely use them as part of a heuristic, yes.
Post by Paolo Ambrosio
Alternatively, if we didn't want Turnip & regex to coexist in a single
run, we could supply a flag to Cucumber-JVM to tell it which pattern
matching to use.
They have to be able to coexist. Otherwise it becomes too hard to gradually
migrate from one to another.
Post by Paolo Ambrosio
There's the snippet generator to consider, too. i.e. Turnip or regex.
Cucumber-JVM has a --snippets [underscore|camelcase] option to indicate how
you want methods named for java snippets.

I suggest we use the same one, just with comma:

--snippets underscore,turnip

Ruby can do the same, except underscore|camelcase is irrelevant since
stepdefs are closures.
Post by Paolo Ambrosio
If we detect ambiguity, we could force the user to give hints, for example
RegExp (slowly easing people toward that convention).
WDYT?
Who wants to take a stab at implementing this? I think it's simple enough
that it can live alongside the cucumber codebase - we don't need a separate
lib.
Aslak
Post by aslak hellesoy
[3] https://github.com/jnicklas/turnip#placeholders
[4]
https://github.com/jnicklas/turnip/blob/master/lib/turnip/placeholder.rb
Post by aslak hellesoy
[5]
https://github.com/Behat/Behat/blob/master/src/Behat/Behat/Definition/Pattern/Policy/TurnipPatternPolicy.php
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/d/optout.
George Dinwiddie
2014-07-16 13:39:02 UTC
Permalink
Aslak,
Post by aslak hellesoy
Regular expressions are powerful. They are also ugly and many people
struggle with them.
I'd like to introduce an alternative to regular expressions for step
definitions: Turnip expressions [3]. (We'd still support regular
expressions).
Is there a specification for Turnip expressions?

I worry that we're trading a well-defined expression language that has
syntax that seems unfamiliar to many today, for a vaguely-defined
expression language that will grow in complexity to try to match the
expressiveness. I'm uncomfortable with languages that are only defined
by their implementation.

- George
Post by aslak hellesoy
The source code is here [4]. They are also supported in Behat, source
here [5].
What do people think? Welcome addition?
[3] https://github.com/jnicklas/turnip#placeholders
[4] https://github.com/jnicklas/turnip/blob/master/lib/turnip/placeholder.rb
[5]
https://github.com/Behat/Behat/blob/master/src/Behat/Behat/Definition/Pattern/Policy/TurnipPatternPolicy.php
--
--
----------------------------------------------------------------------
* George Dinwiddie * http://blog.gdinwiddie.com
Software Development http://www.idiacomputing.com
Consultant and Coach http://www.agilemaryland.org
----------------------------------------------------------------------
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/d/optout.
Steve Tooke
2014-07-21 10:15:59 UTC
Permalink
Post by George Dinwiddie
Aslak,
Post by aslak hellesoy
Regular expressions are powerful. They are also ugly and many people
struggle with them.
I'd like to introduce an alternative to regular expressions for step
definitions: Turnip expressions [3]. (We'd still support regular
expressions).
Is there a specification for Turnip expressions?
There isn't! The idea comes from a cucumber alternative in ruby, that
has 3 simple rules:

1. Captures are specified using named placeholders, e.g.

Given "a :creature called :name"

This will match

Given a dog called Rover

or

Given a cat called "C for"

or

Given a 'siberian tiger' called 'Mr. Cuddly'

2. Step definitions can have optional parts, e.g.

Given "a(n) :creature called :name"

This will match

Given a dog called Rover

or

Given an elephant called Nelly

3. Step definitions can have alternative parts, e.g.

Given "a dog is awake/asleep"

This will match:

Given a dog is awake

or

Given a dog is asleep
Post by George Dinwiddie
I worry that we're trading a well-defined expression language that has
syntax that seems unfamiliar to many today, for a vaguely-defined
expression language that will grow in complexity to try to match the
expressiveness.
I don't think the plan is to remove the regular expression step
definitions, just to provide an alternative that is simpler (clearer?)
for most cases.

The turnip implementation also provides support for creating custom
placeholders[2], should you need to extend the capturing behaviour.
Post by George Dinwiddie
I'm uncomfortable with languages that are only defined
by their implementation.
This is definitely something we should be aware of, and perhaps part of
this discussion can be specifying our version of turnip expressions.

For me the idea is that the step definition "language" is very simple.
We should make sure that it stays that way, and encourage people to use
regular expressions where they are more appropriate.

Steve
--
E: steve-***@public.gmane.org
T: +44 7919 337 463
http://tooky.co.uk | http://kickstartacademy.io |
https://twitter.com/tooky
Post by George Dinwiddie
Post by aslak hellesoy
The source code is here [4]. They are also supported in Behat, source
here [5].
What do people think? Welcome addition?
[3] https://github.com/jnicklas/turnip#placeholders
[4] https://github.com/jnicklas/turnip/blob/master/lib/turnip/placeholder.rb
[5]
https://github.com/Behat/Behat/blob/master/src/Behat/Behat/Definition/Pattern/Policy/TurnipPatternPolicy.php
--
--
----------------------------------------------------------------------
* George Dinwiddie * http://blog.gdinwiddie.com
Software Development http://www.idiacomputing.com
Consultant and Coach http://www.agilemaryland.org
----------------------------------------------------------------------
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/d/optout.
Loading...