From 85f5bba71d43e3d80df61025d04682fef3586266 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Janis=20Daniel=20Da=CC=88hne?=
 <janis.daehne2@student.uni-halle.de>
Date: Tue, 5 Nov 2019 18:12:06 +0100
Subject: [PATCH] - expected regex as output is now displayed better (tooltip)
 - regex + use diff option now works together as expected - missing output is
 now displayed properly (text: missing)

---
 i18n/en.ts                                    |  1 +
 i18n/i18nRoot.ts                              |  1 +
 .../consolePanel/consoleItem.tsx              | 73 ++++++++++++++++---
 src/constants.ts                              |  2 +-
 src/helpers/convertersAndTransformers.ts      |  6 ++
 src/styles/common.styl                        |  3 +
 src/types/testResults.ts                      |  6 ++
 src/types/testsAndTestProtocol.ts             |  7 ++
 8 files changed, 86 insertions(+), 13 deletions(-)

diff --git a/i18n/en.ts b/i18n/en.ts
index 435701c9..91be421d 100644
--- a/i18n/en.ts
+++ b/i18n/en.ts
@@ -262,6 +262,7 @@ export const lang_en: LangObj = {
   "unknown/ignored line": "unknown/ignored line",
   "The previous (your) output was wrong. This is the correct output. Blue characters are missing, red ones are too much (inside your output) [For regex lines, starting with '(regex):' there is no diff display option].": "The previous (your) output was wrong. This is the correct output. Blue characters are missing, red ones are too much (inside your output) [For regex lines, starting with '(regex):' there is no diff display option].",
   "The previous (your) output was wrong. This is the correct output.": "The previous (your) output was wrong. This is the correct output.",
+  "Your output must match this regex" : "Your output must match this regex",
   "Use diff": "Use diff",
   "If enabled and your output was wrong then the diff against the expected output is displayed as your output. If disabled the wrong output is marked red instead. For further help (if enabled) hover over the rectangle left to the expected output.": "If enabled and your output was wrong then the diff against the expected output is displayed as your output. If disabled the wrong output is marked red instead. For further help (if enabled) hover over the rectangle left to the expected output.",
   "Replace Spaces": "Replace Spaces",
diff --git a/i18n/i18nRoot.ts b/i18n/i18nRoot.ts
index 971aa0f1..45ca6965 100644
--- a/i18n/i18nRoot.ts
+++ b/i18n/i18nRoot.ts
@@ -265,6 +265,7 @@ export interface LangObj {
   "unknown/ignored line": string
   "The previous (your) output was wrong. This is the correct output. Blue characters are missing, red ones are too much (inside your output) [For regex lines, starting with '(regex):' there is no diff display option].": string
   "The previous (your) output was wrong. This is the correct output.": string
+  "Your output must match this regex": string
   "Use diff": string
   "If enabled and your output was wrong then the diff against the expected output is displayed as your output. If disabled the wrong output is marked red instead. For further help (if enabled) hover over the rectangle left to the expected output.": string
   "Replace Spaces": string
diff --git a/src/components/sites/doExerciseSite/consolePanel/consoleItem.tsx b/src/components/sites/doExerciseSite/consolePanel/consoleItem.tsx
index 7926365a..d400f29e 100644
--- a/src/components/sites/doExerciseSite/consolePanel/consoleItem.tsx
+++ b/src/components/sites/doExerciseSite/consolePanel/consoleItem.tsx
@@ -486,11 +486,26 @@ class consoleItem extends React.Component<Props, any> {
           </div>
         }
         {
-          //output (user program, if hasOutputMismatched color differently to indicate error)
+          this.props.item.type === TestProtocolType.isMissingOutput &&
+          <div className="console-input-output-line">
+            <div className="input-part">
+            </div>
+            <div className={'program-part-mismatch'}>
+            </div>
+            <div className="output-part bg-white-colored">
+              <div>
+                <pre className="mar-null not-important-colored" style={{fontStyle: 'italic'}}>
+                  missing
+                  <span className="white-colored" style={{pointerEvents: 'none'}}>no.</span>
+              </pre>
+              </div>
+            </div>
+          </div>
+        }
+        {
           this.props.item.type === TestProtocolType.isOutput &&
           <div className="console-input-output-line">
             <div className="input-part">
-
             </div>
             <div className={this.props.item.hasOutputMismatched
                             ? 'program-part-mismatch'
@@ -504,9 +519,22 @@ class consoleItem extends React.Component<Props, any> {
                 !this.props.item.hasOutputMismatched &&
                 <div>
                   <pre className="mar-null">
+                  {
+                    startsWith(this.props.item.content, "(regex):") &&
+                    <MyPopup trigger={
+                      <Icon className="hoverable" name="registered"/>
+                    }
+                             content={getI18n(this.props.langId, "Your output must match this regex")}
+                             position="top left"
+                             offset={leftIconPopupOffset + 5}
+                             wide
+                    />
+                  }
                   {
                     //only convert color if all is ok... else we have an mismatch and we want to compare...no colors
-                    this.convertConsoleLineToAsciiColoredLine(contentTransformer(this.props.item.content))
+                    startsWith(this.props.item.content, "(regex):")
+                    ? this.convertConsoleLineToAsciiColoredLine(contentTransformer(this.props.item.content.substr("(regex):".length)))
+                    : this.convertConsoleLineToAsciiColoredLine(contentTransformer(this.props.item.content))
                   }
                   </pre>
                 </div>
@@ -517,7 +545,7 @@ class consoleItem extends React.Component<Props, any> {
                   &&
                   (
                     !this.props.useDiffIfOutputMismatched
-                    || startsWith(this.props.item.content, "(regex):")
+                    || (this.props.nextItem !== null && startsWith(this.props.nextItem.content, "(regex):")) //if next item is an expected regex then do output without showing diff... (other branch of see bot regex case)
                   )
                 ) &&
                 <div className="error-colored">
@@ -531,7 +559,7 @@ class consoleItem extends React.Component<Props, any> {
               {
                 //diff output, if we use diff output we cannot use regex because this doesn't make sense
                 (this.props.item.hasOutputMismatched && this.props.useDiffIfOutputMismatched
-                  && !startsWith(this.props.item.content, "(regex):")
+                  && (this.props.nextItem === null || !startsWith(this.props.nextItem.content, "(regex):")) //if next item is an expected regex then do not show diff (because not possible for regex)
                 ) &&
                 <div>
                   <pre className="mar-null">
@@ -612,7 +640,21 @@ class consoleItem extends React.Component<Props, any> {
               <div>
                 <pre className="mar-null">
                   {
-                    contentTransformer(this.props.item.content)
+                    startsWith(this.props.item.content, "(regex):") &&
+                    <MyPopup trigger={
+                      <Icon className="hoverable" name="registered"/>
+                    }
+                             content={getI18n(this.props.langId, "Your output must match this regex")}
+                             position="top left"
+                             offset={leftIconPopupOffset + 5}
+                             wide
+                    />
+                  }
+
+                  {
+                    startsWith(this.props.item.content, "(regex):")
+                    ? contentTransformer(this.props.item.content.substr("(regex):".length))
+                    : contentTransformer(this.props.item.content)
                   }
                 </pre>
               </div>
@@ -678,20 +720,27 @@ class consoleItem extends React.Component<Props, any> {
                         horizontalOffset={leftIconPopupOffset}
                         content={
                           <div className="flexed-h stacked-checkboxes">
-                            <Checkbox label={`${getI18n(this.props.langId, "Ignore case")} (${CompareTestOptions.ignoreCase})`}
-                                      checked={compareTest.ignoreCase}
-                                      disabled
+                            <Checkbox
+                              label={`${getI18n(this.props.langId, "Ignore case")} (${CompareTestOptions.ignoreCase})`}
+                              checked={compareTest.ignoreCase}
+                              disabled
                             />
                             <Checkbox
-                              label={`${getI18n(this.props.langId, "Ignore all additional empty lines in the user file")} (${CompareTestOptions.ignoreAllEmptyOrWhitespacesOnlyLines})`}
+                              label={`${getI18n(this.props.langId,
+                                                "Ignore all additional empty lines in the user file"
+                              )} (${CompareTestOptions.ignoreAllEmptyOrWhitespacesOnlyLines})`}
                               checked={compareTest.ignoreAllEmptyOrWhitespacesOnlyLines}
                               disabled
                             />
-                            <Checkbox label={`${getI18n(this.props.langId, "Ignore leading whitespaces")} (${CompareTestOptions.ignoreLeadingWhitespaces})`}
+                            <Checkbox label={`${getI18n(this.props.langId,
+                                                        "Ignore leading whitespaces"
+                            )} (${CompareTestOptions.ignoreLeadingWhitespaces})`}
                                       checked={compareTest.ignoreLeadingWhitespaces}
                                       disabled
                             />
-                            <Checkbox label={`${getI18n(this.props.langId, "Ignore trailing whitespaces")} (${CompareTestOptions.ignoreTrailingWhitespaces})`}
+                            <Checkbox label={`${getI18n(this.props.langId,
+                                                        "Ignore trailing whitespaces"
+                            )} (${CompareTestOptions.ignoreTrailingWhitespaces})`}
                                       checked={compareTest.ignoreTrailingWhitespaces}
                                       disabled
                             />
diff --git a/src/constants.ts b/src/constants.ts
index a018fa08..982f45fb 100644
--- a/src/constants.ts
+++ b/src/constants.ts
@@ -13,7 +13,7 @@ import Logger from './helpers/logger'
  * y - breaking changes / new features
  * z - fixes, small changes
  */
-export const versionString = '2.5.5'
+export const versionString = '2.5.6'
 
 
 export const supportMail = 'yapex@informatik.uni-halle.de'
diff --git a/src/helpers/convertersAndTransformers.ts b/src/helpers/convertersAndTransformers.ts
index b81bbf9f..986d3534 100644
--- a/src/helpers/convertersAndTransformers.ts
+++ b/src/helpers/convertersAndTransformers.ts
@@ -783,6 +783,12 @@ export function convertTestProtocol(protocol: ReadonlyArray<string>,
             content: TestProtocol.endOfUserProgramString,
           }
           // this is the last because only e would also match expected and vice versa
+        } else if (line === TestProtocol.missingOutput) {
+           return {
+             type: TestProtocolType.isMissingOutput,
+             hasOutputMismatched: false,
+             content: '',
+           }
         } else if (line.length > 0 && line[0] === TestProtocol.regexOutputSign) {
 
           return {
diff --git a/src/styles/common.styl b/src/styles/common.styl
index f6e330f5..40effa71 100644
--- a/src/styles/common.styl
+++ b/src/styles/common.styl
@@ -70,6 +70,9 @@ add(a, b)
 .light-grey-bg-colored {
   background-color #e9e9e9
 }
+.bg-white-colored {
+  background-color white
+}
 
 .grey-colored {
   color lightgrey
diff --git a/src/types/testResults.ts b/src/types/testResults.ts
index c323b6af..a622e906 100644
--- a/src/types/testResults.ts
+++ b/src/types/testResults.ts
@@ -240,6 +240,7 @@ export enum TestResultCodes {
 /**
  * the test protocol from test server (e.g. regex blackbox line is missing because this is a normal output)
  * @see TestProtocol
+ * @see convertTestProtocolFromString
  */
 export enum TestProtocolType {
   /**
@@ -273,6 +274,11 @@ export enum TestProtocolType {
    */
   isExitCode,
 
+  /**
+   * we expected output but the user program didn't output anything
+   */
+  isMissingOutput,
+
   /**
    * the expected user program exit code line
    * if we have an exit code and expected exit code the expected exit code must be the next item after the exit code
diff --git a/src/types/testsAndTestProtocol.ts b/src/types/testsAndTestProtocol.ts
index c7eeec8f..e196d5be 100644
--- a/src/types/testsAndTestProtocol.ts
+++ b/src/types/testsAndTestProtocol.ts
@@ -562,6 +562,7 @@ export interface TestAnswerFromBackend {
  *
  * the test protocol lines can start with these characters...
  * @see TestProtocolType
+ * @see convertTestProtocolFromString
  */
 export enum TestProtocol {
   /**
@@ -586,6 +587,12 @@ export enum TestProtocol {
    * the protocol string that indicates an error
    */
   errorPrefix = 'error:',
+
+  /**
+   * we expected output but the user program didn't output anything
+   */
+  missingOutput = 'miss',
+
   /**
    * the protocol string that indicates a output line that was expected but not outputted from the user program
    */
-- 
GitLab