Commit 47e88b01 authored by Diegodlh's avatar Diegodlh
Browse files

add match transformation tests

parent f6bb582e
......@@ -3,6 +3,7 @@ import {
JoinTransformation,
RangeTransformation,
SplitTransformation,
MatchTransformation,
TransformationConfigTypeError,
} from "./transformation";
......@@ -219,3 +220,70 @@ describe("Range transformation", () => {
);
});
});
describe("Match transformation", () => {
it("extracts single occurrence of target substring", async () => {
const transformation = new MatchTransformation();
transformation.config = "matching";
const input = ["a substring inside a string"];
expect(await transformation.transform(input)).toEqual(["substring"]);
});
it("extracts multiple occurrences of target substring", async () => {
const transformation = new MatchTransformation();
transformation.config = "substring";
const input = ["a substring and another substring inside a string"];
expect(await transformation.transform(input)).toEqual([
"substring",
"substring",
]);
});
it("returns empty array for non-matching substring", async () => {
const transformation = new MatchTransformation();
transformation.config = "substring";
const input = ["a string without target"];
expect(await transformation.transform(input)).toEqual([]);
});
it("extracts single occurrence of target itemwise", async () => {
const transformation = new MatchTransformation();
transformation.config = "matching";
const input = ["a matching string", "another matching string"];
expect(await transformation.transform(input)).toEqual([
"matching",
"matching",
]);
});
it("ignores input items without target substring", async () => {
const transformation = new MatchTransformation();
transformation.config = "substring";
const input = [
"a string with substring",
"a string without",
"another with substring",
];
expect(await transformation.transform(input)).toEqual([
"substring",
"substring",
]);
});
it("combines input before matching if itemwise off", async () => {
const transformation = new MatchTransformation(false);
transformation.config = "sub,string";
const input = ["a sub", "string in combined string"];
expect(await transformation.transform(input)).toEqual(["sub,string"]);
});
it("uses regular expressions", async () => {
const transformation = new MatchTransformation(false);
transformation.config = "(sub)?string";
const input = ["a substring inside a string"];
expect(await transformation.transform(input)).toEqual([
"substring",
"string",
]);
});
});
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment