pub struct CheckLine { /* private fields */ }
Expand description
A compare op with some text to compare against
Implementations
sourceimpl CheckLine
impl CheckLine
sourcepub fn new(spec: &str) -> Result<Self>
pub fn new(spec: &str) -> Result<Self>
new from spec : OP,Text
Examples found in repository?
src/bin/cdx/verify_main.rs (line 56)
≺ ≻
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
pub fn main(argv: &[String], settings: &mut Settings) -> Result<()> {
let prog = args::ProgSpec::new("Verify file contents.", args::FileCount::Many);
const A: [ArgSpec; 10] = [
arg! {"report", "r", "Number", "How many failures to report before exit."},
arg! {"first", "f", "Op,Value", "'FirstLine Op Value' must be true. E.g LT,a for first line is less than 'a'."},
arg! {"last", "l", "Op,Value", "'LastLine Op Value' must be true."},
arg! {"key", "k", "Spec", "How to compare adjacent lines"},
arg! {"sort", "s", "", "Check that the file is sorted."},
arg! {"unique", "u", "", "Check that the file is sorted, with unique lines."},
arg! {"pattern", "p", "Col,Spec,Pattern", "Select line where this col matches this pattern."},
arg! {"show-matchers", "", "", "Print available matchers"},
arg! {"show-const", "", "", "Print available constants"},
arg! {"show-func", "", "", "Print available functions"},
];
let (args, files) = args::parse(&prog, &A, argv, settings)?;
let mut list = LineMatcherList::new_with(Combiner::And);
let mut comp = LineCompList::new();
let mut do_sort = false;
let mut do_unique = false;
let mut max_fails = 5;
let mut first: Option<CheckLine> = None;
let mut last: Option<CheckLine> = None;
for x in args {
if x.name == "pattern" {
list.push(&x.value)?;
} else if x.name == "key" {
comp.add(&x.value)?;
} else if x.name == "or" {
list.multi = Combiner::Or;
} else if x.name == "fail" {
max_fails = x.value.to_usize_whole(x.value.as_bytes(), "max fails")?;
} else if x.name == "sort" {
do_sort = true;
} else if x.name == "first" {
first = Some(CheckLine::new(&x.value)?);
} else if x.name == "last" {
last = Some(CheckLine::new(&x.value)?);
} else if x.name == "unique" {
do_sort = true;
do_unique = true;
} else if x.name == "show-const" {
expr::show_const();
return Ok(());
} else if x.name == "show-func" {
expr::show_func();
return Ok(());
} else {
unreachable!();
}
}
if comp.is_empty() {
comp.add("")?;
}
let mut fails = 0;
for x in &files {
let mut f = Reader::new(&settings.text_in);
f.open(x)?;
if f.is_empty() {
continue;
}
list.lookup(&f.names())?;
comp.lookup(&f.names())?;
if f.is_done() {
continue;
}
if first.is_some()
&& !first.as_ref().unwrap().line_ok_verbose(
f.curr_line(),
&mut comp,
f.line_number(),
)?
{
fails += 1;
}
let num_cols = f.names().len();
loop {
let mut did_fail = false;
if f.curr().len() != num_cols {
eprintln!(
"Expected {num_cols} columns, but line {} of {} had {}",
f.line_number() + 1,
x,
f.curr().len()
);
did_fail = true;
}
if !list.ok_verbose(f.curr_line(), f.line_number(), x) {
did_fail = true;
}
if f.getline()? {
if last.is_some()
&& !last.as_ref().unwrap().line_ok_verbose(
f.prev_line(1),
&mut comp,
f.line_number() - 1,
)?
{
fails += 1;
}
break;
}
if do_sort {
did_fail = did_fail || comp_check(&f, &mut comp, do_unique);
}
if did_fail {
fails += 1;
if fails >= max_fails {
break;
}
}
}
if fails > 0 {
return cdx_err(CdxError::Silent);
}
}
Ok(())
}
sourcepub fn line_ok_verbose(
&self,
line: &TextLine,
comp: &mut LineCompList,
line_num: usize
) -> Result<bool>
pub fn line_ok_verbose(
&self,
line: &TextLine,
comp: &mut LineCompList,
line_num: usize
) -> Result<bool>
compare line OP text, return true if match, print to stderr if non-mtch
Examples found in repository?
src/bin/cdx/verify_main.rs (lines 89-93)
≺ ≻
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
pub fn main(argv: &[String], settings: &mut Settings) -> Result<()> {
let prog = args::ProgSpec::new("Verify file contents.", args::FileCount::Many);
const A: [ArgSpec; 10] = [
arg! {"report", "r", "Number", "How many failures to report before exit."},
arg! {"first", "f", "Op,Value", "'FirstLine Op Value' must be true. E.g LT,a for first line is less than 'a'."},
arg! {"last", "l", "Op,Value", "'LastLine Op Value' must be true."},
arg! {"key", "k", "Spec", "How to compare adjacent lines"},
arg! {"sort", "s", "", "Check that the file is sorted."},
arg! {"unique", "u", "", "Check that the file is sorted, with unique lines."},
arg! {"pattern", "p", "Col,Spec,Pattern", "Select line where this col matches this pattern."},
arg! {"show-matchers", "", "", "Print available matchers"},
arg! {"show-const", "", "", "Print available constants"},
arg! {"show-func", "", "", "Print available functions"},
];
let (args, files) = args::parse(&prog, &A, argv, settings)?;
let mut list = LineMatcherList::new_with(Combiner::And);
let mut comp = LineCompList::new();
let mut do_sort = false;
let mut do_unique = false;
let mut max_fails = 5;
let mut first: Option<CheckLine> = None;
let mut last: Option<CheckLine> = None;
for x in args {
if x.name == "pattern" {
list.push(&x.value)?;
} else if x.name == "key" {
comp.add(&x.value)?;
} else if x.name == "or" {
list.multi = Combiner::Or;
} else if x.name == "fail" {
max_fails = x.value.to_usize_whole(x.value.as_bytes(), "max fails")?;
} else if x.name == "sort" {
do_sort = true;
} else if x.name == "first" {
first = Some(CheckLine::new(&x.value)?);
} else if x.name == "last" {
last = Some(CheckLine::new(&x.value)?);
} else if x.name == "unique" {
do_sort = true;
do_unique = true;
} else if x.name == "show-const" {
expr::show_const();
return Ok(());
} else if x.name == "show-func" {
expr::show_func();
return Ok(());
} else {
unreachable!();
}
}
if comp.is_empty() {
comp.add("")?;
}
let mut fails = 0;
for x in &files {
let mut f = Reader::new(&settings.text_in);
f.open(x)?;
if f.is_empty() {
continue;
}
list.lookup(&f.names())?;
comp.lookup(&f.names())?;
if f.is_done() {
continue;
}
if first.is_some()
&& !first.as_ref().unwrap().line_ok_verbose(
f.curr_line(),
&mut comp,
f.line_number(),
)?
{
fails += 1;
}
let num_cols = f.names().len();
loop {
let mut did_fail = false;
if f.curr().len() != num_cols {
eprintln!(
"Expected {num_cols} columns, but line {} of {} had {}",
f.line_number() + 1,
x,
f.curr().len()
);
did_fail = true;
}
if !list.ok_verbose(f.curr_line(), f.line_number(), x) {
did_fail = true;
}
if f.getline()? {
if last.is_some()
&& !last.as_ref().unwrap().line_ok_verbose(
f.prev_line(1),
&mut comp,
f.line_number() - 1,
)?
{
fails += 1;
}
break;
}
if do_sort {
did_fail = did_fail || comp_check(&f, &mut comp, do_unique);
}
if did_fail {
fails += 1;
if fails >= max_fails {
break;
}
}
}
if fails > 0 {
return cdx_err(CdxError::Silent);
}
}
Ok(())
}
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for CheckLine
impl Send for CheckLine
impl Sync for CheckLine
impl Unpin for CheckLine
impl UnwindSafe for CheckLine
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more