|
| 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 | +open FSharp.Compiler.SourceCodeServices |
| 7 | + |
| 8 | +[<TestFixture>] |
| 9 | +module ``Basic Grammar Element Constants`` = |
| 10 | + |
| 11 | + [<Test>] |
| 12 | + let `` Basic constants compile `` () = |
| 13 | + CompilerAssert.Pass |
| 14 | + """ |
| 15 | +let sbyteConst = 1y |
| 16 | +let int16Const = 1us |
| 17 | +let int32Const = 1ul |
| 18 | +let int64Const = 1UL |
| 19 | + |
| 20 | +let byteConst = 1uy |
| 21 | +let uint16Const = 1us |
| 22 | +let uint32Const = 1ul |
| 23 | +let uint64Const = 1uL |
| 24 | + |
| 25 | +let ieee32Const1 = 1.0f |
| 26 | +let ieee32Const2 = 1.0F |
| 27 | +let ieee32Const3 = 0x0000000000000001lf |
| 28 | + |
| 29 | +let ieee64Const1 = 1.0 |
| 30 | +let ieee64Const2 = 0x0000000000000001LF |
| 31 | + |
| 32 | +let bigintConst = 1I |
| 33 | + |
| 34 | +// let bignumConst = 1N - you need a reference to PowerPack.dll now |
| 35 | + |
| 36 | +let decimalConst1 = 1.0M |
| 37 | +let decimalConst2 = 1.0m |
| 38 | + |
| 39 | +let charConst = '1' |
| 40 | + |
| 41 | +let stringConst = "1" |
| 42 | + |
| 43 | +let bytestringConst = "1"B |
| 44 | + |
| 45 | +let bytecharConst = '1'B |
| 46 | + |
| 47 | +let boolConst1 = true |
| 48 | +let boolConst2 = false |
| 49 | + |
| 50 | +let unitConst = () |
| 51 | + """ |
| 52 | + |
| 53 | + [<Test>] |
| 54 | + let ``Long with underscores``() = |
| 55 | + CompilerAssert.CompileExeAndRun |
| 56 | + """ |
| 57 | +let creditCardNumber = 1234_5678_9012_3456L |
| 58 | +let socialSecurityNumber = 999_99_9999L |
| 59 | +
|
| 60 | +if socialSecurityNumber <> 999999999L then failwith "Wrong parsing" |
| 61 | +if creditCardNumber <> 1234567890123456L then failwith "Wrong parsing" |
| 62 | +exit 0 |
| 63 | + """ |
| 64 | + |
| 65 | + [<Test>] |
| 66 | + let ``float 32 with underscores``() = |
| 67 | + CompilerAssert.CompileExeAndRun |
| 68 | + """ |
| 69 | +let pi = 3.14_15F |
| 70 | +if pi <> 3.1415F then failwith "Wrong parsing" |
| 71 | +exit 0 |
| 72 | + """ |
| 73 | + |
| 74 | + [<Test>] |
| 75 | + let ``int with underscores hexBytes``() = |
| 76 | + CompilerAssert.CompileExeAndRun |
| 77 | + """ |
| 78 | +let hexBytes = 0xFF_EC_DE_5E |
| 79 | +if hexBytes <> 0xFFECDE5E then failwith "Wrong parsing" |
| 80 | +exit 0 |
| 81 | + """ |
| 82 | + |
| 83 | + |
| 84 | + [<Test>] |
| 85 | + let ``int with underscore hexWords``() = |
| 86 | + CompilerAssert.CompileExeAndRun |
| 87 | + """ |
| 88 | +let hexWords = 0xCAFE_BABE |
| 89 | +if hexWords <> 0xCAFEBABE then failwith "Wrong parsing" |
| 90 | +exit 0 |
| 91 | + """ |
| 92 | + |
| 93 | + [<Test>] |
| 94 | + let ``Long with underscores maxLong``() = |
| 95 | + CompilerAssert.CompileExeAndRun |
| 96 | + """ |
| 97 | +let maxLong = 0x7fff_ffff_ffff_ffffL |
| 98 | +if maxLong <> 0x7fffffffffffffffL then failwith "Wrong parsing" |
| 99 | +exit 0 |
| 100 | + """ |
| 101 | + |
| 102 | + [<Test>] |
| 103 | + let ``int with underscore nybbles``() = |
| 104 | + CompilerAssert.CompileExeAndRun |
| 105 | + """ |
| 106 | +let nybbles = 0b0010_0101 |
| 107 | +if nybbles <> 0b00100101 then failwith "Wrong parsing" |
| 108 | +exit 0 |
| 109 | + """ |
| 110 | + |
| 111 | + [<Test>] |
| 112 | + let ``int with underscores bytes``() = |
| 113 | + CompilerAssert.CompileExeAndRun |
| 114 | + """ |
| 115 | +let bytes = 0b11010010_01101001_10010100_10010010 |
| 116 | +if bytes <> 0b11010010011010011001010010010010 then failwith "Wrong parsing" |
| 117 | +exit 0 |
| 118 | + """ |
| 119 | + |
| 120 | + [<Test>] |
| 121 | + let ``int with single underscore literal``() = |
| 122 | + CompilerAssert.CompileExeAndRun |
| 123 | + """ |
| 124 | +let x2 = 5_2 |
| 125 | +if x2 <> 52 then failwith "Wrong parsing" |
| 126 | +exit 0 |
| 127 | + """ |
| 128 | + |
| 129 | + [<Test>] |
| 130 | + let ``int with multiple underscores literal``() = |
| 131 | + CompilerAssert.CompileExeAndRun |
| 132 | + """ |
| 133 | +let x4 = 5_______2 |
| 134 | +if x4 <> 52 then failwith "Wrong parsing" |
| 135 | +exit 0 |
| 136 | + """ |
| 137 | + |
| 138 | + [<Test>] |
| 139 | + let ``int with single underscore Hex literal``() = |
| 140 | + CompilerAssert.CompileExeAndRun |
| 141 | + """ |
| 142 | +let x7 = 0x5_2 |
| 143 | +if x7 <> 0x52 then |
| 144 | + failwith "Wrong parsing" |
| 145 | +exit 0 |
| 146 | + """ |
| 147 | + |
| 148 | + [<Test>] |
| 149 | + let ``int with single underscore after leading zero literal``() = |
| 150 | + CompilerAssert.CompileExeAndRun |
| 151 | + """ |
| 152 | +let x9 = 0_52 |
| 153 | +if x9 <> 052 then failwith "Wrong parsing" |
| 154 | +exit 0 |
| 155 | + """ |
| 156 | + |
| 157 | + [<Test>] |
| 158 | + let ``int with single underscore after leteral with leading zero ``() = |
| 159 | + CompilerAssert.CompileExeAndRun |
| 160 | + """ |
| 161 | +let x10 = 05_2 |
| 162 | +if x10 <> 052 then failwith "Wrong parsing" |
| 163 | +exit 0 |
| 164 | + """ |
| 165 | + |
| 166 | + [<Test>] |
| 167 | + let ``int with single underscore after octo leteral ``() = |
| 168 | + CompilerAssert.CompileExeAndRun |
| 169 | + """ |
| 170 | +let x14 = 0o5_2 |
| 171 | +if x14 <> 0o52 then failwith "Wrong parsing" |
| 172 | +exit 0 |
| 173 | + """ |
| 174 | + |
| 175 | + |
| 176 | + |
| 177 | + |
0 commit comments