@@ -67,24 +67,24 @@ const runTest = async (testInput) => {
67
67
68
68
html . push ( "</table>\n" ) ;
69
69
70
- const pg = new PGlite ( ) ;
71
- await pg . exec ( createTable ) ;
72
- for ( let index = 0 ; index < testInput . inputs . length ; index ++ ) {
73
- const input = testInput . inputs [ index ] ;
74
- if ( ! input ) {
75
- continue ;
70
+ if ( testInput . inputs && testInput . inputs . length > 0 ) {
71
+ const pg = new PGlite ( ) ;
72
+ await pg . exec ( createTable ) ;
73
+ for ( let index = 0 ; index < testInput . inputs . length ; index ++ ) {
74
+ const input = testInput . inputs [ index ] ;
75
+ if ( ! input ) {
76
+ continue ;
77
+ }
78
+ await pg . query (
79
+ "INSERT INTO rxp_test (id, input, regex, replacement) VALUES ($1, $2, $3, $4)" ,
80
+ [ index , input , testInput . regex , testInput . replacement ]
81
+ ) ;
76
82
}
77
- await pg . query (
78
- "INSERT INTO rxp_test (id, input, regex, replacement) VALUES ($1, $2, $3, $4)" ,
79
- [ index + 1 , input , testInput . regex , testInput . replacement ]
80
- ) ;
81
- }
82
83
83
- const debugData = await pg . query ( "SELECT * FROM rxp_test" ) ;
84
- console . log ( debugData ) ;
84
+ const debugData = await pg . query ( "SELECT * FROM rxp_test" ) ;
85
85
86
- const resultData = await pg . query (
87
- `SELECT
86
+ const resultData = await pg . query (
87
+ `SELECT
88
88
(id+1)::varchar AS id,
89
89
input,
90
90
(input SIMILAR TO regex)::varchar AS similar_to,
@@ -95,75 +95,75 @@ const runTest = async (testInput) => {
95
95
substring(input from regex) AS substring_from,
96
96
regexp_replace(input, regex, replacement) AS replace
97
97
FROM rxp_test`
98
- ) ;
99
- console . log ( resultData ) ;
98
+ ) ;
100
99
101
- const matchData = await pg . query ( `SELECT
100
+ const matchData = await pg . query ( `SELECT
102
101
(id+1)::varchar AS id,
103
102
UNNEST(regexp_matches(input, regex))
104
103
FROM rxp_test` ) ;
105
- console . log ( matchData ) ;
106
- /*for (const row of matchData.rows) {
104
+ // console.log(matchData);
105
+ /*for (const row of matchData.rows) {
107
106
if row[0] in matches {
108
107
matches[row[0]].append(row[1])
109
108
else:
110
109
matches[row[0]] = [ row[1] ]
111
110
*/
112
- html . push ( '<table class="table table-bordered table-striped">\n' ) ;
113
- html . push ( "\t<thead>\n" ) ;
114
- html . push ( "\t\t<tr>\n" ) ;
115
- html . push ( '\t\t\t<th style="text-align:center;">Test</th>\n' ) ;
116
- html . push ( "\t\t\t<th>Target String</th>\n" ) ;
117
- html . push ( "\t\t\t<th>SIMILAR TO</th>\n" ) ;
118
- html . push ( "\t\t\t<th>~</th>\n" ) ;
119
- html . push ( "\t\t\t<th>~*</th>\n" ) ;
120
- html . push ( "\t\t\t<th>!~</th>\n" ) ;
121
- html . push ( "\t\t\t<th>!~*</th>\n" ) ;
122
- html . push ( "\t\t\t<th>substring()</th>\n" ) ;
123
- html . push ( "\t\t\t<th>regex_replace()</th>\n" ) ;
124
- html . push ( "\t\t\t<th>regex_matches()</th>\n" ) ;
125
- html . push ( "\t\t</tr>" ) ;
126
- html . push ( "\t</thead>" ) ;
127
- html . push ( "\t<tbody>" ) ;
128
-
129
- for ( const row of resultData . rows ) {
111
+ html . push ( '<table class="table table-bordered table-striped">\n' ) ;
112
+ html . push ( "\t<thead>\n" ) ;
130
113
html . push ( "\t\t<tr>\n" ) ;
131
- html . push ( '\t\t\t<td style="text-align:center">' ) ;
132
- html . push ( h ( row . id ) ) ;
133
- html . push ( "</td>\n" ) ;
134
-
135
- for ( const col of [
136
- "input" ,
137
- "similar_to" ,
138
- "tilde" ,
139
- "tilde_star" ,
140
- "not_tilde" ,
141
- "not_tilde_star" ,
142
- "substring_from" ,
143
- "replace" ,
144
- ] ) {
145
- html . push ( "\t\t\t<td>" ) ;
146
- html . push ( h ( row [ col ] ) ) ;
114
+ html . push ( '\t\t\t<th style="text-align:center;">Test</th>\n' ) ;
115
+ html . push ( "\t\t\t<th>Target String</th>\n" ) ;
116
+ html . push ( "\t\t\t<th>SIMILAR TO</th>\n" ) ;
117
+ html . push ( "\t\t\t<th>~</th>\n" ) ;
118
+ html . push ( "\t\t\t<th>~*</th>\n" ) ;
119
+ html . push ( "\t\t\t<th>!~</th>\n" ) ;
120
+ html . push ( "\t\t\t<th>!~*</th>\n" ) ;
121
+ html . push ( "\t\t\t<th>substring()</th>\n" ) ;
122
+ html . push ( "\t\t\t<th>regex_replace()</th>\n" ) ;
123
+ html . push ( "\t\t\t<th>regex_matches()</th>\n" ) ;
124
+ html . push ( "\t\t</tr>" ) ;
125
+ html . push ( "\t</thead>" ) ;
126
+ html . push ( "\t<tbody>" ) ;
127
+
128
+ for ( const row of resultData . rows ) {
129
+ html . push ( "\t\t<tr>\n" ) ;
130
+ html . push ( '\t\t\t<td style="text-align:center">' ) ;
131
+ html . push ( h ( row . id ) ) ;
147
132
html . push ( "</td>\n" ) ;
148
- }
149
133
150
- html . push ( "\t\t\t<td>" ) ;
151
- /*if row[0] not in matches:
134
+ for ( const col of [
135
+ "input" ,
136
+ "similar_to" ,
137
+ "tilde" ,
138
+ "tilde_star" ,
139
+ "not_tilde" ,
140
+ "not_tilde_star" ,
141
+ "substring_from" ,
142
+ "replace" ,
143
+ ] ) {
144
+ html . push ( "\t\t\t<td>" ) ;
145
+ html . push ( h ( row [ col ] ) ) ;
146
+ html . push ( "</td>\n" ) ;
147
+ }
148
+
149
+ html . push ( "\t\t\t<td>" ) ;
150
+ /*if row[0] not in matches:
152
151
html.push("<i>(none)</i>")
153
152
else:
154
153
matchlist = matches[row[0]]
155
154
for matchloop in range(0, len(matchlist)):
156
155
html.push("%d: %s<br/>" % (matchloop+1, safe_escape(matchlist[matchloop])))
157
156
*/
158
- html . push ( "</td>\n" ) ;
157
+ html . push ( "</td>\n" ) ;
159
158
160
- html . push ( "\t\t</tr>\n" ) ;
161
- }
159
+ html . push ( "\t\t</tr>\n" ) ;
160
+ }
162
161
163
- html . push ( "\t</tbody>\n" ) ;
164
- html . push ( "</table>\n" ) ;
162
+ html . push ( "\t</tbody>\n" ) ;
163
+ html . push ( "</table>\n" ) ;
165
164
166
- await pg . close ( ) ;
165
+ await pg . close ( ) ;
166
+ }
167
167
168
168
return {
169
169
success : true ,
0 commit comments