File tree Expand file tree Collapse file tree 1 file changed +24
-58
lines changed Expand file tree Collapse file tree 1 file changed +24
-58
lines changed Original file line number Diff line number Diff line change 11use self :: Suffix :: * ;
22use self :: TargetFeature :: * ;
33use std:: env;
4- use std:: fmt;
4+ use std:: fmt:: { self , Write as _ } ;
55use std:: fs:: File ;
66use std:: io:: prelude:: * ;
77use std:: io:: { self , BufReader } ;
@@ -1856,66 +1856,32 @@ fn gen_test(
18561856 1 => type_to_global_type ( out_t) . to_string ( ) ,
18571857 _ => format ! ( "[{}; {}]" , type_to_native_type( out_t) , type_len( out_t) ) ,
18581858 } ;
1859- let t = {
1860- match para_num {
1861- 1 => {
1862- format ! (
1863- r#"
1864- let a{};
1865- let e{};
1866- let r: {} = transmute({}{}(transmute(a)));
1867- assert_eq!(r, e);
1868- "# ,
1869- values( in_t[ 0 ] , & a) ,
1870- values( out_t, & e) ,
1871- r_type,
1872- name,
1873- const_value
1874- )
1875- }
1876- 2 => {
1877- format ! (
1878- r#"
1879- let a{};
1880- let b{};
1881- let e{};
1882- let r: {} = transmute({}{}(transmute(a), transmute(b)));
1883- assert_eq!(r, e);
1884- "# ,
1885- values( in_t[ 0 ] , & a) ,
1886- values( in_t[ 1 ] , & b) ,
1887- values( out_t, & e) ,
1888- r_type,
1889- name,
1890- const_value
1891- )
1892- }
1893- 3 => {
1894- format ! (
1895- r#"
1896- let a{};
1897- let b{};
1898- let c{};
1859+ let mut call_params = String :: new ( ) ;
1860+ assert ! ( matches!( para_num, 1 ..=3 ) ) ;
1861+ for i in 0 ..para_num {
1862+ let chr = char:: from ( b'a' + i as u8 ) ;
1863+ let v = match i {
1864+ 0 => & a,
1865+ 1 => & b,
1866+ 2 => & c,
1867+ _ => unreachable ! ( ) ,
1868+ } ;
1869+ write ! ( test, "\n let {chr}{};" , values( in_t[ i as usize ] , v) ) . unwrap ( ) ;
1870+ if i != 0 {
1871+ call_params. push_str ( ", " ) ;
1872+ }
1873+ write ! ( call_params, "transmute({chr})" ) . unwrap ( ) ;
1874+ }
1875+ write ! (
1876+ test,
1877+ r#"
18991878 let e{};
1900- let r: {} = transmute({}{}(transmute(a), transmute(b), transmute(c) ));
1879+ let r: {r_type } = transmute({name}{const_value}({call_params} ));
19011880 assert_eq!(r, e);
19021881"# ,
1903- values( in_t[ 0 ] , & a) ,
1904- values( in_t[ 1 ] , & b) ,
1905- values( in_t[ 2 ] , & c) ,
1906- values( out_t, & e) ,
1907- r_type,
1908- name,
1909- const_value
1910- )
1911- }
1912- _ => {
1913- panic ! ( "no support para_num:{}" , para_num. to_string( ) )
1914- }
1915- }
1916- } ;
1917-
1918- test. push_str ( & t) ;
1882+ values( out_t, & e)
1883+ )
1884+ . unwrap ( ) ;
19191885 }
19201886 test. push_str ( " }\n " ) ;
19211887 test
You can’t perform that action at this time.
0 commit comments