test17.spec.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import Lexers from './../grammar/';
  2. import * as Expressions from './../js/ast/expressions/';
  3. import * as Commands from './../js/ast/commands/';
  4. import { Operators } from './../js/ast/operators';
  5. import {Types} from './../js/ast/types';
  6. import {
  7. IVProgParser
  8. } from './../js/ast/ivprogParser';
  9. describe('Variable declaration inside a function', () => {
  10. let input = `programa {
  11. funcao inicio() {
  12. inteiro a
  13. a = a + 1
  14. }
  15. }`;
  16. const lexer = Lexers['pt_br'];
  17. const ast = {
  18. global: [ ],
  19. functions: [
  20. new Commands.Function(null,Types.VOID,[],
  21. new Commands.CommandBlock([
  22. new Commands.Declaration('a',Types.INTEGER,null,false)],[
  23. new Commands.Assign('a',
  24. new Expressions.InfixApp(Operators.ADD, new Expressions.VariableLiteral('a'), new Expressions.IntLiteral(1)))]))
  25. ]
  26. }
  27. it(`must be inside the variables list`, () => {
  28. const as = new IVProgParser(input, lexer);
  29. const fun = as.parseTree();
  30. expect(fun).toEqual(ast);
  31. });
  32. });