@@ -77,6 +77,26 @@ type HostExternTests () =
7777 | VOption ( Some ( VInt 20 L)) -> ()
7878 | _ -> Assert.Fail( " Expected chosen map value 20 for key b" )
7979
80+ [<Test>]
81+ member _. ``Map.map maps values and Map.iter applies key - value iterator`` () =
82+ match Helpers.evalWithExterns externs " Map.ofList [(\" a\" , 1); (\" b\" , 2)] |> Map.map (fun v -> v + 10) |> Map.tryGet \" b\" " with
83+ | VOption ( Some ( VInt 12 L)) -> ()
84+ | _ -> Assert.Fail( " Expected mapped map value 12 for key b" )
85+
86+ let original = Console.Out
87+ use writer = new StringWriter()
88+ Console.SetOut( writer)
89+ try
90+ let result =
91+ Helpers.evalWithExterns externs
92+ " Map.ofList [(\" a\" , 1); (\" b\" , 2)] |> Map.iter (fun key -> fun value -> print $\" {key}:{value}\" )"
93+ match result with
94+ | VUnit -> ()
95+ | _ -> Assert.Fail( " Expected unit" )
96+ writer.ToString() .Replace( " \r\n " , " \n " ) .TrimEnd() |> should equal " a:1\n b:2"
97+ finally
98+ Console.SetOut( original)
99+
80100 [<Test>]
81101 member _. ``Fs write - side externs operate under root confinement`` () =
82102 let root = Path.Combine( Path.GetTempPath(), " fscript-host-extern-tests" , Guid.NewGuid() .ToString( " N" ))
@@ -105,6 +125,15 @@ type HostExternTests () =
105125 | VList [ VInt 1 L; VInt 2 L; VInt 3 L; VInt 4 L ] -> ()
106126 | _ -> Assert.Fail( " Expected mapped int list" )
107127
128+ [<Test>]
129+ member _. ``List.empty behaves as a value and cannot be invoked`` () =
130+ match Helpers.evalWithExterns externs " List.empty |> List.length" with
131+ | VInt 0 L -> ()
132+ | _ -> Assert.Fail( " Expected empty list length 0" )
133+
134+ let act () = Helpers.evalWithExterns externs " List.empty ()" |> ignore
135+ act |> should throw typeof< TypeException>
136+
108137 [<Test>]
109138 member _. ``List.iter external applies function and returns unit`` () =
110139 let original = Console.Out
0 commit comments