-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.lua
38 lines (29 loc) · 1.43 KB
/
test.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
vex = require("vex")
print("Test Matching\n")
tester = vex():startofline():find("http"):maybe("s"):find("://"):maybe("www."):anythingbut(" "):endofline()
testURL = "https://github.com"
print("Testing \n\t" .. tester:pattern() .. "\nagainst\n\t" .. testURL .. "\n")
res = tester:match(testURL)
print(res and "It works!" or "It's broken!")
print("\n\nTest Replacing\n")
repStr = "Replace a bird with a duck"
print(repStr)
res = vex():find("bird"):gsub(repStr, "duck")
print(res)
print("\n\nTest Quantifiers\n")
hello = vex():begincapture():find("he"):find("l"):exactly(2):find("o, World!"):endcapture():withanycase():anything()
testStr = "Hello, World! This is Verbal Expressions!"
print("With 2 l's")
print("\t" .. hello:pattern())
print("\t" .. testStr)
print("\t" .. (hello:match(testStr) or "No match!"))
testStr = "Helo, World! This is Verbal Expressions!"
print("With 1 l")
print("\t" .. hello:pattern())
print("\t" .. testStr)
print("\t" .. (hello:match(testStr) or "No match!"))
print("\n\nTest Captures\n")
str = "cat and dog and fish and buffalo buffalo buffalo buffalo buffalo buffalo"
tester = vex():begincapture():find("cat"):endcapture():find(" and "):begincapture():find("dog"):endcapture():find(" and "):begincapture():find("fish"):endcapture():find(" and "):begincapture():begingroup():find("buffalo"):maybe(" "):endgroup():nomorethan(3):endcapture():anything()
cat, dog, fish, buffalo = tester:match(str)
print(cat, dog, fish, buffalo)