public object this[string key] { set { var usage = _variables.GetUsages(key); if (usage == null) { throw new KeyNotFoundException($"Variable '{key}' not found in scope"); } var converter = FunnyTypeConverters.GetInputConverter(value.GetType()); usage.Source.InternalFunnyValue = converter.ToFunObject(value); } get { var usage = _variables.GetUsages(key); if (usage == null) { throw new KeyNotFoundException($"Variable '{key}' not found in scope"); } var output = usage.Source; if (output.IsReadonly) { throw new KeyNotFoundException($"Variable '{key}' is input and cannot be read"); } return(output.GetClrValue()); } }
public void ConvertString(string value) { var converter = FunnyTypeConverters.GetInputConverter(typeof(string)); Assert.AreEqual(FunnyType.Text, converter.FunnyType); Assert.AreEqual(new TextFunArray(value), converter.ToFunObject(value)); }
public void ArrayOfStructTypes() { var inputUsers = new[] { new UserMoqType("vasa", 42, 17.1), new UserMoqType("peta", 41, 17.0), new UserMoqType("kata", 40, -17.1) }; var converter = FunnyTypeConverters.GetInputConverter(inputUsers.GetType()); Assert.AreEqual( FunnyType.ArrayOf(FunnyType.StructOf( ("name", FunnyType.Text), ("age", FunnyType.Int32), ("size", FunnyType.Real))), converter.FunnyType); var value = converter.ToFunObject(inputUsers); Assert.IsInstanceOf <ImmutableFunArray>(value); var secondElememt = ((ImmutableFunArray)value).GetElementOrNull(1) as FunnyStruct; Assert.IsNotNull(secondElememt, ((ImmutableFunArray)value).GetElementOrNull(1).GetType().Name + " is wrong type"); Assert.AreEqual(inputUsers[1].Name, (secondElememt.GetValue("name") as TextFunArray).ToText()); Assert.AreEqual(inputUsers[1].Age, secondElememt.GetValue("age")); Assert.AreEqual(inputUsers[1].Size, secondElememt.GetValue("size")); }
public ConcreteLambdaWrapperFunction(string id, Func <Tin, Tout> function) { Name = id; _function = function; _argConverter = FunnyTypeConverters.GetOutputConverter(typeof(Tin)); _resultConverter = FunnyTypeConverters.GetInputConverter(typeof(Tout)); ArgTypes = new[] { _argConverter.FunnyType }; ReturnType = _resultConverter.FunnyType; }
private void AssertFunnyConvert(object originClrObject) { var inputConverter = FunnyTypeConverters.GetInputConverter(originClrObject.GetType()); var outputConverter = FunnyTypeConverters.GetOutputConverter(originClrObject.GetType()); var funObject = inputConverter.ToFunObject(originClrObject); var clrObject = outputConverter.ToClrObject(funObject); Assert.IsTrue(TestHelper.AreSame(originClrObject, clrObject)); }
public void ConvertPrimitiveTypeArrays(object primitiveValue, BaseFunnyType expectedTypeName) { var clrType = primitiveValue.GetType(); var converter = FunnyTypeConverters.GetInputConverter(clrType); Assert.AreEqual(FunnyType.ArrayOf(FunnyType.PrimitiveOf(expectedTypeName)), converter.FunnyType); var convertedValue = converter.ToFunObject(primitiveValue); Assert.AreEqual(primitiveValue, convertedValue); }
public void ConvertArrayOfStrings() { string[] inputValue = { "vasa", "kata", "" }; var converter = FunnyTypeConverters.GetInputConverter(inputValue.GetType()); Assert.AreEqual(FunnyType.ArrayOf(FunnyType.Text), converter.FunnyType); Assert.AreEqual(new ImmutableFunArray( inputValue.Select(i => new TextFunArray(i)).ToArray(), FunnyType.Text), converter.ToFunObject(inputValue)); }
public void ArrayOfArrayOfAnything() { object[][] inputValue = { new object[] { 1, 2, "kate" }, new object[] { 2, 1, "kate" }, new object[] { } }; var converter = FunnyTypeConverters.GetInputConverter(inputValue.GetType()); Assert.AreEqual(FunnyType.ArrayOf(FunnyType.ArrayOf(FunnyType.Anything)), converter.FunnyType); var value = converter.ToFunObject(inputValue); Assert.IsInstanceOf <ImmutableFunArray>(value); Assert.AreEqual(3, ((ImmutableFunArray)value).Count); }
public void StructType() { var inputUser = new UserMoqType("vasa", 42, 17.1); var converter = FunnyTypeConverters.GetInputConverter(inputUser.GetType()); Assert.AreEqual(FunnyType.StructOf( ("name", FunnyType.Text), ("age", FunnyType.Int32), ("size", FunnyType.Real)), converter.FunnyType); var value = converter.ToFunObject(inputUser); Assert.IsInstanceOf <FunnyStruct>(value); var converted = (FunnyStruct)value; Assert.AreEqual(inputUser.Name, (converted.GetValue("name") as TextFunArray).ToText()); Assert.AreEqual(inputUser.Age, converted.GetValue("age")); Assert.AreEqual(inputUser.Size, converted.GetValue("size")); }
public object ToFunObject(object clrObject) { var converter = FunnyTypeConverters.GetInputConverter(clrObject.GetType()); return(converter.ToFunObject(clrObject)); }
public void RequrisiveType_Throws() { NodeMoqType obj = new NodeMoqType("vasa", new NodeMoqType("peta")); Assert.Throws <ArgumentException>(() => FunnyTypeConverters.GetInputConverter(obj.GetType())); }