test49.spec.js 890 B

123456789101112131415161718192021222324252627282930313233343536
  1. import { IVProgParser } from './../js/ast/ivprogParser';
  2. import { SemanticAnalyser } from './../js/processor/semantic/semanticAnalyser';
  3. import { LanguageService } from '../js/services/languageService';
  4. describe('The semantic analyser', function () {
  5. const code = `programa {
  6. const inteiro V = 1
  7. funcao inicio() {
  8. inteiro a = 5
  9. a = aNumber()
  10. }
  11. funcao inteiro aNumber () {
  12. inteiro a = 5
  13. se (V == 1) {
  14. retorne a + 3
  15. } senao {
  16. a = a * 2
  17. }
  18. }
  19. }`;
  20. localStorage.setItem('ivprog.lang', 'pt');
  21. const lexer = LanguageService.getCurrentLexer();
  22. it(`should guarantee that a function has an accessible return`, function () {
  23. const parser = new IVProgParser(code, lexer);
  24. const sem = new SemanticAnalyser(parser.parseTree());
  25. const fun = sem.analyseTree.bind(sem);
  26. expect(fun).toThrow();
  27. });
  28. });