private void ConstructorEnabledObjectLiterals() { Test("Two instances of constructor-supporting [ObjectLiteral] single-string-property class where string values match", assert => { assert.StrictEqual( ComponentPropsHelpers.DoPropsReferencesMatch( new ConstructorObjectLiteralSingleStringPropertyClass("abc"), new ConstructorObjectLiteralSingleStringPropertyClass("abc") ), true ); }); Test("Two instances of constructor-supporting [ObjectLiteral] single-function-property class where functions are equivalent anonymous static lambdas that Bridge lifts to named methods", assert => { assert.StrictEqual( ComponentPropsHelpers.DoPropsReferencesMatch( new ConstructorObjectLiteralSingleFunctionPropertyClass(value => Console.WriteLine(value)), new ConstructorObjectLiteralSingleFunctionPropertyClass(value => Console.WriteLine(value)) ), true ); }); Test("Two instances of constructor-supporting [ObjectLiteral] single-function-property class where functions are equivalent bound functions", assert => { assert.StrictEqual( ComponentPropsHelpers.DoPropsReferencesMatch( new ConstructorObjectLiteralSingleFunctionPropertyClass(InstanceMethod), new ConstructorObjectLiteralSingleFunctionPropertyClass(InstanceMethod) ), true ); }); // These two props instances will be given then exact same reference, so this is a really easy case Test("Two instances of constructor-supporting [ObjectLiteral] single-function-property class where functions are the same function property on a known reference", assert => { var bindToTarget = new SingleFunctionPropertyClass(value => Console.WriteLine(value)); assert.StrictEqual( ComponentPropsHelpers.DoPropsReferencesMatch( new ConstructorObjectLiteralSingleFunctionPropertyClass(bindToTarget.OnChange), new ConstructorObjectLiteralSingleFunctionPropertyClass(bindToTarget.OnChange) ), true ); }); }
private void RegularBridgeClasses() { Test("Two instances of single-string-property class where string values match", assert => { assert.StrictEqual( ComponentPropsHelpers.DoPropsReferencesMatch( new SingleStringPropertyClass("abc"), new SingleStringPropertyClass("abc") ), true ); }); Test("Two instances of single-function-property class where functions are equivalent anonymous static lambdas that Bridge lifts to named methods", assert => { assert.StrictEqual( ComponentPropsHelpers.DoPropsReferencesMatch( new SingleFunctionPropertyClass(value => Console.WriteLine(value)), new SingleFunctionPropertyClass(value => Console.WriteLine(value)) ), true ); }); Test("Two instances of single-function-property class where functions are equivalent bound functions", assert => { assert.StrictEqual( ComponentPropsHelpers.DoPropsReferencesMatch( new SingleFunctionPropertyClass(InstanceMethod), new SingleFunctionPropertyClass(InstanceMethod) ), true ); }); // These two props instances will be given then exact same reference, so this is a really easy case Test("Two instances of single-function-property class where functions are the same function property on a known reference", assert => { var bindToTarget = new SingleFunctionPropertyClass(value => Console.WriteLine(value)); assert.StrictEqual( ComponentPropsHelpers.DoPropsReferencesMatch( new SingleFunctionPropertyClass(bindToTarget.OnChange), new SingleFunctionPropertyClass(bindToTarget.OnChange) ), true ); }); // These C# lamdbas are clearly equivalent but it's not possible for the JavaScript code to know this for sure because it can only see the function content // of them and can't tell for sure that they haven't been bound to different instances using JavaScript's bind facility. If the solution is 100% Bridge then // this shouldn't be the same case because Bridge will bind functions (using its own mechanism) when it has to. However, if the solution ISN'T entirely from // Bridge-compiled C# code then there could be other code creating bound functions and then it would not be reliable to compare the two functions by their // content. Currently, there is a switch for this behaviour that is set to false and within an internal class and so it can't be set to true by consumers // of Bridge.React (apart from this project, which has access to internal-accessibility members). Test("Two instances of single-function-property class where functions are equivalent anonymous static lambdas that Bridge can't lift to named methods (EXPERIMENTAL)", assert => { var outerValue = "abc"; // Having the lambdas access this value prevents them from being lifted into their own methods var optimiseFunctionComparisonsBasedOnSolutionBeingPureBridge = ComponentPropsHelpers.OptimiseFunctionComparisonsBasedOnSolutionBeingPureBridge; try { ComponentPropsHelpers.OptimiseFunctionComparisonsBasedOnSolutionBeingPureBridge = true; assert.StrictEqual( ComponentPropsHelpers.DoPropsReferencesMatch( new SingleFunctionPropertyClass(value => Console.WriteLine(outerValue + ":" + value)), new SingleFunctionPropertyClass(value => Console.WriteLine(outerValue + ":" + value)) ), true ); } finally { ComponentPropsHelpers.OptimiseFunctionComparisonsBasedOnSolutionBeingPureBridge = optimiseFunctionComparisonsBasedOnSolutionBeingPureBridge; } }); Test("Two instance of a single-property class where property has custom Equals implementation (where both values are considered equivalent)", assert => { assert.StrictEqual( ComponentPropsHelpers.DoPropsReferencesMatch( new SingleCaseInsensitiveStringPropertyClass(new CaseInsensitiveString("abc")), new SingleCaseInsensitiveStringPropertyClass(new CaseInsensitiveString("ABC")) ), true ); }); // TODO: Check with nulls // TODO: Add false-result comparisons }