Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wildcards in tests #2298

Open
kylegoetz opened this issue Jun 2, 2023 · 2 comments
Open

Wildcards in tests #2298

kylegoetz opened this issue Jun 2, 2023 · 2 comments
Labels
enhancement Feature request test Related to tests

Comments

@kylegoetz
Copy link

kylegoetz commented Jun 2, 2023

Suppose I want to test a rule that parses variable names, but the top level of my file cannot have a variable name. Say variable names only appear four rules deep from the top level.

There isn't a straightforward way to do unit tests on just the variable name rule.

Something like

===
var name
===
foo = bar { baz ; fizz .
---
(fakelang
  (term_declaration
    (left_hand_side
      (symbol
        (var_name)))
    (equals)
    (rhs
      (and so on))))

The problem is that this test would fail if the rules term_declaration, left_hand_side, symbol, equals, rhs, and so on were to fail. Even if I changed one of those names (say left_hand_side became lhs), it would break tests intended to test something completely unrelated.

It would be really nice if I could write an expected test result using something like

---
(fakelang
  (* (var_name) *))

The motivation for this is that I have a lot of types of literals that I'd like to test the rules for, but the top level of my code can only be one of a few things, so all my literal tests are of the form

===
boolean literal
===
x = true
---
(unison
  (term_declaration
    (wordy_id)
    (equals)
    (boolean)))

First, this gets wordy to test one rule. Second, the thing that actually has made testing a pain in the butt, is if I decide a totally unrelated rule, currently called wordy_id, shoudl isntead be called name, it breaks every test for literals even though it has nothing to do with the rules I'm testing.

@kylegoetz
Copy link
Author

kylegoetz commented Jun 2, 2023

Maybe instead you could identify the parent rule to "start with"? So then something like

---
x = true
---
[term_declaration] (wordy_id) (equals) (boolean)

That doesn't fix it for all cases, but it does let you ignore a lot of upstream boilerplate to get to what you're actually testing.

@dundargoc dundargoc added the enhancement Feature request label Feb 9, 2024
@dundargoc dundargoc changed the title Feature Request: Wildcards in tests Wildcards in tests Feb 9, 2024
@ObserverOfTime ObserverOfTime added the test Related to tests label Apr 13, 2024
@extradosages
Copy link

Being able to write unit tests for sub-rules is key!

Maybe instead you could identify the parent rule to "start with"? So then something like

---
x = true
---
[term_declaration] (wordy_id) (equals) (boolean)

That doesn't fix it for all cases, but it does let you ignore a lot of upstream boilerplate to get to what you're actually testing.

This is the way to go ☝️.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature request test Related to tests
Projects
None yet
Development

No branches or pull requests

5 participants
@kylegoetz @extradosages @ObserverOfTime @dundargoc and others