<commit_before>﻿module CheckedDynamicOperatorsEvaluationTests

open Xunit
open Swensen.Unquote
open System
open System.Reflection

let inline testEval expr expected =
    let result = expr |> eval
    result =! expected

let testEvalCheckedOverflow expr =
    let e = 
        <@ try 
               %expr |> ignore; null
           with e -> e @> |> eval

    test <@ let ty = e.GetType() in ty = typeof<OverflowException> || ty = typeof<TargetInvocationException> @>

[<Fact>]
let ``op_Multiply primitive overflows`` () =
    testEvalCheckedOverflow <@ Checked.(*) Int32.MaxValue Int32.MaxValue @>

[<Fact(Skip="No type handy")>]
let ``op_Multiply reflection overflows`` () =
    ()

[<Fact>]
let ``op_Subtraction primitive overflows`` () =
    testEvalCheckedOverflow <@ Checked.(-) Int32.MinValue 1 @>

[<Fact(Skip="No type handy")>]
let ``op_Subtraction reflection overflows`` () =
    ()

[<Fact>]
let ``op_Addition primitive overflows`` () =
    testEvalCheckedOverflow <@ Checked.(+) Int32.MaxValue 1 @>
<commit_msg>better info when e is null in testEvalCheckOverflow internal test assertion<commit_after>﻿module CheckedDynamicOperatorsEvaluationTests

open Xunit
open Swensen.Unquote
open System
open System.Reflection

let inline testEval expr expected =
    let result = expr |> eval
    result =! expected

let testEvalCheckedOverflow expr =
    let e = 
        <@ try 
               %expr |> ignore; null
           with e -> e @> |> eval

    test <@ e <> null && let ty = e.GetType() in ty = typeof<OverflowException> || ty = typeof<TargetInvocationException> @>

[<Fact>]
let ``op_Multiply primitive overflows`` () =
    testEvalCheckedOverflow <@ Checked.(*) Int32.MaxValue Int32.MaxValue @>

[<Fact(Skip="No type handy")>]
let ``op_Multiply reflection overflows`` () =
    ()

[<Fact>]
let ``op_Subtraction primitive overflows`` () =
    testEvalCheckedOverflow <@ Checked.(-) Int32.MinValue 1 @>

[<Fact(Skip="No type handy")>]
let ``op_Subtraction reflection overflows`` () =
    ()

[<Fact>]
let ``op_Addition primitive overflows`` () =
    testEvalCheckedOverflow <@ Checked.(+) Int32.MaxValue 1 @>

{'fraction_non_alphanumeric': 0.13283089967027792, 'fraction_numerical': 0.009420631182289214, 'mean_word_length': 3.838268792710706, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 36, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6435533', 'n_tokens_mistral': 689, 'n_tokens_neox': 643, 'n_words': 180}