All files / tr8-script/validators/rules no-world-and-ext-source-for-request-rule.ts

100% Statements 11/11
83.33% Branches 5/6
100% Functions 1/1
100% Lines 10/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36            1x   4x 2x 2x 2x 2x 1x       1x 1x                 2x                
import { autoInjectable } from "tsyringe";
 
import { Tr8AST } from "../../domain/ast.js";
import { SemanticValidationRule, ValidationResult } from "../validator.js";
 
@autoInjectable()
class NoWorldAndExtSourceForRequestRule implements SemanticValidationRule {
  validate(ast: Tr8AST): ValidationResult {
    if (ast.type === "REQ") {
      const { txs } = ast;
      for (const tx of txs) {
        for (const source of tx.sources) {
          if (source.book.type === "world") {
            return {
              isValid: false,
              errors: ["Request cannot have world as a source."],
            };
          E} else if (source.extern) {
            return {
              isValid: false,
              errors: ["Request cannot involve external source."],
            };
          }
        }
      }
    }
 
    return {
      isValid: true,
      errors: [],
    };
  }
}
 
export { NoWorldAndExtSourceForRequestRule };