// Stable anchors and annotation records use the real Library data model. #import, file "../apps/library/books.zi"; #program_export Check :: () -> s32 { for chapter: cast(s32)1..BookChapters(0) { if BookChapterTitle(0, chapter) == "" || BookChapter(0, chapter) == "" { return 8 } } if BookChapterTitle(0, 1) != "The Nameless Tao" || BookChapterTitle(0, 81) != "Words That Are True" { return 9 } if BookChapterTitle(0, 0) != "" || BookChapterTitle(0, 82) != "" { return 10 } if !BookChapterArtApproved(0) || BookChapterArtApproved(-1) || BookChapterArtApproved(1) { return 11 } if BookChapterArt(0, 1) != "assets/library/tao-te-ching/chapter-1.avif" || BookChapterArt(0, 81) != "assets/library/tao-te-ching/chapter-81.avif" || BookChapterArt(0, 0) != "" || BookChapterArt(0, 82) != "" || BookChapterArt(1, 1) != "" { return 12 } pages: [4]LibraryPage = .[LibraryPage.{1, 0, 50, false}, LibraryPage.{1, 51, 100, false}, LibraryPage.{2, 0, 25, false}, LibraryPage.{2, 26, 80, false}] if LibraryPageFor(pages[:], 1, 51, false) != 1 || LibraryPageFor(pages[:], 2, 40, false) != 3 { return 1 } larger: [3]LibraryPage = .[LibraryPage.{1, 0, 25, false}, LibraryPage.{1, 26, 50, false}, LibraryPage.{1, 51, 100, false}] if LibraryPageFor(larger[:], 1, 30, false) != 1 || LibraryPageFor(pages[:], 1, 30, false) != 0 { return 2 } // Picture pages open each chapter on their own; text positions skip them. pictured: [5]LibraryPage = .[LibraryPage.{1, 0, 0, true}, LibraryPage.{1, 0, 50, false}, LibraryPage.{1, 51, 100, false}, LibraryPage.{2, 0, 0, true}, LibraryPage.{2, 0, 25, false}] if LibraryPageFor(pictured[:], 1, 0, true) != 0 || LibraryPageFor(pictured[:], 1, 0, false) != 1 || LibraryPageFor(pictured[:], 1, 60, false) != 2 || LibraryPageFor(pictured[:], 2, 0, true) != 3 || LibraryPageFor(pictured[:], 2, 0, false) != 4 || LibraryPageFor(pages[:], 2, 0, true) != 2 { return 13 } notes: [2]LibraryAnnotation = .[LibraryAnnotation.{12, 40, true, "Keep the quiet.\n水の道"}, LibraryAnnotation.{60, 99, false, "A second note, with: 3 4 5\n"}] saved := EncodeLibraryAnnotations(notes[:]) restored: [LIBRARY_ANNOTATION_LIMIT]LibraryAnnotation count := DecodeLibraryAnnotations(saved, restored[:]) if count != 2 { return 3 } for index: cast(s32)0..1 { if restored[index].start != notes[index].start || restored[index].end != notes[index].end || restored[index].highlighted != notes[index].highlighted || restored[index].note != notes[index].note { return 4 } } if !LibraryOverlaps(larger[0], restored[0]) || !LibraryOverlaps(larger[1], restored[0]) || LibraryOverlaps(larger[2], restored[0]) || LibraryOverlaps(pictured[0], restored[0]) { return 5 } if DecodeLibraryAnnotations("12 40 1 99999\nmissing", restored[:]) != 0 || DecodeLibraryAnnotations("-1 2 0 0\n", restored[:]) != 0 { return 6 } at: s32 if ReadLibraryNumber("214748364700", *at) != -1 { return 7 } return 0 }