import std/unittest

import ../src/passage_query

suite "passage query parser":
  test "uses the default translation when no marker is present":
    let queries = parsePassageQueries("John 3:16", "kjv")

    check queries.len == 1
    check queries[0].referenceText == "John 3:16"
    check queries[0].translation == "kjv"

  test "uses a trailing translation marker":
    let queries = parsePassageQueries("2 John 5 (KJV)", "esv")

    check queries.len == 1
    check queries[0].referenceText == "2 John 5"
    check queries[0].translation == "kjv"

  test "parses mixed translation queries":
    let queries = parsePassageQueries("2 John 5 (KJV); 2 John 5 (ESV)", "mev")

    check queries.len == 2
    check queries[0].referenceText == "2 John 5"
    check queries[0].translation == "kjv"
    check queries[1].referenceText == "2 John 5"
    check queries[1].translation == "esv"

  test "uses the default translation per unmarked reference":
    let queries = parsePassageQueries("John 3:16; Psalm 23 (MEV)", "nkjv")

    check queries.len == 2
    check queries[0].referenceText == "John 3:16"
    check queries[0].translation == "nkjv"
    check queries[1].referenceText == "Psalms 23"
    check queries[1].translation == "mev"

  test "rejects unknown translation markers":
    expect ValueError:
      discard parsePassageQueries("John 3:16 (XYZ)", "esv")

  test "rejects unknown default translations":
    expect ValueError:
      discard parsePassageQueries("John 3:16", "xyz")
