Skip to content

Commit

Permalink
Move BasicConstants.fs Tests To Nunit
Browse files Browse the repository at this point in the history
  • Loading branch information
falfaddaghi committed Jul 27, 2019
1 parent 969a9c4 commit 7d017cb
Show file tree
Hide file tree
Showing 5 changed files with 179 additions and 101 deletions.
2 changes: 1 addition & 1 deletion src/fsharp/xlf/FSComp.txt.es.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
</trans-unit>
<trans-unit id="followingPatternMatchClauseHasWrongType">
<source>All branches of a pattern match expression must return values of the same type as the first branch, which here is '{0}'. This branch returns a value of type '{1}'.</source>
<target state="translated">Todas las ramas de una expresión de coincidencia de patrón deben devolver valores del mismo tipo. La primera rama devolvió un valor de tipo "{0}", pero esta rama devolvió un valor de tipo "\{1 \}".</target>
<target state="new">All branches of a pattern match expression must return values of the same type as the first branch, which here is '{0}'. This branch returns a value of type '{1}'.</target>
<note />
</trans-unit>
<trans-unit id="patternMatchGuardIsNotBool">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.

namespace FSharp.Compiler.UnitTests

open NUnit.Framework
open FSharp.Compiler.SourceCodeServices

[<TestFixture>]
module ``Basic Grammar Element Constaints`` =

[<Test>]
let `` Basic constaints compile `` () =
CompilerAssert.Pass
"""
let sbyteConst = 1y
let int16Const = 1us
let int32Const = 1ul
let int64Const = 1UL
let byteConst = 1uy
let uint16Const = 1us
let uint32Const = 1ul
let uint64Const = 1uL
let ieee32Const1 = 1.0f
let ieee32Const2 = 1.0F
let ieee32Const3 = 0x0000000000000001lf
let ieee64Const1 = 1.0
let ieee64Const2 = 0x0000000000000001LF
let bigintConst = 1I
// let bignumConst = 1N - you need a reference to PowerPack.dll now
let decimalConst1 = 1.0M
let decimalConst2 = 1.0m
let charConst = '1'
let stringConst = "1"
let bytestringConst = "1"B
let bytecharConst = '1'B
let boolConst1 = true
let boolConst2 = false
let unitConst = ()
"""

[<Test>]
let ``Long with underscores``() =
CompilerAssert.CompileExeAndRun
"""
let creditCardNumber = 1234_5678_9012_3456L
let socialSecurityNumber = 999_99_9999L
if socialSecurityNumber <> 999999999L then failwith "Wrong parsing"
if creditCardNumber <> 1234567890123456L then failwith "Wrong parsing"
exit 0
"""

[<Test>]
let ``float 32 with underscores``() =
CompilerAssert.CompileExeAndRun
"""
let pi = 3.14_15F
if pi <> 3.1415F then failwith "Wrong parsing"
exit 0
"""

[<Test>]
let ``int with underscores hexBytes``() =
CompilerAssert.CompileExeAndRun
"""
let hexBytes = 0xFF_EC_DE_5E
if hexBytes <> 0xFFECDE5E then failwith "Wrong parsing"
exit 0
"""


[<Test>]
let ``int with underscore hexWords``() =
CompilerAssert.CompileExeAndRun
"""
let hexWords = 0xCAFE_BABE
if hexWords <> 0xCAFEBABE then failwith "Wrong parsing"
exit 0
"""

[<Test>]
let ``Long with underscores maxLong``() =
CompilerAssert.CompileExeAndRun
"""
let maxLong = 0x7fff_ffff_ffff_ffffL
if maxLong <> 0x7fffffffffffffffL then failwith "Wrong parsing"
exit 0
"""

[<Test>]
let ``int with underscore nybbles``() =
CompilerAssert.CompileExeAndRun
"""
let nybbles = 0b0010_0101
if nybbles <> 0b00100101 then failwith "Wrong parsing"
exit 0
"""

[<Test>]
let ``int with underscores bytes``() =
CompilerAssert.CompileExeAndRun
"""
let bytes = 0b11010010_01101001_10010100_10010010
if bytes <> 0b11010010011010011001010010010010 then failwith "Wrong parsing"
exit 0
"""

[<Test>]
let ``int with single underscore literal``() =
CompilerAssert.CompileExeAndRun
"""
let x2 = 5_2
if x2 <> 52 then failwith "Wrong parsing"
exit 0
"""

[<Test>]
let ``int with multiple underscores literal``() =
CompilerAssert.CompileExeAndRun
"""
let x4 = 5_______2
if x4 <> 52 then failwith "Wrong parsing"
exit 0
"""

[<Test>]
let ``int with single underscore Hex literal``() =
CompilerAssert.CompileExeAndRun
"""
let x7 = 0x5_2
if x7 <> 0x52 then
failwith "Wrong parsing"
exit 0
"""

[<Test>]
let ``int with single underscore after leading zero literal``() =
CompilerAssert.CompileExeAndRun
"""
let x9 = 0_52
if x9 <> 052 then failwith "Wrong parsing"
exit 0
"""

[<Test>]
let ``int with single underscore after leteral with leading zero ``() =
CompilerAssert.CompileExeAndRun
"""
let x10 = 05_2
if x10 <> 052 then failwith "Wrong parsing"
exit 0
"""

[<Test>]
let ``int with single underscore after octo leteral ``() =
CompilerAssert.CompileExeAndRun
"""
let x14 = 0o5_2
if x14 <> 0o52 then failwith "Wrong parsing"
exit 0
"""




1 change: 1 addition & 0 deletions tests/fsharp/FSharpSuite.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<Compile Include="tests.fs" />
<Compile Include="Compiler\ILChecker.fs" />
<Compile Include="Compiler\CompilerAssert.fs" />
<Compile Include="Compiler\Conformance\BasicGrammarElements\BasicConstants.fs" />
<Compile Include="Compiler\ErrorMessages\ConstructorTests.fs" />
<Compile Include="Compiler\ErrorMessages\AccessOfTypeAbbreviationTests.fs" />
<Compile Include="Compiler\ErrorMessages\ElseBranchHasWrongTypeTests.fs" />
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
SOURCE=BasicConstants.fs # BasicConstants.fs
NOMONO,NoMT SOURCE=E_BasicConstantsBigNum40.fsx SCFLAGS="--test:ErrorRanges" # E_BasicConstantsBigNum40.fsx


Expand Down

0 comments on commit 7d017cb

Please sign in to comment.