Cotton code
41 lines · 1.9 KB · RustRaw
use super::*;use crate::definitions::builtin_table_definition;use serde_json::json;fn todo_pages(record: Value, room: Option<PageRoom>) -> Vec<RecordPage> {    record_pages(builtin_table_definition("todo").unwrap(), record.as_object().unwrap(), room)}#[test]fn a_todo_without_notes_has_one_page() {    assert_eq!(todo_pages(json!({ "title": "Post the letter" }), None), [RecordPage::Face]);    assert_eq!(todo_pages(json!({ "title": "Post the letter", "notes": "  \n" }), None), [RecordPage::Face]);}#[test]fn a_todos_notes_are_page_two() {    let notes = "Stamps are in the drawer.";    assert_eq!(        todo_pages(json!({ "title": "Post the letter", "notes": notes }), None),        [RecordPage::Face, RecordPage::Text { column: "notes".into(), range: 0..notes.len() }]    );}#[test]fn long_notes_run_on_over_pages_of_the_later_size() {    let notes = (1..=12).map(|n| format!("Line {n}")).collect::<Vec<_>>().join("\n");    let cut = todo_pages(json!({ "title": "Pack", "notes": notes }), Some(PageRoom { columns: 20, first: 2, rest: 5 }));    assert_eq!(cut.len(), 4, "{cut:?}");    assert_eq!(cut[0], RecordPage::Face);    let RecordPage::Text { range, .. } = &cut[1] else { panic!("{cut:?}") };    assert!(notes[range.clone()].starts_with("Line 1\n") && notes[range.clone()].trim_end().ends_with("Line 5"), "{:?}", &notes[range.clone()]);}#[test]fn a_card_with_pages_turns_to_each_column_that_holds_words_in_order() {    let mut definition = builtin_table_definition("todo").unwrap().clone();    definition.card.as_mut().unwrap().pages = vec!["notes".into(), "title".into()];    let record = json!({ "title": "Invented title", "notes": "" });    let cut = record_pages(&definition, record.as_object().unwrap(), None);    assert_eq!(cut, [RecordPage::Face, RecordPage::Text { column: "title".into(), range: 0..14 }], "an empty column is no page");}