aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorErik Terpstra <erterpstra@gmail.com>2020-06-20 11:00:40 +0200
committerLouis Pilfold <louis@lpil.uk>2020-06-20 13:17:48 +0100
commitea3a318c0d6c133c8c05d9fa20a7adddc500ad75 (patch)
treea59508d7e1a89fea986692cc765ffe3cdef24d4f /test
parent8acab03caea114f5abbe40af59e1f6de207bce91 (diff)
downloadgleam_stdlib-ea3a318c0d6c133c8c05d9fa20a7adddc500ad75.tar.gz
gleam_stdlib-ea3a318c0d6c133c8c05d9fa20a7adddc500ad75.zip
Regex module
Diffstat (limited to 'test')
-rw-r--r--test/gleam/regex_test.gleam46
1 files changed, 46 insertions, 0 deletions
diff --git a/test/gleam/regex_test.gleam b/test/gleam/regex_test.gleam
new file mode 100644
index 0000000..d7ffc2d
--- /dev/null
+++ b/test/gleam/regex_test.gleam
@@ -0,0 +1,46 @@
+import gleam/regex.{FromStringError, Options}
+import gleam/should
+
+pub fn from_string_test() {
+ assert Ok(re) = regex.from_string("[0-9]")
+
+ regex.match(re, "abc123")
+ |> should.equal(True)
+
+ regex.match(re, "abcxyz")
+ |> should.equal(False)
+
+ assert Error(from_string_err) = regex.from_string("[0-9")
+
+ from_string_err
+ |> should.equal(
+ FromStringError(
+ error: "missing terminating ] for character class",
+ index: 4,
+ ),
+ )
+}
+
+pub fn from_string_with_test() {
+ let options = Options(case_insensitive: True, multi_line: False)
+ assert Ok(re) = regex.from_string_with(options, "[A-B]")
+
+ regex.match(re, "abc123")
+ |> should.equal(True)
+
+ let options = Options(case_insensitive: False, multi_line: True)
+ assert Ok(re) = regex.from_string_with(options, "^[0-9]")
+
+ regex.match(re, "abc\n123")
+ |> should.equal(True)
+}
+
+pub fn match_test() {
+ assert Ok(re) = regex.from_string("^f.o.?")
+
+ regex.match(re, "foo")
+ |> should.equal(True)
+
+ regex.match(re, "boo")
+ |> should.equal(False)
+}