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

tablex: Add deep & shallow for copy, overlay; remove redundant recursion; add tests #52

Merged
merged 4 commits into from
Mar 6, 2022

Conversation

idbrii
Copy link
Contributor

@idbrii idbrii commented Mar 4, 2022

Remove redundant recursion

Remove recursion from second loop of deep_equals. The first loop already checked for equality so the second only needs to check if the keys are there. Add test to validate.

Add deep & shallow for copy, overlay

BREAKING Implement the comment over copy():

  • Replace copy with shallow_copy, deep_copy.
    • These copy functions copy any input type instead of requiring a table. That makes it easier to write generic code where you just want to copy some input without knowing anything about it. Like an event system, save system, etc.
  • Replace overlay with shallow_overlay, deep_overlay.

Add corresponding tests.

Tests can be run with testy which is a low setup test framework -- it runs local functions prefixed with test_ and uses assert to detect failures.

Add github action to run tests on PR. See test output: success on idbrii@d48d4b0 fail on idbrii@d917e96. You can see that using vanilla assert() gives different output from batteries assert because testy provides a low-noise and non stopping

The second loop doesn't care if the values are equal. It only checks if
the keys are there. The first loop already checked for equality.

Add tests to prove correctness using testy.lua.
Replace copy with shallow_copy, deep_copy.
Replace overlay with shallow_overlay, deep_overlay.

Significant rewrite of these functions and their semantics to update to
the note above them.

Add corresponding tests.
Run tests on CI so they're useful for catching errors in PRs.
Allowing shallow_copy/deep_copy to accept any type makes it easier to
write generic code where you just want to copy some input without
knowing anything about it. Like an event system, save system, etc.

Add corresponding test.

Tests pass
@1bardesign
Copy link
Owner

I'm actually a bit hesitant to have tests in the repo for size reasons; a lot of folks including myself will use the repo as a submodule and end up packaging the tests up along with the code if they do it "the straightforward way". The alternative is having them in an external repo like the examples though, and that seems likely to get noses out of joint as well.

In the interest of getting this merged, I'll raise an issue to talk about a long term solution to this.

@1bardesign 1bardesign merged commit 461c3a8 into 1bardesign:master Mar 6, 2022
@1bardesign 1bardesign mentioned this pull request Mar 6, 2022
@idbrii idbrii deleted the table-deep-test branch March 7, 2022 02:21
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.

None yet

2 participants