summaryrefslogtreecommitdiffstats
path: root/test/w3c/convert-tests.sh
blob: cb138a2adeedf68f6590b3334e333f20dc8cc2d0 (plain)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/bin/bash

#
# Convert all SCXML IRP tests from the W3C for specific datamodels
#

ME=`basename $0`
DIR="$( cd "$( dirname "$0" )" && pwd )"
cd $DIR

if [ "$#" -lt 2 ]; then
    echo "At least one datamodel needs to be specified:"
    echo "   $0 ecma c89 lua jexl namespace xpath promela prolog [pattern]"
    exit 1
fi


while [ "$2" != "" ]; do
	case $1 in
		ecma )
			ECMA=$1 
			shift ;;
		c89 )
			C89=$1 
			shift ;;
		lua )
			LUA=$1 
			shift ;;
		jexl ) 
			JEXL=$1 
			shift ;;
		namespace ) 
			NAMESPACE=$1 
			shift ;;
		xpath ) 
			XPATH=$1 
			shift ;;
		promela ) 
			PROMELA=$1 
			shift ;;
		prolog ) 
			PROLOG=$1 
			shift ;;
		* )
			echo "unknown datamodel $1"
			exit 1
	esac
done

TXMLS=`ls txml/$1.txml contrib/$1.txml`
TRANSFORM="java -jar /Users/sradomski/Developer/Applications/SaxonHE9-4-0-7J/saxon9he.jar"

# see http://saxon.sourceforge.net/saxon6.5.1/using-xsl.html
for TXML in $TXMLS
do
	echo -n "Processing $TXML for "
	TARGETFILE=`basename $TXML .txml`.scxml
	if [ "$ECMA" != "" ]; then
		echo -n "ecma " && $TRANSFORM $TXML confEcma.xsl -o:ecma/$TARGETFILE
	fi
	if [ "$C89" != "" ]; then
		echo -n "c89 " && $TRANSFORM $TXML confC89.xsl -o:c89/$TARGETFILE
	fi
	if [ "$JEXL" != "" ]; then
		echo -n "jexl " && $TRANSFORM $TXML confJEXL.xsl -o:jexl/$TARGETFILE
	fi
	if [ "$NAMESPACE" != "" ]; then
		echo -n "namespace " && $TRANSFORM ecma/$TARGETFILE confNamespace.xsl -o:namespace/$TARGETFILE
	fi
	if [ "$XPATH" != "" ]; then
		echo -n "xpath " && $TRANSFORM $TXML confXPath.xsl -o:xpath/$TARGETFILE
	fi
	if [ "$PROMELA" != "" ]; then
		echo -n "promela " && $TRANSFORM $TXML confPromela.xsl -o:promela/$TARGETFILE
	fi
	if [ "$PROLOG" != "" ]; then
		echo -n "prolog " && $TRANSFORM $TXML confProlog.xsl -o:prolog/$TARGETFILE
	fi
	if [ "$LUA" != "" ]; then
		echo -n "lua " && $TRANSFORM $TXML confLua.xsl -o:lua/$TARGETFILE
	fi
	echo
done

# make sure substitutions are idempotent!

if [ "$LUA" != "" ]; then
	# percent needs to be escaped in lua patterns
	sed -i.orig 's/this%20is%20some%20content/this%%20is%%20some%%20content/g' ./lua/test520.scxml

	# x-www-form-urlencode will not preserve the type and we default to string
	sed -i.orig 's/Var1==2/tonumber(Var1)==2/g' ./lua/test567.scxml
  
	# we can pass test562 even though it it ecmascript specific
	sed -i.orig 's/datamodel=\"ecmascript\"/datamodel=\"lua\"/g' ./lua/test562.scxml
  
fi

if [ "$NAMESPACE" != "" ]; then
	# unnamespace embedded xml in namespace tests
	sed -i.orig 's/scxml:book/book/g' ./namespace/test557.scxml
	sed -i.orig 's/scxml:book/book/g' ./namespace/test561.scxml
fi

cp txml/*.txt ecma/
cp txml/*.txt namespace/
cp txml/*.txt xpath/
cp txml/*.txt promela/
cp txml/*.txt prolog/
cp txml/*.txt lua/
cp txml/*.txt jexl/

find ./ecma -type f -exec grep -Ili 'datamodel="xpath"' {} \; |xargs rm -fv
find ./namespace -type f -exec grep -Ili 'datamodel="xpath"' {} \; |xargs rm -fv
find ./xpath -type f -exec grep -Ili 'datamodel="ecmascript"' {} \; |xargs rm -fv

find ./promela -type f -exec grep -Ili 'datamodel="xpath"' {} \; |xargs rm -fv
find ./promela -type f -exec grep -Ili 'datamodel="ecmascript"' {} \; |xargs rm -fv
find ./promela -type f -exec grep -Ili 'datamodel="null"' {} \; |xargs rm -fv

find ./prolog -type f -exec grep -Ili 'datamodel="xpath"' {} \; |xargs rm -fv
find ./prolog -type f -exec grep -Ili 'datamodel="ecmascript"' {} \; |xargs rm -fv
find ./prolog -type f -exec grep -Ili 'datamodel="null"' {} \; |xargs rm -fv

find ./c89 -type f -exec grep -Ili 'datamodel="xpath"' {} \; |xargs rm -fv
find ./c89 -type f -exec grep -Ili 'datamodel="ecmascript"' {} \; |xargs rm -fv
find ./c89 -type f -exec grep -Ili 'datamodel="null"' {} \; |xargs rm -fv

find ./lua -type f -exec grep -Ili 'datamodel="xpath"' {} \; |xargs rm -fv
find ./lua -type f -exec grep -Ili 'datamodel="ecmascript"' {} \; |xargs rm -fv
find ./lua -type f -exec grep -Ili 'datamodel="null"' {} \; |xargs rm -fv

find ./jexl -type f -exec grep -Ili 'datamodel="xpath"' {} \; |xargs rm -fv
find ./jexl -type f -exec grep -Ili 'datamodel="ecmascript"' {} \; |xargs rm -fv
find ./jexl -type f -exec grep -Ili 'datamodel="null"' {} \; |xargs rm -fv

# create other encoding tests from the utf8 one
for ENC in ISO-8859-15 WINDOWS-1252;
do
	export ENC=$ENC
	find . -name "test-enc-UTF8.scxml" -exec sh -c 'sed "s/UTF-8/${ENC}/g" {} > $(dirname {})/test-enc-${ENC}.tmp.scxml' \;
	find . -name "test-enc-${ENC}.tmp.scxml" -exec sh -c 'iconv -f UTF-8 -t ${ENC} {} > $(dirname {})/test-enc-${ENC}.scxml' \;
	find . -name "test-enc-${ENC}.tmp.scxml" -exec rm {} \;
done

# find . -name "tmp.scxml" -exec rm {} \;
# find . -name "tmp.scxml.orig" -exec rm {} \;

# test436 is the null datamodel
mv ./ecma/test436.scxml ./null
rm ./namespace/test436.scxml
rm ./xpath/test436.scxml
rm ./promela/test436.scxml
rm ./prolog/test436.scxml
rm ./lua/test436.scxml
rm ./jexl/test436.scxml

# format all SCXML files
SCXMLS=`find . -type f -name '*.scxml'`
for SCXML in $SCXMLS
do
	mv $SCXML $SCXML.unformatted.xml
	xmllint --format $SCXML.unformatted.xml > $SCXML
	rm $SCXML.unformatted.xml
done