Open
Conversation
Initial commit of implementation and tests for ip_compare(), designed for use with Puppet's `sort()` to sort a series of IP addresses into binary-numerical order, regardless of the human-readable representation in which they were originally written.
Initial commit of greater_than, equal_or_greater_than, equal_to, equal_or_less_than, and less_than comparator functions and their unit tests.
28f5ed7 to
027c115
Compare
Important realization that made me feel kinda dumb: if you want to handle the case of comparing with-prefix form to no-prefix form, you can't just key your normalization pass off of both values being one or the other. Normalize each value individually, which solves the problem correctly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is based on the work already submitted in #14, and includes another update to the PDK templates (although unfortunately not very much of one, this time). This adds some usefull functions for comparing and equality-testing IP addresses, both with equivalent functions for traditional boolean-return comparisons (
>,>=,==,<=, and<), and for use with functions like Puppet'ssort(), which execute a block and expect one of-1,0, or1as return to indicate whether the left operand is smaller than, equal to, or greater than the right, and will perform arbitrarily elaborate sorts accordingly.My specific need for this was the
sort()case to put a list of IP addresses in sorted order to (hopefully) match the output of a certain popularly-unpopular network management tool, and the others were just simple enough at that point that there wasn't a good reason NOT to include them (or at least, that's what I thought until I started writing docs for all of them, heh).