test17.spec.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. import { LanguageService } from '../js/services/languageService';
  10. describe('Variable declaration inside a function', () => {
  11. let input = `programa {
  12. funcao inicio() {
  13. inteiro a
  14. a = a + 1
  15. }
  16. }`;
  17. const lexer = LanguageService.getCurrentLexer();
  18. const ast = {
  19. global: [ ],
  20. functions: [
  21. new Commands.Function(null,Types.VOID,[],
  22. new Commands.CommandBlock([
  23. new Commands.Declaration('a',Types.INTEGER,null,false)],[
  24. new Commands.Assign('a',
  25. new Expressions.InfixApp(Operators.ADD, new Expressions.VariableLiteral('a'), new Expressions.IntLiteral(1)))]))
  26. ]
  27. }
  28. it(`must be inside the variables list`, () => {
  29. const as = new IVProgParser(input, lexer);
  30. const fun = as.parseTree();
  31. expect(fun).toEqual(ast);
  32. });
  33. });