Test

Struct Test 

Source
pub struct Test<'a> {
    pub result: bool,
    pub number: Option<i32>,
    pub description: Option<&'a str>,
    pub directive: Option<Directive<'a>>,
    pub yaml: Vec<&'a str>,
}
Expand description

A Test declaring the result of some test-case.

Fields§

§result: bool

Result of the test.

§number: Option<i32>

Number of the test.

§description: Option<&'a str>

Description of the test.

§directive: Option<Directive<'a>>

Directive detailing this tests meta-execution.

§yaml: Vec<&'a str>

List of YAML lines detailing the test execution.

Implementations§

Source§

impl<'a> Test<'a>

Source

pub fn parse_from_str(content: &'a str) -> Result<Self>

Parse Test from a &str.

§Examples

Parsing a TAP test may look like this:

use tapconsooomer::Test;

let content = "not ok 1 - foo()";
let test = Test::parse_from_str(content).expect("Parser error");
assert_eq!(test.result, false);
assert_eq!(test.number, Some(1));
assert_eq!(test.description, Some("foo()"));
assert_eq!(test.directive.is_none(), true);
assert_eq!(test.yaml.len(), 0);

Note, many attributes of a TAP test are optional. A minimal TAP test may look like this:

use tapconsooomer::Test;

let content = "ok";
let test = Test::parse_from_str(content).expect("Parser error");
assert_eq!(test.result, true);
assert_eq!(test.number, None);
assert_eq!(test.description, None);
assert_eq!(test.directive.is_none(), true);
assert_eq!(test.yaml.len(), 0);

TAP tests may also optionally contain a YAML block. While no parsing of actual YAML syntax is performed, the parser captures each line inside the YAML block in a Vec:

use tapconsooomer::Test;

let content = concat!(
    "not ok 2 - bar()\n",
    "  ---\n",
    "  message: invalid input\n",
    "  status: failed\n",
    "  ...\n",
);
let test = Test::parse_from_str(content).expect("Parser error");
assert_eq!(test.result, false);
assert_eq!(test.number, Some(2));
assert_eq!(test.description, Some("bar()"));
assert_eq!(test.directive.is_none(), true);
assert_eq!(test.yaml.len(), 2);
assert_eq!(test.yaml, ["message: invalid input", "status: failed"])

Trait Implementations§

Source§

impl<'a> Debug for Test<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> Serialize for Test<'a>

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Test<'a>

§

impl<'a> RefUnwindSafe for Test<'a>

§

impl<'a> Send for Test<'a>

§

impl<'a> Sync for Test<'a>

§

impl<'a> Unpin for Test<'a>

§

impl<'a> UnwindSafe for Test<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.