Commit ef6c7c41 authored by mredlek's avatar mredlek

Readd generating get_type tests

parent fb3899c5
......@@ -23,6 +23,7 @@ mod signals;
mod signatures;
mod slot_ext;
mod slots;
mod test;
mod writer;
pub use self::boilerplate::Boilerplate;
......@@ -32,6 +33,7 @@ pub use self::instance::Instance;
pub use self::interface::Interface;
pub use self::private::Private;
use self::test::Test;
use self::writer::RustWriter;
use crate::hir::Program;
......
//! This file contains the instantion of all the data that is instantiated once
//! and stored in a static variable
use gen::Test;
use crate::gen::boilerplate;
use crate::gen::boilerplateext::BoilerplateExt;
use crate::hir::{Override, OverrideItem};
......@@ -28,6 +29,7 @@ impl<'lt, 'ast: 'lt, Boilerplate: boilerplate::Boilerplate<'ast>> ToTokens
let gen_vtable_init_slots = self.gen_vtable_init_slots();
let gen_impl_vtable = self.gen_impl_vtable();
let gen_get_type = self.gen_get_type();
let gen_test_get_type = Test::new(self.boilerplate);
tokens.extend(quote!{
#gen_struct_def
......@@ -50,6 +52,8 @@ impl<'lt, 'ast: 'lt, Boilerplate: boilerplate::Boilerplate<'ast>> ToTokens
}
#gen_get_type
#gen_test_get_type
})
}
}
......
///! This file has code to generate a test to test the generated gobject type.
///! The test can find missing parents or other user error which
///! can't be collected during codegen
/// ! This file has code to generate a test to test the generated gobject type.
/// ! The test can find missing parents or other user error which
/// ! can't be collected during codegen
use gen::boilerplate;
use std::marker::PhantomData;
use proc_macro2::{TokenStream};
use proc_macro2::{Ident, TokenStream};
use quote::ToTokens;
use std::marker::PhantomData;
pub struct Test<'lt, 'ast: 'lt, Boilerplate: boilerplate::Boilerplate<'ast> + 'lt> {
boilerplate: &'lt Boilerplate,
......@@ -13,16 +12,14 @@ pub struct Test<'lt, 'ast: 'lt, Boilerplate: boilerplate::Boilerplate<'ast> + 'l
}
impl<'lt, 'ast: 'lt, Boilerplate: boilerplate::Boilerplate<'ast>> ToTokens
for Test<'lt, 'ast, Boilerplate>
for Test<'lt, 'ast, Boilerplate>
{
fn to_tokens(&self, tokens: &mut TokenStream) {
tokens.extend(self.gen_test());
}
}
impl<'lt, 'ast: 'lt, Boilerplate: boilerplate::Boilerplate<'ast>>
Test<'lt, 'ast, Boilerplate>
{
impl<'lt, 'ast: 'lt, Boilerplate: boilerplate::Boilerplate<'ast>> Test<'lt, 'ast, Boilerplate> {
pub fn new(boilerplate: &'lt Boilerplate) -> Self {
let phantom = PhantomData;
Test {
......@@ -31,12 +28,20 @@ Test<'lt, 'ast, Boilerplate>
}
}
fn gen_test(&self) -> TokenStream
{
let get_type_fn_name = self.names.get_type_fn();
let test_get_type_fn_name = Ident::new(("test_".to_owned() + self.names.get_type_fn().to_string().as_str()).as_str(), ::proc_macro2::Span::call_site());
let ancestors = self.class.ancestors.iter().map(|anc| anc.rust_type());
let name_instance = &self.names.instance();
fn gen_test(&self) -> TokenStream {
let test_get_type_fn_name = Ident::new(
("test_".to_owned() + self.boilerplate.names().get_type_fn().to_string().as_str())
.as_str(),
::proc_macro2::Span::call_site(),
);
let ancestors = self.boilerplate.ancestors().iter().filter_map(|anc| {
if anc.is_fundamental() {
None
} else {
Some(anc.instance())
}
});
let name_instance = &self.boilerplate.names().instance();
quote! {
#[test]
fn #test_get_type_fn_name()
......@@ -52,20 +57,20 @@ Test<'lt, 'ast, Boilerplate>
current = parent;
if let Some(pos) = parents.iter().position(|x| x == &current) {
parents.swap_remove(pos);
} else if current != Type::BaseObject {
} else if current != Type::BaseObject && current != Type::BaseInterface {
panic!("Unregistered parent \"{}\"", current.name());
}
}
current = <#name_instance as ::gobject_class::glib::types::StaticType>::static_type();
for interface in current.interfaces() {
if let Some(pos) = interfaces.iter().position(|x: &::glib::Type| x == &current) {
if let Some(pos) = interfaces.iter().position(|x: &::glib::Type| x == &interface) {
interfaces.swap_remove(pos);
} else {
} else if interface != ::glib::Type::BaseInterface {
panic!("Unregistered interface \"{}\"", current.name());
}
}
}
}
}
}
\ No newline at end of file
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment