using System; using System.Collections.Generic; using JetBrains.Diagnostics; using JetBrains.Lifetimes; using JetBrains.Rd; using JetBrains.Rd.Base; using JetBrains.Rd.Util; using NUnit.Framework; using System.Collections.Immutable; namespace Test.RdFramework.Util; [TestFixture] public class RdBindableExUtilTest { [Test] public void IsBindableTest() { var instance = new RdBindableTestClass(); Assert.IsTrue(instance.IsBindable()); Assert.IsTrue(new[] { instance }.IsBindable()); Assert.IsTrue(new List { instance }.IsBindable()); IRdBindable bindable = instance; Assert.IsTrue(bindable.IsBindable()); Assert.IsTrue(new[] { bindable }.IsBindable()); Assert.IsTrue(new List { bindable }.IsBindable()); object obj = instance; Assert.IsTrue(obj.IsBindable()); Assert.IsTrue(new[] { obj }.IsBindable()); Assert.IsTrue(new List { obj }.IsBindable()); var i = 0; Assert.IsFalse(i.IsBindable()); Assert.IsFalse(new[] { i }.IsBindable()); Assert.IsFalse(new List { i }.IsBindable()); Assert.IsFalse(new List { i }.IsBindable()); Assert.IsFalse(((ImmutableArray)default).IsBindable()); // cannot be enumerated, but should not throw exception Assert.IsFalse(ImmutableArray.Create(1).IsBindable()); } [Test] public void IsBindableFastTest() { Assert.IsTrue(RdBindableEx.FastIsBindable.Value); Assert.IsTrue(RdBindableEx.FastIsBindable>.Value); Assert.IsTrue(RdBindableEx.FastIsBindable.Value); Assert.IsTrue(RdBindableEx.FastIsBindable.Value); Assert.IsTrue(RdBindableEx.FastIsBindable>.Value); Assert.IsTrue(RdBindableEx.FastIsBindable.Value); Assert.IsFalse(RdBindableEx.FastIsBindable.Value); Assert.IsFalse(RdBindableEx.FastIsBindable>.Value); Assert.IsFalse(RdBindableEx.FastIsBindable.Value); Assert.IsFalse(RdBindableEx.FastIsBindable.Value); Assert.IsFalse(RdBindableEx.FastIsBindable>.Value); Assert.IsFalse(RdBindableEx.FastIsBindable.Value); } private class RdBindableTestClass : IRdBindable { public RName Location { get; } public IProtocol TryGetProto() { throw new NotImplementedException(); } public bool TryGetSerializationContext(out SerializationCtx ctx) { throw new NotImplementedException(); } public void Print(PrettyPrinter printer) { throw new NotImplementedException(); } public RdId RdId { get; set; } public void PreBind(Lifetime lf, IRdDynamic parent, string name) { throw new NotImplementedException(); } public void Bind() { throw new NotImplementedException(); } public void Identify(IIdentities identities, RdId id) { throw new NotImplementedException(); } } }