Skip to content

Commit

Permalink
Coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
sffc committed Jun 6, 2020
1 parent 2194dbf commit 0d6828a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
13 changes: 13 additions & 0 deletions components/datap_json/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ impl From<serde_json::error::Error> for Error {
}

/// A data provider reading from a JSON file.
#[derive(Debug)]
pub struct JsonDataProvider {
data: schema::JsonSchema,
}
Expand Down Expand Up @@ -58,3 +59,15 @@ impl<'a> datap::DataProvider<'a, 'a> for JsonDataProvider {
Ok(response)
}
}

#[test]
fn test_empty_str() {
let result = JsonDataProvider::from_str("");
assert!(result.is_err());
let err = result.unwrap_err();
println!("{:?}", err); // Coverage for Debug trait
// An unconditional let is possible here because it is a one-element enum.
// If more cases are needed, see https://github.com/rust-lang/rfcs/pull/1303
let Error::JsonError(json_err) = err;
assert_eq!(json_err.classify(), serde_json::error::Category::Eof);
}
4 changes: 2 additions & 2 deletions components/datap_json/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ use serde::{Deserialize, Serialize};
#[allow(unused_imports)]
use std::prelude::v1::*;

#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, Debug)]
pub(crate) struct DecimalJsonSchema {
pub(crate) symbols_v1_a: datap::decimal::SymbolsV1,
}

#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, Debug)]
pub(crate) struct JsonSchema {
pub(crate) decimal: DecimalJsonSchema,
}
1 change: 1 addition & 0 deletions components/datap_json/tests/test_file_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ fn test_read_json() {
let file = File::open("tests/testdata/all.json").unwrap();
let reader = BufReader::new(file);
let json_data_provider = JsonDataProvider::from_reader(reader).unwrap();
println!("{:?}", json_data_provider); // Coverage for Debug trait
let response = json_data_provider
.load(&datap::Request {
locale: "root".to_string(),
Expand Down
8 changes: 8 additions & 0 deletions components/datap_json/tests/test_no_std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ fn test_read_string() {
check_data(decimal_data);
}

#[test]
fn test_read_utf8() {
let provider = JsonDataProvider::from_slice(DATA.as_bytes()).unwrap();
let response = get_response(&provider);
let decimal_data: &datap::decimal::SymbolsV1 = response.borrow_payload().unwrap();
check_data(decimal_data);
}

#[test]
fn test_borrow_payload_mut() {
let provider = get_provider();
Expand Down

0 comments on commit 0d6828a

Please sign in to comment.