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
5439069c
Commit
5439069c
authored
Jul 24, 2016
by
Sehny
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tests for history indexing and truncating.
parent
de70cffe
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
2 deletions
+48
-2
src/lib.rs
src/lib.rs
+0
-2
src/test.rs
src/test.rs
+48
-0
No files found.
src/lib.rs
View file @
5439069c
#![feature(deque_extras)]
extern
crate
termion
;
extern
crate
unicode_width
;
...
...
src/test.rs
View file @
5439069c
use
super
::
*
;
use
context
;
use
std
::
env
;
use
std
::
fs
;
use
std
::
io
::{
BufReader
,
BufRead
};
fn
assert_cursor_pos
(
s
:
&
str
,
cursor
:
usize
,
expected_pos
:
CursorPosition
)
{
let
buf
=
Buffer
::
from
(
s
.to_owned
());
let
words
=
context
::
get_buffer_words
(
&
buf
);
...
...
@@ -54,3 +58,47 @@ fn test_buffer_actions() {
text
:
"."
.chars
()
.collect
(),
}]);
}
#[test]
fn
test_history_indexing
()
{
let
mut
h
=
History
::
new
();
h
.push
(
Buffer
::
from
(
"a"
))
.unwrap
();
h
.push
(
Buffer
::
from
(
"b"
))
.unwrap
();
h
.push
(
Buffer
::
from
(
"c"
))
.unwrap
();
assert_eq!
(
h
.len
(),
3
);
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
());
}
#[test]
fn
test_in_memory_history_truncating
()
{
let
mut
h
=
History
::
new
();
h
.set_max_size
(
2
);
for
_
in
0
..
4
{
h
.push
(
Buffer
::
from
(
"a"
))
.unwrap
();
}
assert_eq!
(
h
.len
(),
2
);
}
#[test]
fn
test_in_file_history_truncating
()
{
let
mut
tmp_file
=
env
::
temp_dir
();
tmp_file
.push
(
"liner_test_file123456.txt"
);
{
let
mut
h
=
History
::
new
();
h
.set_file_name
(
String
::
from
(
tmp_file
.to_string_lossy
()
.into_owned
()));
h
.set_max_file_size
(
5
);
for
_
in
0
..
20
{
h
.push
(
Buffer
::
from
(
"a"
))
.unwrap
();
}
}
let
f
=
fs
::
File
::
open
(
tmp_file
.clone
())
.unwrap
();
let
r
=
BufReader
::
new
(
f
);
let
count
=
r
.lines
()
.count
();
assert_eq!
(
count
,
5
);
fs
::
remove_file
(
tmp_file
)
.unwrap
();
}
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