<commit_before>package net.orfjackal.specsy

import org.junit.Test
import org.junit.Assert._
import org.hamcrest.CoreMatchers._
import collection.mutable.{Buffer}
import net.orfjackal.specsy.internal._

class ExecutionModelTest {
  val runner = new SpecRunner
  val spy = Buffer[String]()

  @Test
  def there_is_one_root_spec() {
    runner.run(c => {
      c.run("root", {
        spy.append("root")
      })
    })

    assertThat(spy, is(Buffer("root")))
  }

  @Test
  def the_root_spec_can_contain_multiple_nested_child_specs() {
    runner.run(c => {
      c.run("root", {
        spy.append("root")

        c.specify("child A", {
          spy.append("A")

          c.specify("child AA", {
            spy.append("AA")
          })
        })
      })
    })

    assertThat(spy, is(Buffer("root", "A", "AA")))
  }

  @Test
  def the_specs_are_executed_one_branch_at_a_time_until_all_are_executed() {
    runner.run(c => {
      c.run("root", {
        spy.append("root")

        c.specify("child A", {
          spy.append("A")
        })
        c.specify("child B", {
          spy.append("B")
        })
      })
    })

    assertThat(spy, is(Buffer("root", "A", "root", "B")))
  }

  @Test
  def variables_declared_inside_specs_are_isolated_from_the_side_effects_of_sibling_specs() {
    runner.run(c => {
      c.run("root", {
        var i = 0

        c.specify("child A", {
          i += 1
          spy.append("A" + i)
        })
        c.specify("child B", {
          i += 1
          spy.append("B" + i)
        })
      })
    })

    assertThat(spy, is(Buffer("A1", "B1")))
  }
}<commit_msg>Clarification to the execution model<commit_after>package net.orfjackal.specsy

import org.junit.Test
import org.junit.Assert._
import org.hamcrest.CoreMatchers._
import collection.mutable.{Buffer}
import net.orfjackal.specsy.internal._

class ExecutionModelTest {
  val runner = new SpecRunner
  val spy = Buffer[String]()

  @Test
  def there_is_one_root_spec() {
    runner.run(c => {
      c.run("root", {
        spy.append("root")
      })
    })

    assertThat(spy, is(Buffer("root")))
  }

  @Test
  def the_root_spec_can_contain_multiple_nested_child_specs() {
    runner.run(c => {
      c.run("root", {
        spy.append("root")

        c.specify("child A", {
          spy.append("A")

          c.specify("child AA", {
            spy.append("AA")
          })
        })
      })
    })

    assertThat(spy, is(Buffer("root", "A", "AA")))
  }

  @Test
  def the_specs_are_executed_one_branch_at_a_time_until_all_are_executed() {
    runner.run(c => {
      c.run("root", {
        spy.append("root")

        c.specify("child A", {
          spy.append("A")
        })
        c.specify("child B", {
          spy.append("B")
        })
      })
    })

    assertThat(spy, is(Buffer("root", "A", "root", "B")))
  }

  @Test
  def variables_declared_inside_specs_are_isolated_from_the_side_effects_of_sibling_specs() {
    runner.run(c => {
      c.run("root", {
        var i = 0

        c.specify("child A", {
          i += 1
          spy.append("A" + i)
        })
        c.specify("child B", {
          i += 1
          spy.append("B" + i)
        })
      })
    })

    assertThat(spy, is(Buffer("A1", "B1")))
  }

  @Test
  def child_specs_are_executed_immediately_where_they_are_declared() {
    runner.run(c => {
      c.run("root", {
        var i = 0

        c.specify("child A", {
          spy.append("A" + i)
        })
        i += 1

        c.specify("child B", {
          spy.append("B" + i)
        })
      })
    })

    assertThat(spy, is(Buffer("A0", "B1")))
  }
}
{'fraction_non_alphanumeric': 0.16221426604241257, 'fraction_numerical': 0.003855687138529331, 'mean_word_length': 2.034252297410192, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, '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': '5710887', 'n_tokens_mistral': 1345, 'n_tokens_neox': 1333, 'n_words': 195}