repo_description: 💻 An assembler for custom, user-defined instruction sets! https://hlorenzi.github.io/customasm/web/
repo_topics: asm assembler assembly assembly-language bytecode bytecode-compiler compiler custom customizable instruction-set instruction-set-architecture machine-code microprocessor processor-architecture rust rust-lang user-defined virtual-machine vm webassembly
code: use crate::*;
  
  
  mod examples;
  mod excerpt;
  mod expr;
  mod file;
  mod file_navigation;
  mod lib;
  
  
  // generated by build script
  include!(concat!(env!("OUT_DIR"), "/std_files.rs"));
  
  
  pub enum ExpectedResult<T>
  {
  	Pass(T),
  	Fail((&'static str, usize, &'static str))
  }
  
  
  pub fn expect_result<T>(
  	report: &mut diagn::Report,
  	fileserver: &mut dyn util::FileServer,
  	got: Option<T>,
  	expected: ExpectedResult<T>)
  	where T: std::fmt::Debug + PartialEq
  {
  	util::enable_windows_ansi_support();
  	
  	let mut msgs = Vec::<u8>::new();
  	report.print_all(&mut msgs, fileserver, true);
  	print!("{}", String::from_utf8(msgs).unwrap());
  	
  	if let ExpectedResult::Pass(result) = expected
  	{
  		if report.has_errors()
  		{
  			panic!("expected to pass but failed");
  		}
  		
  		if got.is_none()
  		{
  			panic!("expected to pass but failed");
  		}
  		
  		if let Some(got) = got
  		{
  			if got != result
  				{ panic!("test failed\nexpected: {:?}\n     got: {:?}", result, got); }
  		}
  	}
  	
  	else if let ExpectedResult::Fail(err) = expected
  	{
  		if got.is_some()
  		{
  			panic!("expected to fail but passed\n     got: {:?}", got.unwrap());
  		}
  		
  		if !report.has_errors()
  		{
  			panic!("expected to fail but passed");
  		}
  		
  		if !report.has_first_error_at(fileserver, err.0, err.1 - 1, err.2)
  		{
  			panic!("expected a certain error but got other errors\nexpected: ({:?}, {}, {:?})", err.0, err.1, err.2);
  		}
  	}
  }