~ioiojo/kiwi

1d15a5e46e81ad93cbd3abd574956d5d0d0d82eb — Andy Weidenbaum 2 years ago a5230f6
s/—|–/-' to be more tty friendly
M kiwi/macros.fnl => kiwi/macros.fnl +1 -1
@@ 27,7 27,7 @@
      (when new-local-fns
        ;; e.g. `(let [action require binds {path :module/path}] ...)`
        (each [action binds (pairs new-local-fns)]
          ;; lua tables are passed by reference — `current` gets mutated
          ;; lua tables are passed by reference - `current` gets mutated
          (let [action-str (tostring action)
                current (or (. local-fns action-str) {})]
            (tset local-fns action-str current)

M src/fir_arg.rs => src/fir_arg.rs +7 -7
@@ 43,10 43,10 @@ use crate::utils;
/// call to `Peekable::peek()` has revealed the iterator's next item exists.
const PEEKABLE_NEXT_EXPECT: &str = "Peek-checked `Iterator` unexpectedly returned `None`";

/// Error message for `rlua::Table::get(1).expect()` — which should always succeed.
/// Error message for `rlua::Table::get(1).expect()` - which should always succeed.
const TABLE_GET_1_EXPECT: &str = "`rlua::Table::get(1)` unexpectedly failed";

/// Error message for `rlua::Table::get(2).expect()` — which should always succeed.
/// Error message for `rlua::Table::get(2).expect()` - which should always succeed.
const TABLE_GET_2_EXPECT: &str = "`rlua::Table::get(2)` unexpectedly failed";

/// Error message for `try_into::<NumberGteZero>().expect()`, designed for situations


@@ 571,9 571,9 @@ impl TryFrom<Table<'_>> for FoodAvg {

    fn try_from(table: Table) -> InputFoodAvgResult<Self> {
        // Make the sequence `Peekable` to facilitate checking for ratios. Or rather, to
        // facilitate not needing to e.g. `sequence_values` twice — as would be necessary
        // facilitate not needing to e.g. `sequence_values` twice - as would be necessary
        // if instead `.nth(1)` were used to check whether the second list element were a
        // ratio — or similar.
        // ratio - or similar.
        let mut iter = table
            .sequence_values::<Value>()
            .map(|v| v.expect(SEQUENCE_VALUES_EXPECT))


@@ 604,7 604,7 @@ impl TryFrom<Table<'_>> for FoodAvg {
}

// `first` is part of a (kludgy) workaround for checking whether `table` in
// `FoodAvg::try_from(table)` — previously determined to be a list — contains
// `FoodAvg::try_from(table)` - previously determined to be a list - contains
// interspersed ratios, without iterating over `table` twice.
fn handle_food_avg_ratio<'a, I>(mut iter: Peekable<I>, first: Value) -> InputFoodAvgResult<FoodAvg>
where


@@ 1062,8 1062,8 @@ impl TryFrom<Value<'_>> for AminoAcids {
                        // `AminoAcidsBuilder::try_from(table)` returns `Err` when
                        // `table` contains unsupported keypairs. Since it has returned
                        // `Ok` in this case, and since all `AminoAcids` fields are
                        // optional — and with `AminoAcidsBuilder` being implemented
                        // sans any custom validation logic — calling `builder.build()`
                        // optional - and with `AminoAcidsBuilder` being implemented
                        // sans any custom validation logic - calling `builder.build()`
                        // here should always succeed.
                        let amino_acids = builder
                            .build()

M src/fir_consts.rs => src/fir_consts.rs +2 -2
@@ 14,7 14,7 @@ pub const META_BUILDER_DEFAULT_BUILD_EXPECT: &str = "`MetaBuilder` unexpectedly 
/// call to `Iterator::len(iter)` has revealed `iter`'s length to be at least one.
pub const NTH_EXPECT: &str = "Length-checked `Iterator` unexpectedly returned `None`";

/// Error message for `Iterator::Item.expect()` in `rlua::TablePairs`es — which `rlua`
/// Error message for `Iterator::Item.expect()` in `rlua::TablePairs`es - which `rlua`
/// wraps in `Result` to facilitate lazily converting Lua types to Rust. Presumably this
/// can only fail if the user requests a Rust type which doesn't implement `FromLua`.
pub const PAIRS_EXPECT: &str = "`rlua::TablePairs::pairs()` unexpectedly failed";


@@ 26,7 26,7 @@ pub const PARTITIONED_EXPECT: &str = "Partitioning unexpectedly failed";
/// which should always succeed.
pub const REGISTRY_VALUE_EXPECT: &str = "Fetching registry value unexpectedly failed";

/// Error message for `Iterator::Item.expect()` in `rlua::TableSequence`s — which `rlua`
/// Error message for `Iterator::Item.expect()` in `rlua::TableSequence`s - which `rlua`
/// wraps in `Result` to facilitate lazily converting Lua types to Rust. Presumably this
/// can only fail if the user requests a Rust type which doesn't implement `FromLua`.
pub const SEQUENCE_VALUES_EXPECT: &str = "`rlua::TableSequence` unexpectedly failed";

M src/fir_traits.rs => src/fir_traits.rs +1 -1
@@ 1,6 1,6 @@
use rlua::{Context, Function, Table, Value};

/// Error message for `rlua::Table::contains_key(1).expect()` — which should always succeed.
/// Error message for `rlua::Table::contains_key(1).expect()` - which should always succeed.
const TABLE_CONTAINS_KEY_1_EXPECT: &str = "`rlua::Table::contains_key(1)` unexpectedly failed";

pub trait FennelView<'a> {

M src/food.rs => src/food.rs +2 -2
@@ 963,8 963,8 @@ impl Add<Food> for Simple {
pub struct Composite {
    pub meta: Meta,

    /// `Env` is optional in `Composite` foods because macronutrient values — which would
    /// otherwise have to be obtained by consulting an `Env` — can be automatically
    /// `Env` is optional in `Composite` foods because macronutrient values - which would
    /// otherwise have to be obtained by consulting an `Env` - can be automatically
    /// derived from constituent foods comprising the `Composite`. Constituent foods are
    /// guaranteed to contain at least one `Simple` food¹, which are in turn guaranteed
    /// to contain an `Env`.

M src/food_env.rs => src/food_env.rs +1 -1
@@ 7,7 7,7 @@ use crate::food_measure::ServingSizeish;

/// The `Simple` food “environment”. Encapsulates values which vary upon food math, e.g.
/// the `protein` value reported (see: `kiwi::Value`) increases if the user multiplies
/// the food — and its “food environment” — by a number greater than 1.
/// the food - and its “food environment” - by a number greater than 1.
#[derive(Clone, Debug)]
pub struct SimpleEnv {
    /// The serving size applicable to the other `Env` fields.

M src/food_value.rs => src/food_value.rs +2 -2
@@ 472,7 472,7 @@ impl Value for Composite {
            }
        }

        // `Env` not found for this `Composite` food. Walk its constituents — there must
        // `Env` not found for this `Composite` food. Walk its constituents - there must
        // be at least one.
        let mut serving_size: Vec<ServingSize> = Vec::with_capacity(1);



@@ 850,7 850,7 @@ fn multiply_per(
    per.into_iter()
        .map(|(unit_of_measure, conversion_factor)| {
            // Take the product of the *inverse of the multiplier* and the conversion
            // factor to counter the underlying serving size growing or shrinking —
            // factor to counter the underlying serving size growing or shrinking -
            // `multiply_per` happens in lockstep with `multiply_serving_size`.
            let conversion_factor = {
                let inverse_multiplier = 1.0 / multiplier;

M src/plan.rs => src/plan.rs +4 -4
@@ 46,7 46,7 @@ pub struct Plan {
    /// 4. Thermic Effect of Activity (Exercise)
    ///
    /// For simplicity, factors 2-4 are condensed into a single factor called *Activity
    /// Level*. The specified Activity Level controls the Katch–McArdle multiplier on BMR.
    /// Level*. The specified Activity Level controls the Katch-McArdle multiplier on BMR.
    pub tdee: f64,

    /// Recommended Caloric Intake


@@ 153,9 153,9 @@ impl From<Profile> for Plan {
    }
}

/// Calculate BMR using the [Mifflin–St. Jeor equation].
/// Calculate BMR using the [Mifflin-St. Jeor equation].
///
/// [Mifflin–St. Jeor equation]: https://en.wikipedia.org/wiki/Basal_metabolic_rate
/// [Mifflin-St. Jeor equation]: https://en.wikipedia.org/wiki/Basal_metabolic_rate
fn bmr_from_profile(weight: f64, height: f64, age: i64, gender: &Gender) -> f64 {
    let s = match gender {
        Gender::Male => 5.0,


@@ 167,7 167,7 @@ fn bmr_from_profile(weight: f64, height: f64, age: i64, gender: &Gender) -> f64 
    (w + h - a) + s
}

/// Given Activity Level, return Katch–McArdle multiplier.
/// Given Activity Level, return Katch-McArdle multiplier.
fn multiplier_from_activity_level(activity_level: &ActivityLevel) -> f64 {
    match activity_level {
        ActivityLevel::Sedentary => 1.2,

M tests/data/complex/cfg/pantry/branded/prometeo.kiwi => tests/data/complex/cfg/pantry/branded/prometeo.kiwi +1 -1
@@ 3,7 3,7 @@
(pantry M)

(food emmer-penne-farro-dicocco
  "Prometeo: Emmer Penne — Farro Dicocco."
  "Prometeo: Emmer Penne - Farro Dicocco."
  {:serving-size [100 :g]
   :protein 7
   :carbs 80

M tests/data/complex/cfg/pantry/branded/the-forager-food-co.kiwi => tests/data/complex/cfg/pantry/branded/the-forager-food-co.kiwi +1 -1
@@ 3,7 3,7 @@
(pantry M)

(food risotto-rice-tasmanian-mushroom-black-truffle
  "The Forager Food Co.: Risotto Rice — Tasmanian Mushroom & Black Truffle."
  "The Forager Food Co.: Risotto Rice - Tasmanian Mushroom & Black Truffle."
  {:serving-size [100 :g]
   :protein 10
   :carbs 80

M tests/data/complex/cfg/pantry/init.kiwi => tests/data/complex/cfg/pantry/init.kiwi +1 -1
@@ 133,7 133,7 @@
; - salt
(let [crimini-porcini-mushroom (food [crimini-mushroom porcini-mushroom])]
  (food umami-seasoning-blend
    "Trader Joe's — Mushroom & Co — Umami Seasoning Blend"
    "Trader Joe's - Mushroom & Co - Umami Seasoning Blend"
    {:serving-size [12 :g]
     :source "portland product label"}
    {crimini-porcini-mushroom 0.05}

M tests/data/macros/cfg/pantry/init.fnl => tests/data/macros/cfg/pantry/init.fnl +1 -1
@@ 53,7 53,7 @@
   :per {:tbsp [6.9 :g]}})

(food umami-seasoning-blend
  "Trader Joe's — Mushroom & Co — Umami Seasoning Blend"
  "Trader Joe's - Mushroom & Co - Umami Seasoning Blend"
  {:serving-size [100 :g]}
  [{onion-powder [1 :tbsp]} 1])


M tests/data/normal/dir/pantry/init.fnl => tests/data/normal/dir/pantry/init.fnl +1 -1
@@ 45,7 45,7 @@
   :per {:tbsp [6.9 :g]}}))

(local umami-seasoning-blend (food.new
  "Trader Joe's — Mushroom & Co — Umami Seasoning Blend"
  "Trader Joe's - Mushroom & Co - Umami Seasoning Blend"
  {:serving-size [100 :g]}
  [{onion-powder [1 :tbsp]} 1]))


M tests/tests.rs => tests/tests.rs +2 -2
@@ 963,7 963,7 @@ fn complex_pantry_works() {

            let umami_seasoning_blend_docstring =
                <Food as Value>::docstring(&umami_seasoning_blend).expect("umami_seasoning_blend.docstring()");
            let umami_seasoning_blend_docstring_expected = "Trader Joe's — Mushroom & Co — Umami Seasoning Blend".to_string();
            let umami_seasoning_blend_docstring_expected = "Trader Joe's - Mushroom & Co - Umami Seasoning Blend".to_string();
            let umami_seasoning_blend_docstring_expected = Some(umami_seasoning_blend_docstring_expected);
            assert_eq!(umami_seasoning_blend_docstring, umami_seasoning_blend_docstring_expected);



@@ 1041,7 1041,7 @@ fn complex_pantry_works() {
            lua_ctx
                .load(r#"local umami_seasoning_blend = pantry["umami-seasoning-blend"]
                         local umami_seasoning_blend_docstring = umami_seasoning_blend:docstring()
                         assert(umami_seasoning_blend_docstring == "Trader Joe's — Mushroom & Co — Umami Seasoning Blend")
                         assert(umami_seasoning_blend_docstring == "Trader Joe's - Mushroom & Co - Umami Seasoning Blend")
                         local umami_seasoning_blend_aka = umami_seasoning_blend:aka()
                         assert(umami_seasoning_blend_aka == nil)
                         local umami_seasoning_blend_serving_size = umami_seasoning_blend:serving_size()