Skip to content

Commit ffdcd63

Browse files
committed
Simplify CI and formatting configuration
1 parent 932ad28 commit ffdcd63

File tree

10 files changed

+77
-194
lines changed

10 files changed

+77
-194
lines changed

.github/workflows/ci.yml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: Continuous integration
2+
on: [push, pull_request]
3+
4+
jobs:
5+
ci:
6+
runs-on: ubuntu-latest
7+
steps:
8+
- uses: actions/checkout@v3
9+
- uses: dtolnay/rust-toolchain@stable
10+
- run: cargo build
11+
- run: cargo test

.github/workflows/rust.yml

-35
This file was deleted.

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/target
22
Cargo.lock
33
bench/target
4+
.DS_Store

rustfmt.toml

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
unstable_features = true
2-
3-
overflow_delimited_expr = true
4-
spaces_around_ranges = true
5-
use_field_init_shorthand = true
6-
1+
use_small_heuristics = "Max"
72
max_width = 90
8-
struct_lit_width = 40
93
chain_width = 70
10-
single_line_if_else_max_width = 60
4+
struct_lit_width = 50
5+
use_field_init_shorthand = true
6+
merge_derives = false

src/chunk.rs

+19-26
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ impl ChunksExt for [Spanned<Chunk>] {
150150
fn span(&self) -> Span {
151151
let start = self.first().map(|c| c.span.start).unwrap_or(0);
152152
let end = self.last().map(|c| c.span.end).unwrap_or(start);
153-
start .. end
153+
start..end
154154
}
155155

156156
fn to_biblatex_string(&self, is_verbatim: bool) -> String {
@@ -181,7 +181,7 @@ impl ChunksExt for [Spanned<Chunk>] {
181181
}
182182
}
183183

184-
for _ in 0 .. if extra_brace { 2 } else { 1 } {
184+
for _ in 0..if extra_brace { 2 } else { 1 } {
185185
res.push('}');
186186
}
187187

@@ -210,7 +210,7 @@ pub(crate) fn join_chunk_list(chunks: ChunksRef, sep: &str) -> Chunks {
210210
} else {
211211
res.push(Spanned::new(
212212
Chunk::Normal(sep.to_string()),
213-
chunk.span.start .. chunk.span.start,
213+
chunk.span.start..chunk.span.start,
214214
));
215215
}
216216

@@ -234,20 +234,20 @@ pub(crate) fn split_token_lists(vals: ChunksRef, keyword: &str) -> Vec<Chunks> {
234234
let mut start = val.span.start;
235235

236236
while let Some(pos) = target.find(keyword) {
237-
let first = target[.. pos].trim_end();
237+
let first = target[..pos].trim_end();
238238
latest.push(Spanned::new(
239239
Chunk::Normal(first.to_string()),
240-
start .. start + pos,
240+
start..start + pos,
241241
));
242242
out.push(std::mem::take(&mut latest));
243243

244-
target = target[pos + keyword.len() ..].trim_start();
244+
target = target[pos + keyword.len()..].trim_start();
245245
start += pos + keyword.len();
246246
}
247247

248248
latest.push(Spanned::new(
249249
Chunk::Normal(target.to_string()),
250-
start .. val.span.end,
250+
start..val.span.end,
251251
));
252252
} else {
253253
latest.push(val.clone());
@@ -308,7 +308,7 @@ pub(crate) fn split_values(
308308
}
309309

310310
if chunk_idx + 1 < src.len() {
311-
new.extend(src.drain(chunk_idx + 1 ..));
311+
new.extend(src.drain(chunk_idx + 1..));
312312
}
313313

314314
let item = src.last_mut().unwrap();
@@ -317,8 +317,8 @@ pub(crate) fn split_values(
317317
let (s1, s2) = content.split_at(str_idx);
318318

319319
let boundry = item.span.start.saturating_add(str_idx);
320-
item.span = item.span.start .. boundry;
321-
let new_span = boundry .. boundry.saturating_add(s2.len());
320+
item.span = item.span.start..boundry;
321+
let new_span = boundry..boundry.saturating_add(s2.len());
322322

323323
let s1 = s1.trim_end().to_string();
324324
let s2 = s2.trim_start().to_string();
@@ -364,13 +364,9 @@ pub(crate) mod tests {
364364

365365
#[test]
366366
fn test_split() {
367-
let vls = &[
368-
s(N("split "), 1 .. 7),
369-
s(V("exac^tly"), 9 .. 17),
370-
s(N("here"), 19 .. 23),
371-
];
372-
let ref1 = &[s(N("split "), 1 .. 7), s(V("exac^"), 9 .. 14)];
373-
let ref2 = &[s(V("tly"), 14 .. 17), s(N("here"), 19 .. 23)];
367+
let vls = &[s(N("split "), 1..7), s(V("exac^tly"), 9..17), s(N("here"), 19..23)];
368+
let ref1 = &[s(N("split "), 1..7), s(V("exac^"), 9..14)];
369+
let ref2 = &[s(V("tly"), 14..17), s(N("here"), 19..23)];
374370

375371
let split = split_values(vls, 1, 5);
376372
assert_eq!(split.0, ref1);
@@ -380,16 +376,13 @@ pub(crate) mod tests {
380376
#[test]
381377
fn test_split_at_normal_char() {
382378
let vls = &[
383-
s(N("split "), 1 .. 7),
384-
s(V("not, "), 9 .. 14),
385-
s(N("but rather, here"), 16 .. 32),
386-
];
387-
let ref1 = &[
388-
s(N("split "), 1 .. 7),
389-
s(V("not, "), 9 .. 14),
390-
s(N("but rather"), 16 .. 26),
379+
s(N("split "), 1..7),
380+
s(V("not, "), 9..14),
381+
s(N("but rather, here"), 16..32),
391382
];
392-
let ref2 = &[s(N("here"), 28 .. 32)];
383+
let ref1 =
384+
&[s(N("split "), 1..7), s(V("not, "), 9..14), s(N("but rather"), 16..26)];
385+
let ref2 = &[s(N("here"), 28..32)];
393386

394387
let split = split_at_normal_char(vls, ',', true);
395388
assert_eq!(split.0, ref1);

src/lib.rs

+7-29
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,7 @@ fn convert_result<T>(err: Result<T, RetrievalError>) -> Result<Option<T>, TypeEr
103103
impl Bibliography {
104104
/// Create a new, empty bibliography.
105105
pub fn new() -> Self {
106-
Self {
107-
entries: Vec::new(),
108-
keys: BTreeMap::new(),
109-
}
106+
Self { entries: Vec::new(), keys: BTreeMap::new() }
110107
}
111108

112109
/// Parse a bibliography from a source string.
@@ -266,11 +263,7 @@ impl Bibliography {
266263
if !first {
267264
write!(sink, "\n")?;
268265
}
269-
writeln!(
270-
sink,
271-
"{}",
272-
entry.to_bibtex_string().map_err(|_| fmt::Error)?
273-
)?;
266+
writeln!(sink, "{}", entry.to_bibtex_string().map_err(|_| fmt::Error)?)?;
274267
first = false;
275268
}
276269
Ok(())
@@ -995,10 +988,7 @@ mod tests {
995988
let rashid = bibliography.get("rashid2016").unwrap();
996989
match rashid.pagination() {
997990
Err(RetrievalError::TypeError(s)) => {
998-
assert_eq!(
999-
s,
1000-
TypeError::new(352..359, TypeErrorKind::UnknownPagination)
1001-
);
991+
assert_eq!(s, TypeError::new(352..359, TypeErrorKind::UnknownPagination));
1002992
}
1003993
_ => {
1004994
panic!()
@@ -1099,14 +1089,8 @@ mod tests {
10991089
let contents = fs::read_to_string("tests/cross.bib").unwrap();
11001090
let mut bibliography = Bibliography::parse(&contents).unwrap();
11011091

1102-
assert_eq!(
1103-
bibliography.get_mut("haug2019").unwrap().verify().is_ok(),
1104-
true
1105-
);
1106-
assert_eq!(
1107-
bibliography.get_mut("cannonfodder").unwrap().verify().is_ok(),
1108-
true
1109-
);
1092+
assert_eq!(bibliography.get_mut("haug2019").unwrap().verify().is_ok(), true);
1093+
assert_eq!(bibliography.get_mut("cannonfodder").unwrap().verify().is_ok(), true);
11101094

11111095
let ill = bibliography.get("ill-defined").unwrap();
11121096
let report = ill.verify();
@@ -1129,17 +1113,11 @@ mod tests {
11291113

11301114
let e = bibliography.get("macmillan").unwrap();
11311115
assert_eq!(e.publisher().unwrap()[0].format_verbatim(), "Macmillan");
1132-
assert_eq!(
1133-
e.location().unwrap().format_verbatim(),
1134-
"New York and London"
1135-
);
1116+
assert_eq!(e.location().unwrap().format_verbatim(), "New York and London");
11361117

11371118
let book = bibliography.get("recursive").unwrap();
11381119
assert_eq!(book.publisher().unwrap()[0].format_verbatim(), "Macmillan");
1139-
assert_eq!(
1140-
book.location().unwrap().format_verbatim(),
1141-
"New York and London"
1142-
);
1120+
assert_eq!(book.location().unwrap().format_verbatim(), "New York and London");
11431121
assert_eq!(
11441122
book.title().unwrap().format_verbatim(),
11451123
"Recursive shennenigans and other important stuff"

src/raw.rs

+8-21
Original file line numberDiff line numberDiff line change
@@ -190,22 +190,16 @@ impl<'s> BiblatexParser<'s> {
190190

191191
/// Eat a delimiter.
192192
fn brace(&mut self, open: bool) -> Result<(), ParseError> {
193-
let (brace, token) = if open {
194-
('{', Token::OpeningBrace)
195-
} else {
196-
('}', Token::ClosingBrace)
197-
};
193+
let (brace, token) =
194+
if open { ('{', Token::OpeningBrace) } else { ('}', Token::ClosingBrace) };
198195

199196
let peeked = self.s.peek();
200197

201198
if peeked == Some(brace) || peeked == Some('\"') {
202199
self.s.eat();
203200
Ok(())
204201
} else {
205-
Err(ParseError::new(
206-
self.here(),
207-
ParseErrorKind::Expected(token),
208-
))
202+
Err(ParseError::new(self.here(), ParseErrorKind::Expected(token)))
209203
}
210204
}
211205

@@ -224,10 +218,7 @@ impl<'s> BiblatexParser<'s> {
224218
/// Eat an equals sign.
225219
fn equals(&mut self) -> Result<(), ParseError> {
226220
if !self.s.eat_if('=') {
227-
Err(ParseError::new(
228-
self.here(),
229-
ParseErrorKind::Expected(Token::Equals),
230-
))
221+
Err(ParseError::new(self.here(), ParseErrorKind::Expected(Token::Equals)))
231222
} else {
232223
Ok(())
233224
}
@@ -433,10 +424,7 @@ impl<'s> BiblatexParser<'s> {
433424
self.s.eat_while(is_id_continue);
434425
Ok(Spanned::new(self.s.from(idx), idx..self.s.cursor()))
435426
} else {
436-
Err(ParseError::new(
437-
self.here(),
438-
ParseErrorKind::Expected(Token::Identifier),
439-
))
427+
Err(ParseError::new(self.here(), ParseErrorKind::Expected(Token::Identifier)))
440428
}
441429
}
442430

@@ -495,10 +483,9 @@ impl<'s> BiblatexParser<'s> {
495483
self.s.eat_whitespace();
496484
let fields = self.fields()?;
497485

498-
self.res.entries.push(Spanned::new(
499-
RawEntry { key, kind, fields },
500-
start..self.s.cursor(),
501-
));
486+
self.res
487+
.entries
488+
.push(Spanned::new(RawEntry { key, kind, fields }, start..self.s.cursor()));
502489
Ok(())
503490
}
504491

0 commit comments

Comments
 (0)