Skip to content

Catch edge cases were delimiters are wrongfully caught#312

Merged
abitrolly merged 2 commits intochubin:masterfrom
Jan200101:PR/g++
Nov 13, 2021
Merged

Catch edge cases were delimiters are wrongfully caught#312
abitrolly merged 2 commits intochubin:masterfrom
Jan200101:PR/g++

Conversation

@Jan200101
Copy link
Copy Markdown
Contributor

related to #308

implements more robust logic that splits on the first delim it finds that isn't followed by the same delim

@abitrolly
Copy link
Copy Markdown
Collaborator

This part of code badly needs some test table with expected inputs and outputs. I am having a hard time trying to juggle them in my head.

I spent some time juggling with re.split but then it turned out to be too complicated with no solution.

In [4]: delim = re.escape('+')                                                                                                                                            

In [5]: re.split(delim, '/g++ whoa')                                                                                                                                      
Out[5]: ['/g', '', ' whoa']

In [6]: re.split("%s+" % delim, '/g++ whoa')                                                                                                                              
Out[6]: ['/g', ' whoa']

In [7]: re.split("%s+" % delim, '/g++')                                                                                                                                   
Out[7]: ['/g', '']
...

In [21]: re.split("%s(?:[^%s])" % (delim, delim), '/ge+ll33+++')                                                                                                          
Out[21]: ['/ge', 'l33+++']
...

@Jan200101
Copy link
Copy Markdown
Contributor Author

I don't have a complete list of would be inputs, but here are a few test cases that should correctly split query and section:

rm+-rf, rm -rf, g++

@abitrolly
Copy link
Copy Markdown
Collaborator

@Jan200101 how about moving that function to the root scope without modification in a separate commit?

This way we will be able to test previous behavior in automated fashion with bisect.

@Jan200101
Copy link
Copy Markdown
Contributor Author

sure thing

@abitrolly
Copy link
Copy Markdown
Collaborator

Well, I actually thought about moving only one function, as it is the only thing which behavior needs to be tested right now. Otherwise the diff becomes quite unreadable. And the move commit needs to be code modification commit for the old behavior to be testable.

@Jan200101
Copy link
Copy Markdown
Contributor Author

Jan200101 commented Oct 15, 2021

I had taken the initiative to move out all functions but reversed that

the first commit now moves the nested function out of the scope
and the second commit implements the logic

@abitrolly
Copy link
Copy Markdown
Collaborator

So the way to go from here. I need to setup a development environment to fix tests in master before going further. Then I need to run tests to intercept all queries passed to _add_section_name() and record queries to file. Then record input and output as a test. Then apply these changes, and run the tests.

abitrolly added a commit that referenced this pull request Oct 22, 2021
@abitrolly
Copy link
Copy Markdown
Collaborator

@Jan200101 I've merged one of your commits and added tests on top to the master. If you rebase this and add a couple of edge cases to the list of tested strings, this will be ready to go in.

@Jan200101
Copy link
Copy Markdown
Contributor Author

I've added some tests that have + in their name that should be unchanged.

I had added another test case locally but kept it out because it fails the test.
I'll leave it up to you if the test is valid or not

split = """
g++ -O2
g++/-O2
"""

@Jan200101
Copy link
Copy Markdown
Contributor Author

I've reworked the logic slightly to deal with the test case above as well as to ease the exception handling a little bit.

Comment thread lib/cheat_wrapper.py Outdated
@Jan200101
Copy link
Copy Markdown
Contributor Author

CI failure seems unrelated to PR.

@abitrolly
Copy link
Copy Markdown
Collaborator

CI errors are strange. Need to investigate them before going on.

@abitrolly
Copy link
Copy Markdown
Collaborator

Fixed tests in #317. Should become green after rebase.

@abitrolly abitrolly merged commit 0ff765a into chubin:master Nov 13, 2021
abitrolly added a commit that referenced this pull request Nov 13, 2021
abitrolly added a commit that referenced this pull request Nov 13, 2021
@abitrolly
Copy link
Copy Markdown
Collaborator

While going through the logic I found that it could still strip ++ in lines, so that g++g++ becomes g+/g++, so in #318 I replaced it with a regexp that only matches a single + in the middle. Thanks for the PR pointing out to the solution.

grayed pushed a commit to grayed/cheat.sh that referenced this pull request Nov 17, 2021
grayed pushed a commit to grayed/cheat.sh that referenced this pull request Nov 17, 2021
grayed pushed a commit to grayed/cheat.sh that referenced this pull request Nov 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants