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} ;
2
3
use Span ;
3
4
use span:: { Row , Column } ;
4
5
use std:: path:: { Path , PathBuf } ;
@@ -8,20 +9,25 @@ struct MockFileLoader;
8
9
impl FileLoader for MockFileLoader {
9
10
fn read < U > ( file_name : & Path ) -> Result < File < U > , Error > {
10
11
let text = format ! ( "{}\n Hello\n World\n Hello, World!\n " , file_name. display( ) ) ;
11
- Ok ( File {
12
+ let text_file = TextFile {
12
13
line_indices : make_line_indices ( & text) ,
13
14
text : text,
14
15
changed : false ,
16
+ } ;
17
+ Ok ( File {
18
+ kind : FileKind :: Text ( text_file) ,
15
19
user_data : None ,
16
20
} )
17
21
}
18
22
19
23
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\n Hfooo\n World\n Hello, 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\n Hfooo\n World\n Hello, World!\n " ) ;
29
+ }
23
30
}
24
-
25
31
Ok ( ( ) )
26
32
}
27
33
}
@@ -120,21 +126,23 @@ fn test_changes(with_len: bool) {
120
126
vfs. on_changes ( & [ make_change ( with_len) ] ) . unwrap ( ) ;
121
127
let files = vfs. get_cached_files ( ) ;
122
128
assert ! ( files. len( ) == 1 ) ;
123
- assert ! ( files[ & PathBuf :: from( "foo" ) ] == "foo\n Hfooo\n World\n Hello, World!\n " ) ;
124
- assert ! (
125
- vfs. load_file( & Path :: new( "foo" ) ) == Ok ( "foo\n Hfooo\n World\n Hello, World!\n " . to_owned( ) )
129
+ assert_eq ! ( files[ & PathBuf :: from( "foo" ) ] , "foo\n Hfooo\n World\n Hello, World!\n " ) ;
130
+ assert_eq ! (
131
+ vfs. load_file( & Path :: new( "foo" ) ) . unwrap( ) ,
132
+ FileContents :: Text ( "foo\n Hfooo\n World\n Hello, World!\n " . to_owned( ) ) ,
126
133
) ;
127
- assert ! (
128
- vfs. load_file( & Path :: new( "bar" ) ) == Ok ( "bar\n Hello\n World\n Hello, World!\n " . to_owned( ) )
134
+ assert_eq ! (
135
+ vfs. load_file( & Path :: new( "bar" ) ) . unwrap( ) ,
136
+ FileContents :: Text ( "bar\n Hello\n World\n Hello, World!\n " . to_owned( ) ) ,
129
137
) ;
130
138
131
139
vfs. on_changes ( & [ make_change_2 ( with_len) ] ) . unwrap ( ) ;
132
140
let files = vfs. get_cached_files ( ) ;
133
141
assert ! ( files. len( ) == 2 ) ;
134
- assert ! ( files[ & PathBuf :: from( "foo" ) ] == "foo\n Hfooo\n Worlaye carumballo, World!\n " ) ;
135
- assert ! (
136
- vfs. load_file( & Path :: new( "foo" ) ) ==
137
- Ok ( "foo\n Hfooo\n Worlaye carumballo, World!\n " . to_owned( ) )
142
+ assert_eq ! ( files[ & PathBuf :: from( "foo" ) ] , "foo\n Hfooo\n Worlaye carumballo, World!\n " ) ;
143
+ assert_eq ! (
144
+ vfs. load_file( & Path :: new( "foo" ) ) . unwrap ( ) ,
145
+ FileContents :: Text ( "foo\n Hfooo\n Worlaye carumballo, World!\n " . to_owned( ) ) ,
138
146
) ;
139
147
}
140
148
@@ -197,7 +205,7 @@ fn test_user_data(with_len: bool) {
197
205
198
206
// compute and read data.
199
207
vfs. with_user_data ( & Path :: new ( "foo" ) , |u| {
200
- assert_eq ! ( u. as_ref( ) . unwrap( ) . 0 , "foo\n Hello\n World\n Hello, World!\n " ) ;
208
+ assert_eq ! ( u. as_ref( ) . unwrap( ) . 0 , Some ( "foo\n Hello\n World\n Hello, World!\n " ) ) ;
201
209
* u. unwrap ( ) . 1 = 43 ;
202
210
Ok ( ( ) )
203
211
} ) . unwrap ( ) ;
0 commit comments