Skip to content
This repository was archived by the owner on Mar 1, 2019. It is now read-only.

Commit 127acfe

Browse files
authored
Merge pull request #19 from kngwyu/fix-test
Fix test
2 parents b432dbf + 079bc77 commit 127acfe

File tree

1 file changed

+24
-16
lines changed

1 file changed

+24
-16
lines changed

src/test.rs

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
use super::{VfsInternal, Change, FileLoader, File, Error, make_line_indices};
1+
use super::{VfsInternal, Change, FileLoader, File, FileKind, FileContents,
2+
Error, TextFile, make_line_indices};
23
use Span;
34
use span::{Row, Column};
45
use std::path::{Path, PathBuf};
@@ -8,20 +9,25 @@ struct MockFileLoader;
89
impl FileLoader for MockFileLoader {
910
fn read<U>(file_name: &Path) -> Result<File<U>, Error> {
1011
let text = format!("{}\nHello\nWorld\nHello, World!\n", file_name.display());
11-
Ok(File {
12+
let text_file = TextFile {
1213
line_indices: make_line_indices(&text),
1314
text: text,
1415
changed: false,
16+
};
17+
Ok(File {
18+
kind: FileKind::Text(text_file),
1519
user_data: None,
1620
})
1721
}
1822

1923
fn write(file_name: &Path, file: &FileKind) -> Result<(), Error> {
20-
if file_name.display().to_string() == "foo" {
21-
assert_eq!(file.changed, true);
22-
assert_eq!(file.text, "foo\nHfooo\nWorld\nHello, World!\n");
24+
if let FileKind::Text(ref text_file) = *file {
25+
if file_name.display().to_string() == "foo" {
26+
// TODO: is this test useful still?
27+
assert_eq!(text_file.changed, false);
28+
assert_eq!(text_file.text, "foo\nHfooo\nWorld\nHello, World!\n");
29+
}
2330
}
24-
2531
Ok(())
2632
}
2733
}
@@ -120,21 +126,23 @@ fn test_changes(with_len: bool) {
120126
vfs.on_changes(&[make_change(with_len)]).unwrap();
121127
let files = vfs.get_cached_files();
122128
assert!(files.len() == 1);
123-
assert!(files[&PathBuf::from("foo")] == "foo\nHfooo\nWorld\nHello, World!\n");
124-
assert!(
125-
vfs.load_file(&Path::new("foo")) == Ok("foo\nHfooo\nWorld\nHello, World!\n".to_owned())
129+
assert_eq!(files[&PathBuf::from("foo")], "foo\nHfooo\nWorld\nHello, World!\n");
130+
assert_eq!(
131+
vfs.load_file(&Path::new("foo")).unwrap(),
132+
FileContents::Text("foo\nHfooo\nWorld\nHello, World!\n".to_owned()),
126133
);
127-
assert!(
128-
vfs.load_file(&Path::new("bar")) == Ok("bar\nHello\nWorld\nHello, World!\n".to_owned())
134+
assert_eq!(
135+
vfs.load_file(&Path::new("bar")).unwrap(),
136+
FileContents::Text("bar\nHello\nWorld\nHello, World!\n".to_owned()),
129137
);
130138

131139
vfs.on_changes(&[make_change_2(with_len)]).unwrap();
132140
let files = vfs.get_cached_files();
133141
assert!(files.len() == 2);
134-
assert!(files[&PathBuf::from("foo")] == "foo\nHfooo\nWorlaye carumballo, World!\n");
135-
assert!(
136-
vfs.load_file(&Path::new("foo")) ==
137-
Ok("foo\nHfooo\nWorlaye carumballo, World!\n".to_owned())
142+
assert_eq!(files[&PathBuf::from("foo")], "foo\nHfooo\nWorlaye carumballo, World!\n");
143+
assert_eq!(
144+
vfs.load_file(&Path::new("foo")).unwrap(),
145+
FileContents::Text("foo\nHfooo\nWorlaye carumballo, World!\n".to_owned()),
138146
);
139147
}
140148

@@ -197,7 +205,7 @@ fn test_user_data(with_len: bool) {
197205

198206
// compute and read data.
199207
vfs.with_user_data(&Path::new("foo"), |u| {
200-
assert_eq!(u.as_ref().unwrap().0, "foo\nHello\nWorld\nHello, World!\n");
208+
assert_eq!(u.as_ref().unwrap().0, Some("foo\nHello\nWorld\nHello, World!\n"));
201209
*u.unwrap().1 = 43;
202210
Ok(())
203211
}).unwrap();

0 commit comments

Comments
 (0)