<commit_before>package edmin

import fastparse.core.ParseError
import fastparse.core.Parsed.Failure
import monix.eval.Task
import monix.execution.Ack
import utest._

import scala.concurrent.Future
import scala.scalajs.js

object QQASTTest extends utest.TestSuite {

  import monix.execution.Scheduler.Implicits.global

  val tests = this {

    import QQAST._

    "optimize simple compositions" - {
      optimize(ComposeFilters(IdFilter, SelectKey("key"))) ==> SelectKey("key")
      optimize(ComposeFilters(IdFilter, ComposeFilters(SelectKey("key"), IdFilter))) ==> SelectKey("key")
    }

    "optimize pipes and dots to the same thing" - {
      optimize(QQParser.ensequencedFilters.parse(".key | .dang").get.value) ==> ComposeFilters(SelectKey("key"), SelectKey("dang"))
      optimize(QQParser.ensequencedFilters.parse(".key.dang").get.value) ==> ComposeFilters(SelectKey("key"), SelectKey("dang"))
    }

    "select keys" - {
      val dict = js.Dictionary("present" -> 1)
      for {
        _ <- compile(SelectKey("present"))(dict).runAsyncGetFirst map (_.get ==> 1)
        _ <- compile(SelectKey("absent"))(dict).runAsyncGetFirst map (_.get ==> null)
      } yield ()
    }

    "select index" - {
      val arr = js.Array(1, 2)
      def checkIndex(index: Int, result: Int) =
        compile(SelectIndex(index))(arr).runAsyncGetFirst map { _.get ==> result }
      for {
        _ <- checkIndex(-3, null)
        _ <- checkIndex(-2, 1)
        _ <- checkIndex(-1, 2)
        _ <- checkIndex(0, 1)
        _ <- checkIndex(1, 2)
        _ <- checkIndex(2, null)
      } yield ()
    }

    "select range" - {
      val arr = js.Array(1, 2, 3, 4)
      def checkRange(start: Int, end: Int, result: Array[Int]) =
        compile(SelectRange(start, end))(arr).runAsyncGetFirst map { _.get.asInstanceOf[js.Array[Int]].toArray ==> result }
      for {
        _ <- checkRange(0, 0, Array())
        _ <- checkRange(0, 1, Array(1))
        _ <- checkRange(0, 2, Array(1, 2))
        _ <- checkRange(0, 3, Array(1, 2, 3))
        _ <- checkRange(0, 4, Array(1, 2, 3, 4))
        _ <- checkRange(0, 5, Array(1, 2, 3, 4))
        _ <- checkRange(1, 5, Array(2, 3, 4))
      } yield ()
    }

  }
}<commit_msg>Added enlist test<commit_after>package edmin

import fastparse.core.ParseError
import fastparse.core.Parsed.Failure
import monix.eval.Task
import monix.execution.Ack
import utest._

import scala.concurrent.Future
import scala.scalajs.js

object QQASTTest extends utest.TestSuite {

  import monix.execution.Scheduler.Implicits.global

  val tests = this {

    import QQAST._

    "optimize simple compositions" - {
      optimize(ComposeFilters(IdFilter, SelectKey("key"))) ==> SelectKey("key")
      optimize(ComposeFilters(IdFilter, ComposeFilters(SelectKey("key"), IdFilter))) ==> SelectKey("key")
    }

    "optimize pipes and dots to the same thing" - {
      optimize(QQParser.ensequencedFilters.parse(".key | .dang").get.value) ==> ComposeFilters(SelectKey("key"), SelectKey("dang"))
      optimize(QQParser.ensequencedFilters.parse(".key.dang").get.value) ==> ComposeFilters(SelectKey("key"), SelectKey("dang"))
    }

    "select keys" - {
      val dict = js.Dictionary("present" -> 1)
      for {
        _ <- compile(SelectKey("present"))(dict).runAsyncGetFirst map (_.get ==> 1)
        _ <- compile(SelectKey("absent"))(dict).runAsyncGetFirst map (_.get ==> null)
      } yield ()
    }

    "select index" - {
      val arr = js.Array(1, 2)
      def checkIndex(index: Int, result: Any) =
        compile(SelectIndex(index))(arr).runAsyncGetFirst map { _.get ==> result }
      for {
        _ <- checkIndex(-3, null)
        _ <- checkIndex(-2, 1)
        _ <- checkIndex(-1, 2)
        _ <- checkIndex(0, 1)
        _ <- checkIndex(1, 2)
        _ <- checkIndex(2, null)
      } yield ()
    }

    "select range" - {
      val arr = js.Array(1, 2, 3, 4)
      def checkRange(start: Int, end: Int, result: Array[Int]) =
        compile(SelectRange(start, end))(arr).runAsyncGetFirst map { _.get.asInstanceOf[js.Array[Int]].toArray ==> result }
      for {
        _ <- checkRange(0, 0, Array())
        _ <- checkRange(0, 1, Array(1))
        _ <- checkRange(0, 2, Array(1, 2))
        _ <- checkRange(0, 3, Array(1, 2, 3))
        _ <- checkRange(0, 4, Array(1, 2, 3, 4))
        _ <- checkRange(0, 5, Array(1, 2, 3, 4))
        _ <- checkRange(1, 5, Array(2, 3, 4))
      } yield ()
    }

    "collect results" - {
      val arr = js.Array(1, 2, 3, 4)
      for {
        _ <- compile(CollectResults(IdFilter))(arr).foldLeftF[List[js.Any]](Nil)((x, y) => y :: x).runAsyncGetFirst map { _.get.reverse ==> List(1, 2, 3, 4) }
      } yield ()
    }

  }
}
{'fraction_non_alphanumeric': 0.16389244558258642, 'fraction_numerical': 0.022620571916346564, 'mean_word_length': 2.7436102236421727, 'pattern_counts': {'":': 0, '<': 34, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7473414', 'n_tokens_mistral': 1690, 'n_tokens_neox': 1594, 'n_words': 324}