<commit_before>/*
 * Copyright 2001-2013 Artima, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.scalatest
package exceptions

import org.scalatest.prop.TableDrivenPropertyChecks
import org.scalactic.source

class StackDepthExceptionSpec extends FunSpec with Matchers with TableDrivenPropertyChecks {

  class FunException(
    messageFun: StackDepthException => Option[String],
    cause: Option[Throwable],
    val pos: Option[source.Position],
    failedCodeStackDepthFun: StackDepthException => Int
  ) extends StackDepthException(messageFun, cause, Right(failedCodeStackDepthFun)) {
    def severedAtStackDepth: FunException = {
      val truncated = getStackTrace.drop(failedCodeStackDepth)
      val e = new FunException(messageFun, cause, pos, e => 0)
      e.setStackTrace(truncated)
      e
    }
  }

  class NoFunException(
    message: Option[String],
    cause: Option[Throwable],
    val pos: Option[source.Position],
    failedCodeStackDepth: Int
  ) extends StackDepthException(message, cause, failedCodeStackDepth) {
    def severedAtStackDepth: NoFunException = {
      val truncated = getStackTrace.drop(failedCodeStackDepth)
      val e = new NoFunException(message, cause, pos, 0)
      e.setStackTrace(truncated)
      e
    }
  }

  val invalidFunCombos =
    Table[StackDepthException => Option[String], Option[Throwable], StackDepthException => Int](
      ("messageFun",     "cause",              "failedCodeStackDepthFun"),
      (null,             Some(new Exception),  e => 17),
      (e => Some("hi"),  null,                 e => 17),
      (e => Some("hi"),  Some(null),           e => 17),
      (e => Some("hi"),  Some(new Exception),  null)
    )

  val invalidNoFunCombos =
    Table(
      ("message",   "cause"),
      (null,        Some(new Exception)),
      (Some(null),  Some(new Exception)),
      (Some("hi"),  null),
      (Some("hi"),  Some(null))
    )

  describe("A StackDepthException") {

    it should behave like aStackDepthExceptionWhenGivenNulls(
      (message, cause, failedCodeStackDepth) => new NoFunException(message, cause, Some(source.Position.here), failedCodeStackDepth),
      (messageFun, cause, failedCodeStackDepthFun) => new FunException(messageFun, cause, Some(source.Position.here), failedCodeStackDepthFun)
    )<commit_msg>Clean up StackDepthExceptionSpec before adding tests about failedCodeFilePathname.<commit_after>/*
 * Copyright 2001-2013 Artima, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.scalatest
package exceptions

import org.scalatest.prop.TableDrivenPropertyChecks
import org.scalactic.source

class StackDepthExceptionSpec extends FunSpec with Matchers with TableDrivenPropertyChecks {

  class FunException(
    messageFun: StackDepthException => Option[String],
    cause: Option[Throwable],
    failedCodeStackDepthFun: StackDepthException => Int
  ) extends StackDepthException(messageFun, cause, Right(failedCodeStackDepthFun)) {
    def severedAtStackDepth: FunException = {
      val truncated = getStackTrace.drop(failedCodeStackDepth)
      val e = new FunException(messageFun, cause, e => 0)
      e.setStackTrace(truncated)
      e
    }
  }

  class NoFunException(
    message: Option[String],
    cause: Option[Throwable],
    failedCodeStackDepth: Int
  ) extends StackDepthException(message, cause, failedCodeStackDepth) {
    def severedAtStackDepth: NoFunException = {
      val truncated = getStackTrace.drop(failedCodeStackDepth)
      val e = new NoFunException(message, cause, 0)
      e.setStackTrace(truncated)
      e
    }
  }

  val invalidFunCombos =
    Table[StackDepthException => Option[String], Option[Throwable], StackDepthException => Int](
      ("messageFun",     "cause",              "failedCodeStackDepthFun"),
      (null,             Some(new Exception),  e => 17),
      (e => Some("hi"),  null,                 e => 17),
      (e => Some("hi"),  Some(null),           e => 17),
      (e => Some("hi"),  Some(new Exception),  null)
    )

  val invalidNoFunCombos =
    Table(
      ("message",   "cause"),
      (null,        Some(new Exception)),
      (Some(null),  Some(new Exception)),
      (Some("hi"),  null),
      (Some("hi"),  Some(null))
    )

  describe("A StackDepthException") {

    it should behave like aStackDepthExceptionWhenGivenNulls(
      (message, cause, failedCodeStackDepth) => new NoFunException(message, cause, failedCodeStackDepth),
      (messageFun, cause, failedCodeStackDepthFun) => new FunException(messageFun, cause, failedCodeStackDepthFun)
    )
{'fraction_non_alphanumeric': 0.10195305500806306, 'fraction_numerical': 0.007167174341515857, 'mean_word_length': 3.5641864268192966, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6964897', 'n_tokens_mistral': 1572, 'n_tokens_neox': 1512, 'n_words': 457}