Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upinitial rework of syntest to be usable internally #185
Conversation
|
Just some architectural requests to make it fit better as a public API. Let me know if you made any real changes to the main body of the function you moved, I didn't read it, assuming it's just a copy-paste. |
| use syntect::highlighting::ScopeSelectors; | ||
| use syntect::easy::{ScopeRegionIterator}; | ||
| use syntect::parsing::{SyntaxSet}; | ||
| use syntect::easy::{SyntaxTestFileResult, SyntaxTestOutputOptions, process_syntax_test_assertions}; |
This comment has been minimized.
This comment has been minimized.
trishume
Jul 2, 2018
Owner
I don't think this should go in the easy module.
That's for simple wrappers for common use cases. Syntax tests are neither a wrapper around a more advanced API, nor a common use case.
They should probably go in their own syntax_tests module or something
| Success(usize), | ||
| } | ||
|
|
||
| pub fn process_syntax_test_assertions(syntax: &SyntaxDefinition, text: &str, testtoken_start: &str, testtoken_end: Option<&str>, out_opts: &SyntaxTestOutputOptions) -> SyntaxTestFileResult { |
This comment has been minimized.
This comment has been minimized.
trishume
Jul 2, 2018
Owner
If this is now going to be a public API, could you add a doc comment with short descriptions of what the parameters do? Also useful for our own reference.
| @@ -174,6 +174,236 @@ impl<'a> Iterator for ScopeRegionIterator<'a> { | |||
| } | |||
| } | |||
|
|
|||
| #[derive(Clone, Copy)] | |||
| pub struct SyntaxTestOutputOptions { | |||
This comment has been minimized.
This comment has been minimized.
trishume
Jul 2, 2018
Owner
Now that this is an API, it seems a bit weird for it to just print things to stdout.
Maybe you could add a lifetime parameter to this struct and add a output: &'a io::Write member. Alternatively you could add an extra parameter for the output to the process function.
Then the function then uses writeln! instead of println! to write to, and the process function would probably need to return an io::Result. Then syntest and possibly also unit tests could just pass stdout.
|
I have moved it to a new |
|
Nice, thanks for picking this up :)! In the current form, I don't think we should make it a public API. An API with the only output being some printed text doesn't seem very useful generally. So I would do either one of these two things:
(With the latter, we could do some nice things such as formatting as HTML so you can more easily see the actual scopes, show the results in a text editor instead, etc.) |
|
Printed text isn't the only output - the API returns the successful/failed assertion count too ;) I would guess that changing the API to return structs with the information about the assertions, and printing them from the |
|
Hehe :). Is it possible to make it return an |
|
I think that returning an iterator with the results is a cool idea, it would allow a consumer of the API to fail fast when a failure occurs, if so desired. Though I guess it would likely prevent the use cases we mentioned above, whereby the (optionally colored) output could be combined with the syntax test results, as it would only iterate over those results and then the file would have to be parsed again to achieve an integrated view, which isn't ideal. Marking the API for internal use only would solve needing to make further complicated changes at the moment. But changing the method to |
|
Okay I'll try and give the new implementation a real review then, likely this weekend. If you'd like I can probably also do the @robinst I agree it's not the greatest thing to have as a public API but:
|
|
Sorry I'm so late on reviewing this, I wanted to use my limited syntect bandwidth for stuff that needed to be in the 3.0 release. This is still on my TODO list. |
|
No worries, the work you did on the color schemes was awesome and indeed more important ;) |
keith-hall commentedJul 2, 2018
this is an initial rework of the
syntestexample, to make it usable internally, as it would be useful for parser tests (see #180 (comment)). I think it will need some more work to properly support assertions that extend over the end of the line (#175) and spill over onto not only the next line, but also the line afterwards etc. although such a scenario may never come up in real life use.