[Outdated] Basic Util Files For GoDiffX

Review Request #11830 — Created Oct. 1, 2021 and updated — Latest diff uploaded

Information

DiffX
master

Reviewers

All of the basic files have now been created along with some tests. This includes errors,
sections, options, text, and unified diffs.

I added the outdated tag because I started overwriting some of these basic things while
working on reader.go. It also does not make much sense to ship this on its own since
there aren't really any useful functions.

A test file was created on my machine in another directiory (~/Desktop/GoTest) and the module
was imported there. Since it does not make sense for semi-functional code to be pushed to Github,
I setup the local test file to think it's getting its information from
github.com/beanbaginc/diffx/go/godiffx when in reality, it is just checking my local copy. I can
overwrite this whenever code gets published to make sure it still works properly, but that is likely
something that can come towards the end of the project.

There is testing written for every file now and Go reports it having 98.1% coverage. The remaining 1.9%
is due to small redundancies in error handling where I don't expect a function to ever error at a certain
point, but I have code to handle it in case something odd happens.

The only other piece that still needs to be tested is the Go docs themselves. I have not had enough time
to spin up a local server where I can see what the documentation looks like, but I plan to do that soon
and will update this description once that is finished. I don't expect any issues but this is my first time
creating go docs so we will see.

Diff Revision 5

This is not the most recent revision of the diff. The latest diff is revision 8. See what's changed.

orig
1
2
3
4
5
6
7
8

Commits

First Last Summary ID Author
Create LICENSE and README for project
First commit for godiffx, just boilerplate based off of pydiffx. Testing done: NA
4552441df26f5bc1f71e0957b915eb5d294e2c88 Jordan
Create basic support files for diffx.
Created errors.go, sections.go, options.go, and text.go. These will all be based on their python equivalents from pydiffx. At the moment, there is no code within them besides stating which package they are apart of. No functionality introduced so no testing done.
53615b11759d77a06b2a0d6aa8f387beeb1eced7 Jordan
Write basic constants for options.go
Added the basic functions to options.go based on what is in options.py for pydiffx. This was accomplished via enums using iota in go. The implementation may be tweaked overtime once I actually need to start using them. The functionality of these was tested in another go file. This was also the first time I tried testing the godiffx module locally and it worked!
ed55e923e78ead35565ee3f344a234516cfc3921 Jordan
Wrote code for sections.go
sections.go is based off of sections.py, and the functionality was replicated as close as possible to that file. One hiccup was that Go does not support sets natively, but an easy work around is to use sets and just set all of the keys to true. Code was tested by creating the struct in another file that imported this module. The default parameter method was tested and properly adds in the default values and the getters were all functioning as expected.
3659b78ffe8b8cc27d23a5d1f497f2bb0ab00a21 Jordan
Update documentation for sections.go
Basic documentation via comments was added to the code in sections.go. No new functionality was introduced so there was no additional testing.
398e1cd37ede5380265ee716bb93f7217bfa9996 Jordan
Write all custom errors for godiffx.
These are based on the errors that were created for pydiffx. Go does not use errors in the same way, but an error struct was created and an error can be returned whenever needed by other functions. One note is that at the moment, there is no unicode support since I am not very familiar with it or implementing it, but I assume it will be as simple as changing the type and possibly importing the library in the future. This was tested by importing the module locally and testing each of the different types of errors. The init function was validated to ensure it would not overwrite an existing error and the Err function was tested to ensure it printed properly. I also tested to ensure the baseDiffXError was not accessible.
37da0122f047f79a5cb92e0aeba4d0b5711196ec Jordan
Add documentation and fix line value for DiffXParseError
Basic documentation was added to all of the functions and errors. They are all pretty simple definitions based off of what was used in the pydiffx version. There was also a modification made to the way line and column values are treated in DiffXParseError. Originally this was set to just use the values as they are passed in. However, pydiffx assumes these are 0 based so the message increments it by 1. This change was tested by importing the module locally in another file.
b9ade0ac8f01e150291ac24e2bebc38b01276cbc Jordan
Create text values and write SplitLines
Following the example from text.py, the maps have been created for godiffx as well. One thing to note is the utils folder is now gone. This is because when creating a module in Go, you actually don't use nested directories since those will then belong to a new package. Another change is that instead of using a map for the objects like in python, structs were created along with a way to initialize their default values. The reasoning behind this is that BOMS uses tuples to store multiple values in pydiffx, but tuples don't exist in Go. The SplitLines method was also written. This took a fair bit of time while I experimented and learned about the best way to handle bytes. The bytes.Buffer seems to be a very efficient data structure that comes with some functionality. Time will tell if this is the right way to go! All of the objects have been tested in the separate project using this module and I have run SplitLines with what I believe to be the proper behaviour.
ddb24d486e20a4f3365cb1186c647575d2ff3458 Jordan
Fix Errors and Write StripBom Method.
I made a silly mistake when creating the errors by naming the error functions 'Err()' instead of 'Error()' so they were not quite working like errors yet, so that has been resolved. I also wrote the StripBom method which will remove a given BOM from a byte buffer if it exists. In order to do this, I made a method that can retrieve the BOM given a string of the encoding type. I tested out the methods again in main. To test StripBom, I created a buffer that held "\uFEFF is a string that starts with a Byte Order Mark" and compared its length to before and after running the function. The buffer that the function returns will be shorter but it will not mutate the buffer passed in.
87a9119601141817aa81cef3e8b163a7d20b4f7b Jordan
Created test files and wrote init tests for Errors.go
All of the test files were created and can be run with the command 'go test'. I have written all of the Init tests for errors.go except for the base class since I am not 100% sure how to test private methods. However, I don't think it is too important since all of the other test cases work.
0576404dacb4b9f6ac9f5eceb9c29ee97c022b2a Jordan
Finish tests for errors.go
Finished writing the rest of the tests for errors.go, specifically all of the tests for the Error() methods. The only testing that was done was running the test suite and seeing all of the new tests pass.
40257068d62ca72958a447221529a04876ca908a Jordan
Add testing for sections.go
The testing itself is pretty trivial, since it just ensure the init methods works properly and that the set functions return the proper sets. The ValidSectionStates function has a very long test since there are so many different pieces that need to be checked. Not sure if this can be simplified some way in the future.
cb86e91b7b51ac9be3ed52c35fd9aab20baefa90 Jordan
Wrote unit tests for finished functions in text.go
While there is still a bit of work to be done for text.go, the unit tests for the finished functions have now been added in. These tests try to test for every edge case I can think of, but suggestions are welcome! I also do not know if there is a better way to run these tests. Currently, each test is rather large with a number of small pieces it tests for a function. It seems like Go tests usually have one test per function instead of multiple tests for different edge cases of a function, but if I find something new then I will make adjustments. The ony strategy I saw is to make a struct with test data, but I feel it would bloat the code a bit due to the number of byte buffers needed.
6f73cf4159218d416aa97234e19481982e6c2c94 Jordan
Create new error for invalid encoding.
Since it seemed relatively straightforward to add my own encoding and there weren't any great go modules I found with a quick search, I have started creating a function to encode in some given utf scheme. It makes sense to begin by creating an error that can be thrown in case someone provides an invalid string. A go test has been created as well in the same manner as all of the other error tests to ensure InvalidEncodingError works properly.
13bebc89fe5764f1da87e795230cab2eaddd1cb4 Jordan
Create encode method for text.go
I created an encode function based off of what Python does. There weren't any libraries I found quick that seemed to cover the different utf styles. I based their implementation off of the returns for unix and dos newlines. I have not created tests for the function yet, but I manually tested it by using the function in another project and comparing the output to Python
b5ef19b54466ccd7e3b3a961188974203b0c15f4 Jordan
Add GetNewlineForType function in text.go
This function is the same as the version in pydiffx. One note is that it returns a byte slice instead of a buffer, but I thought this would make more sense since it will usually only be a few bytes at most. There is no testing created for this function yet, it will be written at a later time. But it was manually tested with utf8 and utf16.
0951ce3c23a99b2d1b5e53128ebdd85feb28e413 Jordan
Finish manually testing all functions for text.go
All functions have now been written and manually tested in text.go. I thought I had things working on Saturday, but there was still an issue related to an EOF error that I had to sort out. Manual testing was done by creating a buffer that had both unix and dos newlines as well as an empty one where it assumed we used unix. No tests have been written for the newline guessing or getting.
5678c06d947b2c40ff5e73814a2ae1af36812da4 Jordan
Write tests for line ending methods.
This commit just adds a couple tests to ensure the GuessLineEnding and GetNewlineForType functions work properly.
3225e18cd1e33cf1f473cedfff7eb37fdb9df982 Jordan
Wrote unit test for encoding function
Just a quick unit test for encoding function. It's very inclusive and covers every possible return. I noticed that Go only thinks I have ~90% coverage for my tests, so I will likely spend some time trying to identify the edge cases I missed.
1a455560529844e0eb504cb130b8136534fbf337 Jordan
go/LICENSE
go/README.md
go/godiffx/errors.go
go/godiffx/errors_test.go
go/godiffx/go.mod
go/godiffx/options.go
go/godiffx/sections.go
go/godiffx/sections_test.go
go/godiffx/text.go
go/godiffx/text_test.go
Loading...