aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-11-09 16:27:54 -0500
committerBruce Hill <bruce@bruce-hill.com>2024-11-09 16:27:54 -0500
commit898bee15817573b5ab865a1dae7e52da310affa8 (patch)
treeb8531a828190997a63a1e1ef32f4aa568304e61c /test
parent7a4f2e73addf6dfcde2a6b17b62b961608e556a0 (diff)
Introduce a `Match` struct to represent pattern matching results, which
improves the usability of a lot of the APIs. Also bugfix some issues with ranges.
Diffstat (limited to 'test')
-rw-r--r--test/ranges.tm9
-rw-r--r--test/text.tm22
2 files changed, 20 insertions, 11 deletions
diff --git a/test/ranges.tm b/test/ranges.tm
index c611957f..0ff67c1a 100644
--- a/test/ranges.tm
+++ b/test/ranges.tm
@@ -1,5 +1,14 @@
func main():
+ >> r := 5:to(10):by(2)
+ = Range(first=5, last=10, step=2)
+ >> r.first
+ = 5
+ >> r.last
+ = 10
+ >> r.step
+ = 2
+
>> Range(1, 5) == 1:to(5)
= yes
diff --git a/test/text.tm b/test/text.tm
index 6ecd211b..cf95878e 100644
--- a/test/text.tm
+++ b/test/text.tm
@@ -169,17 +169,17 @@ func main():
= []
!! Test text:find_all()
- >> " one two three ":find_all($/{alpha}/)
- = ["one", "two", "three"]
+ >> " #one #two #three ":find_all($/#{alpha}/)
+ = [Match(text="#one", index=2, captures=["one"]), Match(text="#two", index=8, captures=["two"]), Match(text="#three", index=13, captures=["three"])]
- >> " one two three ":find_all($/{!space}/)
- = ["one", "two", "three"]
+ >> " #one #two #three ":find_all($/#{!space}/)
+ = [Match(text="#one", index=2, captures=["one"]), Match(text="#two", index=8, captures=["two"]), Match(text="#three", index=13, captures=["three"])]
>> " ":find_all($/{alpha}/)
= []
>> " foo(baz(), 1) doop() ":find_all($/{id}(?)/)
- = ["foo(baz(), 1)", "doop()"]
+ = [Match(text="foo(baz(), 1)", index=2, captures=["foo", "baz(), 1"]), Match(text="doop()", index=17, captures=["doop", ""])]
>> "":find_all($Pattern'')
= []
@@ -189,13 +189,13 @@ func main():
!! Test text:find()
>> " one two three ":find($/{id}/, start=-999)
- = !Int
+ = !Match
>> " one two three ":find($/{id}/, start=999)
- = !Int
+ = !Match
>> " one two three ":find($/{id}/)
- = 2?
+ = Match(text="one", index=2, captures=["one"])?
>> " one two three ":find($/{id}/, start=5)
- = 8?
+ = Match(text="two", index=8, captures=["two"])?
!! Test text slicing:
>> "abcdef":slice()
@@ -225,7 +225,7 @@ func main():
= !Text
>> "one two; three four":find_all($/; {..}/)
- = ["; three four"]
+ = [Match(text="; three four", index=8, captures=["three four"])]
>> malicious := "{xxx}"
>> $/$malicious/
@@ -261,7 +261,7 @@ func main():
else:
fail("Failed to match")
- >> "hello world":map($/world/, Text.upper)
+ >> "hello world":map($/world/, func(m:Match): m.text:upper())
= "hello WORLD"
>> "Abc":repeat(3)