1 //! A module used to test codegen. 2 //! 3 //! This imports a single codegen output; while modifying the codegen crate, 4 //! this file can be regenerated to check that changes compile, without needing 5 //! to rebuild everything. 6 //! 7 //! To rebuild this input and test it, run: 8 //! 9 //! $ cargo run --bin=codegen resources/test_plan.toml && cargo test 10 11 pub mod records { 12 include!("../generated/generated_test_records.rs"); 13 } 14 15 pub mod formats { 16 include!("../generated/generated_test_formats.rs"); 17 } 18 19 pub mod offsets_arrays { 20 include!("../generated/generated_test_offsets_arrays.rs"); 21 22 #[test] array_offsets()23 fn array_offsets() { 24 let builder = crate::test_helpers::BeBuffer::new() 25 .push(MajorMinor::VERSION_1_0) 26 .push(12_u16) // offset to 0xdead 27 .push(0u16) // nullable 28 .push(2u16) // array len 29 .push(12u16) // array offset 30 .extend([0xdead_u16, 0xbeef]); 31 32 let table = KindsOfOffsets::read(builder.font_data()).unwrap(); 33 assert_eq!(table.nonnullable().unwrap().value(), 0xdead); 34 35 let array = table.array().unwrap(); 36 assert_eq!(array, &[0xdead, 0xbeef]); 37 } 38 } 39 40 pub mod flags { 41 include!("../generated/generated_test_flags.rs"); 42 43 #[test] basics()44 fn basics() { 45 let all = ValueFormat::all(); 46 let none = ValueFormat::empty(); 47 assert!(all.contains(ValueFormat::X_PLACEMENT)); 48 assert!(all.contains(ValueFormat::Y_PLACEMENT)); 49 assert!(!none.contains(ValueFormat::X_PLACEMENT)); 50 assert!(!none.contains(ValueFormat::Y_PLACEMENT)); 51 assert_eq!(none, ValueFormat::default()); 52 } 53 54 #[test] formatting()55 fn formatting() { 56 let all = ValueFormat::all(); 57 assert_eq!(format!("{all:?}"), "X_PLACEMENT | Y_PLACEMENT"); 58 let none = ValueFormat::empty(); 59 assert_eq!(format!("{none:?}"), "(empty)"); 60 let xplace = ValueFormat::X_PLACEMENT; 61 assert_eq!(format!("{xplace:?}"), "X_PLACEMENT"); 62 } 63 64 // not exactly a test, but this will fail to compile if these are missing 65 #[test] impl_traits()66 fn impl_traits() { 67 fn impl_check<T: Copy + std::hash::Hash + Eq + Ord>() {} 68 impl_check::<ValueFormat>(); 69 } 70 } 71 72 pub mod enums { 73 include!("../generated/generated_test_enum.rs"); 74 } 75 76 pub mod count_all { 77 use crate::FontData; 78 79 include!("../generated/generated_test_count_all.rs"); 80 81 /// Test for count(..) with element sizes > 1 82 #[test] element_size_greater_than_one_with_padding()83 fn element_size_greater_than_one_with_padding() { 84 // Size of 13 ensures we have an extra padding byte 85 let bytes = [0u8; 13]; 86 // Generated table has a 2 byte field above the array 87 let remainder_len = bytes.len() - 2; 88 let data = FontData::new(&bytes); 89 // Trailing array with 16-bit elements 90 assert!(remainder_len % 2 != 0); 91 let count16 = CountAll16::read(data).unwrap(); 92 assert_eq!(count16.remainder().len(), remainder_len / 2); 93 // Trailing array with 32-bit elements 94 assert!(remainder_len % 4 != 0); 95 let count32 = CountAll32::read(data).unwrap(); 96 assert_eq!(count32.remainder().len(), remainder_len / 4); 97 } 98 } 99