<commit_before>﻿// Learn more about F# at http://fsharp.net

namespace Tests


open NUnit.Framework
open System
open Dynamitey
open System.Dynamic
open System.Collections.Generic
open System.Xml.Linq
open System.Numerics
open Microsoft.CSharp.RuntimeBinder
open FSharp.Interop.Dynamic
open FsUnit
open System.Linq.Expressions
open FSharp.Interop.Dynamic.Operators
module Tests=

    type TestEvent()=
        let event1 = new Event<EventHandler<EventArgs>, EventArgs>()
        [<CLIEvent>]
        member this.Event = event1.Publish
        member this.OnEvent(obj:Object, args:EventArgs)=
           event1.Trigger(obj,args)

    type TestFuncs()=
        static member Plus3:Func<int,int> =
          Return<int>.Arguments<int>(fun x-> x + 3)

    type DynamicOperatorMock()=
        inherit DynamicObject()
        override this.TryBinaryOperation(binder, arg, result) =
            result <- binder.Operation
            true

    type DynamicWeirdFlakyIndexer()=
        inherit DynamicObject()
        let stuff = Dictionary<obj * obj, obj>()

        override this.TryGetIndex(binder, indexes, result) =
            result <- stuff.[(indexes.[0], indexes.[1])]
            true
        
        override this.TrySetIndex(binder, indexes, value) =
            stuff.Add((indexes.[0], indexes.[1]),value)
            true

    [<TestFixture>]
    type ``Basic Dynamic Operator Tests`` ()=

        [<Test>] member basic.``Call method off of an object dynamically`` ()=
                       "HelloWorld"?Substring(0,5) |> should equal "Hello"


        [<Test>] member basic.``Test Expando Set and Get`` ()=
                        let ex1 = ExpandoObject()
                        ex1?Test<-"Hi";
                        ex1?Test |> should equal "Hi"


        [<Test>] member basic.``Test Direct Invoke`` ()=
                        !?Dynamic.Curry(Dyn.staticContext(typeof<string>))?Format("Test {0} {1}") (1,2) |>
                            should equal "Test 1 2"


        [<Test>] member basic.``Test Void Method`` ()=
                        let array = List<string>()
                        array?Add("1");
                        array.[0] |> should equal "1"


        [<Test>] member basic.``Test SetAll`` ()=
                        let e1 = ExpandoObject()
                        !?Dynamic.InvokeSetAll (e1, [("One",1);("Two",2)])
                        e1?One |> should equal 1
                        e1?Two |> should equal 2


        [<Test>] member basic.``Test Lambda methods`` ()=
#if NETCOREAPP2_0
                        Assert.Ignore(".NET Core 2.0.0 has major dynamic bug")
#endif

                        let ex1 = DynamicObjects.Dictionary()
                        ex1?TestLam<- (fun x -> 42 + x)
                        ex1?TestLam2<- (fun x y -> y+ 42 + x)
                        ex1?TestDel<- TestFuncs.Plus3
                        ex1?TestLam(1) |> should equal 43
                        ex1?TestLam2(1, 2) |> should equal 45
                        ex1?TestDel(2) |> should equal 5


        [<Test>] member basic.``Test FSharp Lambda 3 arg `` ()=
#if NETCOREAPP2_0
                        Assert.Ignore(".NET Core 2.0.0 has major dynamic bug")
#endif
                        let dyn = (fun x y z -> x + y - z) :> obj
                        !?dyn (3,2,1) |> should equal 4


        [<Test>] member basic.``Test FSharp Lambda 4 arg`` ()=
#if NETCOREAPP2_0
                        Assert.Ignore(".NET Core 2.0.0 has major dynamic bug")
#endif
                        let dyn = (fun x y z bbq -> x + y - z - bbq) :> obj  in
                        !?dyn (3, 2, 1, 5) |> should equal -1


        [<Test>] member basic.``Test FSharp Lambda 5 arg`` ()=
#if NETCOREAPP2_0
                        Assert.Ignore(".NET Core 2.0.0 has major dynamic bug")
#endif
                        let unknownfunc = (fun x y z bbq etc -> x + y - z - bbq + etc) :> obj in
                        !?unknownfunc (3, 2, 1, 5, 9) |> should equal 8


        [<Test>] member basic.``Test Events`` ()=
                        let pocoObj = TestEvent()
                        let refBool = ref false
                        let myevent = EventHandler<EventArgs>(fun obj arg -> (refBool := true))

                        //Add event dynamically
                        Dyn.addAssignMember pocoObj "Event" myevent
                        pocoObj.OnEvent(null,null)
                        !refBool |> should equal true

                        //Remove event dynamically
                        refBool :=false
                        Dyn.subtractAssignMember pocoObj "Event" myevent
                        !refBool |> should equal false


        [<Test>] member basic.``Test NamedArgs`` ()=
                        let buildObj = !?Build<ExpandoObject>.NewObject (
                                                                            Dyn.namedArg "One" 1,
                                                                            Dyn.namedArg "Two" 2
                                                                        )
                        buildObj?One |> should equal 1
                        buildObj?Two |> should equal 2
<commit_msg>Update tests to not skip on .net core 2.0<commit_after>﻿// Learn more about F# at http://fsharp.net

namespace Tests


open NUnit.Framework
open System
open Dynamitey
open System.Dynamic
open System.Collections.Generic
open System.Xml.Linq
open System.Numerics
open Microsoft.CSharp.RuntimeBinder
open FSharp.Interop.Dynamic
open FsUnit
open System.Linq.Expressions
open FSharp.Interop.Dynamic.Operators
module Tests=

    type TestEvent()=
        let event1 = new Event<EventHandler<EventArgs>, EventArgs>()
        [<CLIEvent>]
        member this.Event = event1.Publish
        member this.OnEvent(obj:Object, args:EventArgs)=
           event1.Trigger(obj,args)

    type TestFuncs()=
        static member Plus3:Func<int,int> =
          Return<int>.Arguments<int>(fun x-> x + 3)

    type DynamicOperatorMock()=
        inherit DynamicObject()
        override this.TryBinaryOperation(binder, arg, result) =
            result <- binder.Operation
            true

    type DynamicWeirdFlakyIndexer()=
        inherit DynamicObject()
        let stuff = Dictionary<obj * obj, obj>()

        override this.TryGetIndex(binder, indexes, result) =
            result <- stuff.[(indexes.[0], indexes.[1])]
            true
        
        override this.TrySetIndex(binder, indexes, value) =
            stuff.Add((indexes.[0], indexes.[1]),value)
            true

    [<TestFixture>]
    type ``Basic Dynamic Operator Tests`` ()=

        [<Test>] member basic.``Call method off of an object dynamically`` ()=
                       "HelloWorld"?Substring(0,5) |> should equal "Hello"


        [<Test>] member basic.``Test Expando Set and Get`` ()=
                        let ex1 = ExpandoObject()
                        ex1?Test<-"Hi";
                        ex1?Test |> should equal "Hi"


        [<Test>] member basic.``Test Direct Invoke`` ()=
                        !?Dynamic.Curry(Dyn.staticContext(typeof<string>))?Format("Test {0} {1}") (1,2) |>
                            should equal "Test 1 2"


        [<Test>] member basic.``Test Void Method`` ()=
                        let array = List<string>()
                        array?Add("1");
                        array.[0] |> should equal "1"


        [<Test>] member basic.``Test SetAll`` ()=
                        let e1 = ExpandoObject()
                        !?Dynamic.InvokeSetAll (e1, [("One",1);("Two",2)])
                        e1?One |> should equal 1
                        e1?Two |> should equal 2


        [<Test>] member basic.``Test Lambda methods`` ()=
                        let ex1 = DynamicObjects.Dictionary()
                        ex1?TestLam<- (fun x -> 42 + x)
                        ex1?TestLam2<- (fun x y -> y+ 42 + x)
                        ex1?TestDel<- TestFuncs.Plus3
                        ex1?TestLam(1) |> should equal 43
                        ex1?TestLam2(1, 2) |> should equal 45
                        ex1?TestDel(2) |> should equal 5


        [<Test>] member basic.``Test FSharp Lambda 3 arg `` ()=
                        let dyn = (fun x y z -> x + y - z) :> obj
                        !?dyn (3,2,1) |> should equal 4


        [<Test>] member basic.``Test FSharp Lambda 4 arg`` ()=
                        let dyn = (fun x y z bbq -> x + y - z - bbq) :> obj  in
                        !?dyn (3, 2, 1, 5) |> should equal -1


        [<Test>] member basic.``Test FSharp Lambda 5 arg`` ()=
                        let unknownfunc = (fun x y z bbq etc -> x + y - z - bbq + etc) :> obj in
                        !?unknownfunc (3, 2, 1, 5, 9) |> should equal 8


        [<Test>] member basic.``Test Events`` ()=
                        let pocoObj = TestEvent()
                        let refBool = ref false
                        let myevent = EventHandler<EventArgs>(fun obj arg -> (refBool := true))

                        //Add event dynamically
                        Dyn.addAssignMember pocoObj "Event" myevent
                        pocoObj.OnEvent(null,null)
                        !refBool |> should equal true

                        //Remove event dynamically
                        refBool :=false
                        Dyn.subtractAssignMember pocoObj "Event" myevent
                        !refBool |> should equal false


        [<Test>] member basic.``Test NamedArgs`` ()=
                        let buildObj = !?Build<ExpandoObject>.NewObject (
                                                                            Dyn.namedArg "One" 1,
                                                                            Dyn.namedArg "Two" 2
                                                                        )
                        buildObj?One |> should equal 1
                        buildObj?Two |> should equal 2

{'fraction_non_alphanumeric': 0.1117688371626367, 'fraction_numerical': 0.017457610113374135, 'mean_word_length': 1.358731661145291, 'pattern_counts': {'":': 0, '<': 61, '<?xml version=': 0, '>': 101, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4355380', 'n_tokens_mistral': 2848, 'n_tokens_neox': 2537, 'n_words': 754}