tweag / topiary

https://topiary.tweag.io/
MIT License
575 stars 29 forks source link

Introduce `coverage` subcommand #785

Closed nbacquey closed 3 weeks ago

nbacquey commented 3 weeks ago

Description

This PR adds a subcommand to the CLI, to check how much of a language query matches against the given input.

Here are examples of the new subcommand output:

$ topiary coverage -l rust <<EOF                             
enum Mode4 {
    Closed,                                 
    /* just leaving the current mode unchanged */
    Either,
}                      
EOF              
Query coverage: 48.00%
Unmatched queries:                                                                       
[                                                                                        
  "as"                                      
  "const"              
  "else"
  "extern"                                                                               
  "fn"
  "for"                                                                                  
  "if"                    
  "let"                                                                                  
  (mutable_specifier)                       
  (scoped_use_list)
  "struct"                                  
  "type"      
  "unsafe"                     
  (visibility_modifier)
  "while"
  "="
  "=="
  "-"
  "+"
  "->"
] @prepend_space @append_space

; Append spaces

[
  ":"
] @append_space

[...]

; PhantomData<&'a ()>

(_
  (lifetime) @append_space
  [(array_type) (generic_type) (primitive_type) (unit_type)]
)
$ topiary coverage topiary-cli/tests/samples/input/rust.rs 
Query coverage: 100.00%
All queries are matched

It is a major step towards #674

Checklist

Checklist before merging: