Browse Source

Fix a typo in the write function

-Include write command test cases
-Output.sendOutput should only receive strings as parameters
Lucas de Souza 6 years ago
parent
commit
2864d65a22
2 changed files with 30 additions and 1 deletions
  1. 1 1
      js/processor/ivprogProcessor.js
  2. 29 0
      tests/test38.spec.js

+ 1 - 1
js/processor/ivprogProcessor.js

@@ -254,7 +254,7 @@ export class IVProgProcessor {
 
   runWriteFunction (store) {
     const val = store.applyStore('p1');
-    this.output.sendOutput(val.val);
+    this.output.sendOutput(''+val.value);
     return Promise.resolve(store);
   }
 

+ 29 - 0
tests/test38.spec.js

@@ -0,0 +1,29 @@
+import Lexers from './../grammar/';
+import { IVProgParser } from './../js/ast/ivprogParser';
+import { IVProgProcessor} from './../js/processor/ivprogProcessor'
+import { OutputTest } from './../js/util/outputTest';
+
+describe('The write function', function () {
+
+  const code = `programa {
+
+    funcao inicio() {
+      real a = 8.01
+      escreva(a)
+    }
+  }`;
+
+  const output = new OutputTest();
+
+  const lexer = Lexers['pt_br'];
+
+  it(`should print the value passed to it, no matter it's type`, function (done) {
+    const parser = new IVProgParser(code, lexer);
+    const exec = new IVProgProcessor(parser.parseTree());
+    exec.registerOutput(output);
+    exec.interpretAST().then(sto => {
+      expect(output.list).toEqual(['8.01']);
+      done();
+    }).catch( err => done(err));
+  });
+});