Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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`` =

[<Theory>]
[<InlineData("1up")>]
[<InlineData("3._1415F")>]
[<InlineData("999_99_9999_L")>]
[<InlineData("52_")>]
[<InlineData("0_x52")>]
[<InlineData("0x_52")>]
[<InlineData("0x52_")>]
[<InlineData("052_")>]
[<InlineData("0_o52")>]
[<InlineData("0o_52")>]
[<InlineData("0o52_")>]
[<InlineData("2.1_e2F")>]
[<InlineData("2.1e_2F")>]
[<InlineData("1.0_F")>]
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)."

[<Fact>]
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 '.'"
|]

[<Fact>]
let ``_52 is invalid numeric literal``() =
CompilerAssert.TypeCheckSingleError
"""
let foo = 1up // int
let x = _52
"""
Copy link
Contributor

@KevinRansom KevinRansom Jul 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test is checking that an identifier that a literal that starts with a numeric is detected as invalid, and is a valid test case, why the change?

Thanks

Kevin

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original test case for 1up got merged as a InlineData into the Theory above, with other similar test cases from this migration.
The _52 test case is from this migration (put it as separate, because it has a different behaviour, i.e. two error messages).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ThorstenReichert

sweet, thanks.

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."


[<Fact>]
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"

[<Fact>]
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"
]

[<Theory>]
[<InlineData("1.0E28M")>]
[<InlineData("1.0E-28M")>]
let ``Valid Numeric Literals`` literal =
// Regressiont test for FSharp1.0: 2543 - Decimal literals do not support exponents

CompilerAssert.Pass ("let x = " + literal)
Original file line number Diff line number Diff line change
@@ -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

[<TestFixture>]
module ``Char Constants`` =

[<TestCase('\a', 7 )>] // alert
[<TestCase('\b', 8 )>] // backspace
[<TestCase('\t', 9 )>] // horizontal tab
[<TestCase('\n', 10)>] // new line
[<TestCase('\v', 11)>] // vertical tab
[<TestCase('\f', 12)>] // form feed
[<TestCase('\r', 13)>] // return
[<TestCase('\"', 34)>] // double quote
[<TestCase('\'', 39)>] // single quote
[<TestCase('\\', 92)>] // backslash
let ``Escape characters`` character value =
Assert.areEqual character (char value)
Original file line number Diff line number Diff line change
@@ -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

[<TestFixture>]
module ``Decimal Constants`` =

[<Test>]
let ``Product of decimal constants``() =
let oneOfOneMiDec = 1.0E-6M
let oneMiDec = 1.0E+6M

Assert.areEqual 1.0M (oneOfOneMiDec * oneMiDec)

[<Test>]
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

[<Test>]
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

[<Test>]
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
Original file line number Diff line number Diff line change
@@ -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

[<TestFixture>]
module ``Integer Constants`` =

[<Test>]
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)

[<Test>]
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

[<Test>]
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)
3 changes: 3 additions & 0 deletions tests/fsharp/FSharpSuite.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
<Compile Include="Compiler\CodeGen\EmittedIL\CeEdiThrow.fs" />
<Compile Include="Compiler\Conformance\DataExpressions\ComputationExpressions.fs" />
<Compile Include="Compiler\Conformance\BasicGrammarElements\BasicConstants.fs" />
<Compile Include="Compiler\Conformance\BasicGrammarElements\CharConstants.fs" />
<Compile Include="Compiler\Conformance\BasicGrammarElements\DecimalConstants.fs" />
<Compile Include="Compiler\Conformance\BasicGrammarElements\IntegerConstants.fs" />
<Compile Include="Compiler\Conformance\Properties\ILMemberAccessTests.fs" />
<Compile Include="Compiler\ConstraintSolver\PrimitiveConstraints.fs" />
<Compile Include="Compiler\ConstraintSolver\MemberConstraints.fs" />
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading