<commit_before>module Test.Runner.String exposing (Summary, run, runWithOptions)

{-| # String Runner

Run a test and present its results as a nicely-formatted String, along with
a count of how many tests passed and failed.

This is a quick way to get decent test outputs which can then be presented in
various different environments. See `Test.Runner.Log` for an example.

@docs Summary, run, runWithOptions
-}

import Random.Pcg as Random
import Test exposing (Test)
import Expect exposing (Expectation)
import String
import Test.Runner exposing (Runner(..))


{-| The output string, the number of passed tests,
and the number of failed tests.
-}
type alias Summary =
    { output : String, passed : Int, failed : Int }


toOutput : Summary -> Runner -> Summary
toOutput =
    flip (toOutputHelp [])


toOutputHelp : List String -> Runner -> Summary -> Summary
toOutputHelp labels runner summary =
    case runner of
        Runnable runnable ->
            let
                output =
                    summary.output ++ "\n\n" ++ outputLabels labels
            in
                Test.Runner.run runnable
                    |> List.foldl fromExpectation { summary | output = output }

        Labeled label subRunner ->
            toOutputHelp (label :: labels) subRunner summary

        Batch runners ->
            List.foldl (toOutputHelp labels) summary runners


fromExpectation : Expectation -> Summary -> Summary
fromExpectation expectation summary =
    case Expect.getFailure expectation of
        Nothing ->
            { summary | passed = summary.passed + 1 }

        Just { given, message } ->
            let
                prefix =
                    if String.isEmpty given then
                        ""
                    else
                        "Given " ++ given ++ "\n▔▔▔▔▔\n\n"

                newOutput =
                    "\n\n" ++ indentLines (prefix ++ message) ++ "\n"
            in
                { output = summary.output ++ newOutput
                , failed = summary.failed + 1
                , passed = summary.passed
                }


outputLabels : List String -> String
outputLabels labels =
    labels
        |> Test.Runner.formatLabels ((++) "↓ ") ((++) "✗ ")<commit_msg>Update Given formatting<commit_after>module Test.Runner.String exposing (Summary, run, runWithOptions)

{-| # String Runner

Run a test and present its results as a nicely-formatted String, along with
a count of how many tests passed and failed.

This is a quick way to get decent test outputs which can then be presented in
various different environments. See `Test.Runner.Log` for an example.

@docs Summary, run, runWithOptions
-}

import Random.Pcg as Random
import Test exposing (Test)
import Expect exposing (Expectation)
import String
import Test.Runner exposing (Runner(..))


{-| The output string, the number of passed tests,
and the number of failed tests.
-}
type alias Summary =
    { output : String, passed : Int, failed : Int }


toOutput : Summary -> Runner -> Summary
toOutput =
    flip (toOutputHelp [])


toOutputHelp : List String -> Runner -> Summary -> Summary
toOutputHelp labels runner summary =
    case runner of
        Runnable runnable ->
            let
                output =
                    summary.output ++ "\n\n" ++ outputLabels labels
            in
                Test.Runner.run runnable
                    |> List.foldl fromExpectation { summary | output = output }

        Labeled label subRunner ->
            toOutputHelp (label :: labels) subRunner summary

        Batch runners ->
            List.foldl (toOutputHelp labels) summary runners


fromExpectation : Expectation -> Summary -> Summary
fromExpectation expectation summary =
    case Expect.getFailure expectation of
        Nothing ->
            { summary | passed = summary.passed + 1 }

        Just { given, message } ->
            let
                prefix =
                    if String.isEmpty given then
                        ""
                    else
                        "Given " ++ given ++ "\n\n"

                newOutput =
                    "\n\n" ++ (prefix ++ indentLines message) ++ "\n"
            in
                { output = summary.output ++ newOutput
                , failed = summary.failed + 1
                , passed = summary.passed
                }


outputLabels : List String -> String
outputLabels labels =
    labels
        |> Test.Runner.formatLabels ((++) "↓ ") ((++) "✗ ")
{'fraction_non_alphanumeric': 0.08792680205311315, 'fraction_numerical': 0.0008926578888640928, 'mean_word_length': 1.8953488372093024, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 33, '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': '2854188', 'n_tokens_mistral': 1163, 'n_tokens_neox': 1080, 'n_words': 410}