compile / test / format gleam code markdown code blocks in module and function comments #3017
Replies: 8 comments 3 replies
-
For an example of doctests in Elixir, see https://hexdocs.pm/elixir/docs-tests-and-with.html#doctests |
Beta Was this translation helpful? Give feedback.
-
I think formatting gleam code in a doc comment's code block could be nice. I like the idea of having a nice and consistent look across all examples. |
Beta Was this translation helpful? Give feedback.
-
For running the compiler and-or doctests we could do the following, using forward ticks here for demo only.
|
Beta Was this translation helpful? Give feedback.
-
Testing if github ignores flag of flagged docblock ( import gleam/int
{1 + 2} |> int.divide(2)
> 1 |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
I have edited my comment above to include how the expected function return value, stdout or stderr could be tested/captured. |
Beta Was this translation helpful? Give feedback.
-
I wonder if the testing part could for demo purposes done as a community plugin first. It would not happen at lsp/save-time and would not report back syntax errors or doctest failures right away but it could be a good POC that is useful on its own and stdlib could even be upgraded to yse it, if it is good enough? |
Beta Was this translation helpful? Give feedback.
-
If doctests make it into the gleam itself, the generated erlang could be placed as erlang doctests: https://www.erlang.org/eeps/eep-0059#doctests This improves documentation for the beam eco-system and improves gleam's appeal to use it as for beam eco system libraries. |
Beta Was this translation helpful? Give feedback.
-
@doctest
or similar attribute to run those whengleam test
is executed, again putting them into virtual test functions and respecting importsAnother few languages could be supported for formatting, such as Erlang, Elixir, JavaScript, TypeScript, XML, HTML, CSS, JSON, TOML, SQL.Tagging @giacomocavalieri as requested
Edit: I think doctests are great (for pure functions) as they can reside with function docs and function typespecs all in one place for best comprehension.
Beta Was this translation helpful? Give feedback.
All reactions