ingraph 0.1.0

A declaration-driven indexing framework: records and nodes are written as Rust types, and the storage rows, the dataflow between them and the GraphQL query surface are emitted from the declaration.
Documentation
use super::{JsonElement, json_elements};

#[test]
fn an_array_is_the_elements_between_brackets() {
  assert_eq!(json_elements::<i64>(&[]), "[]");
  assert_eq!(json_elements(&[1i64]), "[1]");
  assert_eq!(json_elements(&[1i64, -2, 3]), "[1,-2,3]");
  assert_eq!(json_elements(&[true, false]), "[true,false]");
}

/// The precision rule: a JSON number is a double, so the three widths it would round render as
/// decimal STRINGS. `u64::MAX` is the case that shows it — the nearest double is one greater, so a
/// bare number would compare equal to a key that is not this one.
#[test]
fn the_widths_a_double_would_round_are_quoted() {
  assert_eq!(json_elements(&[u64::MAX]), "[\"18446744073709551615\"]");
  assert_eq!(json_elements(&[u128::MAX]), format!("[\"{}\"]", u128::MAX));
  assert_eq!(json_elements(&[i128::MIN]), format!("[\"{}\"]", i128::MIN));

  // The widths it holds exactly stay numbers.
  assert_eq!(json_elements(&[i64::MIN]), format!("[{}]", i64::MIN));
  assert_eq!(json_elements(&[u32::MAX]), "[4294967295]");
}

#[test]
fn a_string_escapes_what_json_requires_and_nothing_else() {
  let mut out = String::new();
  "a\"b\\c\nd\te\r\u{1}f".push_json(&mut out);
  assert_eq!(out, "\"a\\\"b\\\\c\\nd\\te\\r\\u0001f\"");

  // UTF-8 rides through as it stands — JSON strings are text, not bytes.
  let mut out = String::new();
  "café ✓".push_json(&mut out);
  assert_eq!(out, "\"café ✓\"");
}

#[test]
fn bytes_render_as_lowercase_hex() {
  assert_eq!(json_elements(&[vec![0x89u8, 0x50, 0x0f]]), "[\"89500f\"]");
  assert_eq!(json_elements(&[[0u8, 255]]), "[\"00ff\"]");
}

/// A borrowed element encodes as the owned one does, and `f32` widens through `f64` — so the two
/// float rows agree on every value both can hold.
#[test]
fn a_borrowed_element_and_a_widened_float_agree_with_their_twins() {
  let owned = 1.5f64;
  assert_eq!(json_elements(&[&owned]), json_elements(&[owned]));
  assert_eq!(json_elements(&[1.5f32]), json_elements(&[1.5f64]));
}