diff --git a/src/Fable.AST/Fable.fs b/src/Fable.AST/Fable.fs index a64c25dc97..d240d7876d 100644 --- a/src/Fable.AST/Fable.fs +++ b/src/Fable.AST/Fable.fs @@ -501,8 +501,6 @@ type NumberValue = | Float32 of System.Single | Float64 of System.Double | Decimal of System.Decimal - // a workaround to do char arithmetics, see #2614 TODO: can we do better? TypeCast didn't work - | CharNumber of NumberKind * System.Char type ValueKind = // The AST from F# compiler is a bit inconsistent with ThisValue and BaseValue. @@ -559,7 +557,6 @@ type ValueKind = | NumberValue.Float32 _ -> NumberKind.Float32 | NumberValue.Float64 _ -> NumberKind.Float64 | NumberValue.Decimal _ -> NumberKind.Decimal - | NumberValue.CharNumber(kind, _) -> kind |> fun kind -> Number(kind, info) | RegexConstant _ -> Regex | NewOption(_, t, isStruct) -> Option(t, isStruct) diff --git a/src/Fable.Transforms/Dart/Fable2Dart.fs b/src/Fable.Transforms/Dart/Fable2Dart.fs index e322f48774..d3002b88c3 100644 --- a/src/Fable.Transforms/Dart/Fable2Dart.fs +++ b/src/Fable.Transforms/Dart/Fable2Dart.fs @@ -721,7 +721,6 @@ module Util = let transformNumberLiteral com (r: Option) (v: Fable.NumberValue) = match v with - | Fable.NumberValue.CharNumber(Dart.Replacements.DartInt, x) -> Expression.integerLiteral (int64 x) | Fable.NumberValue.Int8 x -> Expression.integerLiteral (int64 x) | Fable.NumberValue.UInt8 x -> Expression.integerLiteral (int64 x) | Fable.NumberValue.Int16 x -> Expression.integerLiteral (int64 x) @@ -730,6 +729,7 @@ module Util = | Fable.NumberValue.UInt32 x -> Expression.integerLiteral (int64 x) | Fable.NumberValue.Int64 x -> Expression.integerLiteral (x) | Fable.NumberValue.UInt64 x -> Expression.integerLiteral (int64 x) + | Fable.NumberValue.Float16 x -> Expression.doubleLiteral (float x) | Fable.NumberValue.Float32 x -> Expression.doubleLiteral (float x) | Fable.NumberValue.Float64 x -> Expression.doubleLiteral (x) | _ -> $"Numeric literal is not supported: %A{v}" |> addErrorAndReturnNull com r diff --git a/src/Fable.Transforms/Dart/Replacements.fs b/src/Fable.Transforms/Dart/Replacements.fs index edcf13a8a8..b5c6f9e045 100644 --- a/src/Fable.Transforms/Dart/Replacements.fs +++ b/src/Fable.Transforms/Dart/Replacements.fs @@ -548,7 +548,7 @@ let rec getZero (com: ICompiler) (ctx: Context) (t: Type) = | String -> makeStrConst "" // Using empty string instead of null so Dart doesn't complain | Number(BigInt, _) as t -> Helper.LibCall(com, "BigInt", "fromInt32", t, [ makeIntConst 0 ]) | Number(Decimal, _) as t -> makeIntConst 0 |> makeDecimalFromExpr com None t - | Number(kind, uom) -> NumberConstant(NumberValue.ZeroOfKind kind, uom) |> makeValue None + | Number(kind, uom) -> NumberConstant(NumberValue.GetZero kind, uom) |> makeValue None | Builtin(BclTimeSpan | BclTimeOnly) -> getZeroTimeSpan t | Builtin BclDateTime as t -> Helper.LibCall(com, "Date", "minValue", t, []) | Builtin BclDateTimeOffset as t -> Helper.LibCall(com, "DateOffset", "minValue", t, []) @@ -567,7 +567,7 @@ let getOne (com: ICompiler) (ctx: Context) (t: Type) = | Boolean -> makeBoolConst true | Number(BigInt, _) as t -> Helper.LibCall(com, "BigInt", "fromInt32", t, [ makeIntConst 1 ]) | Number(Decimal, _) as t -> makeIntConst 1 |> makeDecimalFromExpr com None t - | Number(kind, uom) -> NumberConstant(NumberValue.OneOfKind kind, uom) |> makeValue None + | Number(kind, uom) -> NumberConstant(NumberValue.GetOne kind, uom) |> makeValue None | ListSingleton(CustomOp com ctx None t "get_One" [] e) -> e | _ -> makeIntConst 1 diff --git a/src/Fable.Transforms/FSharp2Fable.Util.fs b/src/Fable.Transforms/FSharp2Fable.Util.fs index be2bdb894b..9792ba8631 100644 --- a/src/Fable.Transforms/FSharp2Fable.Util.fs +++ b/src/Fable.Transforms/FSharp2Fable.Util.fs @@ -2147,13 +2147,18 @@ module Util = let fableMemberFunctionOrValue = FsMemberFunctionOrValue(memb) :> Fable.MemberFunctionOrValue + let attributeFullNames = + fableMemberFunctionOrValue.Attributes + |> Seq.map (fun attr -> attr.Entity.FullName) + |> List.ofSeq + Fable.MemberRef( FsEnt.Ref(ent), { CompiledName = memb.CompiledName IsInstance = memb.IsInstanceMember NonCurriedArgTypes = nonCurriedArgTypes - AttributeFullNames = fableMemberFunctionOrValue.Attributes |> Seq.map (fun attr -> attr.Entity.FullName) |> List.ofSeq + AttributeFullNames = attributeFullNames } ) | ent -> @@ -2182,13 +2187,18 @@ module Util = let fableMemberFunctionOrValue = FsMemberFunctionOrValue(memb) :> Fable.MemberFunctionOrValue + let attributeFullNames = + fableMemberFunctionOrValue.Attributes + |> Seq.map (fun attr -> attr.Entity.FullName) + |> List.ofSeq + Fable.MemberRef( FsEnt.Ref(ent), { CompiledName = memb.CompiledName IsInstance = memb.IsInstanceMember NonCurriedArgTypes = None - AttributeFullNames = fableMemberFunctionOrValue.Attributes |> Seq.map (fun attr -> attr.Entity.FullName) |> List.ofSeq + AttributeFullNames = attributeFullNames } ) | ent -> diff --git a/src/Fable.Transforms/Fable2Babel.fs b/src/Fable.Transforms/Fable2Babel.fs index 886fedaf4a..d3917f4e17 100644 --- a/src/Fable.Transforms/Fable2Babel.fs +++ b/src/Fable.Transforms/Fable2Babel.fs @@ -1615,24 +1615,23 @@ module Util = StringTemplate(tag, List.toArray parts, values, r) |> Literal | Fable.NumberConstant(v, _) -> match v with - | Fable.NumberValue.Decimal x -> JS.Replacements.makeDecimal com r value.Type x |> transformAsExpr com ctx - | Fable.NumberValue.BigInt x -> Expression.bigintLiteral (string x, ?loc = r) - | Fable.NumberValue.Int64 x -> Expression.bigintLiteral (string x, ?loc = r) - | Fable.NumberValue.UInt64 x -> Expression.bigintLiteral (string x, ?loc = r) - // | Fable.NumberValue.Int128 x -> Expression.bigintLiteral(string x, ?loc=r) - // | Fable.NumberValue.UInt128 x -> Expression.bigintLiteral(string x, ?loc=r) - | Fable.NumberValue.NativeInt x -> Expression.bigintLiteral (string x, ?loc = r) - | Fable.NumberValue.UNativeInt x -> Expression.bigintLiteral (string x, ?loc = r) | Fable.NumberValue.Int8 x -> Expression.numericLiteral (float x, ?loc = r) | Fable.NumberValue.UInt8 x -> Expression.numericLiteral (float x, ?loc = r) | Fable.NumberValue.Int16 x -> Expression.numericLiteral (float x, ?loc = r) | Fable.NumberValue.UInt16 x -> Expression.numericLiteral (float x, ?loc = r) | Fable.NumberValue.Int32 x -> Expression.numericLiteral (float x, ?loc = r) | Fable.NumberValue.UInt32 x -> Expression.numericLiteral (float x, ?loc = r) - // | Fable.NumberValue.Float16 x -> Expression.numericLiteral(float x, ?loc=r) + | Fable.NumberValue.Int64 x -> Expression.bigintLiteral (string x, ?loc = r) + | Fable.NumberValue.UInt64 x -> Expression.bigintLiteral (string x, ?loc = r) + // | Fable.NumberValue.Int128(u,l) -> Expression.bigintLiteral(string System.Int128(u,l), ?loc=r) + // | Fable.NumberValue.UInt128(u,l) -> Expression.bigintLiteral(string System.UInt128(u,l), ?loc=r) + | Fable.NumberValue.BigInt x -> Expression.bigintLiteral (string x, ?loc = r) + | Fable.NumberValue.NativeInt x -> Expression.bigintLiteral (string x, ?loc = r) + | Fable.NumberValue.UNativeInt x -> Expression.bigintLiteral (string x, ?loc = r) + | Fable.NumberValue.Float16 x -> Expression.numericLiteral (float x, ?loc = r) | Fable.NumberValue.Float32 x -> Expression.numericLiteral (float x, ?loc = r) | Fable.NumberValue.Float64 x -> Expression.numericLiteral (float x, ?loc = r) - | Fable.NumberValue.CharNumber(_, x) -> Expression.numericLiteral (float x, ?loc = r) + | Fable.NumberValue.Decimal x -> JS.Replacements.makeDecimal com r value.Type x |> transformAsExpr com ctx | _ -> addErrorAndReturnNull com r $"Numeric literal is not supported: %A{v}" | Fable.RegexConstant(source, flags) -> Expression.regExpLiteral (source, flags, ?loc = r) | Fable.NewArray(newKind, typ, kind) -> diff --git a/src/Fable.Transforms/Python/Fable2Python.fs b/src/Fable.Transforms/Python/Fable2Python.fs index 036294c1bb..5a12381f13 100644 --- a/src/Fable.Transforms/Python/Fable2Python.fs +++ b/src/Fable.Transforms/Python/Fable2Python.fs @@ -1668,7 +1668,6 @@ module Util = let transformCurry (com: IPythonCompiler) (ctx: Context) expr arity : Expression * Statement list = com.TransformAsExpr(ctx, Replacements.Api.curryExprAtRuntime com arity expr) - let makeInteger (com: IPythonCompiler) (ctx: Context) r _t intName (x: obj) = let cons = libValue com ctx "types" intName let value = Expression.intConstant (x, ?loc = r) @@ -1679,7 +1678,6 @@ module Util = let value = Expression.floatConstant (x, ?loc = r) Expression.call (cons, [ value ], ?loc = r), [] - let transformValue (com: IPythonCompiler) (ctx: Context) r value : Expression * Statement list = match value with | Fable.BaseValue(None, _) -> Expression.identifier "super()", [] @@ -1710,28 +1708,34 @@ module Util = makeBinOp None Fable.String acc (makeStrConst part) BinaryPlus ) |> transformAsExpr com ctx - | Fable.NumberConstant(x, _) -> - match x with - | Fable.NumberValue.Decimal x -> Py.Replacements.makeDecimal com r value.Type x |> transformAsExpr com ctx - | Fable.NumberValue.Int64 x -> makeInteger com ctx r value.Type "int64" x - | Fable.NumberValue.UInt64 x -> makeInteger com ctx r value.Type "uint64" x + | Fable.NumberConstant(v, _) -> + match v with | Fable.NumberValue.Int8 x -> makeInteger com ctx r value.Type "int8" x | Fable.NumberValue.UInt8 x -> makeInteger com ctx r value.Type "uint8" x | Fable.NumberValue.Int16 x -> makeInteger com ctx r value.Type "int16" x | Fable.NumberValue.UInt16 x -> makeInteger com ctx r value.Type "uint16" x | Fable.NumberValue.Int32 x -> Expression.intConstant (x, ?loc = r), [] | Fable.NumberValue.UInt32 x -> makeInteger com ctx r value.Type "uint32" x - // | Fable.NumberValue.CharNumber _ -> makeNumber com ctx r value.Type "char" x + | Fable.NumberValue.Int64 x -> makeInteger com ctx r value.Type "int64" x + | Fable.NumberValue.UInt64 x -> makeInteger com ctx r value.Type "uint64" x + // | Fable.NumberValue.Int128(u,l) -> Expression.intConstant (System.Int128(u,l), ?loc = r), [] + // | Fable.NumberValue.UInt128(u,l) -> Expression.intConstant (System.UInt128(u,l), ?loc = r), [] + | Fable.NumberValue.BigInt x -> Expression.intConstant (x, ?loc = r), [] + | Fable.NumberValue.NativeInt x -> Expression.intConstant (x, ?loc = r), [] + | Fable.NumberValue.UNativeInt x -> Expression.intConstant (x, ?loc = r), [] // TODO: special consts also need attention | Fable.NumberValue.Float64 x when x = infinity -> Expression.name "float('inf')", [] | Fable.NumberValue.Float64 x when x = -infinity -> Expression.name "float('-inf')", [] | Fable.NumberValue.Float64 x when Double.IsNaN(x) -> Expression.name "float('nan')", [] | Fable.NumberValue.Float32 x when Single.IsNaN(x) -> libCall com ctx r "types" "float32" [ Expression.stringConstant "nan" ], [] + | Fable.NumberValue.Float16 x when Single.IsNaN(x) -> + libCall com ctx r "types" "float32" [ Expression.stringConstant "nan" ], [] + | Fable.NumberValue.Float16 x -> makeFloat com ctx r value.Type "float32" (float x) | Fable.NumberValue.Float32 x -> makeFloat com ctx r value.Type "float32" (float x) | Fable.NumberValue.Float64 x -> Expression.floatConstant (x, ?loc = r), [] - // TODO: get rid of wildcard and fix, intConstant can't be catch-all, it includes Float16 and CharNumber at very least - | _ -> Expression.intConstant (x, ?loc = r), [] + | Fable.NumberValue.Decimal x -> Py.Replacements.makeDecimal com r value.Type x |> transformAsExpr com ctx + | _ -> addErrorAndReturnNull com r $"Numeric literal is not supported: %A{v}", [] | Fable.NewArray(newKind, typ, kind) -> match newKind with | Fable.ArrayValues values -> makeArray com ctx values kind typ diff --git a/src/Fable.Transforms/Python/Replacements.fs b/src/Fable.Transforms/Python/Replacements.fs index eb17c6f2a2..118763b3a1 100644 --- a/src/Fable.Transforms/Python/Replacements.fs +++ b/src/Fable.Transforms/Python/Replacements.fs @@ -351,9 +351,9 @@ let toInt com (ctx: Context) r targetType (args: Expr list) = | _ -> FableError $"Unexpected non-integer type %A{typeTo}" |> raise match sourceType, targetType with - | Char, _ -> - //Helper.InstanceCall(args.Head, "charCodeAt", targetType, [ makeIntConst 0 ]) + | Char, Number(typeTo, _) -> Helper.LibCall(com, "char", "char_code_at", targetType, [ args.Head; makeIntConst 0 ]) + |> emitCast typeTo | String, _ -> stringToInt com ctx r targetType args | Number(BigInt, _), _ -> Helper.LibCall(com, "big_int", castBigIntMethod targetType, targetType, args) | Number(typeFrom, _), Number(typeTo, _) -> @@ -696,7 +696,7 @@ let rec getZero (com: ICompiler) ctx (t: Type) = | Boolean -> makeBoolConst false | Number(BigInt, _) as t -> Helper.LibCall(com, "big_int", "fromInt32", t, [ makeIntConst 0 ]) | Number(Decimal, _) as t -> makeIntConst 0 |> makeDecimalFromExpr com None t - | Number(kind, uom) -> NumberConstant(NumberValue.ZeroOfKind kind, uom) |> makeValue None + | Number(kind, uom) -> NumberConstant(NumberValue.GetZero kind, uom) |> makeValue None | Char | String -> makeStrConst "" // TODO: Use null for string? | Builtin BclTimeSpan -> Helper.LibCall(com, "time_span", "create", t, [ makeIntConst 0 ]) @@ -710,16 +710,14 @@ let rec getZero (com: ICompiler) ctx (t: Type) = let getOne (com: ICompiler) ctx (t: Type) = match t with | Boolean -> makeBoolConst true - | Number(kind, uom) -> NumberConstant(NumberValue.OneOfKind kind, uom) |> makeValue None + | Number(kind, uom) -> NumberConstant(NumberValue.GetOne kind, uom) |> makeValue None | ListSingleton(CustomOp com ctx None t "get_One" [] e) -> e | _ -> makeIntConst 1 let makeAddFunction (com: ICompiler) ctx t = let x = makeUniqueIdent ctx t "x" let y = makeUniqueIdent ctx t "y" - let body = applyOp com ctx None t Operators.addition [ IdentExpr x; IdentExpr y ] - Delegate([ x; y ], body, None, Tags.empty) let makeGenericAdder (com: ICompiler) ctx t = @@ -733,9 +731,7 @@ let makeGenericAverager (com: ICompiler) ctx t = let divideFn = let x = makeUniqueIdent ctx t "x" let i = makeUniqueIdent ctx (Int32.Number) "i" - let body = applyOp com ctx None t Operators.divideByInt [ IdentExpr x; IdentExpr i ] - Delegate([ x; i ], body, None, Tags.empty) objExpr @@ -2738,7 +2734,6 @@ let dates (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr optio | _ -> None | meth -> let args = ignoreFormatProvider com ctx r i.DeclaringEntityFullName meth args - let meth = Naming.removeGetSetPrefix meth |> Naming.lowerFirst Helper.LibCall(com, moduleName, meth, t, args, i.SignatureArgTypes, ?thisArg = thisArg, ?loc = r) diff --git a/src/Fable.Transforms/Replacements.Util.fs b/src/Fable.Transforms/Replacements.Util.fs index 9e18095214..7da6cb9b58 100644 --- a/src/Fable.Transforms/Replacements.Util.fs +++ b/src/Fable.Transforms/Replacements.Util.fs @@ -258,7 +258,7 @@ let toArray r t expr = type NumberValue with - static member ZeroOfKind(kind: NumberKind) : NumberValue = + static member GetZero(kind: NumberKind) : NumberValue = match kind with | NumberKind.Int8 -> NumberValue.Int8(0y: int8) | NumberKind.UInt8 -> NumberValue.UInt8(0uy: uint8) @@ -278,7 +278,7 @@ type NumberValue with | NumberKind.Float64 -> NumberValue.Float64(0.: float) | NumberKind.Decimal -> NumberValue.Decimal(0M: decimal) - static member OneOfKind(kind: NumberKind) : NumberValue = + static member GetOne(kind: NumberKind) : NumberValue = match kind with | NumberKind.Int8 -> NumberValue.Int8(1y: int8) | NumberKind.UInt8 -> NumberValue.UInt8(1uy: uint8) diff --git a/src/Fable.Transforms/Replacements.fs b/src/Fable.Transforms/Replacements.fs index b558bb5f93..efce42c565 100644 --- a/src/Fable.Transforms/Replacements.fs +++ b/src/Fable.Transforms/Replacements.fs @@ -303,7 +303,6 @@ let toLong com (ctx: Context) r targetType (args: Expr list) : Expr = |> wrapLong com ctx r targetType | _ -> addWarning com ctx.InlinePath r "Cannot make conversion because source type is unknown" - TypeCast(args.Head, targetType) let emitIntCast toKind arg = @@ -321,11 +320,9 @@ let toInt com (ctx: Context) r targetType (args: Expr list) = let sourceType = args.Head.Type match sourceType, targetType with - | Char, _ -> - match targetType, args with - | Number(kind, _), Value(CharConstant c, r) :: _ -> - Value(NumberConstant(NumberValue.CharNumber(kind, c), NumberInfo.Empty), r) - | _ -> Helper.InstanceCall(args.Head, "charCodeAt", targetType, [ makeIntConst 0 ]) + | Char, Number(toKind, _) -> + Helper.InstanceCall(args.Head, "charCodeAt", targetType, [ makeIntConst 0 ]) + |> emitIntCast toKind | String, _ -> stringToInt com ctx r targetType args | Number(fromKind, _), Number(toKind, _) -> if needToCast fromKind toKind then @@ -340,7 +337,6 @@ let toInt com (ctx: Context) r targetType (args: Expr list) = TypeCast(args.Head, targetType) | _ -> addWarning com ctx.InlinePath r "Cannot make conversion because source type is unknown" - TypeCast(args.Head, targetType) let round com (args: Expr list) = @@ -669,7 +665,7 @@ let rec getZero (com: ICompiler) (ctx: Context) (t: Type) = | Boolean -> makeBoolConst false | Char | String -> makeStrConst "" // TODO: Use null for string? - | Number(kind, uom) -> NumberConstant(NumberValue.ZeroOfKind kind, uom) |> makeValue None + | Number(kind, uom) -> NumberConstant(NumberValue.GetZero kind, uom) |> makeValue None | Builtin(BclTimeSpan | BclTimeOnly) -> makeIntConst 0 // TODO: Type cast | Builtin BclDateTime as t -> Helper.LibCall(com, "Date", "minValue", t, []) | Builtin BclDateTimeOffset as t -> Helper.LibCall(com, "DateOffset", "minValue", t, []) @@ -682,7 +678,7 @@ let rec getZero (com: ICompiler) (ctx: Context) (t: Type) = let getOne (com: ICompiler) (ctx: Context) (t: Type) = match t with | Boolean -> makeBoolConst true - | Number(kind, uom) -> NumberConstant(NumberValue.OneOfKind kind, uom) |> makeValue None + | Number(kind, uom) -> NumberConstant(NumberValue.GetOne kind, uom) |> makeValue None | ListSingleton(CustomOp com ctx None t "get_One" [] e) -> e | _ -> makeIntConst 1 diff --git a/src/Fable.Transforms/Rust/Replacements.fs b/src/Fable.Transforms/Rust/Replacements.fs index c031822c95..3f3f9a7945 100644 --- a/src/Fable.Transforms/Rust/Replacements.fs +++ b/src/Fable.Transforms/Rust/Replacements.fs @@ -612,7 +612,7 @@ let rec getZero (com: ICompiler) (ctx: Context) (t: Type) = | Boolean -> makeBoolConst false | Number(BigInt, _) -> Helper.LibCall(com, "BigInt", "zero", t, []) | Number(Decimal, _) -> Helper.LibValue(com, "Decimal", "Zero", t) - | Number(kind, uom) -> NumberConstant(NumberValue.ZeroOfKind kind, uom) |> makeValue None + | Number(kind, uom) -> NumberConstant(NumberValue.GetZero kind, uom) |> makeValue None | Char -> CharConstant '\u0000' |> makeValue None | String -> makeStrConst "" // TODO: Use null for string? | Array(typ, _) -> makeArray typ [] @@ -632,7 +632,7 @@ let getOne (com: ICompiler) (ctx: Context) (t: Type) = | Boolean -> makeBoolConst true | Number(BigInt, _) -> Helper.LibCall(com, "BigInt", "one", t, []) | Number(Decimal, _) -> Helper.LibValue(com, "Decimal", "One", t) - | Number(kind, uom) -> NumberConstant(NumberValue.OneOfKind kind, uom) |> makeValue None + | Number(kind, uom) -> NumberConstant(NumberValue.GetOne kind, uom) |> makeValue None | ListSingleton(CustomOp com ctx None t "get_One" [] e) -> e | _ -> makeIntConst 1 diff --git a/src/Fable.Transforms/Transforms.Util.fs b/src/Fable.Transforms/Transforms.Util.fs index 778adf7631..3d2bcf8b8e 100644 --- a/src/Fable.Transforms/Transforms.Util.fs +++ b/src/Fable.Transforms/Transforms.Util.fs @@ -1055,10 +1055,6 @@ module AST = FableError $"Unsupported Number Kind %A{kind} and value %A{x} combination" |> raise - | _, (:? char as x) -> - // TODO: convert to correct NumberValue based on kind ? - NumberValue.Float64(float x) - | _ -> FableError $"Unexpected Number Kind %A{kind} and value %A{value} combination" |> raise diff --git a/tests/Python/TestConvert.fs b/tests/Python/TestConvert.fs index 01b3fbcc1f..5d57610232 100644 --- a/tests/Python/TestConvert.fs +++ b/tests/Python/TestConvert.fs @@ -303,6 +303,7 @@ let ``test System.Convert.ToSByte works`` () = Convert.ToSByte(2.6) |> equal (x+x+x) Convert.ToSByte(3.5) |> equal (x+x+x+x) Convert.ToSByte("1") |> equal x + Convert.ToSByte('a') |> equal 97y (fun () -> Convert.ToSByte("1.4")) |> throwsError "" (fun () -> Convert.ToSByte("foo")) |> throwsError "" @@ -347,6 +348,7 @@ let ``test System.Convert.ToInt16 works`` () = Convert.ToInt16(2.6) |> equal (x+x+x) Convert.ToInt16(3.5) |> equal (x+x+x+x) Convert.ToInt16("1") |> equal x + Convert.ToInt16('a') |> equal 97s (fun () -> Convert.ToInt16("1.4")) |> throwsError "" (fun () -> Convert.ToInt16("foo")) |> throwsError "" @@ -391,6 +393,7 @@ let ``test System.Convert.ToInt32 works`` () = Convert.ToInt32(2.6) |> equal (x+x+x) Convert.ToInt32(3.5) |> equal (x+x+x+x) Convert.ToInt32("1") |> equal x + Convert.ToInt32('a') |> equal 97 (fun () -> Convert.ToInt32("1.4")) |> throwsError "" (fun () -> Convert.ToInt32("foo")) |> throwsError "" @@ -456,6 +459,7 @@ let ``test System.Convert.ToInt64 works`` () = Convert.ToInt64(2.6) |> equal (x+x+x) Convert.ToInt64(3.5) |> equal (x+x+x+x) Convert.ToInt64("1") |> equal x + Convert.ToInt64('a') |> equal 97L (fun () -> Convert.ToInt64("1.4")) |> throwsError "" (fun () -> Convert.ToInt64("foo")) |> throwsError "" @@ -500,6 +504,7 @@ let ``test System.Convert.ToByte works`` () = Convert.ToByte(2.6) |> equal (x+x+x) Convert.ToByte(3.5) |> equal (x+x+x+x) Convert.ToByte("1") |> equal x + Convert.ToByte('a') |> equal 97uy (fun () -> Convert.ToByte("1.4")) |> throwsError "" (fun () -> Convert.ToByte("foo")) |> throwsError "" @@ -544,6 +549,7 @@ let ``test System.Convert.ToUInt16 works`` () = Convert.ToUInt16(2.6) |> equal (x+x+x) Convert.ToUInt16(3.5) |> equal (x+x+x+x) Convert.ToUInt16("1") |> equal x + Convert.ToUInt16('a') |> equal 97us (fun () -> Convert.ToUInt16("1.4")) |> throwsError "" (fun () -> Convert.ToUInt16("foo")) |> throwsError "" @@ -588,6 +594,7 @@ let ``test System.Convert.ToUInt32 works`` () = Convert.ToUInt32(2.6) |> equal (x+x+x) Convert.ToUInt32(3.5) |> equal (x+x+x+x) Convert.ToUInt32("1") |> equal x + Convert.ToUInt32('a') |> equal 97u (fun () -> Convert.ToUInt32("1.4")) |> throwsError "" (fun () -> Convert.ToUInt32("foo")) |> throwsError "" @@ -632,6 +639,7 @@ let ``test System.Convert.ToUInt64 works`` () = Convert.ToUInt64(2.6) |> equal (x+x+x) Convert.ToUInt64(3.5) |> equal (x+x+x+x) Convert.ToUInt64("1") |> equal x + Convert.ToUInt64('a') |> equal 97UL (fun () -> Convert.ToUInt64("1.4")) |> throwsError "" (fun () -> Convert.ToUInt64("foo")) |> throwsError "" diff --git a/tests/Rust/tests/src/ConvertTests.fs b/tests/Rust/tests/src/ConvertTests.fs index 2d2a392ebc..bfa40f5a4c 100644 --- a/tests/Rust/tests/src/ConvertTests.fs +++ b/tests/Rust/tests/src/ConvertTests.fs @@ -319,6 +319,7 @@ let ``System.Convert.ToSByte works`` () = Convert.ToSByte(2.6) |> equal (x+x+x) Convert.ToSByte(3.5) |> equal (x+x+x+x) Convert.ToSByte("1") |> equal x + Convert.ToSByte('a') |> equal 97y [] let ``System.Convert.ToInt16 works`` () = @@ -359,6 +360,7 @@ let ``System.Convert.ToInt16 works`` () = Convert.ToInt16(2.6) |> equal (x+x+x) Convert.ToInt16(3.5) |> equal (x+x+x+x) Convert.ToInt16("1") |> equal x + Convert.ToInt16('a') |> equal 97s [] let ``System.Convert.ToInt32 works`` () = @@ -399,6 +401,7 @@ let ``System.Convert.ToInt32 works`` () = Convert.ToInt32(2.6) |> equal (x+x+x) Convert.ToInt32(3.5) |> equal (x+x+x+x) Convert.ToInt32("1") |> equal x + Convert.ToInt32('a') |> equal 97 [] let ``Special cases conversion to and from Int64 work`` () = @@ -460,6 +463,7 @@ let ``System.Convert.ToInt64 works`` () = Convert.ToInt64(2.6) |> equal (x+x+x) Convert.ToInt64(3.5) |> equal (x+x+x+x) Convert.ToInt64("1") |> equal x + Convert.ToInt64('a') |> equal 97L [] let ``System.Convert.ToByte works`` () = @@ -500,6 +504,7 @@ let ``System.Convert.ToByte works`` () = Convert.ToByte(2.6) |> equal (x+x+x) Convert.ToByte(3.5) |> equal (x+x+x+x) Convert.ToByte("1") |> equal x + Convert.ToByte('a') |> equal 97uy [] let ``System.Convert.ToUInt16 works`` () = @@ -540,6 +545,7 @@ let ``System.Convert.ToUInt16 works`` () = Convert.ToUInt16(2.6) |> equal (x+x+x) Convert.ToUInt16(3.5) |> equal (x+x+x+x) Convert.ToUInt16("1") |> equal x + Convert.ToUInt16('a') |> equal 97us [] let ``System.Convert.ToUInt32 works`` () = @@ -580,6 +586,7 @@ let ``System.Convert.ToUInt32 works`` () = Convert.ToUInt32(2.6) |> equal (x+x+x) Convert.ToUInt32(3.5) |> equal (x+x+x+x) Convert.ToUInt32("1") |> equal x + Convert.ToUInt32('a') |> equal 97u [] let ``System.Convert.ToUInt64 works`` () = @@ -620,6 +627,7 @@ let ``System.Convert.ToUInt64 works`` () = Convert.ToUInt64(2.6) |> equal (x+x+x) Convert.ToUInt64(3.5) |> equal (x+x+x+x) Convert.ToUInt64("1") |> equal x + Convert.ToUInt64('a') |> equal 97UL [] let ``Convert between (un)signed long`` () = // See #1485