Browse Source

Fix code_generator bug where main function would have a fixed named despite lang config

Lucas de Souza 3 years ago
parent
commit
746ec7d823

+ 2 - 15
js/assessment/ivprogAssessment.js

@@ -83,19 +83,6 @@ export class IVProgAssessment {
   writeToConsole (channel, msgType, msgID, ...args) {
     let msg = LocalizedStrings.getString(msgID, msgType);
     msg = LocalizedStrings.processString(msg, args);
-    switch(channel) {
-      case DOMConsole.ERR: {
-        this.domConsole.err(msg);
-        break;
-      }
-      case DOMConsole.INFO: {
-        this.domConsole.info(msg);
-        break;
-      }
-      case DOMConsole.USER: {
-        this.domConsole.write(msg);
-        break;
-      }
-    }
+    this.domConsole.writeRawHTML(msg, channel);
   }
-}
+}

+ 13 - 5
js/io/domConsole.js

@@ -170,6 +170,10 @@ export class DOMConsole {
     this.anyKey = false;
   }
 
+  writeRawHTML (text, channel) {
+    this._appendTextLn(text, channel, false);
+  }
+
   write (text, newLine = false) {
     this._appendText(text, DOMConsole.USER, newLine);
   }
@@ -183,6 +187,7 @@ export class DOMConsole {
   }
 
   async _appendText (text, type, newLine = false) {
+    console.debug('Caling appendText');
     const write_time = Date.now();
     this.pending_writes.push(0);
     await Utils.sleep(5);
@@ -190,7 +195,7 @@ export class DOMConsole {
     if (this.last_clear >= write_time) {
       return;
     }
-    
+
     if (this.currentLine == null) {
       const divClass = this.getClassForType(type);
       const textDiv = document.createElement('div');
@@ -367,9 +372,12 @@ export class DOMConsole {
         let t = outputList[i];
         t = t.replace(/\t/g,'  ');
         t = t.replace(/\s/g," ");
-        if (t.length == 0)
-          t = " "
-        this.write(t, true);
+        if (t.length == 0) {
+          // t = " ";
+          console.debug('Empty string');
+          this.currentLine = null;
+        } else
+          this.write(t, true);
       }
       let t = outputList[i];
       t = t.replace(/\t/g,'  ');
@@ -382,7 +390,7 @@ export class DOMConsole {
       output = output.replace(/\s/g," ");
       this.write(output);
     }
-    
+
   }
 
   clearPendingWrites () {

+ 13 - 6
js/util/iassignHelpers.js

@@ -80,6 +80,7 @@ function compareTestcases (original, student) {
 
 export function autoEval (originalData, callback) {
   const code = generate();
+  //console.debug(code);
   const original = parseActivityData(originalData).getOrElse(undefined);
   if(original == null) {
     alert("iAssign did not provide the original activity data!");
@@ -91,11 +92,17 @@ export function autoEval (originalData, callback) {
     if (!compareTestcases(original.testcases, getTestCases())) {
       return callback(-2); // @FeedbackConvention Casos de teste alterados pelo aluno
     }
-    const ast_code = SemanticAnalyser.analyseFromSource(code);
-    const autoAssessment = new IVProgAssessment(ast_code, getTestCases(), new TestConsole([]));
-    autoAssessment.runTest().then( grade => callback(grade)).catch(err => {
-      console.log(err);
-      callback(-5); // @FeedbackConvention Falha na execução
-    });
+    try {
+      const ast_code = SemanticAnalyser.analyseFromSource(code);
+      const con = new TestConsole([]);
+      const autoAssessment = new IVProgAssessment(ast_code, original.testcases, con);
+      autoAssessment.runTest().then( grade => callback(grade)).catch(err => {
+        console.log(err);
+        callback(-5); // @FeedbackConvention Falha na execução
+      });
+    } catch(e) {
+      console.error(e);
+      callback(-5);
+    }
   }
 }

+ 3 - 2
js/util/outputTest.js

@@ -28,8 +28,9 @@ export class OutputTest extends Output {
         t = t.replace(/\t/g, '  ');
         t = t.replace(/\s/g, " ");
         if (t.length == 0)
-          t = " ";
-        this.write(t, true);
+          this.currentLine = null;
+        else
+          this.write(t, true);
       });
       last = last.replace(/\t/g, '  ');
       last = last.replace(/\s/g, " ");

+ 9 - 5
js/util/testConsole.js

@@ -13,6 +13,9 @@ export class TestConsole {
     this.currentLine = null;
   }
 
+  writeRawHTML (text) {
+    this._appendTextLn(text);
+  }
   write (text, newLine = false) {
     this._appendText(text, DOMConsole.USER, newLine);
   }
@@ -25,7 +28,7 @@ export class TestConsole {
     this._appendTextLn(text, DOMConsole.ERR);
   }
 
-  _appendText (text, type, newLine = false) {
+  _appendText (text, _type, newLine = false) {
     if (this.currentLine == null) {
       this.currentLine = this.list.push('') - 1;
     }
@@ -54,7 +57,7 @@ export class TestConsole {
 
   requestInput () {
     const promise = new Promise( (resolve, reject) => {
-      if(this.index < this.inputList.length) {      
+      if(this.index < this.inputList.length) {
         resolve(this.inputList[this.index]);
         this.index++;
       } else {
@@ -73,8 +76,9 @@ export class TestConsole {
         t = t.replace(/\t/g, '&#x0020;&#x0020;');
         t = t.replace(/\s/g, "&#x0020;");
         if (t.length == 0)
-          t = "&nbsp;";
-        this.write(t, true);
+          this.currentLine = null;
+        else
+          this.write(t, true);
       });
       last = last.replace(/\t/g, '&#x0020;&#x0020;');
       last = last.replace(/\s/g, "&#x0020;");
@@ -86,4 +90,4 @@ export class TestConsole {
       this.write(output);
     }
   }
-}
+}

+ 6 - 3
js/visualUI/code_generator.js

@@ -68,9 +68,12 @@ function functionsCode (function_obj) {
   } else if (function_obj.return_dimensions == 2) {
     ret += "[][] ";
   }
-
-  ret += function_obj.name + " ( ";
-
+  if (function_obj.is_main) {
+    ret += LocalizedStrings.getUI('start');
+  } else {
+    ret += function_obj.name;
+  }
+  ret += " ( ";
   for (let j = 0; j < function_obj.parameters_list.length; j++) {
     ret += parametersCode(function_obj.parameters_list[j]);
     if (j + 1 < function_obj.parameters_list.length) {

+ 1 - 1
package-lock.json

@@ -5808,7 +5808,7 @@
       }
     },
     "line-i18n": {
-      "version": "git+http://200.144.254.107/git/LInE/line-i18n.git#1f6cd8942338fbbb4b794fb7a7a2fae9bf7c4d87",
+      "version": "git+http://200.144.254.107/git/LInE/line-i18n.git#865a6b5a956aa29958a1177f00ca9cacacdba60e",
       "from": "git+http://200.144.254.107/git/LInE/line-i18n.git",
       "requires": {
         "ts-loader": "^5.4.5",