Browse Source

Implement type casting option and config setting

Lucas de Souza 5 years ago
parent
commit
369e96123b
2 changed files with 21 additions and 0 deletions
  1. 1 0
      js/util/config.js
  2. 20 0
      tests/testTypeCast.spec.js

+ 1 - 0
js/util/config.js

@@ -5,6 +5,7 @@ class ConfigObject {
     this.decimalPlaces = 5;
     this.intConvertRoundMode = 2;
     this.default_lang = 'pt';
+    this.enable_type_casting = true;
   }
 
   setConfig (opts) {

+ 20 - 0
tests/testTypeCast.spec.js

@@ -0,0 +1,20 @@
+import { IVProgParser } from './../js/ast/ivprogParser';
+import { LanguageService } from '../js/services/languageService';
+
+describe('When implicit type casting is enabled', function () {
+
+  let input = `programa {
+
+    funcao inicio() {
+      real v = 5
+    }
+  }`;
+
+  const lexer = LanguageService.getCurrentLexer();
+
+  it(`should coerce integer into real`, function () {
+    const parser = new IVProgParser(input, lexer);
+    const fun = parser.parseTree.bind(parser);
+    expect(fun).not.toThrow();
+  });
+});