summaryrefslogtreecommitdiff
path: root/libregex/test
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2015-08-26 12:20:58 -0700
committerOri Bernstein <ori@eigenstate.org>2015-08-26 12:20:58 -0700
commit2bc852bda98762d3bc01548bf972e3f1b137fbfb (patch)
tree74831deed3c9057c5fe0cbb8790d220e855bc792 /libregex/test
parent3de952510eb2a23350d24ed926f19c0cf72a12f2 (diff)
downloadmc-2bc852bda98762d3bc01548bf972e3f1b137fbfb.tar.gz
Move Myrddin libs to lib/ subdirectory.
Diffstat (limited to 'libregex/test')
-rw-r--r--libregex/test/basic.myr39
-rw-r--r--libregex/test/bld.sub7
-rw-r--r--libregex/test/boundaries.myr36
-rw-r--r--libregex/test/capture.myr17
-rw-r--r--libregex/test/class.myr67
-rw-r--r--libregex/test/failmatch.myr7
-rw-r--r--libregex/test/negclass.myr72
-rwxr-xr-xlibregex/test/runtest.sh124
-rw-r--r--libregex/test/testmatch.myr58
-rw-r--r--libregex/test/tests29
-rw-r--r--libregex/test/unicode.myr19
11 files changed, 0 insertions, 475 deletions
diff --git a/libregex/test/basic.myr b/libregex/test/basic.myr
deleted file mode 100644
index 168b547..0000000
--- a/libregex/test/basic.myr
+++ /dev/null
@@ -1,39 +0,0 @@
-use std
-
-use "testmatch.use"
-
-const main = {
- var s : byte[:]
-
- s = std.strjoin([
- "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
- "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
- "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
- "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
- "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
- "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
- "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
- "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
- "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
- "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
- "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
- "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
- ][:], "")
- testmatch(".*bc", "Abc", `std.Some [][:])
- testmatch("(a*)*", "a", `std.Some ["a"][:])
- testmatch("(aa|aab?)*", s, `std.Some ["aa"][:])
- /* greedy matches */
- testmatch("(<.*>).*", "<a foo> blah <bar>", `std.Some [
- "<a foo> blah <bar>",
- ][:])
- testmatch("(<.+>).*", "<a foo> blah <bar>", `std.Some [
- "<a foo> blah <bar>",
- ][:])
- /* reluctant matches */
- testmatch("(<.*?>).*", "<a foo> blah <bar>", `std.Some [
- "<a foo>",
- ][:])
- testmatch("(<.+?>).*", "<a foo> blah <bar>", `std.Some [
- "<a foo>",
- ][:])
-}
diff --git a/libregex/test/bld.sub b/libregex/test/bld.sub
deleted file mode 100644
index 12f8056..0000000
--- a/libregex/test/bld.sub
+++ /dev/null
@@ -1,7 +0,0 @@
-test basic {inc=../libstd,inc=..} = basic.myr testmatch.myr;;
-test boundaries {inc=../libstd,inc=..} = boundaries.myr testmatch.myr;;
-test capture {inc=../libstd,inc=..} = capture.myr testmatch.myr;;
-test class {inc=../libstd,inc=..} = class.myr testmatch.myr;;
-test failmatch {inc=../libstd,inc=..} = failmatch.myr testmatch.myr;;
-test negclass {inc=../libstd,inc=..} = negclass.myr testmatch.myr;;
-test unicode {inc=../libstd,inc=..} = unicode.myr testmatch.myr;;
diff --git a/libregex/test/boundaries.myr b/libregex/test/boundaries.myr
deleted file mode 100644
index 196d197..0000000
--- a/libregex/test/boundaries.myr
+++ /dev/null
@@ -1,36 +0,0 @@
-use std
-use "testmatch.use"
-
-const main = {
- /* expected matches */
- testmatch("\\<([a-z]*)\\>", "abcdef", `std.Some [
- "abcdef",
- ][:])
- testmatch(".*(\\<.*\\>).*", "!m!", `std.Some [ /* single char word in midstring */
- "m",
- ][:])
- testmatch(".*(\\<.*\\>).*", "!m", `std.Some [ /* single char word at end of string */
- "m",
- ][:])
- testmatch(".*(\\<.*\\>).*", "m!", `std.Some [ /* single char word at start of string */
- "m",
- ][:])
- testmatch(".*(\\<.*\\>).*", "!@#!!matches!!%!", `std.Some [ /* word in midstring */
- "matches",
- ][:])
- testmatch(".*(\\<.*\\>).*", "matches!!%!", `std.Some [ /* word at start of string */
- "matches",
- ][:])
- testmatch(".*(\\<.*\\>).*", "!@#!!matches", `std.Some [ /* word at end of string */
- "matches",
- ][:])
- testmatch(".*(\\<.*\\>).*", "!@#!!matches!!%!foo", `std.Some [ /* matches last word in string */
- "foo",
- ][:])
- testmatch(".*(\\<.*\\>).*", "123", `std.Some [ /* numbers are also word bounds */
- "123",
- ][:])
-
- /* nonmatches */
- testmatch("\\<([a-z]*)\\>foo", "abcdefoo", `std.None) /* word boundary needed in midstring */
-}
diff --git a/libregex/test/capture.myr b/libregex/test/capture.myr
deleted file mode 100644
index f270428..0000000
--- a/libregex/test/capture.myr
+++ /dev/null
@@ -1,17 +0,0 @@
-use std
-use "testmatch.use"
-
-const main = {
- testmatch("A(.*)", "Abc", `std.Some ["bc"][:])
- testmatch("A(.*)e", "Abcde", `std.Some ["bcd"][:])
- testmatch("(a|b)+", "abab", `std.Some ["b"][:])
- testmatch("A(b(.*)d)e", "Abcde", `std.Some [
- "bcd",
- "c"
- ][:])
- testmatch("(a?)(a*)(a?)", "aaaa", `std.Some [
- "a",
- "aaa",
- ""
- ][:])
-}
diff --git a/libregex/test/class.myr b/libregex/test/class.myr
deleted file mode 100644
index 284f440..0000000
--- a/libregex/test/class.myr
+++ /dev/null
@@ -1,67 +0,0 @@
-use std
-
-use "testmatch.use"
-
-const main = {
- asciiclass()
- set()
- /*
- unicodeclass()
- negasciiclass()
- negasciirange()
- negset()
- */
-}
-
-const asciiclass = {
- /* \d success */
- testmatch("\\d", "1", `std.Some [][:])
- testmatch("\\d\\d", "13", `std.Some [][:])
- testmatch("\\d+", "13688", `std.Some [][:])
- /* \d fail */
- testmatch("\\d", "x", `std.None)
- testmatch("\\d\\d", "x3", `std.None)
- testmatch("\\d+", "1368f", `std.None)
-
- /* \x success */
- testmatch("\\x", "a", `std.Some [][:])
- testmatch("\\x\\x", "1F", `std.Some [][:])
- testmatch("\\x+", "13b8cDEf", `std.Some [][:])
- /* \x fail */
- testmatch("\\x", "Z", `std.None)
- testmatch("\\x\\x", "fg", `std.None)
- testmatch("\\x+", "13b8cg", `std.None)
-
- /* \s success */
- testmatch("\\s", " ", `std.Some [][:])
- testmatch("\\s\\s", "\t\n", `std.Some [][:])
- testmatch("\\s+", "\t\n\r \t", `std.Some [][:])
- /* \s fail */
- testmatch("\\s", "a", `std.None)
- testmatch("\\s\\s", "i\n", `std.None)
- testmatch("\\s+", "\t\n\r.\t", `std.None)
-
- /* word success */
- testmatch("\\w+", "abcABC0123_", `std.Some [][:])
- /* word fail */
- testmatch("\\w+", "abcABC0123_.", `std.None)
-
- /* \h success */
- testmatch("\\h", " ", `std.Some [][:])
- testmatch("\\h\\h", "\t ", `std.Some [][:])
- testmatch("\\h+", "\t \t ", `std.Some [][:])
- /* \h fail */
- testmatch("\\h", "\n", `std.None)
- testmatch("\\h\\h", "\t\r", `std.None)
- testmatch("\\h+", "\t \t.", `std.None)
-}
-
-const set = {
- /* ranges */
- testmatch("[a-z]*", "abcd", `std.Some [][:])
- testmatch("[a-zA-Z]*", "abCD", `std.Some [][:])
- testmatch("[a-zA-Z0-9_]*", "_abCD018", `std.Some [][:])
-
- testmatch("[abc]*", "abba", `std.Some [][:])
- testmatch("[a-zABC]*", "abBa", `std.Some [][:])
-}
diff --git a/libregex/test/failmatch.myr b/libregex/test/failmatch.myr
deleted file mode 100644
index c501d00..0000000
--- a/libregex/test/failmatch.myr
+++ /dev/null
@@ -1,7 +0,0 @@
-use std
-
-use "testmatch.use"
-
-const main = {
- testmatch(".*bcd", "Abc", `std.None)
-}
diff --git a/libregex/test/negclass.myr b/libregex/test/negclass.myr
deleted file mode 100644
index 19404fa..0000000
--- a/libregex/test/negclass.myr
+++ /dev/null
@@ -1,72 +0,0 @@
-use std
-
-use "testmatch.use"
-
-const main = {
- asciiclass()
- set()
- /*
- unicodeclass()
- negasciiclass()
- negasciirange()
- negset()
- */
-}
-
-const asciiclass = {
- /* \D success */
- testmatch("\\D", "x", `std.Some [][:])
- testmatch("\\D+", "xa!#^cs", `std.Some [][:])
-
- /* \D fail: end of ranges chars */
- testmatch("\\D", "0", `std.None)
- testmatch("\\D", "9", `std.None)
- testmatch("\\D+", "a35x", `std.None)
- testmatch("\\D+", "13688", `std.None)
-
- /* \X success */
- testmatch("\\X", "Z", `std.Some [][:])
- testmatch("\\X\\X", "gg", `std.Some [][:])
- /* \X fail */
- testmatch("\\X", "a", `std.None)
- testmatch("\\X+", "zz13b8cDEf", `std.None)
-
- /* \S success */
- testmatch("\\S", "a", `std.Some [][:])
- testmatch("\\S\\S", "i%", `std.Some [][:])
- testmatch("\\S+", "alskd690!#!!", `std.Some [][:])
-
- /* \S fail */
- testmatch("\\S", " ", `std.None)
- testmatch("\\S\\S", "\t\n", `std.None)
- testmatch("\\S+", "\t \nkait", `std.None)
-
- /* word success */
- testmatch("\\W+", "!%!^^@@!^", `std.Some [][:])
- /* word fail */
- testmatch("\\W+", "a^#$bcABC0123_", `std.None)
-
- /* \H success */
- testmatch("\\H", "\n", `std.Some [][:])
- testmatch("\\H\\H", "\n\r", `std.Some [][:])
- /* \H fail */
- testmatch("\\H+", "\t \t.", `std.None)
- testmatch("\\H\\H", "\t ", `std.None)
- testmatch("\\H+", "\ta35 \t ", `std.None)
-}
-
-const set = {
- /* ranges: should succeed */
- testmatch("[^a-z]*", "ABCD", `std.Some [][:])
- testmatch("[^a-zA-Z]*", "1234", `std.Some [][:])
- testmatch("[^a-zA-Z0-9_]*", "-^^-", `std.Some [][:])
- testmatch("[^abc]*", "d6d", `std.Some [][:])
- testmatch("[^a-zABC]*", "!^!!))#", `std.Some [][:])
-
- /* ranges: should fail */
- testmatch("[^a-z]*", "abcd", `std.None)
- testmatch("[^a-zA-Z]*", "abCD", `std.None)
- testmatch("[^a-zA-Z0-9_]*", "_abCD018", `std.None)
- testmatch("[^abc]*", "abba", `std.None)
- testmatch("[^a-zABC]*", "abBa", `std.None)
-}
diff --git a/libregex/test/runtest.sh b/libregex/test/runtest.sh
deleted file mode 100755
index 95f548f..0000000
--- a/libregex/test/runtest.sh
+++ /dev/null
@@ -1,124 +0,0 @@
-#!/bin/bash
-NFAILURES=0
-NPASSES=0
-
-function build {
- rm -f $1 $1.o $1.s $1.use
- myrbuild $FLAGS -b $1 $1.myr $EXTRA_SRC
-}
-
-function pass {
- PASSED="$PASSED $1"
- NPASSED=$[$NPASSED + 1]
-}
-
-function fail {
- echo "FAIL: $1"
- FAILED="$FAILED $1"
- NFAILED=$[$NFAILED + 1]
-}
-
-function expectstatus {
- ./$1 $3
- if [ $? -eq $2 ]; then
- pass $1
- return
- else
- fail $1
- fi
-}
-
-function expectprint {
- if [ "`./$1 $3`" != "$2" ]; then
- fail $1
- else
- pass $1
- fi
-}
-
-
-function expectcompare {
- if [ x"" != x"$TMPDIR" ]; then
- t=$TMPDIR/myrtest-$1-$RANDOM
- else
- t=/tmp/myrtest-$1-$RANDOM
- fi
- ./$1 $3 > $t
- if cmp $t data/$1-expected; then
- pass $1
- else
- fail $1
- fi
- rm -f $t
-}
-
-function expectfcompare {
- ./$1 $3
- if cmp data/$1-expected $2; then
- pass $1
- else
- fail $1
- fi
-}
-
-function shouldskip {
- if [ -z $ARGS ]; then
- return 1
- fi
-
- for i in $ARGS; do
- if [ $i = $1 ]; then
- return 1
- fi
- done
- return 0
-}
-
-
-# Should build and run
-function B {
- if shouldskip $1; then
- return
- fi
-
- test="$1"; shift
- type="$1"; shift
- res="$1"; shift
- if [ $# > 0 ]; then
- args="$1"; shift
- fi
- build $test
- case $type in
- "E") expectstatus "$test" "$res" "$input";;
- "P") expectprint "$test" "$res" "$input";;
- "C") expectcompare "$test" "$res" "$input";;
- "F") expectfcompare "$test" "$res" "$args";;
- esac
-}
-
-# Should fail
-function F {
- if shouldskip $1; then
- return
- fi
- (build $1) > /dev/null
- if [ $? -eq '1' ]; then
- pass $1
- else
- fail $1
- fi
-}
-
-# Should generate a usefile
-function U {
- return
-}
-
-source tests
-
-echo "PASSED ($NPASSED): $PASSED"
-if [ -z "$NFAILED" ]; then
- echo "SUCCESS"
-else
- echo "FAILURES ($NFAILED): $FAILED"
-fi
diff --git a/libregex/test/testmatch.myr b/libregex/test/testmatch.myr
deleted file mode 100644
index 4600410..0000000
--- a/libregex/test/testmatch.myr
+++ /dev/null
@@ -1,58 +0,0 @@
-use std
-use regex
-
-pkg =
- const testmatch : (pat : byte[:], text : byte[:], expected : std.option(byte[:][:]) -> void)
- const dbgmatch : (pat : byte[:], text : byte[:], expected : std.option(byte[:][:]) -> void)
-;;
-
-const testmatch = {pat, text, expected
- run(regex.compile(pat), pat, text, expected)
-}
-
-const dbgmatch = {pat, text, expected
- run(regex.dbgcompile(pat), pat, text, expected)
-}
-
-const run = {regex, pat, text, expected
- var i, re
-
- re = std.try(regex)
- match regex.exec(re, text)
- | `std.Some res:
- match expected
- | `std.None:
- std.fatal("expected no match, got:")
- for i = 0; i < res.len; i++
- std.put("\t{}: {}\n", i, res[i])
- ;;
- | `std.Some exp:
- if !std.sleq(res[0], text)
- std.put("whole match does not match text!\n")
- std.fatal("failed matching {} over {}\n", pat, text)
- ;;
- res = res[1:]
- if res.len != exp.len
- std.put("mismatch: expected {} matches, got {}\n", exp.len, res.len)
- std.fatal("failed matching {} over {}\n", pat, text)
- ;;
- for i = 0; i < exp.len; i++
- if !std.sleq(res[i], exp[i])
- std.put("mismatch on {}: expected {}, got {}\n", i, exp[i], res[i])
- std.fatal("failed matching {} over {}\n", pat, text)
- ;;
- ;;
- ;;
- | `std.None:
- match expected
- | `std.None: /* : expected failure */
- | `std.Some matches:
- std.put("expected matches:\n")
- for i = 0; i < matches.len; i++
- std.put("\t{}: {}\n", i, matches[i])
- ;;
- std.fatal("no match found\n")
- ;;
- ;;
- regex.free(re)
-}
diff --git a/libregex/test/tests b/libregex/test/tests
deleted file mode 100644
index a5f70f7..0000000
--- a/libregex/test/tests
+++ /dev/null
@@ -1,29 +0,0 @@
-FLAGS=-I../
-EXTRA_SRC=testmatch.myr
-# Format:
-# [B|F] testname [E|P] result
-# [B|F]: Compiler outcome.
-# B: Expect that this test will build.
-# F: Expect that this test will not build.
-# testname: Test case
-# The test that will run. We will try to
-# compile 'testname.myr' to 'testname',
-# and then execute it, verifying the result
-# [E|P|C]: Result type
-# E tells us that the result is an exit status
-# P tells us that the result is on stdout,
-# and should be compared to the value on the
-# line
-# C tells us that the result is on stdout,
-# and should be compared to the contents of
-# the file passed on the line.
-# result: Result value
-# What we compare with. This should be self-
-# evident.
-B basic C
-B boundaries C
-B capture C
-B class C
-B failmatch C
-B negclass C
-B unicode C
diff --git a/libregex/test/unicode.myr b/libregex/test/unicode.myr
deleted file mode 100644
index 5916a1c..0000000
--- a/libregex/test/unicode.myr
+++ /dev/null
@@ -1,19 +0,0 @@
-use std
-use regex
-
-use "testmatch.use"
-
-const main = {
- testmatch(".*bæc", "Abæc", `std.Some [][:])
- testmatch("(\\p{L}*)bæc\\P{L}*", \
- "Aabæc%!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!", \
- `std.Some ["Aa"][:])
- /* test various syntaxen */
- testmatch("(\\pL*)bæc\\PL*", \
- "Aabæc%!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!", \
- `std.Some ["Aa"][:])
- testmatch("(\\p{Letter}*)bæc\\P{Uppercase_Letter}*", \
- "Aabæc%!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!", \
- `std.Some ["Aa"][:])
- testmatch(".", "æ", `std.Some [][:])
-}