@@ -595,6 +595,85 @@ let ``check on-demand production of members``() =
595595 Assert.Equal( 0 , containersType.GetFields( bindAll) .Length) // 5 properties, 5 getters for properties
596596 Assert.Equal( 0 , containersType.GetEvents( bindAll) .Length) // 5 properties, 5 getters for properties
597597
598+ // Tests for ProvidedMeasureBuilder arithmetic operations
599+ [<Fact>]
600+ let ``test ProvidedMeasureBuilder One Product Inverse Ratio Square`` () =
601+ let one = ProvidedMeasureBuilder.One
602+ Assert.Equal( typeof< Microsoft.FSharp.Core.CompilerServices.MeasureOne>, one)
603+
604+ let kg = ProvidedMeasureBuilder.SI " kg"
605+ let m = ProvidedMeasureBuilder.SI " m"
606+
607+ let product = ProvidedMeasureBuilder.Product( kg, m)
608+ Assert.True( product.IsGenericType, " Product should be a generic type" )
609+
610+ let inv = ProvidedMeasureBuilder.Inverse( kg)
611+ Assert.True( inv.IsGenericType, " Inverse should be a generic type" )
612+
613+ let ratio = ProvidedMeasureBuilder.Ratio( m, kg)
614+ Assert.True( ratio.IsGenericType, " Ratio should be a generic type" )
615+
616+ let sq = ProvidedMeasureBuilder.Square( m)
617+ Assert.True( sq.IsGenericType, " Square should be a generic type" )
618+
619+ // Test that ProvidedMeasureBuilder.SI returns null for an unknown unit name
620+ [<Fact>]
621+ let ``test ProvidedMeasureBuilder SI unknown unit`` () =
622+ let unknown = ProvidedMeasureBuilder.SI " foobar_not_a_unit"
623+ Assert.Null( unknown)
624+
625+ // Tests for ProvidedStaticParameter property accessors
626+ [<Fact>]
627+ let ``test ProvidedStaticParameter properties`` () =
628+ let p1 = ProvidedStaticParameter( " myParam" , typeof< int>)
629+ Assert.Equal( " myParam" , p1.Name)
630+ Assert.Equal( typeof< int>, p1.ParameterType)
631+ Assert.Equal( 0 , p1.Position)
632+ Assert.Null( p1.RawDefaultValue)
633+ Assert.False( p1.Attributes.HasFlag( ParameterAttributes.Optional), " parameter without default should not be Optional" )
634+
635+ let p2 = ProvidedStaticParameter( " myParam2" , typeof< string>, " hello" )
636+ Assert.Equal( " myParam2" , p2.Name)
637+ Assert.Equal( typeof< string>, p2.ParameterType)
638+ Assert.Equal( " hello" , p2.RawDefaultValue :?> string)
639+ Assert.True( p2.Attributes.HasFlag( ParameterAttributes.Optional), " parameter with default should be Optional" )
640+
641+ // Tests for TypeProviderForNamespaces.AddNamespace, Namespaces, and Invalidate
642+ [<Fact>]
643+ let ``test TypeProviderForNamespaces AddNamespace and Namespaces`` () =
644+ let refs = Targets.DotNetStandard20FSharpRefs()
645+ let config = Testing.MakeSimulatedTypeProviderConfig( resolutionFolder=__ SOURCE_ DIRECTORY__, runtimeAssembly= " whatever.dll" , runtimeAssemblyRefs= refs)
646+ use tp = new TypeProviderForNamespaces( config)
647+
648+ let ns = " Test.AddNamespace"
649+ let asm = Assembly.GetExecutingAssembly()
650+ let ty = ProvidedTypeDefinition( asm, ns, " TestType" , Some typeof< obj>)
651+ tp.AddNamespace( ns, [ ty])
652+
653+ let namespaces = tp.Namespaces
654+ Assert.True( namespaces |> Array.exists ( fun n -> n.NamespaceName = ns),
655+ sprintf " Namespace '%s ' should be present" ns)
656+
657+ // Test that Invalidate fires the Invalidate event via ITypeProvider
658+ [<Fact>]
659+ let ``test TypeProviderForNamespaces Invalidate`` () =
660+ let refs = Targets.DotNetStandard20FSharpRefs()
661+ let config = Testing.MakeSimulatedTypeProviderConfig( resolutionFolder=__ SOURCE_ DIRECTORY__, runtimeAssembly= " whatever.dll" , runtimeAssemblyRefs= refs)
662+ use tp = new TypeProviderForNamespaces( config)
663+
664+ let mutable fired = false
665+ ( tp :> ITypeProvider) .Invalidate.Add( fun _ -> fired <- true )
666+ tp.Invalidate()
667+ Assert.True( fired, " Invalidate event should have fired" )
668+
669+ // Tests for ProvidedField.SetFieldAttributes
670+ [<Fact>]
671+ let ``test ProvidedField SetFieldAttributes`` () =
672+ let f = ProvidedField( " myField" , typeof< int>)
673+ Assert.Equal( FieldAttributes.Private, f.Attributes)
674+ f.SetFieldAttributes( FieldAttributes.Public)
675+ Assert.Equal( FieldAttributes.Public, f.Attributes)
676+
598677// ---------------------------------------------------------------------------
599678// Tests for type definition properties: nonNullable, hideObjectMethods
600679// Addresses https://github.com/fsprojects/FSharp.TypeProviders.SDK/issues/170
@@ -716,4 +795,4 @@ let ``ProvidedMeasureBuilder SI name (lowercase) creates a FSharpTypeAbbreviatio
716795 match kelvin with
717796 | :? ProvidedTypeSymbol as sym ->
718797 Assert.True( sym.IsFSharpTypeAbbreviation, " SI 'kelvin' should be a FSharpTypeAbbreviation" )
719- | _ -> failwith " Expected ProvidedTypeSymbol for 'kelvin'"
798+ | _ -> failwith " Expected ProvidedTypeSymbol for 'kelvin'"
0 commit comments