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
1 change: 0 additions & 1 deletion tests/fsharp/core/libtest/test.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ let test s b =
else (stderr.WriteLine ("failure: " + s);
reportFailure s)


let format_uint64 outc formatc width left_justify add_zeros num_prefix_if_pos (n:uint64) =
let _ = match formatc with 'd' | 'i' | 'u' -> 10UL | 'o' -> 8UL | 'x' | 'X'-> 16UL | _ -> failwith "invalid value" in
failwith "hello"
Expand Down
249 changes: 248 additions & 1 deletion tests/projects/SelfContained_Trimming_Test/Program.fs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
module Core_printf

open Printf
open Microsoft.FSharp.Reflection
open Printf
open System.Collections.Generic

let failures = ref []

Expand All @@ -11,6 +12,10 @@ let report_failure (s : string) =
failures := !failures @ [s]
()

let check s e r =
if r <> e then
(stderr.WriteLine ($"\n***** {s}: Expected: '{e}' Results: '{r}' = FAIL\n"); report_failure s)

let test t (s1:Lazy<string>) s2 =

let s1 = s1.Force()
Expand Down Expand Up @@ -9094,10 +9099,39 @@ module PercentAPublicTests =
test "test8902" (lazy (sprintf "%A" (IntNumber 10 )).Replace("\n", ";")) """IntNumber 10"""
test "test8903" (lazy (sprintf "%A" (DoubleNumber 12.0)).Replace("\n", ";")) """DoubleNumber 12.0"""

let testPercentAOptionChoiceTypes () =
test "test8920" (lazy (sprintf "%A" None).Replace("\n", ";")) "None"
test "test8921" (lazy (sprintf "%A" (Some 1.030m)).Replace("\n", ";")) "Some 1.030M"
test "test8922" (lazy (sprintf "%A" ValueNone).Replace("\n", ";")) "ValueNone"
test "test8923" (lazy (sprintf "%A" (ValueSome 1.030m)).Replace("\n", ";")) "ValueSome 1.030M"
test "test8924" (lazy (sprintf "%A" (Choice1Of2 "Hello")).Replace("\n", ";")) "Choice1Of2 \"Hello\""
test "test8924" (lazy (sprintf "%A" (Choice1Of2 1.032m)).Replace("\n", ";")) "Choice1Of2 1.032M"

let testUnit () =
test "test8925" (lazy (sprintf "%A" ()).Replace("\n", ";")) "()"

let testTupleTypes () =
test "test8930" (lazy (sprintf "%A" (1, 1.020m, "Hello, World!!!!")).Replace("\n", ";")) """(1, 1.020M, "Hello, World!!!!")"""
test "test8931" (lazy (sprintf "%A" struct ( 1, 1.020m, "Hello, World!!!!" )).Replace("\n", ";")) """struct (1, 1.020M, "Hello, World!!!!")"""

let testCollectionsTypes () =
test "test8940" (lazy (sprintf "%A" [|1;2;3;4;5;6;7;8;9|]).Replace("\n", ";")) "[|1; 2; 3; 4; 5; 6; 7; 8; 9|]"
test "test8941" (lazy (sprintf "%A" [1;2;3;4;5;6;7;8;9]).Replace("\n", ";")) "[1; 2; 3; 4; 5; 6; 7; 8; 9]"
test "test8942" (lazy (sprintf "%A" (seq {1;2;3;4;5;6;7;8;9})).Replace("\n", ";")) "seq [1; 2; 3; 4; ...]"
test "test8943" (lazy (sprintf "%A" [|[|1,2|],[|3,4|]|]).Replace("\n", ";")) "[|([|(1, 2)|], [|(3, 4)|])|]"
test "test8944" (lazy (sprintf "%A" [|[|1;2|];[|3;4|]|]).Replace("\n", ";")) "[|[|1; 2|]; [|3; 4|]|]"
test "test8945" (lazy (sprintf "%A" (dict [(1, "a"); (2, "b"); (3, "c")])).Replace("\n", ";")) "seq [[1, a]; [2, b]; [3, c]]"
test "test8946" (lazy (sprintf "%A" (set [1; 2; 3; 4; 5])).Replace("\n", ";")) "set [1; 2; 3; 4; 5]"
test "test8947" (lazy (sprintf "%A" ([ ("One", 1); ("Two", 2) ] |> Map.ofSeq))) """map [("One", 1); ("Two", 2)]"""

let tests () =
testPercentAMyRecord ()
testPercentAMyAnnonymousRecord ()
testDiscriminatedUnion ()
testPercentAOptionChoiceTypes ()
testUnit ()
testTupleTypes ()
testCollectionsTypes ()

module PercentAInternalTests =
type internal MyInternalRecord =
Expand All @@ -9123,9 +9157,220 @@ module PercentAInternalTests =
testPercentA ()
testPercentPlusA ()

module ClassWithEvents =

type EventClass () =
let event = new Event<string> ()

[<CLIEvent>]
member _.Event = event.Publish

member _.TriggerEvent (arg) = event.Trigger (arg)

let testWithEventClass () =
test "test9200" (
lazy (
let mutable eventstring = ""
let evt = EventClass()
evt.Event.Add(fun arg -> eventstring <- eventstring + $"Event handler: {arg}")
evt.TriggerEvent("Hello World!")
eventstring
))
"""Event handler: Hello World!"""
test "test9201" (
lazy (
let mutable eventstring = ""
let evt = EventClass();
evt.Event.Add(fun arg -> eventstring <- eventstring + $"First handler: {arg}")
evt.Event.Add(fun arg -> eventstring <- eventstring + $" Second handler: {arg}")
evt.TriggerEvent("Hello World!")
eventstring
))
"""First handler: Hello World! Second handler: Hello World!"""
let tests () =
testWithEventClass ()

module SameTestsUsingNonStructuralComparison2 =
open NonStructuralComparison

do check "test9200" (3 > 1) true
do check "test9201" (3y > 1y) true
do check "test9202" (3uy > 1uy) true
do check "test9203" (3s > 1s) true
do check "test9204" (3us > 1us) true
do check "test9205" (3 > 1) true
do check "test9206" (3u > 1u) true
do check "test9207" (3L > 1L) true
do check "test9208" (3UL > 1UL) true
do check "test9209" (3.14 > 3.1) true
do check "test9210" (3.14f > 3.1f) true
do check "test9211" ("bbb" > "aaa") true
do check "test9212" ("bbb" > "bbb") false
do check "test9213" ("aaa" > "bbb") false
do check "test9214" ('b' > 'a') true
do check "test9215" ('a' > 'b') false
do check "test9216" ('b' > 'b') false

do check "test9217" (3 >= 3) true
do check "test9218" (3y >= 3y) true
do check "test9219" (3uy >= 3uy) true
do check "test9220" (3s >= 3s) true
do check "test9221" (3us >= 3us) true
do check "test9222" (3 >= 3) true
do check "test9223" (3u >= 3u) true
do check "test9224" (3L >= 3L) true
do check "test9225" (3UL >= 3UL) true
do check "test9226" (3.14 >= 3.1) true
do check "test9227" (3.14f >= 3.1f) true
do check "test9228" (3.14M >= 3.1M) true
do check "test9229" ("bbb" >= "aaa") true
do check "test9230" ("bbb" >= "bbb") true
do check "test9231" ("aaa" >= "bbb") false
do check "test9232" ('b' >= 'a') true
do check "test9233" ('a' >= 'b') false
do check "test9234" ('b' >= 'b') true

do check "test9235" (3 < 1) false
do check "test9236" (3y < 1y) false
do check "test9237" (3uy < 1uy) false
do check "test9238" (3s < 1s) false
do check "test9239" (3us < 1us) false
do check "test9240" (3 < 1) false
do check "test9241" (3u < 1u) false
do check "test9242" (3L < 1L) false
do check "test9243" (3UL < 1UL) false
do check "test9244" (3.14 < 1.0) false
do check "test9245" (3.14f < 1.0f) false
do check "test9246" (3.14M < 1.0M) false
do check "test9247" ("bbb" < "aaa") false
do check "test9248" ("bbb" < "bbb") false
do check "test9249" ("aaa" < "bbb") true
do check "test9250" ('b' < 'a') false
do check "test9251" ('a' < 'b') true
do check "test9252" ('b' < 'b') false

do check "test9253" (3 <= 1) false
do check "test9254" (3y <= 1y) false
do check "test9255" (3uy <= 1uy) false
do check "test9256" (3s <= 1s) false
do check "test9257" (3us <= 1us) false
do check "test9258" (3 <= 1) false
do check "test9259" (3u <= 1u) false
do check "test9260" (3L <= 1L) false
do check "test9261" (3UL <= 1UL) false
do check "test9262" (3.14 <= 1.0) false
do check "test9263" (3.14f <= 1.0f) false
do check "test9264" (3.14M <= 1.0M) false
do check "test9265" ("bbb" <= "aaa") false
do check "test9266" ("bbb" <= "bbb") true
do check "test9267" ("aaa" <= "bbb") true
do check "test9268" ('b' <= 'a') false
do check "test9269" ('a' <= 'b') true
do check "test9270" ('b' <= 'b') true
do check "test9271" (3 <= 3) true
do check "test9272" (3y <= 3y) true
do check "test9273" (3uy <= 3uy) true
do check "test9274" (3s <= 3s) true
do check "test9275" (3us <= 3us) true
do check "test9276" (3 <= 3) true
do check "test9277" (3u <= 3u) true
do check "test9278" (3L <= 3L) true
do check "test9279" (3UL <= 3UL) true
do check "test9280" (3.14 <= 3.14) true
do check "test9281" (3.14f <= 3.14f) true
do check "test9282" (3.14M <= 3.14M) true

module NonStructuralComparisonOverDateTime =
open NonStructuralComparison
let now = System.DateTime.Now
let tom = now.AddDays 1.0

do check "test9283" (now = tom) false
do check "test9284" (now <> tom) true
do check "test9285" (now < tom) true
do check "test9286" (now <= now) true
do check "test9287" (now <= tom) true
do check "test9288" (tom > now) true
do check "test9289" (now >= now) true
do check "test9290" (tom >= now) true
do check "test9291" (compare now now) 0
do check "test9292" (compare now tom) -1
do check "test9293" (compare tom now) 1
do check "test9294" (max tom tom) tom
do check "test9295" (max tom now) tom
do check "test9296" (max now tom) tom
do check "test9297" (min tom tom) tom
do check "test9298" (min tom now) now
do check "test9299" (min now tom) now

do check "test9301" (ComparisonIdentity.NonStructural.Compare (1, 1)) 0
do check "test9302" (ComparisonIdentity.NonStructural.Compare (0, 1)) -1
do check "test9303" (ComparisonIdentity.NonStructural.Compare (1, 0)) 1
do check "test9304" (ComparisonIdentity.NonStructural.Compare (now, now)) 0
do check "test9305" (ComparisonIdentity.NonStructural.Compare (now, tom)) -1
do check "test9306" (ComparisonIdentity.NonStructural.Compare (tom, now)) 1
do check "test9307" (HashIdentity.NonStructural.Equals (now, now)) true
do check "test9308" (HashIdentity.NonStructural.Equals (now, tom)) false
do check "test9309" (HashIdentity.NonStructural.Equals (tom, now)) false
do check "test9310" (HashIdentity.NonStructural.GetHashCode now) (hash now)
do check "test9311" (HashIdentity.NonStructural.GetHashCode tom) (hash tom)
do check "test9312" (HashIdentity.NonStructural.GetHashCode 11) (hash 11)
do check "test9313" (HashIdentity.NonStructural.GetHashCode 11L) (hash 11L)
do check "test9314" (HashIdentity.NonStructural.GetHashCode 11UL) (hash 11UL)
do check "test9315" (HashIdentity.NonStructural.Equals (1, 1)) true
do check "test9316" (HashIdentity.NonStructural.Equals (1, 0)) false
do check "test9317" (HashIdentity.NonStructural.Equals (0, 1)) false

module NonStructuralComparisonOverTimeSpan =
open NonStructuralComparison
let now = System.TimeSpan.Zero
let tom = System.TimeSpan.FromDays 1.0

do check "test9318" (now = tom) false
do check "test9319" (now <> tom) true
do check "test9320" (now < tom) true
do check "test9381" (now <= now) true
do check "test9382" (now <= tom) true
do check "test9383" (tom > now) true
do check "test9384" (now >= now) true
do check "test9385" (tom >= now) true
do check "test9386" (compare now now) 0
do check "test9387" (compare now tom) -1
do check "test9388" (compare tom now) 1
do check "test9389" (max tom tom) tom
do check "test9390" (max tom now) tom
do check "test9391" (max now tom) tom
do check "test9392" (min tom tom) tom
do check "test9393" (min tom now) now
do check "test9394" (min now tom) now

// Check you can use the operators without opening the module by naming them
module NonStructuralComparisonOverTimeSpanDirect =
let now = System.TimeSpan.Zero
let tom = System.TimeSpan.FromDays 1.0

do check "test9395" (NonStructuralComparison.(=) now tom) false
do check "test9396" (NonStructuralComparison.(<>) now tom) true
do check "test9397" (NonStructuralComparison.(<) now tom) true
do check "test9398" (NonStructuralComparison.(<=) now now) true
do check "test9399" (NonStructuralComparison.(>) tom now) true
do check "test9400" (NonStructuralComparison.(>=) now now) true
do check "test9401" (NonStructuralComparison.compare now now) 0
do check "test9402" (NonStructuralComparison.max tom now) tom
do check "test9403" (NonStructuralComparison.min tom now) now

do check "test9404" (NonStructuralComparison.hash now) (Operators.hash now)
do check "test9405" (NonStructuralComparison.hash tom) (Operators.hash tom)
do check "test9406" (NonStructuralComparison.hash 11) (Operators.hash 11)
do check "test9407" (NonStructuralComparison.hash 11L) (Operators.hash 11L)
do check "test9408" (NonStructuralComparison.hash 11UL) (Operators.hash 11UL)


[<EntryPoint>]
let main _ =

testing1()

func0()
func1000()
func2000()
Expand All @@ -9135,9 +9380,11 @@ let main _ =
func6000()
func7000()
func8000()

PresenceOfReflectionApi.tests ()
PercentAPublicTests.tests ()
PercentAInternalTests.tests ()
ClassWithEvents.testWithEventClass ()

match !failures with
| [] ->
Expand Down
2 changes: 1 addition & 1 deletion tests/projects/SelfContained_Trimming_Test/check.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ if (-not ($output -eq $expected))
}

# Checking that FSharp.Core binary is of expected size (needs adjustments if test is updated).
$expected_len = 265216 # In bytes
$expected_len = 287744 # In bytes
$file = Get-Item .\bin\Release\net7.0\win-x64\publish\FSharp.Core.dll
$file_len = $file.Length
if (-not ($file_len -eq $expected_len))
Expand Down