Browse Source

Send IfThenElse class of last commit.\n Test cases for new command parsers

Lucas Souza 6 years ago
parent
commit
9d1019d272
6 changed files with 134 additions and 0 deletions
  1. 8 0
      js/ast/commands/ifThenElse.js
  2. 26 0
      tests/test05.spec.js
  3. 24 0
      tests/test06.spec.js
  4. 24 0
      tests/test07.spec.js
  5. 27 0
      tests/test08.spec.js
  6. 25 0
      tests/test09.spec.js

+ 8 - 0
js/ast/commands/ifThenElse.js

@@ -0,0 +1,8 @@
+export class IfThenElse {
+
+  constructor (condition, ifTrue, ifFalse) {
+    this.condition = condition;
+    this.ifTrue = ifTrue;
+    this.ifFalse = ifFalse;
+  }
+}

+ 26 - 0
tests/test05.spec.js

@@ -0,0 +1,26 @@
+import Lexers from './../grammar/';
+import {
+    IVProgParser
+} from './../js/ast/ivprogParser';
+import {
+    SyntaxError
+} from './../js/ast/SyntaxError';
+
+describe('IfThenElse command', () => {
+    let input = `funcao inteiro test(real i) {
+      inteiro a = 5 + i
+      a = 5 + G[i][6]
+      se (a > 5) {
+        a = 5
+      } senao {
+        a = 0
+      }
+    }`;
+    const lexer = Lexers['pt_br'];
+
+    it(`should not result in SyntaxError`, () => {
+        const as = new IVProgParser(input, lexer);
+        const fun = as.parseFunction.bind(as);
+        expect(fun).not.toThrow();
+    });
+});

+ 24 - 0
tests/test06.spec.js

@@ -0,0 +1,24 @@
+import Lexers from './../grammar/';
+import {
+    IVProgParser
+} from './../js/ast/ivprogParser';
+import {
+    SyntaxError
+} from './../js/ast/SyntaxError';
+
+describe('While command', () => {
+    let input = `funcao inteiro test(real i) {
+      inteiro a = 5 + i
+      a = 5 + G[i][6]
+      enquanto (a > 5) {
+        a = a + 1
+      }
+    }`;
+    const lexer = Lexers['pt_br'];
+
+    it(`should not result in SyntaxError`, () => {
+        const as = new IVProgParser(input, lexer);
+        const fun = as.parseFunction.bind(as);
+        expect(fun).not.toThrow();
+    });
+});

+ 24 - 0
tests/test07.spec.js

@@ -0,0 +1,24 @@
+import Lexers from './../grammar/';
+import {
+    IVProgParser
+} from './../js/ast/ivprogParser';
+import {
+    SyntaxError
+} from './../js/ast/SyntaxError';
+
+describe('For command', () => {
+    let input = `funcao inteiro test(real i) {
+      inteiro a = 5 + i
+      a = 5 + G[i][6]
+      para (a = 0; a < 5; a = a + 1) {
+         a = a
+      }
+    }`;
+    const lexer = Lexers['pt_br'];
+
+    it(`should not result in SyntaxError`, () => {
+        const as = new IVProgParser(input, lexer);
+        const fun = as.parseFunction.bind(as);
+        expect(fun).not.toThrow();
+    });
+});

+ 27 - 0
tests/test08.spec.js

@@ -0,0 +1,27 @@
+import Lexers from './../grammar/';
+import {
+    IVProgParser
+} from './../js/ast/ivprogParser';
+import {
+    SyntaxError
+} from './../js/ast/SyntaxError';
+
+describe('Break command inside a loop', () => {
+    let input = `funcao inteiro test(real i) {
+      inteiro a = 5 + i
+      a = 5 + G[i][6]
+      enquanto (a > 5) {
+        a = a + 1
+        se (a == 3) {
+          pare
+        }
+      }
+    }`;
+    const lexer = Lexers['pt_br'];
+
+    it(`should not result in SyntaxError`, () => {
+        const as = new IVProgParser(input, lexer);
+        const fun = as.parseFunction.bind(as);
+        expect(fun).not.toThrow();
+    });
+});

+ 25 - 0
tests/test09.spec.js

@@ -0,0 +1,25 @@
+import Lexers from './../grammar/';
+import {
+    IVProgParser
+} from './../js/ast/ivprogParser';
+import {
+    SyntaxError
+} from './../js/ast/SyntaxError';
+
+describe('Break command outside a loop', () => {
+    let input = `funcao inteiro test(real i) {
+      inteiro a = 5 + i
+      a = 5 + G[i][6]
+      enquanto (a > 5) {
+        a = a + 1
+      }
+      pare
+    }`;
+    const lexer = Lexers['pt_br'];
+
+    it(`should result in SyntaxError`, () => {
+        const as = new IVProgParser(input, lexer);
+        const fun = as.parseFunction.bind(as);
+        expect(fun).toThrow();
+    });
+});