All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.specs2.specification.FragmentsFragment.scala Maven / Gradle / Ivy

There is a newer version: 3.7
Show newest version
package org.specs2
package specification

import main.Arguments

/**
 * Fragments can be chained with the ^ method
 */
class FragmentsFragment(fs: =>Fragments) {
  lazy val fragments = fs

  def ^(t: String) = fragments add Text(t)
  def ^(f: Fragment) = f match {
    case s: SpecStart => (fragments specTitleIs s.specName).overrideArgs(s.arguments)
    case _            => fragments add f
  }
  def ^(other: Seq[Fragment]) = fragments add other
  def ^(other: Seq[Fragments], dummy: Int = 0) = fragments add other.flatMap(_.fragments)

  def ^(other: Fragments) = {
    other match {
      case Fragments(t, m, a, Linked(Some(l), so, h))    => fragments add other.fragments
      case Fragments(Some(t), m, a, Linked(None, so, h)) => (fragments add other.middle).specTitleIs(t).overrideArgs(a)
      case Fragments(None, m, a, Linked(None, so, h))    => (fragments add other.middle).overrideArgs(a)
      case _                                             =>  fragments add other.middle
    }
  }

  def ^(other: FragmentsFragment) = fragments add other.fragments
  def ^(a: Arguments)             = fragments add a

}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy