2023-04-19 02:38:18 +00:00
use std ::env ;
use std ::fs ::File ;
use std ::io ::Write ;
use std ::path ::Path ;
2023-04-23 01:45:18 +00:00
2023-04-19 02:38:18 +00:00
use walkdir ::WalkDir ;
fn main ( ) {
let out_dir = env ::var ( " OUT_DIR " ) . unwrap ( ) ;
let destination = Path ::new ( & out_dir ) . join ( " tests.rs " ) ;
let mut test_file = File ::create ( & destination ) . unwrap ( ) ;
write_header ( & mut test_file ) ;
let test_files = WalkDir ::new ( " org_mode_samples " )
. into_iter ( )
. filter ( | e | match e {
Ok ( dir_entry ) = > {
dir_entry . file_type ( ) . is_file ( )
& & Path ::new ( dir_entry . file_name ( ) )
. extension ( )
. map ( | ext | ext . to_ascii_lowercase ( ) = = " org " )
. unwrap_or ( false )
}
Err ( _ ) = > true ,
2023-04-19 18:40:10 +00:00
} )
. collect ::< Result < Vec < _ > , _ > > ( )
. unwrap ( ) ;
2023-04-19 02:38:18 +00:00
for test in test_files {
write_test ( & mut test_file , & test ) ;
}
}
fn write_test ( test_file : & mut File , test : & walkdir ::DirEntry ) {
2023-04-19 18:40:10 +00:00
let test_name = test
. path ( )
. strip_prefix ( " org_mode_samples/ " )
. expect ( " Paths should be under org_mode_samples/ " )
. to_string_lossy ( )
. to_lowercase ( )
. strip_suffix ( " .org " )
. expect ( " Should have .org extension " )
. replace ( " / " , " _ " ) ;
2023-04-19 02:38:18 +00:00
2023-04-21 22:42:31 +00:00
if let Some ( _reason ) = is_expect_fail ( test_name . as_str ( ) ) {
2023-04-19 18:40:10 +00:00
write! ( test_file , " #[ignore] \n " ) . unwrap ( ) ;
}
2023-04-19 02:38:18 +00:00
write! (
test_file ,
include_str! ( " ./tests/test_template " ) ,
name = test_name ,
path = test . path ( ) . display ( )
)
. unwrap ( ) ;
}
fn write_header ( test_file : & mut File ) {
write! (
test_file ,
r #"
2023-07-14 04:25:17 +00:00
#[ feature(exit_status_error) ]
2023-04-19 02:38:18 +00:00
use organic ::compare_document ;
2023-04-21 22:57:38 +00:00
use organic ::parser ::document ;
2023-04-19 02:38:18 +00:00
use organic ::emacs_parse_org_document ;
2023-04-22 00:53:55 +00:00
use organic ::parser ::sexp ::sexp_with_padding ;
2023-04-19 02:38:18 +00:00
" #
)
. unwrap ( ) ;
}
2023-04-19 18:40:10 +00:00
fn is_expect_fail ( name : & str ) -> Option < & str > {
match name {
" drawer_drawer_with_headline_inside " = > Some ( " Apparently lines with :end: become their own paragraph. This odd behavior needs to be investigated more. " ) ,
2023-04-22 02:52:57 +00:00
" element_container_priority_footnote_definition_dynamic_block " = > Some ( " Apparently broken begin lines become their own paragraph. " ) ,
2023-04-22 22:31:40 +00:00
" element_container_priority_drawer_greater_block " = > Some ( " Need to implement subscript. " ) ,
" element_container_priority_dynamic_block_greater_block " = > Some ( " Need to implement subscript. " ) ,
" element_container_priority_footnote_definition_greater_block " = > Some ( " Need to implement subscript. " ) ,
" element_container_priority_greater_block_greater_block " = > Some ( " Need to implement subscript. " ) ,
" element_container_priority_section_greater_block " = > Some ( " Need to implement subscript. " ) ,
" paragraphs_paragraph_with_backslash_line_breaks " = > Some ( " The text we're getting out of the parse tree is already processed to remove line breaks, so our comparison needs to take that into account. " ) ,
2023-07-13 20:52:33 +00:00
" radio_link_before_and_after " = > Some ( " Matching the contents of radio targets not yet implemented. " ) ,
" radio_link_simple " = > Some ( " Matching the contents of radio targets not yet implemented. " ) ,
2023-07-14 22:36:25 +00:00
" radio_link_identical_or_semantically_identical " = > Some ( " Would require having the 2-pass parsing implemented. " ) ,
2023-04-19 18:40:10 +00:00
_ = > None ,
}
}