test60.spec.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  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 { InputTest } from './../js/util/inputTest';
  6. import { IVProgProcessor } from './../js/processor/ivprogProcessor';
  7. describe('Reading a single value into a vector/matrix position', function () {
  8. const code = `programa {
  9. funcao inicio() {
  10. inteiro a[2] = {0,0}
  11. leia(a[0])
  12. escreva(a[0])
  13. }
  14. }`;
  15. localStorage.setItem('ivprog.lang', 'pt');
  16. const lexer = LanguageService.getCurrentLexer();
  17. const out = new OutputTest();
  18. const inPut = new InputTest(['1'])
  19. it(`should produce a valid state`, function (done) {
  20. const parser = new IVProgParser(code, lexer);
  21. const sem = new SemanticAnalyser(parser.parseTree());
  22. const exec = new IVProgProcessor(sem.analyseTree());
  23. exec.registerOutput(out);
  24. exec.registerInput(inPut);
  25. exec.interpretAST().then(sto => {
  26. expect(out.list).toEqual(['1']);
  27. done();
  28. }).catch(err => done(err));
  29. });
  30. });