-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ECMA definition of symmetry operation regexp and associated tests
- Loading branch information
Showing
7 changed files
with
3,982 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#! /bin/sh | ||
|
||
# Test case: test if the provided ECMA-compatible regular expression correctly | ||
# recognises symmetry operation strings. | ||
|
||
#BEGIN DEPEND | ||
|
||
INPUT_GRAMMAR=tests/generated/symops.ecma | ||
|
||
#END DEPEND | ||
|
||
|
||
/usr/bin/env python << EOF | ||
import re | ||
import sys | ||
with open("${INPUT_GRAMMAR}") as f: | ||
expression = [line.strip() for line in f.readlines() if line.strip() and not line.strip().startswith("#")][0] | ||
with open("tests/inputs/symops.lst") as cases: | ||
for case in cases: | ||
if re.match(expression, case): | ||
print(case, end="") | ||
EOF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#! /bin/sh | ||
|
||
# Test case: tests the equivalence of the provided PCRE and ECMA regular | ||
# expressions used in the validation of space group symmetry operations. | ||
# The equivalence is tested by translating the expression from PCRE to the | ||
# subset of the ECMA 262 dialect supported by OPTIMADE. | ||
|
||
set -ue | ||
|
||
#BEGIN DEPEND | ||
|
||
INPUT_PCRE_DEFS=tests/generated/symop_definitions.pcre | ||
INPUT_PCRE_GRAMMAR=tests/generated/symops.pcre | ||
INPUT_ECMA_GRAMMAR=tests/generated/symops.ecma | ||
|
||
#END DEPEND | ||
|
||
PCRE_REGEX=$( \ | ||
grep -v -e '^ *#' -e '^\s+$' ${INPUT_PCRE_GRAMMAR} | \ | ||
perl -ne 's/\s+//g; s/#.*//; s/[\$]$/\\\$/; print;' | \ | ||
perl -ne 's/^[\^][(](.+)[)][(](.+)[)]\{2\}\\[\$]$/^$1$2$2$3\\\$/; print;' \ | ||
) | ||
|
||
EXPANDED_PCRE_REGEX=$( \ | ||
perl -I. -w \ | ||
-e "require '${INPUT_PCRE_DEFS}';" \ | ||
-e "my \$extended_regex = \"${PCRE_REGEX}\";" \ | ||
-e '$extended_regex =~ s/[\s\\]+//g;' \ | ||
-e 'print $extended_regex;' \ | ||
) | ||
|
||
ECMA_REGEX=$( \ | ||
grep -v -e '^ *#' -e '^\s+$' ${INPUT_ECMA_GRAMMAR} | \ | ||
perl -n -e 's/\s+//g; print;' \ | ||
) | ||
|
||
if [ "${EXPANDED_PCRE_REGEX}" = "${ECMA_REGEX}" ] | ||
then | ||
printf '%s\n' 'PASS: expanded regular expressions match.' | ||
else | ||
printf '%s\n' 'FAIL: expanded regular expressions do not match.' | ||
echo "PCRE: ${EXPANDED_PCRE_REGEX}" | ||
echo "ECMA: ${ECMA_REGEX}" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.