snarkvm_synthesizer_program/import/
mod.rsmod bytes;
mod parse;
use console::{
network::prelude::*,
program::{Identifier, ProgramID},
};
#[derive(Clone, PartialEq, Eq, Hash)]
pub struct Import<N: Network> {
program_id: ProgramID<N>,
}
impl<N: Network> Import<N> {
#[inline]
pub const fn program_id(&self) -> &ProgramID<N> {
&self.program_id
}
#[inline]
pub const fn name(&self) -> &Identifier<N> {
self.program_id.name()
}
#[inline]
pub const fn network(&self) -> &Identifier<N> {
self.program_id.network()
}
}
impl<N: Network> TypeName for Import<N> {
#[inline]
fn type_name() -> &'static str {
"import"
}
}
impl<N: Network> Ord for Import<N> {
fn cmp(&self, other: &Self) -> Ordering {
self.program_id.cmp(&other.program_id)
}
}
impl<N: Network> PartialOrd for Import<N> {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
#[cfg(test)]
mod tests {
use super::*;
use console::network::MainnetV0;
type CurrentNetwork = MainnetV0;
#[test]
fn test_import_type_name() -> Result<()> {
assert_eq!(Import::<CurrentNetwork>::type_name(), "import");
Ok(())
}
#[test]
fn test_import_partial_ord() -> Result<()> {
let import1 = Import::<CurrentNetwork>::from_str("import bar.aleo;")?;
let import2 = Import::<CurrentNetwork>::from_str("import foo.aleo;")?;
let import3 = Import::<CurrentNetwork>::from_str("import bar.aleo;")?;
let import4 = Import::<CurrentNetwork>::from_str("import foo.aleo;")?;
assert_eq!(import1.partial_cmp(&import1), Some(Ordering::Equal));
assert_eq!(import1.partial_cmp(&import2), Some(Ordering::Less));
assert_eq!(import1.partial_cmp(&import3), Some(Ordering::Equal));
assert_eq!(import1.partial_cmp(&import4), Some(Ordering::Less));
assert_eq!(import2.partial_cmp(&import1), Some(Ordering::Greater));
assert_eq!(import2.partial_cmp(&import2), Some(Ordering::Equal));
assert_eq!(import2.partial_cmp(&import3), Some(Ordering::Greater));
assert_eq!(import2.partial_cmp(&import4), Some(Ordering::Equal));
assert_eq!(import3.partial_cmp(&import1), Some(Ordering::Equal));
assert_eq!(import3.partial_cmp(&import2), Some(Ordering::Less));
assert_eq!(import3.partial_cmp(&import3), Some(Ordering::Equal));
assert_eq!(import3.partial_cmp(&import4), Some(Ordering::Less));
assert_eq!(import4.partial_cmp(&import1), Some(Ordering::Greater));
assert_eq!(import4.partial_cmp(&import2), Some(Ordering::Equal));
assert_eq!(import4.partial_cmp(&import3), Some(Ordering::Greater));
assert_eq!(import4.partial_cmp(&import4), Some(Ordering::Equal));
Ok(())
}
}