diff --git a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/InvalidNumericLiteralTests.fs b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/InvalidNumericLiteralTests.fs index a20dd89976..720f18a06d 100644 --- a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/InvalidNumericLiteralTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/InvalidNumericLiteralTests.fs @@ -5,16 +5,84 @@ namespace FSharp.Compiler.ErrorMessages.ComponentTests open Xunit open FSharp.Test.Utilities open FSharp.Compiler.SourceCodeServices +open FSharp.Compiler.AbstractIL.Internal module ``Numeric Literals`` = + [] + [] + [] + [] + [] + [] + [] + [] + [] + [] + [] + [] + [] + [] + [] + let ``Invalid Numeric Literals`` literal = + CompilerAssert.TypeCheckSingleError + ("let x = " + literal) + FSharpErrorSeverity.Error + 1156 + (1, 9, 1, 9 + (String.length literal)) + "This is not a valid numeric literal. Valid numeric literals include 1, 0x1, 0o1, 0b1, 1l (int), 1u (uint32), 1L (int64), 1UL (uint64), 1s (int16), 1y (sbyte), 1uy (byte), 1.0 (float), 1.0f (float32), 1.0m (decimal), 1I (BigInteger)." + [] - let ``1up is invalid Numeric Literal``() = + let ``3_(dot)1415F is invalid numeric literal``() = + CompilerAssert.TypeCheckWithErrors + """ +let x = 3_.1415F + """ + [| + FSharpErrorSeverity.Error, 1156, (2, 9, 2, 11), "This is not a valid numeric literal. Valid numeric literals include 1, 0x1, 0o1, 0b1, 1l (int), 1u (uint32), 1L (int64), 1UL (uint64), 1s (int16), 1y (sbyte), 1uy (byte), 1.0 (float), 1.0f (float32), 1.0m (decimal), 1I (BigInteger)."; + FSharpErrorSeverity.Error, 599, (2, 11, 2, 12),"Missing qualification after '.'" + |] + + [] + let ``_52 is invalid numeric literal``() = CompilerAssert.TypeCheckSingleError """ -let foo = 1up // int +let x = _52 """ FSharpErrorSeverity.Error - 1156 - (2, 11, 2, 14) - "This is not a valid numeric literal. Valid numeric literals include 1, 0x1, 0o1, 0b1, 1l (int), 1u (uint32), 1L (int64), 1UL (uint64), 1s (int16), 1y (sbyte), 1uy (byte), 1.0 (float), 1.0f (float32), 1.0m (decimal), 1I (BigInteger)." + 39 + (2, 9, 2, 12) + "The value or constructor '_52' is not defined." + + + [] + let ``1N is invalid numeric literal``() = + CompilerAssert.TypeCheckSingleError + """ +let x = 1N + """ + FSharpErrorSeverity.Error + 0784 + (2, 9, 2, 11) + "This numeric literal requires that a module 'NumericLiteralN' defining functions FromZero, FromOne, FromInt32, FromInt64 and FromString be in scope" + + [] + let ``1N is invalid numeric literal in FSI``() = + if Utils.runningOnMono then () + else + CompilerAssert.RunScriptWithOptions [| "--langversion:preview"; "--test:ErrorRanges" |] + """ +let x = 1N + """ + [ + "This numeric literal requires that a module 'NumericLiteralN' defining functions FromZero, FromOne, FromInt32, FromInt64 and FromString be in scope"; + "Operation could not be completed due to earlier error" + ] + + [] + [] + [] + let ``Valid Numeric Literals`` literal = + // Regressiont test for FSharp1.0: 2543 - Decimal literals do not support exponents + + CompilerAssert.Pass ("let x = " + literal) \ No newline at end of file diff --git a/tests/fsharp/Compiler/Conformance/BasicGrammarElements/CharConstants.fs b/tests/fsharp/Compiler/Conformance/BasicGrammarElements/CharConstants.fs new file mode 100644 index 0000000000..0ff4375ce5 --- /dev/null +++ b/tests/fsharp/Compiler/Conformance/BasicGrammarElements/CharConstants.fs @@ -0,0 +1,21 @@ +// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. + +namespace FSharp.Compiler.UnitTests + +open NUnit.Framework + +[] +module ``Char Constants`` = + + [] // alert + [] // backspace + [] // horizontal tab + [] // new line + [] // vertical tab + [] // form feed + [] // return + [] // double quote + [] // single quote + [] // backslash + let ``Escape characters`` character value = + Assert.areEqual character (char value) \ No newline at end of file diff --git a/tests/fsharp/Compiler/Conformance/BasicGrammarElements/DecimalConstants.fs b/tests/fsharp/Compiler/Conformance/BasicGrammarElements/DecimalConstants.fs new file mode 100644 index 0000000000..4fd012f7a0 --- /dev/null +++ b/tests/fsharp/Compiler/Conformance/BasicGrammarElements/DecimalConstants.fs @@ -0,0 +1,54 @@ +// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. + +namespace FSharp.Compiler.UnitTests + +open NUnit.Framework + +[] +module ``Decimal Constants`` = + + [] + let ``Product of decimal constants``() = + let oneOfOneMiDec = 1.0E-6M + let oneMiDec = 1.0E+6M + + Assert.areEqual 1.0M (oneOfOneMiDec * oneMiDec) + + [] + let ``Sum of decimal constants``() = + let x = + 1.0E0M + + 2.0E1M + + 3.0E2M + + 4.0E3M + + 5.0E4M + + 6.0E5M + + 7.0E6M + + 8.0E7M + + 9.0E8M + + 1.0E-1M + + 2.0E-2M + + 3.0E-3M + + 4.0E-4M + + 5.0E-5M + + 6.0E-6M + + 7.0E-7M + + 8.0E-8M + + 9.0E-9M + + Assert.areEqual 987654321.123456789M x + + [] + let ``Sum of decimal literals with leading zero in exponential``() = + let x = 1.0E00M + 2.0E01M + 3.E02M + 1.E-01M + 2.0E-02M + + Assert.areEqual 321.12M x + + [] + let ``Non-representable small values are rounded to zero``() = + // This test involves rounding of decimals. The F# design is to follow the BCL. + // This means that the behavior is not deterministic, e.g. Mono and NetFx4 round; NetFx2 gives an error + // This is a positive test on Dev10, at least until + // FSHARP1.0:4523 gets resolved. + + Assert.areEqual 0.0M 1.0E-50M \ No newline at end of file diff --git a/tests/fsharp/Compiler/Conformance/BasicGrammarElements/IntegerConstants.fs b/tests/fsharp/Compiler/Conformance/BasicGrammarElements/IntegerConstants.fs new file mode 100644 index 0000000000..a5be0ccde1 --- /dev/null +++ b/tests/fsharp/Compiler/Conformance/BasicGrammarElements/IntegerConstants.fs @@ -0,0 +1,44 @@ +// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. + +namespace FSharp.Compiler.UnitTests + +open NUnit.Framework + +[] +module ``Integer Constants`` = + + [] + let ``Operations with negative one``() = + // Verify the ability to specify negative numbers + // (And not get confused wrt subtraction.) + + let x = -1 + + Assert.areEqual -2 (x + x) + Assert.areEqual 0 (x - x) + Assert.areEqual 1 (x * x) + Assert.areEqual 1 (x / x) + + [] + let ``Operations with negative integers``() = + // Verify the ability to specify negative numbers + // (And not get confused wrt subtraction.) + + let fiveMinusSix = 5 - 6 + let fiveMinusSeven = 5-7 + let negativeSeven = -7 + + Assert.areEqual -1 fiveMinusSix + Assert.areEqual -2 fiveMinusSeven + Assert.areEqual (-1 * 7) negativeSeven + + [] + let ``Functions with negative integers``() = + // Verify the ability to specify negative numbers + // (And not get confused wrt subtraction.) + + let ident x = x + let add x y = x + y + + Assert.areEqual -10 (ident -10) + Assert.areEqual -10 (add -5 -5) \ No newline at end of file diff --git a/tests/fsharp/FSharpSuite.Tests.fsproj b/tests/fsharp/FSharpSuite.Tests.fsproj index a9d05e1fb7..f8d78ae0d1 100644 --- a/tests/fsharp/FSharpSuite.Tests.fsproj +++ b/tests/fsharp/FSharpSuite.Tests.fsproj @@ -33,6 +33,9 @@ + + + diff --git a/tests/fsharpqa/Source/Conformance/BasicGrammarElements/Constants/DecimalLiterals01.fs b/tests/fsharpqa/Source/Conformance/BasicGrammarElements/Constants/DecimalLiterals01.fs deleted file mode 100644 index f78853a422..0000000000 --- a/tests/fsharpqa/Source/Conformance/BasicGrammarElements/Constants/DecimalLiterals01.fs +++ /dev/null @@ -1,26 +0,0 @@ -// #Regression #Conformance #BasicGrammarElements #Constants -#light - -// Regressiont test for FSharp1.0: 2543 - Decimal literals do not support exponents - -let oneOfOneMiDec = 1.0E-6M -let oneMiDec = 1.0E+6M - -let one = oneOfOneMiDec * oneMiDec - -if one <> 1.0M then exit 1 - -let result = 1.0E0M + 2.0E1M + 3.0E2M + 4.0E3M + 5.0E4M + 6.0E5M + 7.0E6M + 8.0E7M + 9.0E8M + - 1.0E-1M + 2.0E-2M + 3.0E-3M + 4.0E-4M + 5.0E-5M + 6.0E-6M + 7.0E-7M + 8.0E-8M + 9.0E-9M - -if result <> 987654321.123456789M then exit 1 - -// Test boundary case -let xMax = 1.0E28M -let XMin = 1.0E-28M - -// Test with leading zeros in exponential and -let y = 1.0E00M + 2.0E01M + 3.E02M + 1.E-01M + 2.0E-02M -if y <> 321.12M then exit 1 - -exit 0 diff --git a/tests/fsharpqa/Source/Conformance/BasicGrammarElements/Constants/DecimalLiterals02.fs b/tests/fsharpqa/Source/Conformance/BasicGrammarElements/Constants/DecimalLiterals02.fs deleted file mode 100644 index ff61e0a1b4..0000000000 --- a/tests/fsharpqa/Source/Conformance/BasicGrammarElements/Constants/DecimalLiterals02.fs +++ /dev/null @@ -1,11 +0,0 @@ -// #Regression #Conformance #BasicGrammarElements #Constants #NoMono -// This is a positive test on Dev10, at least until -// FSHARP1.0:4523 gets resolved. -// - -let ok = 1.0E-50M // parses ok on Dev10 - -if ok <> 0.0M then - exit 1 - -exit 0 diff --git a/tests/fsharpqa/Source/Conformance/BasicGrammarElements/Constants/E_BasicConstantsBigNum01.fsx b/tests/fsharpqa/Source/Conformance/BasicGrammarElements/Constants/E_BasicConstantsBigNum01.fsx deleted file mode 100644 index acc2c91301..0000000000 --- a/tests/fsharpqa/Source/Conformance/BasicGrammarElements/Constants/E_BasicConstantsBigNum01.fsx +++ /dev/null @@ -1,7 +0,0 @@ -// #Regression #Conformance #BasicGrammarElements #Constants -// Verify the ability to specify basic constants - continued - - -//This numeric literal requires that a module 'NumericLiteralN' defining functions FromZero, FromOne, FromInt32, FromInt64 and FromString be in scope - -let bignumConst = 1N diff --git a/tests/fsharpqa/Source/Conformance/BasicGrammarElements/Constants/E_BasicConstantsBigNum40.fsx b/tests/fsharpqa/Source/Conformance/BasicGrammarElements/Constants/E_BasicConstantsBigNum40.fsx deleted file mode 100644 index 8060826cfb..0000000000 --- a/tests/fsharpqa/Source/Conformance/BasicGrammarElements/Constants/E_BasicConstantsBigNum40.fsx +++ /dev/null @@ -1,11 +0,0 @@ -// #Regression #Conformance #BasicGrammarElements #Constants #NoMono #ReqNOMT - -// Verify the ability to specify basic constants - continued - - -// error FS0191: This numeric literal requires that a module 'NumericLiteralN' defining functions FromZero, FromOne, FromInt32, FromInt64 and FromString be in scope -//This numeric literal requires that a module 'NumericLiteralN' defining functions FromZero, FromOne, FromInt32, FromInt64 and FromString be in scope - -let bignumConst = 1N - -exit 1 diff --git a/tests/fsharpqa/Source/Conformance/BasicGrammarElements/Constants/E_DecimalLiterals02.fs b/tests/fsharpqa/Source/Conformance/BasicGrammarElements/Constants/E_DecimalLiterals02.fs deleted file mode 100644 index 18849f241c..0000000000 --- a/tests/fsharpqa/Source/Conformance/BasicGrammarElements/Constants/E_DecimalLiterals02.fs +++ /dev/null @@ -1,9 +0,0 @@ -// #Regression #Conformance #BasicGrammarElements #Constants #NoMono -#light - -// Negative Regressiont test for FSharp1.0: 2543 - Decimal literals do not support exponents -//This number is outside the allowable range for decimal literals - -let invalidDec = 1.0E-50M - -exit 1 diff --git a/tests/fsharpqa/Source/Conformance/BasicGrammarElements/Constants/E_UnderscoreLiterals.fs b/tests/fsharpqa/Source/Conformance/BasicGrammarElements/Constants/E_UnderscoreLiterals.fs deleted file mode 100644 index 7f7e1745b8..0000000000 --- a/tests/fsharpqa/Source/Conformance/BasicGrammarElements/Constants/E_UnderscoreLiterals.fs +++ /dev/null @@ -1,30 +0,0 @@ -//This is not a valid numeric literal. Valid numeric literals include -//This is not a valid numeric literal. Valid numeric literals include -//This is not a valid numeric literal. Valid numeric literals include -//This is not a valid numeric literal. Valid numeric literals include -//This is not a valid numeric literal. Valid numeric literals include -//This is not a valid numeric literal. Valid numeric literals include -//This is not a valid numeric literal. Valid numeric literals include -//This is not a valid numeric literal. Valid numeric literals include -//This is not a valid numeric literal. Valid numeric literals include -//This is not a valid numeric literal. Valid numeric literals include -//This is not a valid numeric literal. Valid numeric literals include -//This is not a valid numeric literal. Valid numeric literals include -//This is not a valid numeric literal. Valid numeric literals include -//This is not a valid numeric literal. Valid numeric literals include - -let pi1 = 3_.1415F -let pi2 = 3._1415F -let socialSecurityNumber1 = 999_99_9999_L -let x1 = _52 -let x2 = 52_ -let x3 = 0_x52 -let x4 = 0x_52 -let x5 = 0x52_ -let x6 = 052_ -let x7 = 0_o52 -let x8 = 0o_52 -let x9 = 0o52_ -let x10 = 2.1_e2F -let x11 = 2.1e_2F -let x12 = 1.0_F \ No newline at end of file diff --git a/tests/fsharpqa/Source/Conformance/BasicGrammarElements/Constants/FullSetOfEscapeCharacters.fs b/tests/fsharpqa/Source/Conformance/BasicGrammarElements/Constants/FullSetOfEscapeCharacters.fs deleted file mode 100644 index e3015854a5..0000000000 --- a/tests/fsharpqa/Source/Conformance/BasicGrammarElements/Constants/FullSetOfEscapeCharacters.fs +++ /dev/null @@ -1,21 +0,0 @@ -// #Regression #Conformance #BasicGrammarElements #Constants -#light - -// Regression test for FSharp1.0: 2956 - F# should have parity with C# wrt escape characters - -let isEscape = - true - && ('\a' = char 7 ) // alert - && ('\b' = char 8 ) // backspace - && ('\t' = char 9 ) // horizontal tab - && ('\n' = char 10) // new line - && ('\v' = char 11) // vertical tab - && ('\f' = char 12) // form feed - && ('\r' = char 13) // return - && ('\"' = char 34) // double quote - && ('\'' = char 39) // single quote - && ('\\' = char 92) // backslash - -if not isEscape then exit 1 - -exit 0 diff --git a/tests/fsharpqa/Source/Conformance/BasicGrammarElements/Constants/NegativeNumbers01.fs b/tests/fsharpqa/Source/Conformance/BasicGrammarElements/Constants/NegativeNumbers01.fs deleted file mode 100644 index 1291c1377b..0000000000 --- a/tests/fsharpqa/Source/Conformance/BasicGrammarElements/Constants/NegativeNumbers01.fs +++ /dev/null @@ -1,14 +0,0 @@ -// #Conformance #BasicGrammarElements #Constants -#light - -// Verify the ability to specify negative numbers -// (And not get confused wrt subtraction.) - -let x = -1 - -if x + x <> -2 then exit 1 -if x - x <> 0 then exit 1 -if x * x <> 1 then exit 1 -if x / x <> 1 then exit 1 - -exit 0 diff --git a/tests/fsharpqa/Source/Conformance/BasicGrammarElements/Constants/NegativeNumbers02.fs b/tests/fsharpqa/Source/Conformance/BasicGrammarElements/Constants/NegativeNumbers02.fs deleted file mode 100644 index c9b4305697..0000000000 --- a/tests/fsharpqa/Source/Conformance/BasicGrammarElements/Constants/NegativeNumbers02.fs +++ /dev/null @@ -1,15 +0,0 @@ -// #Conformance #BasicGrammarElements #Constants -#light - -// Verify the ability to specify negative numbers -// (And not get confused wrt subtraction.) - -let fiveMinusSix = 5 - 6 -let fiveMinusSeven = 5-7 -let negativeSeven = -7 - -if fiveMinusSix <> -1 then exit 1 -if fiveMinusSeven <> -2 then exit 1 -if negativeSeven <> -1 * 7 then exit 1 - -exit 0 diff --git a/tests/fsharpqa/Source/Conformance/BasicGrammarElements/Constants/NegativeNumbers03.fs b/tests/fsharpqa/Source/Conformance/BasicGrammarElements/Constants/NegativeNumbers03.fs deleted file mode 100644 index 751d026a46..0000000000 --- a/tests/fsharpqa/Source/Conformance/BasicGrammarElements/Constants/NegativeNumbers03.fs +++ /dev/null @@ -1,13 +0,0 @@ -// #Conformance #BasicGrammarElements #Constants -#light - -// Verify the ability to specify negative numbers -// (And not get confused wrt subtraction.) - -let ident x = x -let add x y = x + y - -if ident -10 <> -10 then exit 1 -if add -5 -5 <> -10 then exit 1 - -exit 0 diff --git a/tests/fsharpqa/Source/Conformance/BasicGrammarElements/Constants/env.lst b/tests/fsharpqa/Source/Conformance/BasicGrammarElements/Constants/env.lst deleted file mode 100644 index 97183b4978..0000000000 --- a/tests/fsharpqa/Source/Conformance/BasicGrammarElements/Constants/env.lst +++ /dev/null @@ -1,15 +0,0 @@ -NOMONO,NoMT SOURCE=E_BasicConstantsBigNum40.fsx SCFLAGS="--test:ErrorRanges" # E_BasicConstantsBigNum40.fsx - - - SOURCE=NegativeNumbers01.fs # NegativeNumbers01.fs - SOURCE=NegativeNumbers02.fs # NegativeNumbers02.fs - SOURCE=NegativeNumbers03.fs # NegativeNumbers03.fs - - SOURCE=DecimalLiterals01.fs # DecimalLiterals01.fs - -# DecimalLiteral02.fs involves rounding of decimals. The F# design is to follow the BCL. -# This means that the behavior is not deterministic, e.g. Mono and NetFx4 round; NetFx2 gives an error - SOURCE=DecimalLiterals02.fs # DecimalLiterals02.fs - - SOURCE=FullSetOfEscapeCharacters.fs # FullSetOfEscapeCharacters.fs - SOURCE=E_UnderscoreLiterals.fs SCFLAGS="--test:ErrorRanges" # E_UnderscoreLiterals.fs \ No newline at end of file