Skip to content

Commit

Permalink
Improve coverage for raw
Browse files Browse the repository at this point in the history
Signed-off-by: Heinz N. Gies <heinz@licenser.net>
  • Loading branch information
Licenser committed May 17, 2021
1 parent 429511f commit 19d079b
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 48 deletions.
3 changes: 3 additions & 0 deletions tests/script_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ test_cases!(
pp_cyclic,
pp_nest_cyclic,
// INSERT
double_const_mod,
bin_invalid_bits,
bin_invalid_type,
merge_ident,
select_ident,
function_already_defined,
Expand Down
3 changes: 3 additions & 0 deletions tests/script_errors/bin_invalid_bits/error.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Error:
1 | <<event:100>>
| ^^^^^^^^^ negative bits or bits > 64 are are not allowed: 100
1 change: 1 addition & 0 deletions tests/script_errors/bin_invalid_bits/script.tremor
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<<event:100>>
3 changes: 3 additions & 0 deletions tests/script_errors/bin_invalid_type/error.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Error:
1 | <<event/snot>>
| ^^^^^^^^^^ Not a valid data type: 'snot'
1 change: 1 addition & 0 deletions tests/script_errors/bin_invalid_type/script.tremor
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<<event/snot>>
6 changes: 6 additions & 0 deletions tests/script_errors/double_const_mod/error.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Error:
1 | mod test with
2 | const a = 1;
3 | const a = 2;
| ^^^^^^^^^^^ Can't declare the constant `a` twice
4 | end;
4 changes: 4 additions & 0 deletions tests/script_errors/double_const_mod/script.tremor
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
mod test with
const a = 1;
const a = 2;
end;
70 changes: 22 additions & 48 deletions tremor-script/src/ast/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ impl<'script> Upable<'script> for BytesPartRaw<'script> {
return Err(err_generic(
&self,
&self,
&format!("Not a valid data type: '{}' ({:?})", other.join("-"), other),
&format!("Not a valid data type: '{}'", other.join("-")),
&helper.meta,
))
}
Expand Down Expand Up @@ -311,11 +311,8 @@ impl<'script> ModuleRaw<'script> {
let expr = expr.up(helper)?;
let v = reduce2(expr, &helper)?;
helper.consts.insert(name_v, v).map_err(|_old| {
Error::from(ErrorKind::DoubleConst(
Range::from((start, end)).expand_lines(2),
Range::from((start, end)),
name.to_string(),
))
let r = Range::from((start, end));
ErrorKind::DoubleConst(r.expand_lines(2), r, name.to_string())
})?;
}
ExprRaw::FnDecl(f) => {
Expand All @@ -332,14 +329,8 @@ impl<'script> ModuleRaw<'script> {

helper.register_fun(f)?;
}
e => {
return error_generic(
&e,
&e,
&"Can't have expressions inside of modules",
&helper.meta,
)
}
// ALLOW: the gramer doesn't allow this
_ => unreachable!("Can't have expressions inside of modules"),
}
}
helper.module.pop();
Expand Down Expand Up @@ -560,27 +551,9 @@ impl<'script> Upable<'script> for ExprRaw<'script> {
#[allow(clippy::clippy::too_many_lines)]
fn up<'registry>(self, helper: &mut Helper<'script, 'registry>) -> Result<Self::Target> {
Ok(match self {
ExprRaw::Module(ModuleRaw { start, end, .. }) => {
// There is no code path that leads here,
// we still rather have an error in case we made
// an error then unreachable

return Err(ErrorKind::InvalidMod(
Range::from((start, end)).expand_lines(2),
Range::from((start, end)),
)
.into());
}
ExprRaw::Const { start, end, .. } => {
// There is no code path that leads here,
// we still rather have an error in case we made
// an error then unreachable

return Err(ErrorKind::InvalidConst(
Range::from((start, end)).expand_lines(2),
Range::from((start, end)),
)
.into());
// ALLOW: There is no code path that leads here,
ExprRaw::FnDecl(_) | ExprRaw::Const { .. } | ExprRaw::Module(ModuleRaw { .. }) => {
unreachable!()
}
ExprRaw::MatchExpr(m) => match m.up(helper)? {
Match {
Expand Down Expand Up @@ -674,25 +647,16 @@ impl<'script> Upable<'script> for ExprRaw<'script> {
}
ExprRaw::Emit(e) => Expr::Emit(Box::new(e.up(helper)?)),
ExprRaw::Imut(i) => i.up(helper)?.into(),
ExprRaw::FnDecl(f) => {
// There is no code path that leads here,
// we still rather have an error in case we made
// an error then unreachable

return Err(ErrorKind::InvalidFn(
f.extent(&helper.meta).expand_lines(2),
f.extent(&helper.meta),
)
.into());
}
})
}
}

#[cfg(not(tarpaulin_include))] // just dispatch
impl<'script> BaseExpr for ExprRaw<'script> {
fn mid(&self) -> usize {
0
}

fn s(&self, meta: &NodeMetas) -> Location {
match self {
ExprRaw::Const { start, .. } | ExprRaw::Drop { start, .. } => *start,
Expand All @@ -705,6 +669,7 @@ impl<'script> BaseExpr for ExprRaw<'script> {
ExprRaw::Imut(e) => e.s(meta),
}
}

fn e(&self, meta: &NodeMetas) -> Location {
match self {
ExprRaw::Const { end, .. } | ExprRaw::Drop { end, .. } => *end,
Expand Down Expand Up @@ -809,18 +774,17 @@ impl<'script> Upable<'script> for AnyFnRaw<'script> {
}
}

#[cfg(not(tarpaulin_include))] // just dispatch
impl<'script> BaseExpr for AnyFnRaw<'script> {
fn mid(&self) -> usize {
0
}

fn s(&self, _meta: &NodeMetas) -> Location {
match self {
AnyFnRaw::Match(m) => m.start,
AnyFnRaw::Normal(m) => m.start,
}
}

fn e(&self, _meta: &NodeMetas) -> Location {
match self {
AnyFnRaw::Match(m) => m.end,
Expand Down Expand Up @@ -2646,3 +2610,13 @@ pub type ComprehensionCasesRaw<'script, Ex> = Vec<ComprehensionCaseRaw<'script,
pub type ImutComprehensionCasesRaw<'script> = Vec<ImutComprehensionCaseRaw<'script>>;
pub type ArrayPredicatePatternsRaw<'script> = Vec<ArrayPredicatePatternRaw<'script>>;
pub type WithExprsRaw<'script> = Vec<(IdentRaw<'script>, ImutExprRaw<'script>)>;

#[cfg(test)]
mod test {
use super::*;
#[test]
fn default() {
assert_eq!(Endian::default(), Endian::Big);
assert_eq!(BytesDataType::default(), BytesDataType::UnsignedInteger);
}
}

0 comments on commit 19d079b

Please sign in to comment.