@@ -67,24 +67,24 @@ const runTest = async (testInput) => {
6767
6868 html . push ( "</table>\n" ) ;
6969
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+ ) ;
7682 }
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- }
8283
83- const debugData = await pg . query ( "SELECT * FROM rxp_test" ) ;
84- console . log ( debugData ) ;
84+ const debugData = await pg . query ( "SELECT * FROM rxp_test" ) ;
8585
86- const resultData = await pg . query (
87- `SELECT
86+ const resultData = await pg . query (
87+ `SELECT
8888 (id+1)::varchar AS id,
8989 input,
9090 (input SIMILAR TO regex)::varchar AS similar_to,
@@ -95,75 +95,75 @@ const runTest = async (testInput) => {
9595 substring(input from regex) AS substring_from,
9696 regexp_replace(input, regex, replacement) AS replace
9797 FROM rxp_test`
98- ) ;
99- console . log ( resultData ) ;
98+ ) ;
10099
101- const matchData = await pg . query ( `SELECT
100+ const matchData = await pg . query ( `SELECT
102101 (id+1)::varchar AS id,
103102 UNNEST(regexp_matches(input, regex))
104103 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) {
107106 if row[0] in matches {
108107 matches[row[0]].append(row[1])
109108 else:
110109 matches[row[0]] = [ row[1] ]
111110*/
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" ) ;
130113 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 ) ) ;
147132 html . push ( "</td>\n" ) ;
148- }
149133
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:
152151 html.push("<i>(none)</i>")
153152 else:
154153 matchlist = matches[row[0]]
155154 for matchloop in range(0, len(matchlist)):
156155 html.push("%d: %s<br/>" % (matchloop+1, safe_escape(matchlist[matchloop])))
157156 */
158- html . push ( "</td>\n" ) ;
157+ html . push ( "</td>\n" ) ;
159158
160- html . push ( "\t\t</tr>\n" ) ;
161- }
159+ html . push ( "\t\t</tr>\n" ) ;
160+ }
162161
163- html . push ( "\t</tbody>\n" ) ;
164- html . push ( "</table>\n" ) ;
162+ html . push ( "\t</tbody>\n" ) ;
163+ html . push ( "</table>\n" ) ;
165164
166- await pg . close ( ) ;
165+ await pg . close ( ) ;
166+ }
167167
168168 return {
169169 success : true ,
0 commit comments