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

[Do Not Merge] Modify in_position? method to fix inconsistencies #11

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

asasfu
Copy link

@asasfu asasfu commented Nov 25, 2015

in_position? method wasn't working right due to issues with using following-sibling when before and preceding-sibling when after, this corrects it with new, hopefully proper assumptions. The only item that small change didn't fix was last() which was not working for either because of the way siblings treat the last() command as it will always resolve to true on the first match in those cases. This patch assumes that you'll never have more than one [last()] in your xpath for positioning and swaps it out with the correct final array value of augeas matches. We use an invert boolean on 'after' positions as we will always have an empty? resolving as true if the match exists before the item we're looking for. Whereas we'll always have empty? as false if we do a 'before' and the actual item currently exists after the line we're trying to match.

-- I still need to complete the unit tests for this. But this should be a working solution unless some side effects or conflicts can be presented.

this is a patch in reference to #10

in_position? method wasn't working right due to issues with using following-sibling when before and preceding-sibling when after, this corrects it with new, hopefully proper assumptions.  The only item that small change didn't fix was last() which was not working for either because of the way siblings treat the last() command as it will always resolve to true on the first match in those cases.  This patch assumes that you'll never have more than one [last()] in your xpath for positioning and swaps it out with the correct final array value of augeas matches.  We use an invert boolean on 'after' positions as we will always have an empty? resolving as true if the match exists before the item we're looking for.  Whereas we'll always have empty? as false if we do a 'before' and the actual item currently exists after the line we're trying to match.
Previously last_value would only work properly if you were evaluating the top lines of the file so it would be .../1/*, /2/, /3/ etc.  rather than some lines mid way down that would be .../17/*, /18/, /19/ etc.  In siblings we actually need to count items, so we now convert last() to be the count; minus 1 if there's more than one object, otherwise it should stay as 1.  Also, we should return true if the result of last_value is 1 or less(if less it means something probably went wrong because it didn't return any values, so likely that will never happen, but if 1... then it means we have no items of that type or xpath to compare to anyways, so it will never be, before or after, itself; therefore, always in_position.
@raphink
Copy link
Member

raphink commented Dec 21, 2015

LGTM. Any news on the tests @asasfu ?

@raphink raphink added the bug Something isn't working label Dec 21, 2015
@vox-pupuli-tasks
Copy link

Dear @asasfu, thanks for the PR!

This is Vox Pupuli Tasks, your friendly Vox Pupuli Github Bot. I noticed that your pull request has CI failures. Can you please have a look at the failing CI jobs?
If you need any help, you can reach out to us on our IRC channel voxpupuli on Freenode or our Slack channel voxpupuli at slack.puppet.com.
You can find my sourcecode at voxpupuli/vox-pupuli-tasks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working tests-fail
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants