// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { isWildcardComparator } from "./_shared.ts";
import { compare } from "./compare.ts";
function testComparator(version, comparator) {
  if (isWildcardComparator(comparator)) {
    return true;
  }
  const cmp = compare(version, comparator);
  switch(comparator.operator){
    case "=":
    case undefined:
      {
        return cmp === 0;
      }
    case "!=":
      {
        return cmp !== 0;
      }
    case ">":
      {
        return cmp > 0;
      }
    case "<":
      {
        return cmp < 0;
      }
    case ">=":
      {
        return cmp >= 0;
      }
    case "<=":
      {
        return cmp <= 0;
      }
  }
}
export function testComparatorSet(version, set) {
  for (const comparator of set){
    if (!testComparator(version, comparator)) {
      return false;
    }
  }
  if (version.prerelease && version.prerelease.length > 0) {
    // Find the comparator that is allowed to have prereleases
    // For example, ^1.2.3-pr.1 desugars to >=1.2.3-pr.1 <2.0.0
    // That should allow `1.2.3-pr.2` to pass.
    // However, `1.2.4-alpha.notready` should NOT be allowed,
    // even though it's within the range set by the comparators.
    for (const comparator of set){
      if (isWildcardComparator(comparator)) {
        continue;
      }
      const { major, minor, patch, prerelease } = comparator;
      if (prerelease && prerelease.length > 0) {
        if (version.major === major && version.minor === minor && version.patch === patch) {
          return true;
        }
      }
    }
    return false;
  }
  return true;
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImh0dHBzOi8vanNyLmlvL0BzdGQvc2VtdmVyLzAuMjI0LjMvX3Rlc3RfY29tcGFyYXRvcl9zZXQudHMiXSwic291cmNlc0NvbnRlbnQiOlsiLy8gQ29weXJpZ2h0IDIwMTgtMjAyNCB0aGUgRGVubyBhdXRob3JzLiBBbGwgcmlnaHRzIHJlc2VydmVkLiBNSVQgbGljZW5zZS5cblxuaW1wb3J0IHR5cGUgeyBDb21wYXJhdG9yLCBTZW1WZXIgfSBmcm9tIFwiLi90eXBlcy50c1wiO1xuaW1wb3J0IHsgaXNXaWxkY2FyZENvbXBhcmF0b3IgfSBmcm9tIFwiLi9fc2hhcmVk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