-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✅ add tests comparing qs_dart and qs for JavaScript (#10)
- Loading branch information
Showing
8 changed files
with
171 additions
and
0 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,2 @@ | ||
node_modules | ||
package-lock.json |
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,17 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Get the directory of the script | ||
script_dir=$(dirname "$0") | ||
|
||
# Run the JavaScript and Dart scripts and save their outputs | ||
node_output=$(node "$script_dir/qs.js") | ||
dart_output=$(dart run "$script_dir/qs.dart") | ||
|
||
# Compare the outputs | ||
if [ "$node_output" == "$dart_output" ]; then | ||
echo "The outputs are identical." | ||
exit 0 | ||
else | ||
echo "The outputs are different." | ||
exit 1 | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"name": "qs_comparison", | ||
"version": "1.0.0", | ||
"description": "A comparison of query string parsing libraries", | ||
"author": "Klemen Tusar", | ||
"license": "BSD-3-Clause", | ||
"dependencies": { | ||
"qs": "^6.12.1" | ||
} | ||
} |
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,26 @@ | ||
import 'dart:convert' show jsonDecode, jsonEncode; | ||
import 'dart:io' show File, Platform, exitCode, stdout; | ||
import 'package:qs_dart/qs_dart.dart' as qs; | ||
import 'package:cli_script/cli_script.dart' show wrapMain; | ||
import 'package:path/path.dart' as p; | ||
|
||
void main() { | ||
wrapMain(() { | ||
exitCode = 0; | ||
|
||
final String scriptDir = p.dirname(Platform.script.toFilePath()); | ||
final File file = File(p.join(scriptDir, 'test_cases.json')); | ||
final String contents = file.readAsStringSync(); | ||
final List<Map<String, dynamic>> e2eTestCases = | ||
List<Map<String, dynamic>>.from( | ||
jsonDecode(contents), | ||
); | ||
|
||
for (final testCase in e2eTestCases) { | ||
final String encoded = qs.encode(testCase['data']); | ||
final Map decoded = qs.decode(testCase['encoded']); | ||
stdout.writeln('Encoded: $encoded'); | ||
stdout.writeln('Decoded: ${jsonEncode(decoded)}'); | ||
} | ||
}); | ||
} |
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,14 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const qs = require('qs'); | ||
|
||
// Use path.join to combine __dirname with the relative path to test_cases.json | ||
const filePath = path.join(__dirname, 'test_cases.json'); | ||
const e2eTestCases = JSON.parse(fs.readFileSync(filePath).toString()); | ||
|
||
e2eTestCases.forEach(testCase => { | ||
let encoded = qs.stringify(testCase.data); | ||
let decoded = qs.parse(encoded); | ||
console.log('Encoded: ' + encoded); | ||
console.log('Decoded: ' + JSON.stringify(decoded)); | ||
}); |
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,78 @@ | ||
[ | ||
{ | ||
"data": {}, | ||
"encoded": "" | ||
}, | ||
{ | ||
"data": { | ||
"a": "b" | ||
}, "encoded": "a=b" | ||
}, | ||
{ | ||
"data": { | ||
"a": "b", | ||
"c": "d" | ||
}, | ||
"encoded": "a=b&c=d" | ||
}, | ||
{ | ||
"data": { | ||
"a": "b", | ||
"c": "d", | ||
"e": "f" | ||
}, | ||
"encoded": "a=b&c=d&e=f" | ||
}, | ||
{ | ||
"data": { | ||
"a": "b", | ||
"c": "d", | ||
"e": [ | ||
"f", | ||
"g", | ||
"h" | ||
] | ||
}, | ||
"encoded": "a=b&c=d&e[0]=f&e[1]=g&e[2]=h" | ||
}, | ||
{ | ||
"data": { | ||
"a": "b", | ||
"c": "d", | ||
"e": [ | ||
"f", | ||
"g", | ||
"h" | ||
], | ||
"i": { | ||
"j": "k", | ||
"l": "m" | ||
} | ||
}, | ||
"encoded": "a=b&c=d&e[0]=f&e[1]=g&e[2]=h&i[j]=k&i[l]=m" | ||
}, | ||
{ | ||
"data": { | ||
"filters": { | ||
"$or": [ | ||
{ | ||
"date": { | ||
"$eq": "2020-01-01" | ||
} | ||
}, | ||
{ | ||
"date": { | ||
"$eq": "2020-01-02" | ||
} | ||
} | ||
], | ||
"author": { | ||
"name": { | ||
"$eq": "John Doe" | ||
} | ||
} | ||
} | ||
}, | ||
"encoded": "filters[$or][0][date][$eq]=2020-01-01&filters[$or][1][date][$eq]=2020-01-02&filters[author][name][$eq]=John Doe" | ||
} | ||
] |