@@ -4,6 +4,67 @@ open System
44open Fable.Pyxpecto
55open DynamicObj
66
7+ let tests_tryGetTypedValue = testList " TryGetTypedValue" [
8+
9+ testCase " typeof" <| fun _ ->
10+ let a = typeof< int>
11+ Expect.equal a.Name " Int32" " Type should be Int32"
12+
13+ testCase " NonExisting" <| fun _ ->
14+ let a = DynamicObj()
15+ let b = DynObj.tryGetTypedValue< int> " a" a
16+ Expect.isNone b " Value should not exist"
17+
18+ testCase " Correct Int" <| fun _ ->
19+ let a = DynamicObj()
20+ a.SetValue( " a" , 1 )
21+ let b = DynObj.tryGetTypedValue< int> " a" a
22+ Expect.equal b ( Some 1 ) " Value should be 1"
23+
24+ testCase " Incorrect Int" <| fun _ ->
25+ let a = DynamicObj()
26+ a.SetValue( " a" , " 1" )
27+ let b = DynObj.tryGetTypedValue< int> " a" a
28+ Expect.isNone b " Value should not be an int"
29+
30+ testCase " Correct String" <| fun _ ->
31+ let a = DynamicObj()
32+ a.SetValue( " a" , " 1" )
33+ let b = DynObj.tryGetTypedValue< string> " a" a
34+ Expect.equal b ( Some " 1" ) " Value should be '1'"
35+
36+ testCase " Incorrect String" <| fun _ ->
37+ let a = DynamicObj()
38+ a.SetValue( " a" , 1 )
39+ let b = DynObj.tryGetTypedValue< string> " a" a
40+ Expect.isNone b " Value should not be a string"
41+
42+ testCase " Correct List" <| fun _ ->
43+ let a = DynamicObj()
44+ a.SetValue( " a" , [ 1 ; 2 ; 3 ])
45+ let b = DynObj.tryGetTypedValue< int list> " a" a
46+ Expect.equal b ( Some [ 1 ; 2 ; 3 ]) " Value should be [1; 2; 3]"
47+
48+ ptestCase " Incorrect List" <| fun _ ->
49+ let a = DynamicObj()
50+ a.SetValue( " a" , [ 1 ; 2 ; 3 ])
51+ let b = DynObj.tryGetTypedValue< string list> " a" a
52+ Expect.isNone b " Value should not be a string list"
53+
54+ testCase " Correct DynamicObj" <| fun _ ->
55+ let a = DynamicObj()
56+ let b = DynamicObj()
57+ a.SetValue( " a" , b)
58+ let c = DynObj.tryGetTypedValue< DynamicObj> " a" a
59+ Expect.equal c ( Some b) " Value should be a DynamicObj"
60+
61+ testCase " Incorrect DynamicObj" <| fun _ ->
62+ let a = DynamicObj()
63+ a.SetValue( " a" , 1 )
64+ let b = DynObj.tryGetTypedValue< DynamicObj> " a" a
65+ Expect.isNone b " Value should not be a DynamicObj"
66+ ]
67+
768
869let tests_set = testList " Set" [
970
@@ -304,6 +365,7 @@ let tests_copyDynamicProperties = testList "CopyDynamicProperties" [
304365]
305366
306367let main = testList " DynamicObj" [
368+ tests_ tryGetTypedValue
307369 tests_ set
308370 tests_ remove
309371 tests_ formatString
0 commit comments