-
Notifications
You must be signed in to change notification settings - Fork 4
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
Deep copy improvements #46
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1a9871f
WIP more typechecks for deep copy
kMutagene 7dc9638
we must give up transpiling some typechecks, but behavbior is at leas…
kMutagene af340c6
fix structural equality tests, conditional dictionary typechecks
kMutagene 66b31bd
add some dictionary deep copy tests
kMutagene 7144ee8
??
kMutagene 311d17c
Add tests for deep copying all supported dictionaries
kMutagene fd57ba5
implement #44
kMutagene File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
This file contains 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
2,563 changes: 2,563 additions & 0 deletions
2,563
tests/DynamicObject.Tests/CopyUtils.tryDeepCopyObj/Dictionaries.fs
Large diffs are not rendered by default.
Oops, something went wrong.
2 changes: 2 additions & 0 deletions
2
tests/DynamicObject.Tests/CopyUtils.tryDeepCopyObj/DynamicObj.fs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module DeepCopyDynamicObj | ||
|
2 changes: 2 additions & 0 deletions
2
tests/DynamicObject.Tests/CopyUtils.tryDeepCopyObj/DynamicObjCollections.fs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module DeepCopyDynamicObjCollections | ||
|
2 changes: 2 additions & 0 deletions
2
tests/DynamicObject.Tests/CopyUtils.tryDeepCopyObj/ICloneable.fs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module DeepCopyICloneable | ||
|
13 changes: 13 additions & 0 deletions
13
tests/DynamicObject.Tests/CopyUtils.tryDeepCopyObj/Main.fs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module CopyUtils.Tests | ||
|
||
open System | ||
open Fable.Pyxpecto | ||
open DynamicObj | ||
open Fable.Core | ||
|
||
let main = testList "CopyUtils.tryDeepCopyObj" [ | ||
DeepCopyPrimitives.tests_DeepCopyPrimitives | ||
DeepCopyResizeArrays.tests_DeepCopyResizeArrays | ||
DeepCopyDictionaries.tests_DeepCopyDictionaries | ||
] | ||
|
60 changes: 60 additions & 0 deletions
60
tests/DynamicObject.Tests/CopyUtils.tryDeepCopyObj/Primitives.fs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
module DeepCopyPrimitives | ||
|
||
open System | ||
open Fable.Pyxpecto | ||
open DynamicObj | ||
open Fable.Core | ||
open TestUtils | ||
|
||
let tests_DeepCopyPrimitives = testList "Primitives" [ | ||
testCase "bool" <| fun _ -> | ||
let original, copy = constructDeepCopiedObj true | ||
Expect.equal copy original "Expected values of copy and original to be equal" | ||
testCase "byte" <| fun _ -> | ||
let original, copy = constructDeepCopiedObj 1uy | ||
Expect.equal copy original "Expected values of copy and original to be equal" | ||
testCase "sbyte" <| fun _ -> | ||
let original, copy = constructDeepCopiedObj 1y | ||
Expect.equal copy original "Expected values of copy and original to be equal" | ||
testCase "int16" <| fun _ -> | ||
let original, copy = constructDeepCopiedObj 1s | ||
Expect.equal copy original "Expected values of copy and original to be equal" | ||
testCase "uint16" <| fun _ -> | ||
let original, copy = constructDeepCopiedObj 1us | ||
Expect.equal copy original "Expected values of copy and original to be equal" | ||
testCase "int" <| fun _ -> | ||
let original, copy = constructDeepCopiedObj 1 | ||
Expect.equal copy original "Expected values of copy and original to be equal" | ||
testCase "uint" <| fun _ -> | ||
let original, copy = constructDeepCopiedObj 1u | ||
Expect.equal copy original "Expected values of copy and original to be equal" | ||
testCase "int64" <| fun _ -> | ||
let original, copy = constructDeepCopiedObj 1L | ||
Expect.equal copy original "Expected values of copy and original to be equal" | ||
testCase "uint64" <| fun _ -> | ||
let original, copy = constructDeepCopiedObj 1uL | ||
Expect.equal copy original "Expected values of copy and original to be equal" | ||
#if !FABLE_COMPILER | ||
testCase "nativeint" <| fun _ -> | ||
let original, copy = constructDeepCopiedObj (System.IntPtr(1)) | ||
Expect.equal copy original "Expected values of copy and original to be equal" | ||
testCase "unativeint" <| fun _ -> | ||
let original, copy = constructDeepCopiedObj (System.UIntPtr(1u)) | ||
Expect.equal copy original "Expected values of copy and original to be equal" | ||
#endif | ||
testCase "float" <| fun _ -> | ||
let original, copy = constructDeepCopiedObj 1.0 | ||
Expect.equal copy original "Expected values of copy and original to be equal" | ||
testCase "float32" <| fun _ -> | ||
let original, copy = constructDeepCopiedObj 1.0f | ||
Expect.equal copy original "Expected values of copy and original to be equal" | ||
testCase "char" <| fun _ -> | ||
let original, copy = constructDeepCopiedObj 'A' | ||
Expect.equal copy original "Expected values of copy and original to be equal" | ||
testCase "string" <| fun _ -> | ||
let original, copy = constructDeepCopiedObj "Hi" | ||
Expect.equal copy original "Expected values of copy and original to be equal" | ||
testCase "unit" <| fun _ -> | ||
let original, copy = constructDeepCopiedObj () | ||
Expect.equal copy original "Expected values of copy and original to be equal" | ||
] |
148 changes: 148 additions & 0 deletions
148
tests/DynamicObject.Tests/CopyUtils.tryDeepCopyObj/ResizeArrays.fs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
module DeepCopyResizeArrays | ||
|
||
open System | ||
open Fable.Pyxpecto | ||
open DynamicObj | ||
open Fable.Core | ||
open TestUtils | ||
|
||
let tests_DeepCopyResizeArrays = testList "ResizeArrays" [ | ||
testCase "bool" <| fun _ -> | ||
let arr = ResizeArray([true; false]) | ||
let original, copy = constructDeepCopiedObj arr | ||
Expect.sequenceEqual copy original "Expected values of copy and original to be equal" | ||
Expect.notReferenceEqual copy original "Expected values of copy and original to be not reference equal" | ||
arr[0] <- false | ||
Expect.sequenceEqual original (ResizeArray([false; false])) "Original schould have been mutated" | ||
Expect.sequenceEqual copy (ResizeArray([true; false])) "Clone should not be affected by original mutation" | ||
testCase "byte" <| fun _ -> | ||
let arr = ResizeArray([1uy; 2uy]) | ||
let original, copy = constructDeepCopiedObj arr | ||
Expect.sequenceEqual copy original "Expected values of copy and original to be equal" | ||
Expect.notReferenceEqual copy original "Expected values of copy and original to be not reference equal" | ||
arr[0] <- 2uy | ||
Expect.sequenceEqual original (ResizeArray([2uy; 2uy])) "Original schould have been mutated" | ||
Expect.sequenceEqual copy (ResizeArray([1uy; 2uy])) "Clone should not be affected by original mutation" | ||
testCase "sbyte" <| fun _ -> | ||
let arr = ResizeArray([1y; 2y]) | ||
let original, copy = constructDeepCopiedObj arr | ||
Expect.sequenceEqual copy original "Expected values of copy and original to be equal" | ||
Expect.notReferenceEqual copy original "Expected values of copy and original to be not reference equal" | ||
arr[0] <- 2y | ||
Expect.sequenceEqual original (ResizeArray([2y; 2y])) "Original schould have been mutated" | ||
Expect.sequenceEqual copy (ResizeArray([1y; 2y])) "Clone should not be affected by original mutation" | ||
testCase "int16" <| fun _ -> | ||
let arr = ResizeArray([1s; 2s]) | ||
let original, copy = constructDeepCopiedObj arr | ||
Expect.sequenceEqual copy original "Expected values of copy and original to be equal" | ||
Expect.notReferenceEqual copy original "Expected values of copy and original to be not reference equal" | ||
arr[0] <- 2s | ||
Expect.sequenceEqual original (ResizeArray([2s; 2s])) "Original schould have been mutated" | ||
Expect.sequenceEqual copy (ResizeArray([1s; 2s])) "Clone should not be affected by original mutation" | ||
testCase "uint16" <| fun _ -> | ||
let arr = ResizeArray([1us; 2us]) | ||
let original, copy = constructDeepCopiedObj arr | ||
Expect.sequenceEqual copy original "Expected values of copy and original to be equal" | ||
Expect.notReferenceEqual copy original "Expected values of copy and original to be not reference equal" | ||
arr[0] <- 2us | ||
Expect.sequenceEqual original (ResizeArray([2us; 2us])) "Original schould have been mutated" | ||
Expect.sequenceEqual copy (ResizeArray([1us; 2us])) "Clone should not be affected by original mutation" | ||
testCase "int" <| fun _ -> | ||
let arr = ResizeArray([1; 2]) | ||
let original, copy = constructDeepCopiedObj arr | ||
Expect.sequenceEqual copy original "Expected values of copy and original to be equal" | ||
Expect.notReferenceEqual copy original "Expected values of copy and original to be not reference equal" | ||
arr[0] <- 2 | ||
Expect.sequenceEqual original (ResizeArray([2; 2])) "Original schould have been mutated" | ||
Expect.sequenceEqual copy (ResizeArray([1; 2])) "Clone should not be affected by original mutation" | ||
testCase "uint" <| fun _ -> | ||
let arr = ResizeArray([1u; 2u]) | ||
let original, copy = constructDeepCopiedObj arr | ||
Expect.sequenceEqual copy original "Expected values of copy and original to be equal" | ||
Expect.notReferenceEqual copy original "Expected values of copy and original to be not reference equal" | ||
arr[0] <- 2u | ||
Expect.sequenceEqual original (ResizeArray([2u; 2u])) "Original schould have been mutated" | ||
Expect.sequenceEqual copy (ResizeArray([1u; 2u])) "Clone should not be affected by original mutation" | ||
testCase "int64" <| fun _ -> | ||
let arr = ResizeArray([1L; 2L]) | ||
let original, copy = constructDeepCopiedObj arr | ||
Expect.sequenceEqual copy original "Expected values of copy and original to be equal" | ||
Expect.notReferenceEqual copy original "Expected values of copy and original to be not reference equal" | ||
arr[0] <- 2L | ||
Expect.sequenceEqual original (ResizeArray([2L; 2L])) "Original schould have been mutated" | ||
Expect.sequenceEqual copy (ResizeArray([1L; 2L])) "Clone should not be affected by original mutation" | ||
testCase "uint64" <| fun _ -> | ||
let arr = ResizeArray([1uL; 2uL]) | ||
let original, copy = constructDeepCopiedObj arr | ||
Expect.sequenceEqual copy original "Expected values of copy and original to be equal" | ||
Expect.notReferenceEqual copy original "Expected values of copy and original to be not reference equal" | ||
arr[0] <- 2uL | ||
Expect.sequenceEqual original (ResizeArray([2uL; 2uL])) "Original schould have been mutated" | ||
Expect.sequenceEqual copy (ResizeArray([1uL; 2uL])) "Clone should not be affected by original mutation" | ||
testCase "float" <| fun _ -> | ||
let arr = ResizeArray([1.0; 2.0]) | ||
let original, copy = constructDeepCopiedObj arr | ||
Expect.sequenceEqual copy original "Expected values of copy and original to be equal" | ||
Expect.notReferenceEqual copy original "Expected values of copy and original to be not reference equal" | ||
arr[0] <- 2.0 | ||
Expect.sequenceEqual original (ResizeArray([2.0; 2.0])) "Original schould have been mutated" | ||
Expect.sequenceEqual copy (ResizeArray([1.0; 2.0])) "Clone should not be affected by original mutation" | ||
testCase "float32" <| fun _ -> | ||
let arr = ResizeArray([1.0f; 2.0f]) | ||
let original, copy = constructDeepCopiedObj arr | ||
Expect.sequenceEqual copy original "Expected values of copy and original to be equal" | ||
Expect.notReferenceEqual copy original "Expected values of copy and original to be not reference equal" | ||
arr[0] <- 2.0f | ||
Expect.sequenceEqual original (ResizeArray([2.0f; 2.0f])) "Original schould have been mutated" | ||
Expect.sequenceEqual copy (ResizeArray([1.0f; 2.0f])) "Clone should not be affected by original mutation" | ||
testCase "char" <| fun _ -> | ||
let arr = ResizeArray(['A'; 'B']) | ||
let original, copy = constructDeepCopiedObj arr | ||
Expect.sequenceEqual copy original "Expected values of copy and original to be equal" | ||
Expect.notReferenceEqual copy original "Expected values of copy and original to be not reference equal" | ||
arr[0] <- 'B' | ||
Expect.sequenceEqual original (ResizeArray(['B'; 'B'])) "Original schould have been mutated" | ||
Expect.sequenceEqual copy (ResizeArray(['A'; 'B'])) "Clone should not be affected by original mutation" | ||
testCase "string" <| fun _ -> | ||
let arr = ResizeArray(["Hi"; "Bye"]) | ||
let original, copy = constructDeepCopiedObj arr | ||
Expect.sequenceEqual copy original "Expected values of copy and original to be equal" | ||
Expect.notReferenceEqual copy original "Expected values of copy and original to be not reference equal" | ||
arr[0] <- "Bye" | ||
Expect.sequenceEqual original (ResizeArray(["Bye"; "Bye"])) "Original schould have been mutated" | ||
Expect.sequenceEqual copy (ResizeArray(["Hi"; "Bye"])) "Clone should not be affected by original mutation" | ||
testCase "unit" <| fun _ -> | ||
let arr = ResizeArray([(); ()]) | ||
let original, copy = constructDeepCopiedObj arr | ||
Expect.sequenceEqual copy original "Expected values of copy and original to be equal" | ||
Expect.notReferenceEqual copy original "Expected values of copy and original to be not reference equal" | ||
// transpilation fun | ||
let arr2 = ResizeArray([()]) | ||
arr.Add(arr2[0]) | ||
Expect.sequenceEqual original (ResizeArray([(); (); ()])) "Original schould have been mutated" | ||
Expect.sequenceEqual copy (ResizeArray([(); ()])) "Clone should not be affected by original mutation" | ||
|
||
// some cases are not transpilable | ||
|
||
#if !FABLE_COMPILER_PYTHON | ||
testCase "decimal" <| fun _ -> | ||
let arr = ResizeArray([1.0M; 2.0M]) | ||
let original, copy = constructDeepCopiedObj arr | ||
Expect.sequenceEqual copy original "Expected values of copy and original to be equal" | ||
Expect.notReferenceEqual copy original "Expected values of copy and original to be not reference equal" | ||
arr[0] <- 2.0M | ||
Expect.sequenceEqual original (ResizeArray([2.0M; 2.0M])) "Original schould have been mutated" | ||
Expect.sequenceEqual copy (ResizeArray([1.0M; 2.0M])) "Clone should not be affected by original mutation" | ||
#endif | ||
|
||
#if !FABLE_COMPILER | ||
testCase "nativeint" <| fun _ -> | ||
let original, copy = constructDeepCopiedObj (ResizeArray([System.IntPtr(1); System.IntPtr(2)])) | ||
Expect.sequenceEqual copy original "Expected values of copy and original to be equal" | ||
Expect.notReferenceEqual copy original "Expected values of copy and original to be not reference equal" | ||
testCase "unativeint" <| fun _ -> | ||
let original, copy = constructDeepCopiedObj (ResizeArray([System.UIntPtr(1u); System.UIntPtr(2u)])) | ||
Expect.sequenceEqual copy original "Expected values of copy and original to be equal" | ||
Expect.notReferenceEqual copy original "Expected values of copy and original to be not reference equal" | ||
#endif | ||
] |
This file contains 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
This file contains 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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are the missing tests you referenced in #48?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/CSBiology/DynamicObj/blob/main/tests/DynamicObject.Tests/DynamicObj/DeepCopyProperties.fs Contains a few tests for
DynamicObj.DeepCopyProperties
that covers nested Dynamic Objects. I was mainly referring to the underlying functionCopyUtils.tryDeepCopyObj
still missing tests