Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
liner
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
stratact
liner
Commits
4d8dd37c
Commit
4d8dd37c
authored
Jul 24, 2016
by
Sehny
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test history loading
parent
ca809cc8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
6 deletions
+36
-6
src/history.rs
src/history.rs
+4
-4
src/main.rs
src/main.rs
+1
-0
src/test.rs
src/test.rs
+31
-2
No files found.
src/history.rs
View file @
4d8dd37c
...
...
@@ -61,9 +61,8 @@ impl History {
}
/// Set history file name. At the same time enable history.
pub
fn
set_file_name
(
&
mut
self
,
name
:
String
)
->
io
::
Result
<
()
>
{
pub
fn
set_file_name
(
&
mut
self
,
name
:
String
)
{
self
.file_name
=
Some
(
name
);
self
.read_history_from_file
()
}
/// Set maximal number of buffers stored in memory
...
...
@@ -76,10 +75,11 @@ impl History {
self
.max_file_size
=
size
;
}
fn
read_history_from_file
(
&
mut
self
)
->
io
::
Result
<
()
>
{
/// Load history from given file name
pub
fn
load_history
(
&
mut
self
)
->
io
::
Result
<
()
>
{
let
file_name
=
match
self
.file_name
.clone
()
{
Some
(
name
)
=>
name
,
None
=>
return
Err
(
Error
::
new
(
ErrorKind
::
Other
,
"Liner:
internal error
"
)),
None
=>
return
Err
(
Error
::
new
(
ErrorKind
::
Other
,
"Liner:
file name not specified
"
)),
};
let
file
=
try!
(
OpenOptions
::
new
()
.read
(
true
)
.open
(
file_name
));
let
reader
=
BufReader
::
new
(
file
);
...
...
src/main.rs
View file @
4d8dd37c
...
...
@@ -25,6 +25,7 @@ fn main() {
}
println!
(
"History file: {}"
,
file_name
);
con
.history
.set_file_name
(
file_name
);
con
.history
.load_history
();
loop
{
let
res
=
con
.read_line
(
"[prompt]$ "
,
...
...
src/test.rs
View file @
4d8dd37c
...
...
@@ -3,7 +3,7 @@ use context;
use
std
::
env
;
use
std
::
fs
;
use
std
::
io
::{
BufReader
,
BufRead
};
use
std
::
io
::{
BufReader
,
BufRead
,
Write
};
fn
assert_cursor_pos
(
s
:
&
str
,
cursor
:
usize
,
expected_pos
:
CursorPosition
)
{
let
buf
=
Buffer
::
from
(
s
.to_owned
());
...
...
@@ -84,7 +84,7 @@ fn test_in_memory_history_truncating() {
#[test]
fn
test_in_file_history_truncating
()
{
let
mut
tmp_file
=
env
::
temp_dir
();
tmp_file
.push
(
"liner_test_file123
456
.txt"
);
tmp_file
.push
(
"liner_test_file123.txt"
);
{
let
mut
h
=
History
::
new
();
...
...
@@ -102,3 +102,32 @@ fn test_in_file_history_truncating() {
fs
::
remove_file
(
tmp_file
)
.unwrap
();
}
static
TEXT
:
&
'static
str
=
"a
b
c
d
"
;
#[test]
fn
test_reading_from_file
()
{
let
mut
tmp_file
=
env
::
temp_dir
();
tmp_file
.push
(
"liner_test_file456.txt"
);
{
let
mut
f
=
fs
::
OpenOptions
::
new
()
.read
(
true
)
.write
(
true
)
.create
(
true
)
.open
(
tmp_file
.clone
())
.unwrap
();
f
.write_all
(
TEXT
.as_bytes
())
.unwrap
();
}
let
mut
h
=
History
::
new
();
h
.set_file_name
(
String
::
from
(
tmp_file
.to_string_lossy
()
.into_owned
()));
let
_
=
h
.load_history
();
assert_eq!
(
String
::
from
(
h
.buffers
[
0
]
.clone
()),
"a"
.to_string
());
assert_eq!
(
String
::
from
(
h
.buffers
[
1
]
.clone
()),
"b"
.to_string
());
assert_eq!
(
String
::
from
(
h
.buffers
[
2
]
.clone
()),
"c"
.to_string
());
assert_eq!
(
String
::
from
(
h
.buffers
[
3
]
.clone
()),
"d"
.to_string
());
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment