Git Product home page Git Product logo

Comments (5)

ciaranmcnulty avatar ciaranmcnulty commented on July 17, 2024 1

Behat currently uses its own parser which isn't 100% compatible with the Cucumber one. We do attempt to test against the same testdata but exclude some of the example features . The data table examples don't seem to be in that exclusion list, which indicates the Behat parser produces the same result as Cucumber for those testdata.

Therefore a good step would be to add an example with this problematic case to the testdata in this repo and canonicalise the correct parsing. This would help us ensure that other implementations are parsing the source in the same way too.

The good news is that Behat should use the new parser at some point which will mean the parsing will be much more compatible, and maintained in this organisation

from common.

mpkorstanje avatar mpkorstanje commented on July 17, 2024

Unfortunately this looks like a feature to me:

if (escape) {
switch (c) {
case 'n':
cellBuilder.append('\n');
break;
case '\\':
cellBuilder.append('\\');
break;
case '|':
cellBuilder.append('|');
break;
default:
// Invalid escape. We'll just ignore it.
cellBuilder.append("\\");
cellBuilder.appendCodePoint(c);
break;
}

Though since the escape is invalid, I think you might be okay mapping every \ to \\. I don't immediately see any clashes.

So reformatting:

| \o\no\ |

Should yield

| \\o\no\\ |

from common.

jdeniau avatar jdeniau commented on July 17, 2024

OK thank you for your fast response.

One think I find weird then (but that possibly because I do not know the implementation details here) is the fact that there is a difference between \| and the rest : \| are converted to |. But after reading my phrase several times, it seems logical as you want the cell value here.

About mapping \ to \\, that's what I did, but I think that Behat does not escape the same way as cucumber handles it, so changing from \ to \\ in gherkin files does crash on the Behat side (I might open an issue about this when I do investigate a little further on their side).

For the moment I'm still stucked on the prettier plugin, and the hack I found is not pretty 😰

https://github.com/mapado/prettier-plugin-gherkin/blob/main/src/GherkinAST/index.ts#L46-L59

https://github.com/mapado/prettier-plugin-gherkin#escapebackslashes

But it does work for the moment, so that's fine 👍

As an evolution, what do you think about adding the initial data in the AST ? or at least the a endColumn information in the Location of every nodes ? This way we might get the original data when we want (I can not actually do that because the size of the TableCell is lost as the value is transformed).

Thanks again

from common.

mpkorstanje avatar mpkorstanje commented on July 17, 2024

About mapping \ to \, that's what I did, but I think that Behat does not escape the same way as cucumber handles it, so changing from \ to \ in gherkin files does crash on the Behat side (I might open an issue about this when I do investigate a little further on their side).

I think that would be the way forward. I know that @ciaranmcnulty contributes to both Cucumber Gherkin and Behat Gherkin. Perhaps he can help out.

from common.

jdeniau avatar jdeniau commented on July 17, 2024

@ciaranmcnulty thank you for your response.
The file I did work with is escaped_pipes.feature that is in your list. I did not remember all other files.

I did add a file with lots of \ in my test stack and the actual output of the prettier plugin is visible here (but with backslashes escaped, which is nearly unreadable 😄 ).

I think the fix for the prettier plugin should work for now. I will watch carefully the fact that behat will use the cucumber parser and test it once released.

I'm closing this as the option in the prettier plugin should handle most cases.

Thanks @mpkorstanje too for your time.

from common.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.