test: add empty list test

This commit is contained in:
rvcas 2023-06-30 16:12:51 -04:00
parent 291dedf4e8
commit 8a7df7f66b
No known key found for this signature in database
GPG Key ID: C09B64E263F7D68C
13 changed files with 187 additions and 148 deletions

View File

@ -27,3 +27,16 @@ pub fn parser(
tail,
})
}
#[cfg(test)]
mod tests {
use chumsky::Parser;
use crate::assert_expr;
#[test]
fn empty_list() {
assert_expr!("[]");
}
}

View File

@ -0,0 +1,9 @@
---
source: crates/aiken-lang/src/parser/expr/list.rs
description: "Code:\n\n[]"
---
List {
location: 0..2,
elements: [],
tail: None,
}

View File

@ -93,3 +93,26 @@ pub fn type_name_with_args() -> impl Parser<Token, (String, Option<Vec<String>>)
),
)
}
#[cfg(test)]
#[macro_use]
mod macros {
#[macro_export]
macro_rules! assert_expr {
($code:expr) => {
let $crate::parser::lexer::LexInfo { tokens, .. } = $crate::parser::lexer::run($code).unwrap();
let stream = chumsky::Stream::from_iter($crate::ast::Span::create(tokens.len()), tokens.into_iter());
let result = $crate::parser::expr::sequence().parse(stream).unwrap();
insta::with_settings!({
description => concat!("Code:\n\n", $code),
prepend_module_to_snapshot => false,
omit_expression => true
}, {
insta::assert_debug_snapshot!(result);
});
};
}
}

View File

@ -168,7 +168,7 @@ fn qualify_type_name(module: &String, typ_name: &str) -> Document<'static> {
}
#[cfg(test)]
mod test {
mod tests {
use std::cell::RefCell;
use pretty_assertions::assert_eq;

View File

@ -140,7 +140,7 @@ impl From<&Config> for Preamble {
}
#[cfg(test)]
mod test {
mod tests {
use super::*;
use aiken_lang::builtins;
use schema::{Data, Declaration, Items, Schema};

View File

@ -1033,7 +1033,7 @@ Here's the types I followed and that led me to this problem:
}
#[cfg(test)]
pub mod test {
pub mod tests {
use super::*;
use proptest::prelude::*;
use serde_json::{self, json, Value};

View File

@ -177,7 +177,7 @@ impl Validator {
}
#[cfg(test)]
mod test {
mod tests {
use assert_json_diff::assert_json_eq;
use serde_json::{self, json};

View File

@ -1,17 +1,15 @@
#[cfg(test)]
mod test {
use flat_rs::filler::Filler;
use flat_rs::{decode, encode};
use proptest::prelude::*;
use flat_rs::filler::Filler;
use flat_rs::{decode, encode};
use proptest::prelude::*;
prop_compose! {
prop_compose! {
fn arb_big_vec()(size in 255..300, element in any::<u8>()) -> Vec<u8> {
(0..size).map(|_| element).collect()
}
}
}
#[test]
fn encode_bool() {
#[test]
fn encode_bool() {
let bytes = encode(&true).unwrap();
assert_eq!(bytes, vec![0b10000001]);
@ -27,10 +25,10 @@ mod test {
let decoded: bool = decode(bytes.as_slice()).unwrap();
assert!(!decoded);
}
}
#[test]
fn encode_u8() {
#[test]
fn encode_u8() {
let bytes = encode(&3_u8).unwrap();
assert_eq!(bytes, vec![0b00000011, 0b00000001]);
@ -38,9 +36,9 @@ mod test {
let decoded: u8 = decode(bytes.as_slice()).unwrap();
assert_eq!(decoded, 3_u8);
}
}
proptest! {
proptest! {
#[test]
fn encode_isize(x: isize) {
let bytes = encode(&x).unwrap();
@ -104,10 +102,10 @@ mod test {
let decoded: char = decode(&bytes).unwrap();
assert_eq!(decoded, c);
}
}
}
#[test]
fn encode_filler() {
#[test]
fn encode_filler() {
let bytes = encode(&Filler::FillerEnd).unwrap();
assert_eq!(bytes, vec![0b0000001, 0b00000001]);
@ -122,5 +120,4 @@ mod test {
.unwrap();
assert_eq!(bytes, vec![0b0000001, 0b00000001]);
}
}

View File

@ -1,9 +1,7 @@
#[cfg(test)]
mod test {
use flat_rs::zigzag::{to_isize, to_usize};
use proptest::prelude::*;
use flat_rs::zigzag::{to_isize, to_usize};
use proptest::prelude::*;
proptest! {
proptest! {
#[test]
fn zigzag(i: isize) {
let u = to_usize(i);
@ -17,5 +15,4 @@ mod test {
let converted_u = to_usize(i);
assert_eq!(converted_u, u);
}
}
}

View File

@ -808,7 +808,7 @@ pub fn decode_constant_tag(d: &mut Decoder) -> Result<u8, de::Error> {
}
#[cfg(test)]
mod test {
mod tests {
use super::{Constant, Program, Term};
use crate::{
ast::{DeBruijn, Name, Type},

View File

@ -3213,7 +3213,7 @@ impl TryFrom<u8> for StepKind {
}
#[cfg(test)]
mod test {
mod tests {
use super::*;
use pretty_assertions::assert_eq;

View File

@ -503,7 +503,7 @@ fn replace_identity_usage(term: &Term<Name>, original: Rc<Name>) -> Term<Name> {
}
#[cfg(test)]
mod test {
mod tests {
use pallas_primitives::babbage::{BigInt, PlutusData};
use pretty_assertions::assert_eq;

View File

@ -282,7 +282,7 @@ peg::parser! {
}
#[cfg(test)]
mod test {
mod tests {
use num_bigint::BigInt;
use crate::ast::{Constant, Name, Program, Term, Type, Unique};