tokay-lang / tokay

Tokay is a programming language designed for ad-hoc parsing, inspired by awk.
https://tokay.dev
MIT License
239 stars 7 forks source link

Provide a `crate::test::testcase()` function for internal use #83

Open phorward opened 1 year ago

phorward commented 1 year ago

The existing function crate::test::testcase() is a great way to express tests, because a test-case can be expressed as one source file having 3 sections:

'Hello' _ Word
#---
#Hello World Hello Mars
#---
#("World, "Mars")

There are 2 to 3 sections separated by #---:

  1. Is the Tokay input source
  2. Is the input provided, or the expected output
  3. Is the expected output when input is provided

Currently, this implementation runs tokay in a separate process and modifies stdin, stdout and stderr to feed input. It would be nicer to let this work like crate::utils::run() which runs a program on a given source, but with redirected input and output.

phorward commented 1 year ago

Playground for a possible solution: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=1bee6b3dc7140e4b1a20e50c4c44bf7f

The &mut dyn io::Write must become part of Context or Runtime.

phorward commented 1 year ago

Relates to #86