-
Notifications
You must be signed in to change notification settings - Fork 864
Expand file tree
/
Copy pathPrintFunction.fs
More file actions
98 lines (83 loc) · 3.63 KB
/
Copy pathPrintFunction.fs
File metadata and controls
98 lines (83 loc) · 3.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
namespace EmittedIL
open Xunit
open FSharp.Test.Compiler
module PrintFunction =
[<Fact>]
let ``print with int specializes to Int32 ToString with InvariantCulture``() =
FSharp """
module PrintInt
let printInt () = print 42
"""
|> withOptimize
|> compile
|> shouldSucceed
|> verifyIL [
"""call class [netstandard]System.IO.TextWriter [netstandard]System.Console::get_Out()"""
"""call class [netstandard]System.Globalization.CultureInfo [netstandard]System.Globalization.CultureInfo::get_InvariantCulture()"""
"""call instance string [netstandard]System.Int32::ToString(string,"""
"""callvirt instance void [netstandard]System.IO.TextWriter::Write(string)"""]
[<Fact>]
let ``printn with int specializes to Int32 ToString with InvariantCulture``() =
FSharp """
module PrintnInt
let printnInt () = printn 42
"""
|> withOptimize
|> compile
|> shouldSucceed
|> verifyIL [
"""call class [netstandard]System.IO.TextWriter [netstandard]System.Console::get_Out()"""
"""call class [netstandard]System.Globalization.CultureInfo [netstandard]System.Globalization.CultureInfo::get_InvariantCulture()"""
"""call instance string [netstandard]System.Int32::ToString(string,"""
"""callvirt instance void [netstandard]System.IO.TextWriter::WriteLine(string)"""]
[<Fact>]
let ``print with string calls Write directly``() =
FSharp """
module PrintString
let printStr () = print "hello"
"""
|> withOptimize
|> compile
|> shouldSucceed
|> verifyIL [
"""call class [netstandard]System.IO.TextWriter [netstandard]System.Console::get_Out()"""
"""callvirt instance void [netstandard]System.IO.TextWriter::Write(string)"""]
[<Fact>]
let ``print with char calls Write char overload``() =
FSharp """
module PrintChar
let printChar () = print 'A'
"""
|> withOptimize
|> compile
|> shouldSucceed
|> verifyIL [
"""call class [netstandard]System.IO.TextWriter [netstandard]System.Console::get_Out()"""
"""callvirt instance void [netstandard]System.IO.TextWriter::Write(char)"""]
[<Fact>]
let ``print with bool calls Write bool overload``() =
FSharp """
module PrintBool
let printBool () = print true
"""
|> withOptimize
|> compile
|> shouldSucceed
|> verifyIL [
"""call class [netstandard]System.IO.TextWriter [netstandard]System.Console::get_Out()"""
"""callvirt instance void [netstandard]System.IO.TextWriter::Write(bool)"""]
[<Fact>]
let ``printn with float specializes to Double ToString with InvariantCulture``() =
FSharp """
module PrintnFloat
let printnFloat () = printn 3.14
"""
|> withOptimize
|> compile
|> shouldSucceed
|> verifyIL [
"""call class [netstandard]System.IO.TextWriter [netstandard]System.Console::get_Out()"""
"""call class [netstandard]System.Globalization.CultureInfo [netstandard]System.Globalization.CultureInfo::get_InvariantCulture()"""
"""call instance string [netstandard]System.Double::ToString(string,"""
"""callvirt instance void [netstandard]System.IO.TextWriter::WriteLine(string)"""]