From 3c1aa0734157bb2736306c5d545c152614529fb6 Mon Sep 17 00:00:00 2001 From: ee7 <45465154+ee7@users.noreply.github.com> Date: Fri, 4 Jun 2021 19:49:34 +0200 Subject: [PATCH 1/4] sync(sync): fix pretty-printing of JSON There were some strange double quotes and colons. --- src/sync/sync.nim | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/sync/sync.nim b/src/sync/sync.nim index 954cf505..e027528c 100644 --- a/src/sync/sync.nim +++ b/src/sync/sync.nim @@ -7,10 +7,10 @@ type sdIncludeTest, sdExcludeTest, sdSkipTest, sdReplaceTest proc chooseRegularSyncDecision(testCase: ExerciseTestCase): SyncDecision = - echo &"""The following test case is missing:" -{testCase.json.pretty()}: + echo &"""The following test case is missing: +{testCase.json.pretty()} -Do you want to include the test case ([y]es/[n]o/[s]kip)?: +Do you want to include the test case ([y]es/[n]o/[s]kip)? """ case stdin.readLine().toLowerAscii() @@ -25,13 +25,13 @@ Do you want to include the test case ([y]es/[n]o/[s]kip)?: sdSkipTest proc chooseReimplementsSyncDecision(testCase: ExerciseTestCase): SyncDecision = - echo &"""The following test case is missing:" -{testCase.json.pretty()}: + echo &"""The following test case is missing: +{testCase.json.pretty()} It reimplements this test case: -{testCase.reimplements.get().json.pretty()}: +{testCase.reimplements.get().json.pretty()} -Do you want to replace the existing test case ([y]es/[n]o/[s]kip)?: +Do you want to replace the existing test case ([y]es/[n]o/[s]kip)? """ case stdin.readLine().toLowerAscii() From 6f73929371c74b20fc215a0cf662641ba0e7f053 Mon Sep 17 00:00:00 2001 From: ee7 <45465154+ee7@users.noreply.github.com> Date: Fri, 4 Jun 2021 19:49:35 +0200 Subject: [PATCH 2/4] sync(sync): add newline after opening `"""` This is what the Nim style guide currently recommends. --- src/sync/sync.nim | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/sync/sync.nim b/src/sync/sync.nim index e027528c..87c8b54f 100644 --- a/src/sync/sync.nim +++ b/src/sync/sync.nim @@ -7,7 +7,8 @@ type sdIncludeTest, sdExcludeTest, sdSkipTest, sdReplaceTest proc chooseRegularSyncDecision(testCase: ExerciseTestCase): SyncDecision = - echo &"""The following test case is missing: + echo &""" +The following test case is missing: {testCase.json.pretty()} Do you want to include the test case ([y]es/[n]o/[s]kip)? @@ -25,7 +26,8 @@ Do you want to include the test case ([y]es/[n]o/[s]kip)? sdSkipTest proc chooseReimplementsSyncDecision(testCase: ExerciseTestCase): SyncDecision = - echo &"""The following test case is missing: + echo &""" +The following test case is missing: {testCase.json.pretty()} It reimplements this test case: From 1d55d5164f6f35c9017cd201221340d789d96340 Mon Sep 17 00:00:00 2001 From: ee7 <45465154+ee7@users.noreply.github.com> Date: Fri, 4 Jun 2021 19:49:36 +0200 Subject: [PATCH 3/4] sync(sync): prompt on stderr; move user response to end of line I think prompts are supposed to be on `stderr`. It also means we don't need to think about `flushFile(stdout)`. --- src/sync/sync.nim | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/sync/sync.nim b/src/sync/sync.nim index 87c8b54f..988865f3 100644 --- a/src/sync/sync.nim +++ b/src/sync/sync.nim @@ -7,12 +7,11 @@ type sdIncludeTest, sdExcludeTest, sdSkipTest, sdReplaceTest proc chooseRegularSyncDecision(testCase: ExerciseTestCase): SyncDecision = - echo &""" + stderr.write &""" The following test case is missing: {testCase.json.pretty()} -Do you want to include the test case ([y]es/[n]o/[s]kip)? -""" +Do you want to include the test case ([y]es/[n]o/[s]kip)? """ case stdin.readLine().toLowerAscii() of "y", "yes": @@ -22,19 +21,18 @@ Do you want to include the test case ([y]es/[n]o/[s]kip)? of "s", "skip": sdSkipTest else: - echo "Unknown response. Skipping test case..." + stderr.writeLine "Unknown response. Skipping test case..." sdSkipTest proc chooseReimplementsSyncDecision(testCase: ExerciseTestCase): SyncDecision = - echo &""" + stderr.write &""" The following test case is missing: {testCase.json.pretty()} It reimplements this test case: {testCase.reimplements.get().json.pretty()} -Do you want to replace the existing test case ([y]es/[n]o/[s]kip)? -""" +Do you want to replace the existing test case ([y]es/[n]o/[s]kip)? """ case stdin.readLine().toLowerAscii() of "y", "yes": @@ -44,7 +42,7 @@ Do you want to replace the existing test case ([y]es/[n]o/[s]kip)? of "s", "skip": sdSkipTest else: - echo "Unknown response. Skipping test case..." + stderr.writeLine "Unknown response. Skipping test case..." sdSkipTest proc syncDecision(testCase: ExerciseTestCase, mode: Mode): SyncDecision = From 5bd1c17499a264a44abc509a68c0a4b5b6fb3e15 Mon Sep 17 00:00:00 2001 From: ee7 <45465154+ee7@users.noreply.github.com> Date: Fri, 4 Jun 2021 19:49:37 +0200 Subject: [PATCH 4/4] sync(sync): add blank lines to sync messages --- src/sync/sync.nim | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/sync/sync.nim b/src/sync/sync.nim index 988865f3..6f17b8d4 100644 --- a/src/sync/sync.nim +++ b/src/sync/sync.nim @@ -6,6 +6,9 @@ type SyncDecision = enum sdIncludeTest, sdExcludeTest, sdSkipTest, sdReplaceTest +proc writeBlankLines = + stderr.write "\n\n" + proc chooseRegularSyncDecision(testCase: ExerciseTestCase): SyncDecision = stderr.write &""" The following test case is missing: @@ -15,13 +18,17 @@ Do you want to include the test case ([y]es/[n]o/[s]kip)? """ case stdin.readLine().toLowerAscii() of "y", "yes": + writeBlankLines() sdIncludeTest of "n", "no": + writeBlankLines() sdExcludeTest of "s", "skip": + writeBlankLines() sdSkipTest else: stderr.writeLine "Unknown response. Skipping test case..." + writeBlankLines() sdSkipTest proc chooseReimplementsSyncDecision(testCase: ExerciseTestCase): SyncDecision = @@ -36,13 +43,17 @@ Do you want to replace the existing test case ([y]es/[n]o/[s]kip)? """ case stdin.readLine().toLowerAscii() of "y", "yes": + writeBlankLines() sdReplaceTest of "n", "no": + writeBlankLines() sdExcludeTest of "s", "skip": + writeBlankLines() sdSkipTest else: stderr.writeLine "Unknown response. Skipping test case..." + writeBlankLines() sdSkipTest proc syncDecision(testCase: ExerciseTestCase, mode: Mode): SyncDecision =