From a9531a429cbdd5bcd2bc591b5b5eeefe52b33b30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Bene=C5=A1?= Date: Fri, 16 Aug 2024 19:44:13 +0200 Subject: [PATCH] Fix formatting, rename 'dimWhenZeroElse' (sigh) --- libraries/common/test.effekt | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/libraries/common/test.effekt b/libraries/common/test.effekt index 0ec4ee426..ca414bfb7 100644 --- a/libraries/common/test.effekt +++ b/libraries/common/test.effekt @@ -83,7 +83,7 @@ def assertEqual[A](obtained: A, expected: A, msg: String) { equals: (A, A) => Bo def assertEqual[A](obtained: A, expected: A) { equals: (A, A) => Bool } { show: A => String }: Unit / { Assertion, Formatted } = do assert(equals(obtained, expected), Formatted::tryEmit(ANSI::RESET) ++ "Expected: ".dim ++ show(expected).green ++ "\n Obtained: ".dim ++ show(obtained).red) - // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + // NOTE: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ // Here's an accidental capture! Can we prevent this somehow nicely? interface Test { @@ -115,7 +115,7 @@ def suite(name: String, printTimes: Bool) { body: => Unit / { Test, Formatted } def ms(duration: Int): String / Formatted = if (printTimes) { - ("[" ++ bench::formatMs(duration) ++ "]").dim + " " ++ ("[" ++ bench::formatMs(duration) ++ "]").dim } else { "" } @@ -128,26 +128,26 @@ def suite(name: String, printTimes: Bool) { body: => Unit / { Test, Formatted } try { body() } with Test { def success(name, duration) = { passed = passed + 1 - println("✓".green ++ " " ++ name ++ " " ++ duration.ms) + println("✓".green ++ " " ++ name ++ duration.ms) resume(()) } def failure(name, msg, duration) = { failed = failed + 1 - println("✕".red ++ " " ++ name ++ " " ++ duration.ms) + println("✕".red ++ " " ++ name ++ duration.ms) println(" " ++ msg.red) resume(()) } } } - def color(s: String, n: Int) { colorIfNonZero: String => String / Formatted } = + def dimWhenZeroElse(s: String, n: Int) { colorIfNonZero: String => String / Formatted } = if (n == 0) { dim(s) } else { colorIfNonZero(s) } println("") - println(" " ++ (passed.show ++ " pass").color(passed) { green }) - println(" " ++ (failed.show ++ " fail").color(failed) { red }) - println(" " ++ (passed + failed).show ++ " tests total" ++ " " ++ totalDuration.ms) + println(" " ++ (passed.show ++ " pass").dimWhenZeroElse(passed) { green }) + println(" " ++ (failed.show ++ " fail").dimWhenZeroElse(failed) { red }) + println(" " ++ (passed + failed).show ++ " tests total" ++ totalDuration.ms) return failed == 0 }