1
0

test66.spec.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import { IVProgParser } from './../js/ast/ivprogParser';
  2. import { SemanticAnalyser } from './../js/processor/semantic/semanticAnalyser';
  3. import { LanguageService } from '../js/services/languageService';
  4. import { OutputTest } from '../js/util/outputTest';
  5. import { IVProgProcessor } from '../js/processor/ivprogProcessor';
  6. describe('Non initialized matrix', function () {
  7. localStorage.setItem('ivprog.lang', 'pt');
  8. const code = `programa {
  9. funcao inicio() {
  10. cadeia a = "mustache"
  11. cadeia b = "mostacheh"
  12. escreva(editDist(a,b,comprimento(a), comprimento(b)))
  13. }
  14. funcao inteiro editDist(cadeia str1 , cadeia str2 , inteiro m ,inteiro n) {
  15. inteiro l = m + 1
  16. inteiro c = n + 1
  17. inteiro i, j
  18. inteiro mat[l][c]
  19. para(i = 0; i <= m; i = i + 1 ) {
  20. para(j = 0; j <= n; j = j + 1) {
  21. se (i==0) {
  22. mat[i][j] = j
  23. } senao se (j == 0) {
  24. mat[i][j] = i
  25. } senao se (char_at(str1, i-1) == char_at(str2, j-1)) {
  26. mat[i][j] = mat[i-1][j-1]
  27. } senao {
  28. mat[i][j] = 1 + Matematica.minimo({mat[i][j-1], mat[i-1][j], mat[i-1][j-1]})
  29. }
  30. }
  31. }
  32. retorne mat[m][n]
  33. }
  34. }`
  35. const lexer = LanguageService.getCurrentLexer();
  36. const out = new OutputTest();
  37. it(`should not throw an exception`, function (done) {
  38. const parser = new IVProgParser(code, lexer);
  39. const sem = new SemanticAnalyser(parser.parseTree());
  40. const exec = new IVProgProcessor(sem.analyseTree());
  41. exec.registerOutput(out);
  42. exec.interpretAST().then(_ => {
  43. expect(out.list.length).toEqual(1);
  44. done()
  45. }).catch( err => done(err));
  46. });
  47. });