// Generated by bynkc — do not edit by hand.
// test target: shortener.analytics

import { Ok, Err, Some, None, type Result, type Option, type ValidationError } from "../runtime.js";
import * as shortener_analytics from "./../shortener/analytics.js";

class AssertionError extends Error {
  constructor(public location: string, public start: number, public end: number) {
    super(`assertion failed at ${location}`);
  }
}
function __bynkAssertionFailure(location: string, start: number, end: number) {
  return new AssertionError(location, start, end);
}
function __bynkAssert(cond: boolean, location: string, start: number, end: number): void {
  if (!cond) { throw __bynkAssertionFailure(location, start, end); }
}

function makeTestDeps() {
  return {  };
}

async function test_short_code_rejects_too_short_input() {
  try {
    const deps = {};
    const { LongUrl, ShortCode } = shortener_analytics as any;
    const result = ShortCode.fromString("ab");
    void (((__d) => {
        switch (__d.tag) {
          case "Ok": {
            return __bynkAssert((false), "offset 158", 158, 163);
          }
          case "Err": {
            return __bynkAssert((true), "offset 187", 187, 191);
          }
        }
        throw new Error("non-exhaustive match");
      })(result));
    return { pass: true };
  } catch (e) {
    if (e instanceof AssertionError) {
      return { pass: false, error: { message: e.message, location: e.location } };
    }
    return { pass: false, error: { message: String(e), location: "unknown" } };
  }
}

async function test_short_code_accepts_valid_input() {
  try {
    const deps = {};
    const { LongUrl, ShortCode } = shortener_analytics as any;
    const result = ShortCode.fromString("abc123");
    void (((__d) => {
        switch (__d.tag) {
          case "Ok": {
            return __bynkAssert((true), "offset 334", 334, 338);
          }
          case "Err": {
            return __bynkAssert((false), "offset 362", 362, 367);
          }
        }
        throw new Error("non-exhaustive match");
      })(result));
    return { pass: true };
  } catch (e) {
    if (e instanceof AssertionError) {
      return { pass: false, error: { message: e.message, location: e.location } };
    }
    return { pass: false, error: { message: String(e), location: "unknown" } };
  }
}

async function test_long_url_accepts_a_typical_url() {
  try {
    const deps = {};
    const { LongUrl, ShortCode } = shortener_analytics as any;
    const result = LongUrl.fromString("https://example.com/path");
    if (!(result.tag === "Ok")) { throw __bynkAssertionFailure("offset 496", 496, 511); }
    return { pass: true };
  } catch (e) {
    if (e instanceof AssertionError) {
      return { pass: false, error: { message: e.message, location: e.location } };
    }
    return { pass: false, error: { message: String(e), location: "unknown" } };
  }
}

export async function run() {
  const results = [];
  results.push({ name: "short code rejects too-short input", ...(await test_short_code_rejects_too_short_input()) });
  results.push({ name: "short code accepts valid input", ...(await test_short_code_accepts_valid_input()) });
  results.push({ name: "long url accepts a typical url", ...(await test_long_url_accepts_a_typical_url()) });
  return results;
}
