@@ -3,68 +3,82 @@ use std::fs;
33
44fn main ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
55 println ! ( "=== Round-trip Verification ===\n " ) ;
6-
6+
77 // 1. Read original file
88 let original_path = "test-files/test_document.hwp" ;
99 let original_bytes = fs:: read ( original_path) ?;
1010 println ! ( "Original file size: {} bytes" , original_bytes. len( ) ) ;
11-
11+
1212 let original_doc = HwpReader :: from_file ( original_path) ?;
1313 let original_text = original_doc. extract_text ( ) ;
1414 println ! ( "Original text length: {} characters" , original_text. len( ) ) ;
1515 println ! ( "Original text hash: {:x}" , md5:: compute( & original_text) ) ;
16- println ! ( "First 200 chars: {:?}" , & original_text. chars( ) . take( 200 ) . collect:: <String >( ) ) ;
17-
16+ println ! (
17+ "First 200 chars: {:?}" ,
18+ & original_text. chars( ) . take( 200 ) . collect:: <String >( )
19+ ) ;
20+
1821 // 2. Convert to Writer and save
1922 let writer = HwpWriter :: from_document ( original_doc) ;
2023 let roundtrip_path = "verify_roundtrip.hwp" ;
2124 writer. save_to_file ( roundtrip_path) ?;
22-
25+
2326 let roundtrip_bytes = fs:: read ( roundtrip_path) ?;
2427 println ! ( "\n Roundtrip file size: {} bytes" , roundtrip_bytes. len( ) ) ;
25-
28+
2629 // 3. Read back the roundtrip file
2730 let roundtrip_doc = HwpReader :: from_file ( roundtrip_path) ?;
2831 let roundtrip_text = roundtrip_doc. extract_text ( ) ;
2932 println ! ( "Roundtrip text length: {} characters" , roundtrip_text. len( ) ) ;
3033 println ! ( "Roundtrip text hash: {:x}" , md5:: compute( & roundtrip_text) ) ;
31- println ! ( "First 200 chars: {:?}" , & roundtrip_text. chars( ) . take( 200 ) . collect:: <String >( ) ) ;
32-
34+ println ! (
35+ "First 200 chars: {:?}" ,
36+ & roundtrip_text. chars( ) . take( 200 ) . collect:: <String >( )
37+ ) ;
38+
3339 // 4. Compare character by character
3440 println ! ( "\n === Comparison ===" ) ;
3541 if original_text == roundtrip_text {
3642 println ! ( "✅ PERFECT MATCH! Every single character is identical!" ) ;
37-
43+
3844 // Additional verification
3945 let orig_chars: Vec < char > = original_text. chars ( ) . collect ( ) ;
4046 let round_chars: Vec < char > = roundtrip_text. chars ( ) . collect ( ) ;
41-
42- println ! ( "Character count: {} vs {}" , orig_chars. len( ) , round_chars. len( ) ) ;
43-
47+
48+ println ! (
49+ "Character count: {} vs {}" ,
50+ orig_chars. len( ) ,
51+ round_chars. len( )
52+ ) ;
53+
4454 // Check some random positions
4555 let positions = [ 0 , 100 , 500 , 1000 , 5000 ] ;
4656 for & pos in & positions {
4757 if pos < orig_chars. len ( ) {
48- println ! ( "Position {}: '{}' vs '{}'" ,
49- pos, orig_chars[ pos] , round_chars[ pos] ) ;
58+ println ! (
59+ "Position {}: '{}' vs '{}'" ,
60+ pos, orig_chars[ pos] , round_chars[ pos]
61+ ) ;
5062 }
5163 }
5264 } else {
5365 println ! ( "❌ Text differs!" ) ;
54-
66+
5567 // Find first difference
5668 let orig_chars: Vec < char > = original_text. chars ( ) . collect ( ) ;
5769 let round_chars: Vec < char > = roundtrip_text. chars ( ) . collect ( ) ;
58-
70+
5971 for i in 0 ..orig_chars. len ( ) . min ( round_chars. len ( ) ) {
6072 if orig_chars[ i] != round_chars[ i] {
61- println ! ( "First difference at position {}: '{}' vs '{}'" ,
62- i, orig_chars[ i] , round_chars[ i] ) ;
73+ println ! (
74+ "First difference at position {}: '{}' vs '{}'" ,
75+ i, orig_chars[ i] , round_chars[ i]
76+ ) ;
6377 break ;
6478 }
6579 }
6680 }
67-
81+
6882 Ok ( ( ) )
6983}
7084
@@ -77,4 +91,4 @@ mod md5 {
7791 data. hash ( & mut hasher) ;
7892 hasher. finish ( ) as u128
7993 }
80- }
94+ }
0 commit comments