File tree Expand file tree Collapse file tree 2 files changed +48
-1
lines changed
Expand file tree Collapse file tree 2 files changed +48
-1
lines changed Original file line number Diff line number Diff line change 2525 - name : Test
2626 run : cargo test
2727
28+ rust-book :
29+ name : Test with Rust Book
30+ runs-on : ubuntu-latest
31+ steps :
32+ - name : Checkout repository
33+ uses : actions/checkout@v3
34+
35+ - uses : Swatinem/rust-cache@v2
36+ with :
37+ save-if : ${{ github.ref == 'refs/heads/main' }}
38+
39+ - name : Install tools
40+ run : |
41+ sudo apt install gettext
42+ # Debug builds are fine and slightly faster.
43+ cargo install --debug --path i18n-helpers
44+ cargo install --debug --locked --version 0.4.35 mdbook
45+
46+ - name : Checkout Rust Book
47+ uses : actions/checkout@v4
48+ with :
49+ repository : rust-lang/book
50+ # Update the commit hash once in a while to test newer
51+ # versions.
52+ ref : 5b6c1ceaa62ecbd6caef08df39b33b3938e99deb
53+ path : rust-book
54+
55+ - name : Test extracting text from Rust Book
56+ working-directory : rust-book
57+ run : |
58+ MDBOOK_OUTPUT='{"xgettext": {"pot-file": "messages.pot"}}' mdbook build -d po
59+ msgfmt -o /dev/null --statistics po/messages.pot
60+
2861 fuzz :
2962 name : Fuzz test
3063 runs-on : ubuntu-latest
Original file line number Diff line number Diff line change @@ -463,7 +463,11 @@ pub fn extract_messages(document: &str) -> Vec<(usize, String)> {
463463 Group :: Translate ( events) => {
464464 if let Some ( ( lineno, _) ) = events. first ( ) {
465465 let ( text, new_state) = reconstruct_markdown ( events, state) ;
466- messages. push ( ( * lineno, text) ) ;
466+ // Skip empty messages since they are special:
467+ // they contains the PO file metadata.
468+ if !text. trim ( ) . is_empty ( ) {
469+ messages. push ( ( * lineno, text) ) ;
470+ }
467471 state = Some ( new_state) ;
468472 }
469473 }
@@ -688,6 +692,16 @@ mod tests {
688692 assert_extract_messages ( "" , vec ! [ ] ) ;
689693 }
690694
695+ #[ test]
696+ fn extract_messages_empty_html ( ) {
697+ assert_extract_messages ( "<span></span>" , vec ! [ ] ) ;
698+ }
699+
700+ #[ test]
701+ fn extract_messages_whitespace_only ( ) {
702+ assert_extract_messages ( "<span> </span>" , vec ! [ ] ) ;
703+ }
704+
691705 #[ test]
692706 fn extract_messages_single_line ( ) {
693707 assert_extract_messages ( "This is a paragraph." , vec ! [ ( 1 , "This is a paragraph." ) ] ) ;
You can’t perform that action at this time.
0 commit comments