scalacheck-gen-regexp


License

License

MIT
Categories

Categories

Scala Languages
GroupId

GroupId

io.github.wolfendale
ArtifactId

ArtifactId

scalacheck-gen-regexp_2.12
Last Version

Last Version

0.1.3
Release Date

Release Date

Type

Type

jar
Description

Description

scalacheck-gen-regexp
scalacheck-gen-regexp
Project URL

Project URL

https://github.com/wolfendale/scalacheck-gen-regexp
Project Organization

Project Organization

io.github.wolfendale
Source Code Management

Source Code Management

https://github.com/wolfendale/scalacheck-gen-regexp

Download scalacheck-gen-regexp_2.12

How to add to project

<!-- https://jarcasting.com/artifacts/io.github.wolfendale/scalacheck-gen-regexp_2.12/ -->
<dependency>
    <groupId>io.github.wolfendale</groupId>
    <artifactId>scalacheck-gen-regexp_2.12</artifactId>
    <version>0.1.3</version>
</dependency>
// https://jarcasting.com/artifacts/io.github.wolfendale/scalacheck-gen-regexp_2.12/
implementation 'io.github.wolfendale:scalacheck-gen-regexp_2.12:0.1.3'
// https://jarcasting.com/artifacts/io.github.wolfendale/scalacheck-gen-regexp_2.12/
implementation ("io.github.wolfendale:scalacheck-gen-regexp_2.12:0.1.3")
'io.github.wolfendale:scalacheck-gen-regexp_2.12:jar:0.1.3'
<dependency org="io.github.wolfendale" name="scalacheck-gen-regexp_2.12" rev="0.1.3">
  <artifact name="scalacheck-gen-regexp_2.12" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.github.wolfendale', module='scalacheck-gen-regexp_2.12', version='0.1.3')
)
libraryDependencies += "io.github.wolfendale" % "scalacheck-gen-regexp_2.12" % "0.1.3"
[io.github.wolfendale/scalacheck-gen-regexp_2.12 "0.1.3"]

Dependencies

compile (2)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.12.10
org.scala-lang.modules : scala-parser-combinators_2.12 jar 1.1.2

provided (1)

Group / Artifact Type Version
org.scalacheck : scalacheck_2.12 jar 1.14.2

test (2)

Group / Artifact Type Version
org.scalactic : scalactic_2.12 jar 3.0.8
org.scalatest : scalatest_2.12 jar 3.0.8

Project Modules

There are no modules declared in this project.

scalacheck-gen-regexp

A library for creating scalacheck generators from regular expressions

Cross-built for Scala 2.11/2.12/2.13

Installation

In your build.sbt

libraryDependencies += "io.github.wolfendale" %% "scalacheck-gen-regexp" % "[VERSION]"
Quick start
import wolfendale.scalacheck.regexp.RegexpGen

val generator: Gen[String] = RegexpGen.from("[1-9]\\d?(,\\d{3})+")
Supported syntax
Feature Example Notes
Literals a, \\w, 7 Literals are transformed into constant generators
Character Classes [abc], [^abc], [a-zA-Z0-9] Character classes are transformed with Gen.oneOf
Default Classes \w, \d, \S, . These are treated as predefined character classes
Quantifiers a?, b+, c*, d{3}, e{4,5}, f{5,} These use Gen.listOfN to create sized lists of the preceding term
Groups (abc), (?:def) Backreferences are not supported, groups can only be used for grouping terms
Alternates a|b|c, a(b|c)d Alternates are also transformed with Gen.oneOf
Boundaries ^, $, \b Although these will be parsed they do not modify the generator output
Unsupported syntax
Feature Example Notes
Backreferences ([ab]\1) With the current implementation there's no simple way to do this, definitely in consideration for a future release
Octal / Hex / Special Literals \012, \xF1, \p{Lower} Most of these should be simple to implement but I wanted to get an initial release created first
Character Class Intersection [a&&[b]], [a[b]] Difficult to implement currently but not impossible, definite consideration for a future release
Tips for usage
  • In order to represent any character, RegexpGen#from takes an implicit Arbitrary[Char]. There is a default instance provided by scalacheck however for most uses you probably want to provide your own.

  • If you use the + or * quantifiers you'll end up getting huge variance in string sizes. If this isn't what you want, consider bounding the lengths of certain string segments with the {min,max} quantifier.

  • Negated character classes / default classes are implemented by generating an arbitrary Char within certain bounds via suchThat, because of this you can end up throwing away a lot of cases and in certain circumstances your tests may fail. Try to refactor out negative cases.

  • In character classes each option is given equal weighting. If you'd prefer to weight a particular entry you can add it multiple times, this is made easier with string interpolation: s"[${"a-z"*5}\s]". In the example case the generator is 5 times more likely to generate an alpha character than a space.

Versions

Version
0.1.3