mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-06-14 21:31:05 +00:00
497dae2494
The differential testing framework will make a second consumer. There seems to be no re-usable Rust crate for this. But we already have everything here, just needs a small refactor to make it fully re-usable. - Mostly decouple the solc JSON-input-output interface types from the `solidity` frontend crate - Expose the JSON-input-output interface types in a dedicated crate --------- Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
100 lines
2.6 KiB
Rust
100 lines
2.6 KiB
Rust
//! The `solc --standard-json` output selection.
|
|
|
|
pub mod file;
|
|
|
|
use std::collections::BTreeMap;
|
|
|
|
use serde::Deserialize;
|
|
use serde::Serialize;
|
|
|
|
use self::file::File as FileSelection;
|
|
|
|
/// The `solc --standard-json` output selection.
|
|
#[derive(Debug, Serialize, Deserialize, Default, PartialEq)]
|
|
pub struct Selection {
|
|
/// Only the 'all' wildcard is available for robustness reasons.
|
|
#[serde(rename = "*", skip_serializing_if = "Option::is_none")]
|
|
all: Option<FileSelection>,
|
|
|
|
#[serde(skip_serializing_if = "BTreeMap::is_empty", flatten)]
|
|
pub files: BTreeMap<String, FileSelection>,
|
|
}
|
|
|
|
impl Selection {
|
|
/// Creates the selection required by our compilation process.
|
|
pub fn new_required() -> Self {
|
|
Self {
|
|
all: Some(FileSelection::new_required()),
|
|
files: BTreeMap::new(),
|
|
}
|
|
}
|
|
|
|
/// Extends the user's output selection with flag required by our compilation process.
|
|
pub fn extend_with_required(&mut self) -> &mut Self {
|
|
self.all
|
|
.get_or_insert_with(FileSelection::new_required)
|
|
.extend_with_required();
|
|
for (_, v) in self.files.iter_mut() {
|
|
v.extend_with_required();
|
|
}
|
|
self
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod test {
|
|
use std::collections::BTreeMap;
|
|
|
|
use crate::SolcStandardJsonInputSettingsSelectionFile;
|
|
|
|
use super::Selection;
|
|
|
|
#[test]
|
|
fn per_file() {
|
|
let init = Selection {
|
|
all: None,
|
|
files: BTreeMap::from([(
|
|
"Test".to_owned(),
|
|
SolcStandardJsonInputSettingsSelectionFile::new_required(),
|
|
)]),
|
|
};
|
|
|
|
let deser = serde_json::to_string(&init)
|
|
.and_then(|string| serde_json::from_str(&string))
|
|
.unwrap();
|
|
|
|
assert_eq!(init, deser)
|
|
}
|
|
|
|
#[test]
|
|
fn all() {
|
|
let init = Selection {
|
|
all: Some(SolcStandardJsonInputSettingsSelectionFile::new_required()),
|
|
files: BTreeMap::new(),
|
|
};
|
|
|
|
let deser = serde_json::to_string(&init)
|
|
.and_then(|string| serde_json::from_str(&string))
|
|
.unwrap();
|
|
|
|
assert_eq!(init, deser)
|
|
}
|
|
|
|
#[test]
|
|
fn all_and_override() {
|
|
let init = Selection {
|
|
all: Some(SolcStandardJsonInputSettingsSelectionFile::new_required()),
|
|
files: BTreeMap::from([(
|
|
"Test".to_owned(),
|
|
SolcStandardJsonInputSettingsSelectionFile::new_required(),
|
|
)]),
|
|
};
|
|
|
|
let deser = serde_json::to_string(&init)
|
|
.and_then(|string| serde_json::from_str(&string))
|
|
.unwrap();
|
|
|
|
assert_eq!(init, deser)
|
|
}
|
|
}
|