Skip to content

Commit d664b26

Browse files
committed
Add encoding-impl test
1 parent a6a653f commit d664b26

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/swc_ecma_parser/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,12 @@ walkdir = { workspace = true }
4848
codspeed-criterion-compat = { workspace = true }
4949
swc_ecma_ast = { version = "15.0.0", path = "../swc_ecma_ast", features = [
5050
"serde-impl",
51+
"encoding-impl",
5152
] }
5253
swc_ecma_visit = { version = "15.0.0", path = "../swc_ecma_visit" }
5354
swc_malloc = { version = "1.2.3", path = "../swc_malloc" }
5455
testing = { version = "15.0.0", path = "../testing" }
56+
cbor4ii = { workspace = true, features = [ "use_std" ] }
5557

5658
[[example]]
5759
name = "typescript"

crates/swc_ecma_parser/tests/js.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,28 @@ fn run_spec(file: &Path, output_json: &Path, config_path: &Path) {
6363
is_test262: false,
6464
});
6565

66-
let json =
67-
serde_json::to_string_pretty(&program).expect("failed to serialize module as json");
66+
// json
67+
{
68+
let json =
69+
serde_json::to_string_pretty(&program).expect("failed to serialize module as json");
70+
71+
if StdErr::from(json).compare_to_file(output_json).is_err() {
72+
panic!()
73+
}
74+
}
75+
76+
// cbor
77+
{
78+
use cbor4ii::core::utils::{ BufWriter, SliceReader };
79+
use cbor4ii::core::enc::Encode;
80+
use cbor4ii::core::dec::Decode;
81+
82+
let mut buf = BufWriter::new(Vec::new());
83+
program.encode(&mut buf).unwrap();
6884

69-
if StdErr::from(json).compare_to_file(output_json).is_err() {
70-
panic!()
85+
let buf = buf.into_inner();
86+
let mut buf = SliceReader::new(buf.as_slice());
87+
let _program = Program::decode(&mut buf).unwrap();
7188
}
7289

7390
Ok(())

0 commit comments

Comments
 (0)