Skip to content
This repository was archived by the owner on Dec 23, 2024. It is now read-only.

Commit 7bb5031

Browse files
ThorstenReichertnosami
authored andcommitted
Moved fsharpqa/Conformance/BasicGrammarElements/Constants test cases to NUnit (dotnet#9626)
* Migrated DecimalLiterals01.fs test case * Migrated DecimalConstants02.fs test case * Migrated E_BasicConstantsBigNum01.fs test case * Migrated E_BasicConstantsBigNum40.fs test case * Removed unlisted test case * Migrated E_UnderscoreLiterals.fs test case * Migrated FullSetOfEscapeCharacters.fs test case * Migrated NegativeNumbers01.fs, NegativeNumbers02.fs, NegativeNumbers03.fs test cases
1 parent a5d02b5 commit 7bb5031

File tree

16 files changed

+195
-177
lines changed

16 files changed

+195
-177
lines changed

tests/FSharp.Compiler.ComponentTests/ErrorMessages/InvalidNumericLiteralTests.fs

Lines changed: 73 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,84 @@ namespace FSharp.Compiler.ErrorMessages.ComponentTests
55
open Xunit
66
open FSharp.Test.Utilities
77
open FSharp.Compiler.SourceCodeServices
8+
open FSharp.Compiler.AbstractIL.Internal
89

910
module ``Numeric Literals`` =
1011

12+
[<Theory>]
13+
[<InlineData("1up")>]
14+
[<InlineData("3._1415F")>]
15+
[<InlineData("999_99_9999_L")>]
16+
[<InlineData("52_")>]
17+
[<InlineData("0_x52")>]
18+
[<InlineData("0x_52")>]
19+
[<InlineData("0x52_")>]
20+
[<InlineData("052_")>]
21+
[<InlineData("0_o52")>]
22+
[<InlineData("0o_52")>]
23+
[<InlineData("0o52_")>]
24+
[<InlineData("2.1_e2F")>]
25+
[<InlineData("2.1e_2F")>]
26+
[<InlineData("1.0_F")>]
27+
let ``Invalid Numeric Literals`` literal =
28+
CompilerAssert.TypeCheckSingleError
29+
("let x = " + literal)
30+
FSharpErrorSeverity.Error
31+
1156
32+
(1, 9, 1, 9 + (String.length literal))
33+
"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)."
34+
1135
[<Fact>]
12-
let ``1up is invalid Numeric Literal``() =
36+
let ``3_(dot)1415F is invalid numeric literal``() =
37+
CompilerAssert.TypeCheckWithErrors
38+
"""
39+
let x = 3_.1415F
40+
"""
41+
[|
42+
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).";
43+
FSharpErrorSeverity.Error, 599, (2, 11, 2, 12),"Missing qualification after '.'"
44+
|]
45+
46+
[<Fact>]
47+
let ``_52 is invalid numeric literal``() =
1348
CompilerAssert.TypeCheckSingleError
1449
"""
15-
let foo = 1up // int
50+
let x = _52
1651
"""
1752
FSharpErrorSeverity.Error
18-
1156
19-
(2, 11, 2, 14)
20-
"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)."
53+
39
54+
(2, 9, 2, 12)
55+
"The value or constructor '_52' is not defined."
56+
57+
58+
[<Fact>]
59+
let ``1N is invalid numeric literal``() =
60+
CompilerAssert.TypeCheckSingleError
61+
"""
62+
let x = 1N
63+
"""
64+
FSharpErrorSeverity.Error
65+
0784
66+
(2, 9, 2, 11)
67+
"This numeric literal requires that a module 'NumericLiteralN' defining functions FromZero, FromOne, FromInt32, FromInt64 and FromString be in scope"
68+
69+
[<Fact>]
70+
let ``1N is invalid numeric literal in FSI``() =
71+
if Utils.runningOnMono then ()
72+
else
73+
CompilerAssert.RunScriptWithOptions [| "--langversion:preview"; "--test:ErrorRanges" |]
74+
"""
75+
let x = 1N
76+
"""
77+
[
78+
"This numeric literal requires that a module 'NumericLiteralN' defining functions FromZero, FromOne, FromInt32, FromInt64 and FromString be in scope";
79+
"Operation could not be completed due to earlier error"
80+
]
81+
82+
[<Theory>]
83+
[<InlineData("1.0E28M")>]
84+
[<InlineData("1.0E-28M")>]
85+
let ``Valid Numeric Literals`` literal =
86+
// Regressiont test for FSharp1.0: 2543 - Decimal literals do not support exponents
87+
88+
CompilerAssert.Pass ("let x = " + literal)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
2+
3+
namespace FSharp.Compiler.UnitTests
4+
5+
open NUnit.Framework
6+
7+
[<TestFixture>]
8+
module ``Char Constants`` =
9+
10+
[<TestCase('\a', 7 )>] // alert
11+
[<TestCase('\b', 8 )>] // backspace
12+
[<TestCase('\t', 9 )>] // horizontal tab
13+
[<TestCase('\n', 10)>] // new line
14+
[<TestCase('\v', 11)>] // vertical tab
15+
[<TestCase('\f', 12)>] // form feed
16+
[<TestCase('\r', 13)>] // return
17+
[<TestCase('\"', 34)>] // double quote
18+
[<TestCase('\'', 39)>] // single quote
19+
[<TestCase('\\', 92)>] // backslash
20+
let ``Escape characters`` character value =
21+
Assert.areEqual character (char value)
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
2+
3+
namespace FSharp.Compiler.UnitTests
4+
5+
open NUnit.Framework
6+
7+
[<TestFixture>]
8+
module ``Decimal Constants`` =
9+
10+
[<Test>]
11+
let ``Product of decimal constants``() =
12+
let oneOfOneMiDec = 1.0E-6M
13+
let oneMiDec = 1.0E+6M
14+
15+
Assert.areEqual 1.0M (oneOfOneMiDec * oneMiDec)
16+
17+
[<Test>]
18+
let ``Sum of decimal constants``() =
19+
let x =
20+
1.0E0M
21+
+ 2.0E1M
22+
+ 3.0E2M
23+
+ 4.0E3M
24+
+ 5.0E4M
25+
+ 6.0E5M
26+
+ 7.0E6M
27+
+ 8.0E7M
28+
+ 9.0E8M
29+
+ 1.0E-1M
30+
+ 2.0E-2M
31+
+ 3.0E-3M
32+
+ 4.0E-4M
33+
+ 5.0E-5M
34+
+ 6.0E-6M
35+
+ 7.0E-7M
36+
+ 8.0E-8M
37+
+ 9.0E-9M
38+
39+
Assert.areEqual 987654321.123456789M x
40+
41+
[<Test>]
42+
let ``Sum of decimal literals with leading zero in exponential``() =
43+
let x = 1.0E00M + 2.0E01M + 3.E02M + 1.E-01M + 2.0E-02M
44+
45+
Assert.areEqual 321.12M x
46+
47+
[<Test>]
48+
let ``Non-representable small values are rounded to zero``() =
49+
// This test involves rounding of decimals. The F# design is to follow the BCL.
50+
// This means that the behavior is not deterministic, e.g. Mono and NetFx4 round; NetFx2 gives an error
51+
// This is a positive test on Dev10, at least until
52+
// FSHARP1.0:4523 gets resolved.
53+
54+
Assert.areEqual 0.0M 1.0E-50M
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
2+
3+
namespace FSharp.Compiler.UnitTests
4+
5+
open NUnit.Framework
6+
7+
[<TestFixture>]
8+
module ``Integer Constants`` =
9+
10+
[<Test>]
11+
let ``Operations with negative one``() =
12+
// Verify the ability to specify negative numbers
13+
// (And not get confused wrt subtraction.)
14+
15+
let x = -1
16+
17+
Assert.areEqual -2 (x + x)
18+
Assert.areEqual 0 (x - x)
19+
Assert.areEqual 1 (x * x)
20+
Assert.areEqual 1 (x / x)
21+
22+
[<Test>]
23+
let ``Operations with negative integers``() =
24+
// Verify the ability to specify negative numbers
25+
// (And not get confused wrt subtraction.)
26+
27+
let fiveMinusSix = 5 - 6
28+
let fiveMinusSeven = 5-7
29+
let negativeSeven = -7
30+
31+
Assert.areEqual -1 fiveMinusSix
32+
Assert.areEqual -2 fiveMinusSeven
33+
Assert.areEqual (-1 * 7) negativeSeven
34+
35+
[<Test>]
36+
let ``Functions with negative integers``() =
37+
// Verify the ability to specify negative numbers
38+
// (And not get confused wrt subtraction.)
39+
40+
let ident x = x
41+
let add x y = x + y
42+
43+
Assert.areEqual -10 (ident -10)
44+
Assert.areEqual -10 (add -5 -5)

tests/fsharp/FSharpSuite.Tests.fsproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
<Compile Include="Compiler\CodeGen\EmittedIL\CeEdiThrow.fs" />
3434
<Compile Include="Compiler\Conformance\DataExpressions\ComputationExpressions.fs" />
3535
<Compile Include="Compiler\Conformance\BasicGrammarElements\BasicConstants.fs" />
36+
<Compile Include="Compiler\Conformance\BasicGrammarElements\CharConstants.fs" />
37+
<Compile Include="Compiler\Conformance\BasicGrammarElements\DecimalConstants.fs" />
38+
<Compile Include="Compiler\Conformance\BasicGrammarElements\IntegerConstants.fs" />
3639
<Compile Include="Compiler\Conformance\Properties\ILMemberAccessTests.fs" />
3740
<Compile Include="Compiler\ErrorMessages\ConstructorTests.fs" />
3841
<Compile Include="Compiler\ErrorMessages\ClassesTests.fs" />

tests/fsharpqa/Source/Conformance/BasicGrammarElements/Constants/DecimalLiterals01.fs

Lines changed: 0 additions & 26 deletions
This file was deleted.

tests/fsharpqa/Source/Conformance/BasicGrammarElements/Constants/DecimalLiterals02.fs

Lines changed: 0 additions & 11 deletions
This file was deleted.

tests/fsharpqa/Source/Conformance/BasicGrammarElements/Constants/E_BasicConstantsBigNum01.fsx

Lines changed: 0 additions & 7 deletions
This file was deleted.

tests/fsharpqa/Source/Conformance/BasicGrammarElements/Constants/E_BasicConstantsBigNum40.fsx

Lines changed: 0 additions & 11 deletions
This file was deleted.

tests/fsharpqa/Source/Conformance/BasicGrammarElements/Constants/E_DecimalLiterals02.fs

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)