aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorLouis Pilfold <louis@lpil.uk>2020-06-29 20:47:49 +0100
committerLouis Pilfold <louis@lpil.uk>2020-06-30 12:14:27 +0100
commitc8544e558b8b8e2b407ec9650d588401c944d20f (patch)
treeb390bdc5e5807bff7d3f07f22e8ed157584b32f1 /test
parent1ae8354d444013117abdde5987f734b3587592c4 (diff)
downloadgleam_stdlib-c8544e558b8b8e2b407ec9650d588401c944d20f.tar.gz
gleam_stdlib-c8544e558b8b8e2b407ec9650d588401c944d20f.zip
Alter regex API
Diffstat (limited to 'test')
-rw-r--r--test/gleam/regex_test.gleam47
1 files changed, 28 insertions, 19 deletions
diff --git a/test/gleam/regex_test.gleam b/test/gleam/regex_test.gleam
index 8f69fee..3eecccb 100644
--- a/test/gleam/regex_test.gleam
+++ b/test/gleam/regex_test.gleam
@@ -1,48 +1,49 @@
-import gleam/option.{Some, None}
-import gleam/regex.{FromStringError, Match, Options}
+import gleam/io
+import gleam/option.{None, Some}
+import gleam/regex.{CompileError, Match, Options}
import gleam/should
pub fn from_string_test() {
assert Ok(re) = regex.from_string("[0-9]")
- regex.match(re, "abc123")
+ regex.check(re, "abc123")
|> should.equal(True)
- regex.match(re, "abcxyz")
+ regex.check(re, "abcxyz")
|> should.equal(False)
assert Error(from_string_err) = regex.from_string("[0-9")
from_string_err
|> should.equal(
- FromStringError(
+ CompileError(
error: "missing terminating ] for character class",
- index: 4,
+ byte_index: 4,
),
)
}
-pub fn from_string_with_test() {
+pub fn compile_test() {
let options = Options(case_insensitive: True, multi_line: False)
- assert Ok(re) = regex.from_string_with(options, "[A-B]")
+ assert Ok(re) = regex.compile("[A-B]", options)
- regex.match(re, "abc123")
+ regex.check(re, "abc123")
|> should.equal(True)
let options = Options(case_insensitive: False, multi_line: True)
- assert Ok(re) = regex.from_string_with(options, "^[0-9]")
+ assert Ok(re) = regex.compile("^[0-9]", options)
- regex.match(re, "abc\n123")
+ regex.check(re, "abc\n123")
|> should.equal(True)
}
-pub fn match_test() {
+pub fn check_test() {
assert Ok(re) = regex.from_string("^f.o.?")
- regex.match(re, "foo")
+ regex.check(re, "foo")
|> should.equal(True)
- regex.match(re, "boo")
+ regex.check(re, "boo")
|> should.equal(False)
}
@@ -57,21 +58,29 @@ pub fn scan_test() {
assert Ok(re) = regex.from_string("Gl\\w+")
regex.scan(re, "!Gleam")
- |> should.equal([Match(match: "Gleam", index: 1, submatches: [])])
+ |> should.equal([Match(content: "Gleam", byte_index: 1, submatches: [])])
regex.scan(re, "हGleam")
- |> should.equal([Match(match: "Gleam", index: 3, submatches: [])])
+ |> should.equal([Match(content: "Gleam", byte_index: 3, submatches: [])])
regex.scan(re, "𐍈Gleam")
- |> should.equal([Match(match: "Gleam", index: 4, submatches: [])])
+ |> should.equal([Match(content: "Gleam", byte_index: 4, submatches: [])])
assert Ok(re) = regex.from_string("[oi]n a(.?) (\\w+)")
regex.scan(re, "I am on a boat in a lake.")
|> should.equal(
[
- Match(match: "on a boat", index: 5, submatches: [None, Some("boat")]),
- Match(match: "in a lake", index: 15, submatches: [None, Some("lake")]),
+ Match(
+ content: "on a boat",
+ byte_index: 5,
+ submatches: [None, Some("boat")],
+ ),
+ Match(
+ content: "in a lake",
+ byte_index: 15,
+ submatches: [None, Some("lake")],
+ ),
],
)
}