test17.spec.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import * as Expressions from './../js/ast/expressions/';
  2. import * as Commands from './../js/ast/commands/';
  3. import { Operators } from './../js/ast/operators';
  4. import {Types} from './../js/ast/types';
  5. import {
  6. IVProgParser
  7. } from './../js/ast/ivprogParser';
  8. import { LanguageService } from '../js/services/languageService';
  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 = LanguageService.getCurrentLexer();
  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. });