Debian Codegraph @

crates/wasm-metadata/tests/module.rs

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 use std::{str::FromStr, vec};
2
3 use auditable_serde::VersionInfo;
4 use wasm_encoder::Module;
5 use wasm_metadata::*;
6
7 #[test]
8 fn add_to_empty_module() {
9 let mut add = AddMetadata::default();
10 add.name = AddMetadataField::Set("foo".to_owned());
11 add.language = vec![("bar".to_owned(), "1.0".to_owned())];
12 add.processed_by = vec![("baz".to_owned(), "1.0".to_owned())];
13 add.sdk = vec![];
14 add.authors = AddMetadataField::Set(Authors::new("Chashu Cat"));
15 add.description = AddMetadataField::Set(Description::new("Chashu likes tuna"));
16 add.licenses = AddMetadataField::Set(
17 Licenses::new("Apache-2.0 WITH LLVM-exception OR Apache-2.0 OR MIT").unwrap(),
18 );
19 add.source = AddMetadataField::Set(
20 Source::new("https://github.com/bytecodealliance/wasm-tools").unwrap(),
21 );
22 add.homepage = AddMetadataField::Set(
23 Homepage::new("https://github.com/bytecodealliance/wasm-tools").unwrap(),
24 );
25 add.revision = AddMetadataField::Set(Revision::new("de978e17a80c1118f606fce919ba9b7d5a04a5ad"));
26 add.version = AddMetadataField::Set(Version::new("1.0.0"));
27
28 let json_str = r#"{"packages":[{"name":"adler","version":"0.2.3","source":"registry"}]}"#;
29 let info = VersionInfo::from_str(json_str).unwrap();
30 let mut component = Module::new();
31 component.section(&Dependencies::new(info.clone()));
32 let module = component.finish();
33 let module = add.to_wasm(&module).unwrap();
34
35 match Payload::from_binary(&module).unwrap() {
36 Payload::Module(Metadata {
37 name,
38 producers,
39 authors: author,
40 licenses,
41 source,
42 range,
43 description,
44 homepage,
45 revision,
46 version,
47 dependencies,
48 }) => {
49 assert_eq!(name, Some("foo".to_owned()));
50 let producers = producers.expect("some producers");
51 assert_eq!(
52 producers.get("language").unwrap().get("bar").unwrap(),
53 "1.0"
54 );
55 assert_eq!(
56 producers.get("processed-by").unwrap().get("baz").unwrap(),
57 "1.0"
58 );
59
60 assert_eq!(author.unwrap(), Authors::new("Chashu Cat"));
61 assert_eq!(description.unwrap(), Description::new("Chashu likes tuna"));
62 assert_eq!(
63 licenses.unwrap(),
64 Licenses::new("Apache-2.0 WITH LLVM-exception OR Apache-2.0 OR MIT").unwrap()
65 );
66 assert_eq!(
67 source.unwrap(),
68 Source::new("https://github.com/bytecodealliance/wasm-tools").unwrap(),
69 );
70 assert_eq!(
71 homepage.unwrap(),
72 Homepage::new("https://github.com/bytecodealliance/wasm-tools").unwrap(),
73 );
74 assert_eq!(
75 revision.unwrap(),
76 Revision::new("de978e17a80c1118f606fce919ba9b7d5a04a5ad")
77 );
78 assert_eq!(version.unwrap(), Version::new("1.0.0"));
79 assert_eq!(dependencies.unwrap().version_info(), &info,);
80
81 assert_eq!(range.start, 0);
82 assert_eq!(range.end, 455);
83 }
84 _ => panic!("metadata should be module"),
85 }
86 }