-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f6f2563
commit b3339a1
Showing
4 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
// Copyright 2021-present the Core-fn authors. All rights reserved. MIT license. | ||
export { assertEquals } from "https://deno.land/std@0.97.0/testing/asserts.ts"; | ||
export { equal } from "https://deno.land/x/equal@v1.5.0/mod.ts"; | ||
|
||
export const assertEqualsType = <T, U extends T = T>(_actual?: U): void => {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright 2021-present the Core-fn authors. All rights reserved. MIT license. | ||
import { curry } from "../deps.ts"; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
const _match = ( | ||
matcher: string | RegExp, | ||
val: string, | ||
): RegExpMatchArray | null => val.match(matcher); | ||
|
||
/** | ||
* Matches a string with a regular expression, and returns an array containing the results of that search. | ||
* @param matcher - `RegExp` a variable name or string literal containing the regular expression pattern and flags | ||
* @param val - Any `String` | ||
* @returns The result of `val.match(matcher)` | ||
* | ||
* @example | ||
* ```ts | ||
* match(/xyz/, 'vwxyz') // ['xyz'] | ||
* ``` | ||
* | ||
* @beta | ||
*/ | ||
const match = curry(_match); | ||
|
||
export { _match, match }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright 2021-present the Core-fn authors. All rights reserved. MIT license. | ||
import { assertEquals, equal } from "../dev_deps.ts"; | ||
import { _match } from "./match.ts"; | ||
|
||
Deno.test("match", () => { | ||
const table: [string | RegExp, string, RegExpMatchArray | null][] = [ | ||
["", "", [""]], | ||
["c", "abc", ["c"]], | ||
["aaaa", "aa", null], | ||
["abc", "abcdabc", ["abc"]], | ||
[/a/, "bcd", null], | ||
[/a/, "abc", ["a"]], | ||
[/a(.*)/, "abc", ["abc", "bc"]], | ||
[/a(?<name>.*)/, "abc", ["abc", "bc"]], | ||
[/a/g, "abc", ["a"]], | ||
[/a/g, "abaca", ["a", "a", "a"]], | ||
]; | ||
table.forEach(([matcher, val, expected]) => { | ||
assertEquals( | ||
equal( | ||
_match(matcher, val), | ||
expected, | ||
), | ||
true, | ||
`match(${matcher}, ${val}) -> ${expected}`, | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters