(module main)

(import vec_string (empty append len at singleton append2 append3 pair triple is_empty index_or first_or last_or index_option first_option last_option index_of_option last_index_of_option contains count_of concat take starts_with without_prefix ends_with without_suffix drop reverse subvec insert_at insert_range replace_at replace_range remove_at remove_range))

(fn imported_empty_length () -> i32
  (len (empty)))

(fn imported_pair_index () -> string
  (at (pair "slovo" "tree") 1))

(fn original_len_after_append () -> i32
  (let values (vec string) (empty))
  (let more (vec string) (append values "branch"))
  (len values))

(fn option_string_is_some_value ((value (option string)) (expected string)) -> bool
  (if (is_some value)
    (= (unwrap_some value) expected)
    false))

(fn option_i32_is_some_value ((value (option i32)) (expected i32)) -> bool
  (if (is_some value)
    (= (unwrap_some value) expected)
    false))

(fn imported_builder_helpers_ok () -> bool
  (if (= (len (singleton "seed")) 1)
    (if (= (len (append2 (empty) "alpha" "beta")) 2)
      (if (= (len (append3 (singleton "alpha") "beta" "gamma" "delta")) 4)
        (if (= (pair "left" "right") (append2 (empty) "left" "right"))
          (= (triple "red" "green" "blue") (append3 (empty) "red" "green" "blue"))
          false)
        false)
      false)
    false))

(fn imported_query_helpers_ok () -> bool
  (if (is_empty (empty))
    (if (= (first_or (empty) "fallback") "fallback")
      (if (= (first_or (pair "alpha" "beta") "fallback") "alpha")
        (if (= (last_or (triple "red" "green" "blue") "fallback") "blue")
          (if (= (index_or (pair "alpha" "beta") -1 "fallback") "fallback")
            (if (= (index_or (pair "alpha" "beta") 9 "fallback") "fallback")
              (= (index_or (pair "alpha" "beta") 1 "fallback") "beta")
              false)
            false)
          false)
        false)
      false)
    false))

(fn imported_option_query_helpers_ok () -> bool
  (if (is_none (first_option (empty)))
    (if (option_string_is_some_value (first_option (pair "alpha" "beta")) "alpha")
      (if (is_none (last_option (empty)))
        (if (option_string_is_some_value (last_option (triple "red" "green" "blue")) "blue")
          (if (is_none (index_option (pair "alpha" "beta") -1))
            (if (is_none (index_option (pair "alpha" "beta") 9))
              (if (option_string_is_some_value (index_option (pair "alpha" "beta") 1) "beta")
                (if (is_none (index_of_option (append3 (pair "oak" "pine") "birch" "pine" "oak") "cedar"))
                  (if (option_i32_is_some_value (index_of_option (append3 (pair "oak" "pine") "birch" "pine" "oak") "pine") 1)
                    (if (is_none (last_index_of_option (append3 (pair "oak" "pine") "birch" "pine" "oak") "cedar"))
                      (option_i32_is_some_value (last_index_of_option (append3 (pair "oak" "pine") "birch" "pine" "oak") "pine") 3)
                      false)
                    false)
                  false)
                false)
              false)
            false)
          false)
        false)
      false)
    false))

(fn imported_starts_with_helper_ok () -> bool
  (let values (vec string) (append2 (triple "oak" "pine" "birch") "cedar" "maple"))
  (let prefix (vec string) (pair "oak" "pine"))
  (let longer_prefix (vec string) (append2 values "spruce" "elm"))
  (let mismatched_prefix (vec string) (pair "pine" "birch"))
  (if (starts_with values (empty))
    (if (starts_with values prefix)
      (if (starts_with values values)
        (if (starts_with values longer_prefix)
          false
          (if (starts_with values mismatched_prefix)
            false
            (if (= values (append2 (triple "oak" "pine" "birch") "cedar" "maple"))
              (= prefix (pair "oak" "pine"))
              false)))
        false)
      false)
    false))

(fn imported_ends_with_helper_ok () -> bool
  (let values (vec string) (append2 (triple "oak" "pine" "birch") "cedar" "maple"))
  (let suffix (vec string) (pair "cedar" "maple"))
  (let longer_suffix (vec string) (append2 values "spruce" "elm"))
  (let mismatched_suffix (vec string) (pair "cedar" "elm"))
  (if (ends_with values (empty))
    (if (ends_with values suffix)
      (if (ends_with values values)
        (if (ends_with values longer_suffix)
          false
          (if (ends_with values mismatched_suffix)
            false
            (if (= values (append2 (triple "oak" "pine" "birch") "cedar" "maple"))
              (= suffix (pair "cedar" "maple"))
              false)))
        false)
      false)
    false))

(fn imported_without_suffix_helper_ok () -> bool
  (let values (vec string) (append2 (triple "oak" "pine" "birch") "cedar" "maple"))
  (let suffix (vec string) (pair "cedar" "maple"))
  (let longer_suffix (vec string) (append2 values "spruce" "elm"))
  (let mismatched_suffix (vec string) (pair "cedar" "elm"))
  (if (= (without_suffix values (empty)) values)
    (if (= (without_suffix values values) (empty))
      (if (= (without_suffix values suffix) (triple "oak" "pine" "birch"))
        (if (= (without_suffix values longer_suffix) values)
          (if (= (without_suffix values mismatched_suffix) values)
            (if (= values (append2 (triple "oak" "pine" "birch") "cedar" "maple"))
              (= suffix (pair "cedar" "maple"))
              false)
            false)
          false)
        false)
      false)
    false))

(fn imported_without_prefix_helper_ok () -> bool
  (let values (vec string) (append2 (triple "oak" "pine" "birch") "cedar" "maple"))
  (let prefix (vec string) (pair "oak" "pine"))
  (let longer_prefix (vec string) (append2 values "spruce" "elm"))
  (let mismatched_prefix (vec string) (pair "oak" "birch"))
  (if (= (without_prefix values (empty)) values)
    (if (= (without_prefix values values) (empty))
      (if (= (without_prefix values prefix) (triple "birch" "cedar" "maple"))
        (if (= (without_prefix values longer_prefix) values)
          (if (= (without_prefix values mismatched_prefix) values)
            (if (= values (append2 (triple "oak" "pine" "birch") "cedar" "maple"))
              (= prefix (pair "oak" "pine"))
              false)
            false)
          false)
        false)
      false)
    false))

(fn imported_transform_helpers_ok () -> bool
  (if (= (concat (empty) (pair "oak" "pine")) (pair "oak" "pine"))
    (if (= (concat (pair "a" "b") (triple "c" "d" "e")) (append3 (pair "a" "b") "c" "d" "e"))
      (if (= (take (triple "red" "green" "blue") -4) (empty))
        (if (= (take (triple "red" "green" "blue") 2) (pair "red" "green"))
          (if (= (take (pair "red" "green") 9) (pair "red" "green"))
            (if (= (drop (triple "red" "green" "blue") -4) (triple "red" "green" "blue"))
              (if (= (drop (triple "red" "green" "blue") 2) (singleton "blue"))
                (if (= (drop (pair "red" "green") 9) (empty))
                  (if (= (reverse (empty)) (empty))
                    (= (reverse (append3 (pair "oak" "pine") "birch" "cedar" "maple")) (append3 (pair "maple" "cedar") "birch" "pine" "oak"))
                    false)
                  false)
                false)
              false)
            false)
          false)
        false)
      false)
    false))

(fn imported_subvec_helper_ok () -> bool
  (let original (vec string) (append2 (triple "oak" "pine" "birch") "cedar" "maple"))
  (if (= (subvec original -1 2) (empty))
    (if (= (subvec original 3 3) (empty))
      (if (= (subvec original 9 10) (empty))
        (if (= (subvec original 2 99) (triple "birch" "cedar" "maple"))
          (if (= (subvec original 1 4) (triple "pine" "birch" "cedar"))
            (= original (append2 (triple "oak" "pine" "birch") "cedar" "maple"))
            false)
          false)
        false)
      false)
    false))

(fn imported_insert_helper_ok () -> bool
  (let values (vec string) (triple "oak" "pine" "birch"))
  (if (= (insert_at values 1 "cedar") (append2 (pair "oak" "cedar") "pine" "birch"))
    (if (= (insert_at values 3 "cedar") (append values "cedar"))
      (if (= values (triple "oak" "pine" "birch"))
        (if (= (insert_at values -1 "cedar") values)
          (= (insert_at values 4 "cedar") values)
          false)
        false)
      false)
    false))

(fn imported_insert_range_helper_ok () -> bool
  (let values (vec string) (append2 (triple "oak" "pine" "birch") "cedar" "maple"))
  (let inserted (vec string) (pair "elm" "fir"))
  (if (= (insert_range values -1 inserted) values)
    (if (= (insert_range values 2 inserted) (append3 (append2 (pair "oak" "pine") "elm" "fir") "birch" "cedar" "maple"))
      (if (= (insert_range values 5 inserted) (append2 (append2 (triple "oak" "pine" "birch") "cedar" "maple") "elm" "fir"))
        (if (= values (append2 (triple "oak" "pine" "birch") "cedar" "maple"))
          (if (= inserted (pair "elm" "fir"))
            (= (insert_range values 6 inserted) values)
            false)
          false)
        false)
      false)
    false))

(fn imported_replace_helper_ok () -> bool
  (if (= (replace_at (triple "oak" "pine" "birch") 1 "cedar") (triple "oak" "cedar" "birch"))
    (if (= (replace_at (triple "oak" "pine" "birch") -1 "cedar") (triple "oak" "pine" "birch"))
      (= (replace_at (pair "oak" "pine") 2 "cedar") (pair "oak" "pine"))
      false)
    false))

(fn imported_replace_range_helper_ok () -> bool
  (let original (vec string) (append2 (triple "oak" "pine" "birch") "cedar" "maple"))
  (let replacement (vec string) (pair "elm" "fir"))
  (if (= (replace_range original -1 2 replacement) original)
    (if (= (replace_range original 3 3 replacement) original)
      (if (= (replace_range original 4 2 replacement) original)
        (if (= (replace_range original 5 9 replacement) original)
          (if (= (replace_range original 2 99 replacement) (append2 (pair "oak" "pine") "elm" "fir"))
            (if (= (replace_range original 1 4 replacement) (append2 (pair "oak" "elm") "fir" "maple"))
              (if (= original (append2 (triple "oak" "pine" "birch") "cedar" "maple"))
                (= replacement (pair "elm" "fir"))
                false)
              false)
            false)
          false)
        false)
      false)
    false))

(fn imported_remove_helper_ok () -> bool
  (let original (vec string) (triple "oak" "pine" "birch"))
  (let removed_middle (vec string) (remove_at original 1))
  (if (= removed_middle (pair "oak" "birch"))
    (if (= (len removed_middle) 2)
      (if (= (remove_at original 0) (pair "pine" "birch"))
        (if (= (remove_at original 2) (pair "oak" "pine"))
          (if (= original (triple "oak" "pine" "birch"))
            (if (= (remove_at original -1) original)
              (= (remove_at original 3) original)
              false)
            false)
          false)
        false)
      false)
    false))

(fn imported_remove_range_helper_ok () -> bool
  (let original (vec string) (append2 (triple "oak" "pine" "birch") "cedar" "maple"))
  (if (= (remove_range original -1 2) original)
    (if (= (remove_range original 3 3) original)
      (if (= (remove_range original 4 2) original)
        (if (= (remove_range original 5 9) original)
          (if (= (remove_range original 2 99) (pair "oak" "pine"))
            (if (= (remove_range original 1 4) (pair "oak" "maple"))
              (= original (append2 (triple "oak" "pine" "birch") "cedar" "maple"))
              false)
            false)
          false)
        false)
      false)
    false))

(fn imported_real_program_helpers_ok () -> bool
  (let values (vec string) (append2 (triple "oak" "pine" "oak") "birch" "oak"))
  (if (= (original_len_after_append) 0)
    (if (contains values "oak")
      (if (contains values "cedar")
        false
        (if (= (count_of values "oak") 3)
          (= (count_of values "cedar") 0)
          false))
      false)
    false))

(fn helpers_all_ok () -> bool
  (if (= (imported_empty_length) 0)
    (if (= (imported_pair_index) "tree")
      (if (imported_builder_helpers_ok)
        (if (imported_query_helpers_ok)
          (if (imported_option_query_helpers_ok)
            (if (imported_starts_with_helper_ok)
              (if (imported_ends_with_helper_ok)
                (if (imported_without_suffix_helper_ok)
                  (if (imported_without_prefix_helper_ok)
                    (if (imported_transform_helpers_ok)
                      (if (imported_subvec_helper_ok)
                        (if (imported_insert_helper_ok)
                          (if (imported_insert_range_helper_ok)
                            (if (imported_replace_helper_ok)
                              (if (imported_replace_range_helper_ok)
                                (if (imported_remove_helper_ok)
                                  (if (imported_remove_range_helper_ok)
                                    (imported_real_program_helpers_ok)
                                    false)
                                  false)
                                false)
                              false)
                            false)
                          false)
                        false)
                      false)
                    false)
                  false)
                false)
              false)
            false)
          false)
        false)
      false)
    false))

(fn main () -> i32
  (if (helpers_all_ok)
    42
    1))

(test "explicit local vec_string empty len facade"
  (= (imported_empty_length) 0))

(test "explicit local vec_string direct at facade"
  (= (imported_pair_index) "tree"))

(test "explicit local vec_string builder helpers"
  (imported_builder_helpers_ok))

(test "explicit local vec_string query helpers"
  (imported_query_helpers_ok))

(test "explicit local vec_string option query helpers"
  (imported_option_query_helpers_ok))

(test "explicit local vec_string starts_with helper"
  (imported_starts_with_helper_ok))

(test "explicit local vec_string ends_with helper"
  (imported_ends_with_helper_ok))

(test "explicit local vec_string without_suffix helper"
  (imported_without_suffix_helper_ok))

(test "explicit local vec_string without_prefix helper"
  (imported_without_prefix_helper_ok))

(test "explicit local vec_string transform helpers"
  (imported_transform_helpers_ok))

(test "explicit local vec_string subvec helper"
  (imported_subvec_helper_ok))

(test "explicit local vec_string insert helper"
  (imported_insert_helper_ok))

(test "explicit local vec_string insert range helper"
  (imported_insert_range_helper_ok))

(test "explicit local vec_string replace helper"
  (imported_replace_helper_ok))

(test "explicit local vec_string replace range helper"
  (imported_replace_range_helper_ok))

(test "explicit local vec_string remove helper"
  (imported_remove_helper_ok))

(test "explicit local vec_string remove range helper"
  (imported_remove_range_helper_ok))

(test "explicit local vec_string real-program helpers"
  (imported_real_program_helpers_ok))

(test "explicit local vec_string helpers all"
  (= (main) 42))
