<commit_before>package parser

import org.scalatest.FunSuite

import scala.util.parsing.combinator.RegexParsers

class ExprParser extends RegexParsers {
  val number = "[1-9]+".r
  def expr: Parser[Int] = (number ^^ { _.toInt }) ~ opt(operator ~ expr ) ^^ {
    case a ~ None => a
    case a ~ Some("*" ~ b) => a * b
    case a ~ Some("/" ~ b) => a / b
    case a ~ Some("+" ~ b) => a + b
    case a ~ Some("-" ~ b) => a - b
  }
  def operator: Parser[Any] = "+" | "-" | "*" | "/"
}

class ParserTest extends FunSuite {
  test("find all in") {
    val regex = "am".r
    val source = "I am, I am, said he."
    assert((regex findAllIn source size) == 2)
  }

  test("replace all in") {
    val regex = "cats".r
    val source = "I love cats, and cats love me."
    val replacement = "tigers"
    assert((source length) == 30)
    assert((regex replaceAllIn(source, replacement) length) == 34)
  }

  test("parse all") {
    val parser = new ExprParser()
    assert(parser.parseAll(parser.expr, "3+3").get == 6)
    assert(parser.parseAll(parser.expr, "3*3").get == 9)
    assert(parser.parseAll(parser.expr, "9-6").get == 3)
    assert(parser.parseAll(parser.expr, "9/3").get == 3)
  }
}<commit_msg>added date pattern match test<commit_after>package parser

import org.scalatest.FunSuite

import scala.util.parsing.combinator.RegexParsers

class ExprParser extends RegexParsers {
  val number = "[1-9]+".r
  def expr: Parser[Int] = (number ^^ { _.toInt }) ~ opt(operator ~ expr ) ^^ {
    case a ~ None => a
    case a ~ Some("*" ~ b) => a * b
    case a ~ Some("/" ~ b) => a / b
    case a ~ Some("+" ~ b) => a + b
    case a ~ Some("-" ~ b) => a - b
  }
  def operator: Parser[Any] = "+" | "-" | "*" | "/"
}

class ParserTest extends FunSuite {
  test("find all in") {
    val regex = "am".r
    val source = "I am, I am, said he."
    assert((regex findAllIn source size) == 2)
  }

  test("replace all in") {
    val regex = "cats".r
    val source = "I love cats, and cats love me."
    val replacement = "tigers"
    assert((source length) == 30)
    assert((regex replaceAllIn(source, replacement) length) == 34)
  }

  test("pattern match") {
    val date = """(\d\d\d\d)-(\d\d)-(\d\d)""".r
    "2015-09-09" match {
      case date(year, month, day) => assert(year.toInt == 2015 && month.toInt == 9 && day.toInt == 9)
    }
  }

  test("parse all") {
    val parser = new ExprParser()
    assert(parser.parseAll(parser.expr, "3+3").get == 6)
    assert(parser.parseAll(parser.expr, "3*3").get == 9)
    assert(parser.parseAll(parser.expr, "9-6").get == 3)
    assert(parser.parseAll(parser.expr, "9/3").get == 3)
  }
}
{'fraction_non_alphanumeric': 0.18773800456968773, 'fraction_numerical': 0.019801980198019802, 'mean_word_length': 2.818313953488372, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 14, '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': '1674304', 'n_tokens_mistral': 995, 'n_tokens_neox': 953, 'n_words': 257}