Skip to content

Commit 6031354

Browse files
committed
refactor tests
1 parent d3599e5 commit 6031354

1 file changed

Lines changed: 4 additions & 60 deletions

File tree

src/parser.rs

Lines changed: 4 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -418,15 +418,7 @@ mod tests {
418418
let parser = make_test_parser();
419419
let cards = parser.parse(input)?;
420420

421-
assert_eq!(cards.len(), 1);
422-
match &cards[0].content() {
423-
CardContent::Cloze { text, start, end } => {
424-
assert_eq!(text, "Foo bar baz.");
425-
assert_eq!(*start, 4);
426-
assert_eq!(*end, 6);
427-
}
428-
_ => panic!("Expected cloze card"),
429-
}
421+
assert_cloze(&cards, "Foo bar baz.", &[(4, 6)]);
430422
Ok(())
431423
}
432424

@@ -436,23 +428,7 @@ mod tests {
436428
let parser = make_test_parser();
437429
let cards = parser.parse(input)?;
438430

439-
assert_eq!(cards.len(), 2);
440-
match &cards[0].content() {
441-
CardContent::Cloze { text, start, end } => {
442-
assert_eq!(text, "Foo bar baz quux.");
443-
assert_eq!(*start, 4);
444-
assert_eq!(*end, 6);
445-
}
446-
_ => panic!("Expected cloze card"),
447-
}
448-
match &cards[1].content() {
449-
CardContent::Cloze { text, start, end } => {
450-
assert_eq!(text, "Foo bar baz quux.");
451-
assert_eq!(*start, 12);
452-
assert_eq!(*end, 15);
453-
}
454-
_ => panic!("Expected cloze card"),
455-
}
431+
assert_cloze(&cards, "Foo bar baz quux.", &[(4, 6), (12, 15)]);
456432
Ok(())
457433
}
458434

@@ -462,23 +438,7 @@ mod tests {
462438
let parser = make_test_parser();
463439
let cards = parser.parse(input)?;
464440

465-
assert_eq!(cards.len(), 2);
466-
match &cards[0].content() {
467-
CardContent::Cloze { text, start, end } => {
468-
assert_eq!(text, "Foo bar ![](image.jpg) quux.");
469-
assert_eq!(*start, 4);
470-
assert_eq!(*end, 6);
471-
}
472-
_ => panic!("Expected cloze card"),
473-
}
474-
match &cards[1].content() {
475-
CardContent::Cloze { text, start, end } => {
476-
assert_eq!(text, "Foo bar ![](image.jpg) quux.");
477-
assert_eq!(*start, 23);
478-
assert_eq!(*end, 26);
479-
}
480-
_ => panic!("Expected cloze card"),
481-
}
441+
assert_cloze(&cards, "Foo bar ![](image.jpg) quux.", &[(4, 6), (23, 26)]);
482442
Ok(())
483443
}
484444

@@ -488,23 +448,7 @@ mod tests {
488448
let parser = make_test_parser();
489449
let cards = parser.parse(input)?;
490450

491-
assert_eq!(cards.len(), 2);
492-
match &cards[0].content() {
493-
CardContent::Cloze { text, start, end } => {
494-
assert_eq!(text, "foo\nbar\nbaz.");
495-
assert_eq!(*start, 0);
496-
assert_eq!(*end, 2);
497-
}
498-
_ => panic!("Expected cloze card"),
499-
}
500-
match &cards[1].content() {
501-
CardContent::Cloze { text, start, end } => {
502-
assert_eq!(text, "foo\nbar\nbaz.");
503-
assert_eq!(*start, 4);
504-
assert_eq!(*end, 6);
505-
}
506-
_ => panic!("Expected cloze card"),
507-
}
451+
assert_cloze(&cards, "foo\nbar\nbaz.", &[(0, 2), (4, 6)]);
508452
Ok(())
509453
}
510454

0 commit comments

Comments
 (0)