Skip to content

Commit

Permalink
undo inlining of DynObj.combine
Browse files Browse the repository at this point in the history
  • Loading branch information
kMutagene committed Oct 15, 2024
1 parent dcf4e5e commit c886ffa
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 1 deletion.
7 changes: 7 additions & 0 deletions DynamicObj.sln
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "DynamicObject.Immutable.Tes
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{E0867002-4410-4E5F-BE71-46ABBE93ED07}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "FSharpConsole", "tests\FSharpConsole\FSharpConsole.fsproj", "{AF8AE8C7-B7C9-4CAC-9FE4-F5BCF015798D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -81,6 +83,10 @@ Global
{0F6A539F-82D2-4BDC-8BF0-F2D261873B92}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0F6A539F-82D2-4BDC-8BF0-F2D261873B92}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0F6A539F-82D2-4BDC-8BF0-F2D261873B92}.Release|Any CPU.Build.0 = Release|Any CPU
{AF8AE8C7-B7C9-4CAC-9FE4-F5BCF015798D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AF8AE8C7-B7C9-4CAC-9FE4-F5BCF015798D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AF8AE8C7-B7C9-4CAC-9FE4-F5BCF015798D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AF8AE8C7-B7C9-4CAC-9FE4-F5BCF015798D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -92,6 +98,7 @@ Global
{5E7DAC28-7752-4209-B3BB-6DCE54C28AD8} = {E0867002-4410-4E5F-BE71-46ABBE93ED07}
{39192F2D-164B-4905-A7D7-5C5B0FFCD2BB} = {988D804A-3A42-4E46-B233-B64F5C22524B}
{0F6A539F-82D2-4BDC-8BF0-F2D261873B92} = {988D804A-3A42-4E46-B233-B64F5C22524B}
{AF8AE8C7-B7C9-4CAC-9FE4-F5BCF015798D} = {988D804A-3A42-4E46-B233-B64F5C22524B}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {6F5C3597-4524-4A4E-94EC-44857BD0BCEC}
Expand Down
2 changes: 1 addition & 1 deletion src/DynamicObj/DynObj.fs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ module DynObj =
/// <param name="first"></param>
/// <param name="second"></param>
/// <remarks>This function mutates the first input DynamicObj</remarks>
let rec combine (first:#DynamicObj) (second:#DynamicObj) =
let rec combine (first:DynamicObj) (second:DynamicObj) =
//printfn "Type %A" (first.GetType())
/// Consider deep-copy of first
for kv in (second.GetProperties true) do
Expand Down
26 changes: 26 additions & 0 deletions tests/DynamicObject.Tests/DynObj.fs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,26 @@ let tests_ofArray = ptestList "ofArray" [
Expect.equal (dyn.GetPropertyValue("key2")) 2 "Value should be 2"
]

type Inner() =
inherit DynamicObj()
static member init(
?inner_value: string
) =
Inner()
|> DynObj.withOptionalProperty "inner_value" inner_value

type Outer() =
inherit DynamicObj()
static member init(
?A: int,
?B: string,
?Inner: Inner
) =
Outer()
|> DynObj.withOptionalProperty "A" A
|> DynObj.withOptionalProperty "B" B
|> DynObj.withOptionalProperty "Inner" Inner

let tests_combine = testList "combine" [

testCase "Combine flat DOs" <| fun _ ->
Expand Down Expand Up @@ -109,6 +129,12 @@ let tests_combine = testList "combine" [
)

Expect.equal expected combined "Combine nested DOs failed"

testCase "Combine nested DOs with inheriting types" <| fun _ ->
let outer1 = Outer.init(A = 1, B = "first", Inner = Inner.init(inner_value = "inner_first"))
let outer2 = Outer.init(A = 2, B = "second", Inner = Inner.init(inner_value = "inner_second"))
let expected = Outer.init(A = 2, B = "second", Inner = Inner.init(inner_value = "inner_second"))
Expect.equal (expected) (DynObj.combine outer1 outer2 |> unbox) "Combine nested DOs with inheriting types failed"
]

let tests_tryGetTypedPropertyValue = testList "tryGetTypedPropertyValue" [
Expand Down
16 changes: 16 additions & 0 deletions tests/FSharpConsole/FSharpConsole.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Compile Include="Program.fs" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\DynamicObj\DynamicObj.fsproj" />
</ItemGroup>

</Project>
30 changes: 30 additions & 0 deletions tests/FSharpConsole/Program.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// For more information see https://aka.ms/fsharp-console-apps

open DynamicObj

type Inner() =
inherit DynamicObj()
static member init(
?inner_value: string
) =
Inner()
|> DynObj.withOptionalProperty "inner_value" inner_value

type Outer() =
inherit DynamicObj()
static member init(
?A: int,
?B: string,
?Inner: Inner
) =
Outer()
|> DynObj.withOptionalProperty "A" A
|> DynObj.withOptionalProperty "B" B
|> DynObj.withOptionalProperty "Inner" Inner


let outer1 = Outer.init(A = 1, B = "first", Inner = Inner.init(inner_value = "inner_first"))
let outer2 = Outer.init(A = 2, B = "second", Inner = Inner.init(inner_value = "inner_second"))
let expected = Outer.init(A = 2, B = "second", Inner = Inner.init(inner_value = "inner_second"))

printfn "%A" ((DynObj.combine outer1 outer2) = expected)

0 comments on commit c886ffa

Please sign in to comment.