Skip to content

Commit

Permalink
add test for BOM removal
Browse files Browse the repository at this point in the history
  • Loading branch information
finnboeger committed Jan 3, 2021
1 parent e83406f commit e86c69d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ error_chain! {
}
}

fn read_file_to_string<P: AsRef<Path>>(p: P) -> Result<String> {
#[doc(hidden)]
pub fn read_file_to_string<P: AsRef<Path>>(p: P) -> Result<String> {
let p = p.as_ref();
let mut f = File::open(p).chain_err(|| ErrorKind::IOError)?;
let mut reader: Vec<u8> = Vec::new();
Expand Down
8 changes: 8 additions & 0 deletions tests/txt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ extern crate ultrastar_txt;
use std::collections::HashMap;
use std::path::PathBuf;
use ultrastar_txt::*;
use std::path::Path;

// usage:
// assert_error_kind!(some_err, ErrorKind::MyErrorType)
Expand Down Expand Up @@ -346,6 +347,13 @@ fn relative_line_breaks() {
assert_eq!(lines[1].rel.unwrap(), 24);
}

#[test]
fn encoding_utf8_bom() {
let txt = read_file_to_string(Path::new("tests/txts/encoding_utf8_bom.txt")).unwrap();
let header = get_simple_txt_header();
assert_eq!(header, parse_txt_header_str(&txt).unwrap());
}

fn get_simple_txt_str() -> &'static str {
include_str!("txts/simple_txt_with_all_features.txt")
}
Expand Down
26 changes: 26 additions & 0 deletions tests/txts/encoding_utf8_bom.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#TITLE:Testsong
#ARTIST:Testartist
#MP3:Testfile.mp3
#GAP:666
#BPM:123
#GENRE:Music
#EDITION:Testmusic
#COVER:Cover.jpg
#BACKGROUND:BG.jpg
#VIDEO:DLzxrzFCyOs.mp4
#VIDEOGAP:777
#RELATIVE:NO
#LANGUAGE:en
#YEAR:1337
: 0 4 59 Test
: 4 4 59 I
: 8 4 59 'm
* 12 4 59 test
: 16 4 59 ing.
- 20
: 24 4 59 Test
: 28 4 59 I
: 32 4 59 'm
F 36 4 59 test
F 40 4 59 ing.
E

0 comments on commit e86c69d

Please sign in to comment.