From 9f5472e7bd70b2577a6ce52cce1af38b65fa2537 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C5=A0ebek?= <44544735+xsebek@users.noreply.github.com> Date: Tue, 17 May 2022 16:41:12 +0200 Subject: [PATCH] Fix multiline eval plugin padding (#2910) * Test multiline eval results - add test for multiline show instance See #2907 * Fix multiline eval padding See haskell#2907 --- .../hls-eval-plugin/src/Ide/Plugin/Eval/CodeLens.hs | 3 ++- plugins/hls-eval-plugin/test/Main.hs | 1 + .../test/testdata/TMultiResult.expected.hs | 13 +++++++++++++ .../hls-eval-plugin/test/testdata/TMultiResult.hs | 9 +++++++++ 4 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 plugins/hls-eval-plugin/test/testdata/TMultiResult.expected.hs create mode 100644 plugins/hls-eval-plugin/test/testdata/TMultiResult.hs diff --git a/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/CodeLens.hs b/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/CodeLens.hs index 70d7c7d130a..32419d6cadd 100644 --- a/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/CodeLens.hs +++ b/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/CodeLens.hs @@ -358,8 +358,9 @@ runTests EvalConfig{..} e@(_st, _) tests = do dbg "TEST RESULTS" rs let checkedResult = testCheck eval_cfg_diff (section, test) rs + let resultLines = concatMap T.lines checkedResult - let edit = asEdit (sectionFormat section) test (map pad checkedResult) + let edit = asEdit (sectionFormat section) test (map pad resultLines) dbg "TEST EDIT" edit return edit diff --git a/plugins/hls-eval-plugin/test/Main.hs b/plugins/hls-eval-plugin/test/Main.hs index cd334c2693a..a505a2486dd 100644 --- a/plugins/hls-eval-plugin/test/Main.hs +++ b/plugins/hls-eval-plugin/test/Main.hs @@ -68,6 +68,7 @@ tests = , goldenWithEval "Refresh an evaluation" "T5" "hs" , goldenWithEval "Refresh an evaluation w/ lets" "T6" "hs" , goldenWithEval "Refresh a multiline evaluation" "T7" "hs" + , goldenWithEval "Evaluate a multi-line show result" "TMultiResult" "hs" -- Do not escape from comments! , testCase "Semantic and Lexical errors are reported" $ do evalInFile "T8.hs" "-- >>> noFunctionWithThisName" "-- Variable not in scope: noFunctionWithThisName" evalInFile "T8.hs" "-- >>> res = \"a\" + \"bc\"" $ diff --git a/plugins/hls-eval-plugin/test/testdata/TMultiResult.expected.hs b/plugins/hls-eval-plugin/test/testdata/TMultiResult.expected.hs new file mode 100644 index 00000000000..a8ed57a2ced --- /dev/null +++ b/plugins/hls-eval-plugin/test/testdata/TMultiResult.expected.hs @@ -0,0 +1,13 @@ +module TMultiResult where +-- test multiline show instance (see #2907) + +data Multiline = M {l1 :: String, l2 :: String} deriving Read + +instance Show Multiline where + show m = "M {\n l1=" <> show (l1 m) <> ",\n l2=" <> show (l2 m) <> "\n}" + +-- >>> M "first line" "second line" +-- M { +-- l1="first line", +-- l2="second line" +-- } diff --git a/plugins/hls-eval-plugin/test/testdata/TMultiResult.hs b/plugins/hls-eval-plugin/test/testdata/TMultiResult.hs new file mode 100644 index 00000000000..11037e516fd --- /dev/null +++ b/plugins/hls-eval-plugin/test/testdata/TMultiResult.hs @@ -0,0 +1,9 @@ +module TMultiResult where +-- test multiline show instance (see #2907) + +data Multiline = M {l1 :: String, l2 :: String} deriving Read + +instance Show Multiline where + show m = "M {\n l1=" <> show (l1 m) <> ",\n l2=" <> show (l2 m) <> "\n}" + +-- >>> M "first line" "second line"