scala-expect


License

License

MIT
Categories

Categories

Scala Languages
GroupId

GroupId

work.martins.simon
ArtifactId

ArtifactId

scala-expect_2.11
Last Version

Last Version

4.1.0
Release Date

Release Date

Type

Type

jar
Description

Description

scala-expect
scala-expect
Project URL

Project URL

https://github.com/Lasering/scala-expect
Project Organization

Project Organization

work.martins.simon
Source Code Management

Source Code Management

https://github.com/Lasering/scala-expect

Download scala-expect_2.11

How to add to project

<!-- https://jarcasting.com/artifacts/work.martins.simon/scala-expect_2.11/ -->
<dependency>
    <groupId>work.martins.simon</groupId>
    <artifactId>scala-expect_2.11</artifactId>
    <version>4.1.0</version>
</dependency>
// https://jarcasting.com/artifacts/work.martins.simon/scala-expect_2.11/
implementation 'work.martins.simon:scala-expect_2.11:4.1.0'
// https://jarcasting.com/artifacts/work.martins.simon/scala-expect_2.11/
implementation ("work.martins.simon:scala-expect_2.11:4.1.0")
'work.martins.simon:scala-expect_2.11:jar:4.1.0'
<dependency org="work.martins.simon" name="scala-expect_2.11" rev="4.1.0">
  <artifact name="scala-expect_2.11" type="jar" />
</dependency>
@Grapes(
@Grab(group='work.martins.simon', module='scala-expect_2.11', version='4.1.0')
)
libraryDependencies += "work.martins.simon" % "scala-expect_2.11" % "4.1.0"
[work.martins.simon/scala-expect_2.11 "4.1.0"]

Dependencies

compile (4)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.11.8
com.typesafe.scala-logging : scala-logging_2.11 jar 3.4.0
ch.qos.logback : logback-classic jar 1.1.7
com.typesafe : config jar 1.3.0

provided (2)

Group / Artifact Type Version
org.scoverage : scalac-scoverage-runtime_2.11 jar 1.1.1
org.scoverage : scalac-scoverage-plugin_2.11 jar 1.1.1

test (2)

Group / Artifact Type Version
org.scalatest : scalatest_2.11 jar 2.2.6
org.scalacheck : scalacheck_2.11 jar 1.12.5

Project Modules

There are no modules declared in this project.

Scala Expect license

Scaladoc Maven Central

Build Status Codacy Badge Codacy Badge BCH compliance

A Scala implementation of a very small subset of the widely known TCL expect.

Scala Expect comes with three different flavors: core, fluent and dsl.

Install

libraryDependencies += "work.martins.simon" %% "scala-expect" % "6.0.0"

Core

Documentation

Advantages

  • Closer to metal / basis for the other flavors.
  • Immutable and therefore thread-safe.
  • Most errors will be caught at compile time (eg. you won't be able to use a SendWithRegex inside a StringWhen).

Disadvantages

  • Verbose syntax.
  • Can't cleanly add expect blocks/whens/actions based on a condition.

Example

import work.martins.simon.core._
import scala.concurrent.ExecutionContext.Implicits.global

val e = new Expect("bc -i", defaultValue = 5)(
  ExpectBlock(
    StringWhen("For details type `warranty'.")(
      Sendln("1 + 2")
    )
  ),
  ExpectBlock(
    RegexWhen("""\n(\d+)\n""".r)(
      SendlnWithRegex { m =>
        val previousAnswer = m.group(1)
        println(s"Got $previousAnswer")
        s"$previousAnswer + 3"
      }
    )
  ),
  ExpectBlock(
    RegexWhen("""\n(\d+)\n""".r)(
      ReturningWithRegex(_.group(1).toInt)
    )
  )
)
e.run() //Returns 6 inside a Future[Int]

Fluent

Documentation

Advantages

  • Less verbose syntax:
    • StringWhen, RegexWhen, etc is just when.
    • Returning, ReturningWithRegex, etc is just returning.
    • Less commas and parenthesis.
  • Most errors will be caught at compile time.
  • Easy to add expect blocks/whens/actions based on a condition.
  • Easy to refactor the creation of expects.
  • Can be called from Java easily.

Disadvantages

  • Some overhead since the fluent expect is just a builder for a core expect.
  • Mutable - the fluent expect has to maintain a state of the objects that have been built.
  • IDE's will easily mess the custom indentation.

Example

import work.martins.simon.fluent._
import scala.concurrent.ExecutionContext.Implicits.global

val e = new Expect("bc -i", defaultValue = 5) {
  expect
    .when("For details type `warranty'.")
      .sendln("1 + 2")
  expect
    .when("""\n(\d+)\n""".r)
      .sendln { m =>
        val previousAnswer = m.group(1)
        println(s"Got $previousAnswer")
        s"$previousAnswer + 3"
      }
  //This is a shortcut. It works just like the previous expect block.
  expect("""\n(\d+)\n""".r)
    .returning(_.group(1).toInt)
}
e.run() //Returns 6 inside a Future[Int]

DSL

Documentation

Advantages

  • Code will be indented in blocks so IDE's won't mess the indentation.
  • Syntax more close to the TCL expect.
  • Easy to add expect blocks/whens/actions based on a condition.
  • Easy to refactor the creation of expects.

Disadvantages

  • Most errors will only be caught at runtime as opposed to compile time.
  • More overhead than the fluent expect since it's just a wrapper arround fluent expect.
  • Mutable - it uses a fluent expect as the backing expect and a mutable stack to keep track of the current context.

Example

import work.martins.simon.dsl._
import scala.concurrent.ExecutionContext.Implicits.global

val e = new Expect("bc -i", defaultValue = 5) {
  expect {
    when("For details type `warranty'.") {
      sendln("1 + 2")
    }
  }
  expect {
    when("""\n(\d+)\n""".r) {
      sendln { m =>
        val previousAnswer = m.group(1)
        println(s"Got $previousAnswer")
        s"$previousAnswer + 3"
      }
    }
  }
  //This is a shortcut. It works just like the previous expect block.
  expect("""\n(\d+)\n""".r) {
    returning(_.group(1).toInt)
  }
}
e.run() //Returns 6 inside a Future[Int]

License

Scala Expect is open source and available under the MIT license.

Versions

Version
4.1.0
4.0.0
3.1.0
3.0.0
2.2.0
2.1.0
2.0.1
2.0.0
1.11.1
1.11.0
1.10.2
1.10.1
1.10.0
1.9.0
1.8.0
1.7.6
1.7.5
1.7.3
1.7.2