Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

weapon-regex

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

weapon-regex - npm Package Compare versions

Comparing version 0.3.0 to 0.4.1

core/target/js-2.13/weapon-regex-opt/main.js

14

package.json
{
"name": "weapon-regex",
"version": "0.3.0",
"version": "0.4.1",
"description": "weapon-regex",
"main": "core/target/js-2.13/weapon-regex-opt.js",
"main": "core/target/js-2.13/weapon-regex-opt/main.js",
"repository": {
"type": "git",
"url": "https://github.com/Nhaajt/Weapon-regeX"
"url": "https://github.com/stryker-mutator/weapon-regex"
},
"keywords": [
"regex",
"regexp",
"regular expression",
"mutate",
"mutation",
"mutator"
],
"license": "Apache-2.0"
}
# Weapon regeX
[![Mutation testing badge](https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2FNhaajt%2FWeapon-regeX%2Fmain)](https://dashboard.stryker-mutator.io/reports/github.com/Nhaajt/Weapon-regeX/main)
[![Build Status](https://github.com/Nhaajt/Weapon-regeX/workflows/Scala%20CI/badge.svg)](https://github.com/Nhaajt/Weapon-regeX/actions?query=workflow%3AScala%20CI+branch%3Amain)
[<img src="https://img.shields.io/badge/GitHub Pages-🌐-blue" alt="GitHub Pages">](https://nhaajt.github.io/Weapon-regeX/)
[![Mutation testing badge](https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fstryker-mutator%2Fweapon-regex%2Fmain)](https://dashboard.stryker-mutator.io/reports/github.com/stryker-mutator/weapon-regex/main)
[![Build Status](https://github.com/stryker-mutator/weapon-regex/workflows/Scala%20CI/badge.svg)](https://github.com/stryker-mutator/weapon-regex/actions?query=workflow%3AScala%20CI+branch%3Amain)
[![GitHub Pages](https://img.shields.io/static/v1?label=GitHub%20Pages&message=Try%20it!&color=blue&logo=github)](https://stryker-mutator.github.io/weapon-regex/)
<img src="images/WeaponRegeX_logo.svg" width="50%" alt="Weapon regeX Logo">
With Weapon regeX you can mutate regular expressions which can be used in mutation testing. The
With Weapon regeX you can mutate regular expressions which can be used in mutation testing. The
generated regular expressions cover edge cases and typos. Weapon regeX is available for both
Javascript and Scala. The Javascript version of the library is generated from Scala using [ScalaJS](https://www.scala-js.org/).
JavaScript and Scala. The JavaScript version of the library is generated from Scala using [Scala.js](https://www.scala-js.org/).
The current supported versions for Scala are: `2.12.12` and `2.13.3`.
The current supported versions for Scala are: `2.12` and `2.13`.

@@ -17,5 +18,7 @@ # Getting started

## Scala
Add Weapon regeX to your ```build.sbt```.
Add Weapon regeX to your `build.sbt`.
```scala
"io.stryker-mutator" %% "weapon-regex" % "0.1.2"
libraryDependencies += "io.stryker-mutator" %% "weapon-regex" % "0.4.1"
```

@@ -27,11 +30,28 @@

import weaponregex.WeaponRegeX
import scala.util.{Success, Failure}
import scala.util.{Try, Success, Failure}
WeaponRegeX.mutate("^abc(d+|[xyz])$") match {
case Success(mutants) => mutants map (_.pattern) map println
case Failure(e) => print(e.getMessage)
case Success(mutants) => mutants map (_.pattern)
case Failure(e) => throw e
}
// res0: Seq[String] = List(
// "abc(d+|[xyz])$",
// "^abc(d+|[xyz])",
// "\\Aabc(d+|[xyz])$",
// "^abc(?:d+|[xyz])$",
// "^abc(d|[xyz])$",
// "^abc(d{0,}|[xyz])$",
// "^abc(d{2,}|[xyz])$",
// "^abc(d{1}|[xyz])$",
// "^abc(d+?|[xyz])$",
// "^abc(d+|[^xyz])$",
// "^abc(d+|[yz])$",
// "^abc(d+|[xz])$",
// "^abc(d+|[xy])$",
// "^abc(d+|[\\w\\W])$",
// "^abc(d+|[xyz])\\z"
// )
```
## Javascript
## JavaScript

@@ -49,44 +69,57 @@ Install Weapon regeX with `npm`.

let mutants = wrx.mutate("^abc(d+|[xyz])$");
let mutants = wrx.mutate('^abc(d+|[xyz])$');
mutants.forEach(mutant => {
mutants.forEach((mutant) => {
console.log(mutant.pattern);
});
```
[Try it!](https://npm.runkit.com/weapon-regex)
[![Try it!](https://img.shields.io/static/v1?label=RunKit&message=Try%20it!&color=F55FA6&logo=runkit)](https://npm.runkit.com/weapon-regex)
# API
## Scala
The ```mutate``` function has the following signature:
The `mutate` function has the following signature:
```scala
//import scala.util.{Try, Success, Failure}
import weaponregex.model.mutation._
import weaponregex.mutator.BuiltinMutators
import weaponregex.parser.{ParserFlavor, ParserFlavorJVM}
def mutate(
pattern: String,
mutators: Seq[TokenMutator] = BuiltinMutators.all,
mutationLevels: Seq[Int] = null
): Try[Seq[Mutant]]
pattern: String,
mutators: Seq[TokenMutator] = BuiltinMutators.all,
mutationLevels: Seq[Int] = null,
flavor: ParserFlavor = ParserFlavorJVM
): Try[Seq[Mutant]] = ???
WeaponRegeX.mutate _
// res1: (String, Seq[TokenMutator], Seq[Int], ParserFlavor) => Try[Seq[Mutant]] = <function4>
```
With the ```mutators``` argument you can give a select list of mutators that should be used in
the mutation process. If omitted, all builtin mutators will be used. This list will be filtered
depending on the ```mutationLevels``` argument.
A list of ```mutationLevels``` can also be passed to the function. The mutators will be filtered
With the `mutators` argument you can give a select list of mutators that should be used in
the mutation process. If omitted, all built-in mutators will be used. This list will be filtered
depending on the `mutationLevels` argument.
A list of `mutationLevels` can also be passed to the function. The mutators will be filtered
based on the levels in the list. If omitted, no filtering takes place.
This function will return a `Success` of of a sequence of `Mutant` if can be parsed, a `Failure` otherwise.
The `flavor` argument allows setting the parser flavor that will be used to parse the pattern.
Currently, we support a `ParserFlavorJVM` and `ParserFlavorJS`. By default in Scala the JVM flavor is used.
## Javascript
This function will return a `Success` with `Seq[Mutant]` if it can be parsed, or a `Failure` otherwise.
The ```mutate``` function can be called with an options object to control which mutators should be
## JavaScript
The `mutate` function can be called with an options object to control which mutators and which parser flavor should be
used in the mutation process:
```Javascript
```js
const wrx = require('weapon-regex');
let mutants = wrx.mutate("^abc(d+|[xyz])$",{
let mutants = wrx.mutate('^abc(d+|[xyz])$', {
mutators: Array.from(wrx.mutators.values()),
mutationLevels: [1, 2, 3]
mutationLevels: [1, 2, 3],
flavor: ParserFlavorJS
});

@@ -96,32 +129,33 @@ ```

Both options can be omitted, and have the same functionality as the options described in the Scala
API section. You can get a map of mutators from the ```mutators``` attribute of the library. It is
API section. By default in JS the JS parser flavor is used. You can get a map of mutators from the `mutators` attribute of the library. It is
a map from string (mutator name) to a mutator object.
This function will return a JavaScript Array of `Mutant` if can be parsed, or throw an exception otherwise.
This function will return a JavaScript Array of `Mutant` if it can be parsed, or throw an exception otherwise.
# Supported mutators
All the supported mutators and at which mutation level they appear are shown in the table below.
Name | 1 | 2 | 3
--- | --- | --- | ---
[BOLRemoval](#BOLRemoval) | ✅ | ✅ | ✅
[EOLRemoval](#EOLRemoval) | ✅ | ✅ | ✅
[BOL2BOI](#BOL2BOI) | | ✅ | ✅
[EOL2EOI](#EOL2EOI) | | ✅ | ✅
[CharClassNegation](#CharClassNegation) | ✅
[CharClassChildRemoval](#CharClassChildRemoval) | | ✅ | ✅
[CharClassAnyChar](#CharClassAnyChar) | | ✅ | ✅
[CharClassRangeModification](#CharClassRangeModification) | | | ✅
[PredefCharClassNegation](#PredefCharClassNegation) | ✅
[PredefCharClassNullification](#PredefCharClassNullification) | | ✅ | ✅
[PredefCharClassAnyChar](#PredefCharClassAnyChar) | | ✅ | ✅
[QuantifierRemoval](#QuantifierRemoval) | ✅
[QuantifierNChange](#QuantifierNChange) | | ✅ | ✅
[QuantifierNOrMoreModification](#QuantifierNOrMoreModification) | | ✅ | ✅
[QuantifierNOrMoreChange](#QuantifierNOrMoreChange) | | ✅ | ✅
[QuantifierNMModification](#QuantifierNMModification) | | ✅ | ✅
[QuantifierShortModification](#QuantifierShortModification) | | ✅ | ✅
[QuantifierShortChange](#QuantifierShortChange) | | ✅ | ✅
[QuantifierReluctantAddition](#QuantifierReluctantAddition) | | | ✅
[GroupToNCGroup](#GroupToNCGroup) | | ✅ | ✅
| Name | 1 | 2 | 3 |
| --------------------------------------------------------------- | --- | --- | --- |
| [BOLRemoval](#bolremoval) | ✅ | ✅ | ✅ |
| [EOLRemoval](#eolremoval) | ✅ | ✅ | ✅ |
| [BOL2BOI](#bol2boi) | | ✅ | ✅ |
| [EOL2EOI](#eol2eoi) | | ✅ | ✅ |
| [CharClassNegation](#charclassnegation) | ✅ |
| [CharClassChildRemoval](#charclasschildremoval) | | ✅ | ✅ |
| [CharClassAnyChar](#charclassanychar) | | ✅ | ✅ |
| [CharClassRangeModification](#charclassrangemodification) | | | ✅ |
| [PredefCharClassNegation](#predefcharclassnegation) | ✅ |
| [PredefCharClassNullification](#predefcharclassnullification) | | ✅ | ✅ |
| [PredefCharClassAnyChar](#predefcharclassanychar) | | ✅ | ✅ |
| [QuantifierRemoval](#quantifierremoval) | ✅ |
| [QuantifierNChange](#quantifiernchange) | | ✅ | ✅ |
| [QuantifierNOrMoreModification](#quantifiernormoremodification) | | ✅ | ✅ |
| [QuantifierNOrMoreChange](#quantifiernormorechange) | | ✅ | ✅ |
| [QuantifierNMModification](#quantifiernmmodification) | | ✅ | ✅ |
| [QuantifierShortModification](#quantifiershortmodification) | | ✅ | ✅ |
| [QuantifierShortChange](#quantifiershortchange) | | ✅ | ✅ |
| [QuantifierReluctantAddition](#quantifierreluctantaddition) | | | ✅ |
| [GroupToNCGroup](#grouptoncgroup) | | ✅ | ✅ |

@@ -132,39 +166,39 @@ ## Boundary Mutators

It removes the beginning of line character "```^```"
Remove the beginning of line character `^`.
Original | Mutated
--- | ---
```^abc```|```abc```
| Original | Mutated |
| -------- | ------- |
| `^abc` | `abc` |
[Back to table 🔝](#Supported-mutators)
[Back to table 🔝](#supported-mutators)
### EOLRemoval
It removes the end of line character "```$```"
Remove the end of line character `$`.
Original | Mutated
--- | ---
```abc$```|```abc```
| Original | Mutated |
| -------- | ------- |
| `abc$` | `abc` |
[Back to table 🔝](#Supported-mutators)
[Back to table 🔝](#supported-mutators)
### BOL2BOI
It changes the beginning of line character "```^```" to a beginning of input character "```\A```"
Change the beginning of line character `^` to a beginning of input character `\A`.
Original | Mutated
--- | ---
```^abc```|```\Aabc```
| Original | Mutated |
| -------- | ------- |
| `^abc` | `\Aabc` |
[Back to table 🔝](#Supported-mutators)
[Back to table 🔝](#supported-mutators)
### EOL2EOI
It changes the end of line character "```^```" to a end of input character "```\z```"
Change the end of line character `^` to a end of input character `\z`.
Original | Mutated
--- | ---
```abc$```|```abc\z```
| Original | Mutated |
| -------- | ------- |
| `abc$` | `abc\z` |
[Back to table 🔝](#Supported-mutators)
[Back to table 🔝](#supported-mutators)

@@ -175,45 +209,45 @@ ## Character class mutators

It flips the sign of a character class.
Flips the sign of a character class.
Original | Mutated
--- | ---
```[abc]```|```[^abc]```
```[^abc]```|```[abc]```
| Original | Mutated |
| -------- | -------- |
| `[abc]` | `[^abc]` |
| `[^abc]` | `[abc]` |
[Back to table 🔝](#Supported-mutators)
[Back to table 🔝](#supported-mutators)
### CharClassChildRemoval
It removes a child of a character class.
Remove a child of a character class.
Original | Mutated
--- | ---
```[abc]```|```[bc]```
```[abc]```|```[ac]```
```[abc]```|```[ab]```
| Original | Mutated |
| -------- | ------- |
| `[abc]` | `[bc]` |
| `[abc]` | `[ac]` |
| `[abc]` | `[ab]` |
[Back to table 🔝](#Supported-mutators)
[Back to table 🔝](#supported-mutators)
### CharClassAnyChar
It changes a character class to a character class which matches any character.
Change a character class to a character class which matches any character.
Original | Mutated
--- | ---
```[abc]```|```[\w\W]```
| Original | Mutated |
| -------- | -------- |
| `[abc]` | `[\w\W]` |
[Back to table 🔝](#Supported-mutators)
[Back to table 🔝](#supported-mutators)
### CharClassRangeModification
It changes the high and low of a range by one in both directions if possible.
Change the high and low of a range by one in both directions if possible.
Original | Mutated
--- | ---
```[b-y]```|```[a-y]```
```[b-y]```|```[c-y]```
```[b-y]```|```[b-z]```
```[b-y]```|```[b-x]```
| Original | Mutated |
| -------- | ------- |
| `[b-y]` | `[a-y]` |
| `[b-y]` | `[c-y]` |
| `[b-y]` | `[b-z]` |
| `[b-y]` | `[b-x]` |
[Back to table 🔝](#Supported-mutators)
[Back to table 🔝](#supported-mutators)

@@ -224,45 +258,45 @@ ## Predefined character class mutators

It flips the sign of a predefined character class. All the predefined character classes are shown in the table below.
Flips the sign of a predefined character class. All the predefined character classes are shown in the table below.
Original | Mutated
--- | ---
```\d```|```\D```
```\D```|```\d```
```\s```|```\S```
```\S```|```\s```
```\w```|```\W```
```\W```|```\w```
| Original | Mutated |
| -------- | ------- |
| `\d` | `\D` |
| `\D` | `\d` |
| `\s` | `\S` |
| `\S` | `\s` |
| `\w` | `\W` |
| `\W` | `\w` |
[Back to table 🔝](#Supported-mutators)
[Back to table 🔝](#supported-mutators)
### PredefCharClassNullification
It removes the backslash from a predefined character class such as "```\w```".
Remove the backslash from a predefined character class such as `\w`.
Original | Mutated
--- | ---
```\d```|```d```
```\D```|```D```
```\s```|```s```
```\S```|```S```
```\w```|```w```
```\W```|```W```
| Original | Mutated |
| -------- | ------- |
| `\d` | `d` |
| `\D` | `D` |
| `\s` | `s` |
| `\S` | `S` |
| `\w` | `w` |
| `\W` | `W` |
[Back to table 🔝](#Supported-mutators)
[Back to table 🔝](#supported-mutators)
### PredefCharClassAnyChar
It changes a predefined character class to a character class containing the predefined one and its
Change a predefined character class to a character class containing the predefined one and its
negation.
Original | Mutated
--- | ---
```\d```|```[\d\D]```
```\D```|```[\D\d]```
```\s```|```[\s\S]```
```\S```|```[\S\s]```
```\w```|```[\w\W]```
```\W```|```[\W\w]```
| Original | Mutated |
| -------- | -------- |
| `\d` | `[\d\D]` |
| `\D` | `[\D\d]` |
| `\s` | `[\s\S]` |
| `\S` | `[\S\s]` |
| `\w` | `[\w\W]` |
| `\W` | `[\W\w]` |
[Back to table 🔝](#Supported-mutators)
[Back to table 🔝](#supported-mutators)

@@ -273,111 +307,111 @@ ## Quantifier mutators

It removes a quantifier. This is done for all possible quantifiers, even ranges, and the reluctant
Remove a quantifier. This is done for all possible quantifiers, even ranges, and the reluctant
and possessive variants.
Original | Mutated
--- | ---
```abc?```|```abc```
```abc*```|```abc```
```abc+```|```abc```
```abc{1,3}```|```abc```
```abc??```|```abc```
```abc*?```|```abc```
```abc+?```|```abc```
```abc{1,3}?```|```abc```
```abc?+```|```abc```
```abc*+```|```abc```
```abc++```|```abc```
```abc{1,3}+```|```abc```
| Original | Mutated |
| ----------- | ------- |
| `abc?` | `abc` |
| `abc*` | `abc` |
| `abc+` | `abc` |
| `abc{1,3}` | `abc` |
| `abc??` | `abc` |
| `abc*?` | `abc` |
| `abc+?` | `abc` |
| `abc{1,3}?` | `abc` |
| `abc?+` | `abc` |
| `abc*+` | `abc` |
| `abc++` | `abc` |
| `abc{1,3}+` | `abc` |
[Back to table 🔝](#Supported-mutators)
[Back to table 🔝](#supported-mutators)
### QuantifierNChange
It changes the fixed amount quantifier to a couple range variants.
Change the fixed amount quantifier to a couple of range variants.
Original | Mutated
--- | ---
```abc{9}```|```abc{0,9}```
```abc{9}```|```abc{9,}```
| Original | Mutated |
| -------- | ---------- |
| `abc{9}` | `abc{0,9}` |
| `abc{9}` | `abc{9,}` |
[Back to table 🔝](#Supported-mutators)
[Back to table 🔝](#supported-mutators)
### QuantifierNOrMoreModification
It changes the n to infinity range quantifier to a couple variants where the low of the range is
incremented an decremented by one.
Change the `n` to infinity range quantifier to a couple of variants where the low of the range is
incremented and decremented by one.
Original | Mutated
--- | ---
```abc{9,}```|```abc{8,}```
```abc{9,}```|```abc{10,}```
| Original | Mutated |
| --------- | ---------- |
| `abc{9,}` | `abc{8,}` |
| `abc{9,}` | `abc{10,}` |
[Back to table 🔝](#Supported-mutators)
[Back to table 🔝](#supported-mutators)
### QuantifierNOrMoreChange
It turns an N or more range quantifier into a fixed number quantifier.
Turn an `n` or more range quantifier into a fixed number quantifier.
Original | Mutated
--- | ---
```abc{9,}```|```abc{9}```
| Original | Mutated |
| --------- | -------- |
| `abc{9,}` | `abc{9}` |
[Back to table 🔝](#Supported-mutators)
[Back to table 🔝](#supported-mutators)
### QuantifierNMModification
It alters the N to M range quantifier by decrementing or incrementing the high and low of the
Alter the `n` to `m` range quantifier by decrementing or incrementing the high and low of the
range by one.
Original | Mutated
--- | ---
```abc{3,9}```|```abc{2,9}```
```abc{3,9}```|```abc{4,9}```
```abc{3,9}```|```abc{3,8}```
```abc{3,9}```|```abc{3,10}```
| Original | Mutated |
| ---------- | ----------- |
| `abc{3,9}` | `abc{2,9}` |
| `abc{3,9}` | `abc{4,9}` |
| `abc{3,9}` | `abc{3,8}` |
| `abc{3,9}` | `abc{3,10}` |
[Back to table 🔝](#Supported-mutators)
[Back to table 🔝](#supported-mutators)
### QuantifierShortModification
It treats the shorthand quantifiers (`?`, `*`, `+`) as their corresponding range quantifier
Treat the shorthand quantifiers (`?`, `*`, `+`) as their corresponding range quantifier
variant (`{0,1}`, `{0,}`, `{1,}`), and applies the same mutations as mentioned in the mutators
above.
Original | Mutated
--- | ---
```abc?```|```abc{1,1}```
```abc?```|```abc{0,0}```
```abc?```|```abc{0,2}```
```abc*```|```abc{1,}```
```abc+```|```abc{0,}```
```abc+```|```abc{2,}```
| Original | Mutated |
| -------- | ---------- |
| `abc?` | `abc{1,1}` |
| `abc?` | `abc{0,0}` |
| `abc?` | `abc{0,2}` |
| `abc*` | `abc{1,}` |
| `abc+` | `abc{0,}` |
| `abc+` | `abc{2,}` |
[Back to table 🔝](#Supported-mutators)
[Back to table 🔝](#supported-mutators)
### QuantifierShortChange
It changes the shorthand quantifiers `*` and `+` to their fixed range quantifier variant.
Change the shorthand quantifiers `*` and `+` to their fixed range quantifier variant.
Original | Mutated
--- | ---
```abc*```|```abc{0}```
```abc+```|```abc{1}```
| Original | Mutated |
| -------- | -------- |
| `abc*` | `abc{0}` |
| `abc+` | `abc{1}` |
[Back to table 🔝](#Supported-mutators)
[Back to table 🔝](#supported-mutators)
### QuantifierReluctantAddition
It changes greedy quantifiers to reluctant quantifiers.
Change greedy quantifiers to reluctant quantifiers.
Original | Mutated
--- | ---
```abc?```|```abc??```
```abc*```|```abc*?```
```abc+```|```abc+?```
```abc{9}```|```abc{9}?```
```abc{9,}```|```abc{9,}?```
```abc{9,13}```|```abc{9,13}?```
| Original | Mutated |
| ----------- | ------------ |
| `abc?` | `abc??` |
| `abc*` | `abc*?` |
| `abc+` | `abc+?` |
| `abc{9}` | `abc{9}?` |
| `abc{9,}` | `abc{9,}?` |
| `abc{9,13}` | `abc{9,13}?` |
[Back to table 🔝](#Supported-mutators)
[Back to table 🔝](#supported-mutators)

@@ -388,8 +422,10 @@ ## Group mutators

It changes a normal group to a non-capturing group.
Change a normal group to a non-capturing group.
Original | Mutated
--- | ---
```(abc)```|```(?:abc)```
| Original | Mutated |
| -------- | --------- |
| `(abc)` | `(?:abc)` |
[Back to table 🔝](#Supported-mutators)
[Back to table 🔝](#supported-mutators)
_Copyright 2021 Stryker mutator team_
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc