bjpop / language-python

A parser for Python 2.x and 3.x written in Haskell
157 stars 46 forks source link

Quoter #64

Open Pagolin opened 3 years ago

Pagolin commented 3 years ago

I needed a Quasiquoter, so I added a simple one (basically a wrapper for dataToExp. I had the existing test running through, with obviously no error, but didn't manage to add tests yet. However I thought it might be useful for someone.

bjpop commented 3 years ago

This looks great. Can you please show some examples of its use? Maybe some examples can be put in the header documentation for Language.Python.Common.Quoter?

Pagolin commented 3 years ago

Like so?

bjpop commented 3 years ago

Looks great thanks! Would it be possible to add some test cases to the test suite as well?

Pagolin commented 3 years ago

I thought about how to test this. I could compare a) quotes to parse results from files using the test python already there or b) compare quotes to 'handcrafted' (sub)AST.

bjpop commented 3 years ago

Hi @Pagolin.

I would like to pull this code into the repository.

I do prefer to have some test cases to use when doing the pull. Your suggested approach sounds reasonable. I find that testing against hand written ASTs can be a bit laborious, and thus few tests get written this way.

Another approach is to do a kind of "round trip" testing, by quoting some code, then pretty printing it back to a rendered string, and then comparing that string to the expected code.

This is not perfect, because it relies on the pretty printer being stable, and it is not in the spirit of a unit test. However, it tends to be easier to do, and therefore more tests can get written, which has its own advantages.