37 lines
2.0 KiB
Ziran
37 lines
2.0 KiB
Ziran
// 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) != "" ||
|
|
LibraryChapterLabel(3, "") != "3" ||
|
|
LibraryChapterLabel(1, BookChapterTitle(0, 1)) != "1 · The Nameless Tao" { return 10 }
|
|
pages: [4]LibraryPage = .[LibraryPage.{1, 0, 50}, LibraryPage.{1, 51, 100},
|
|
LibraryPage.{2, 0, 25}, LibraryPage.{2, 26, 80}]
|
|
if LibraryPageFor(pages[:], 1, 51) != 1 || LibraryPageFor(pages[:], 2, 40) != 3 { return 1 }
|
|
larger: [3]LibraryPage = .[LibraryPage.{1, 0, 25}, LibraryPage.{1, 26, 50}, LibraryPage.{1, 51, 100}]
|
|
if LibraryPageFor(larger[:], 1, 30) != 1 || LibraryPageFor(pages[:], 1, 30) != 0 { return 2 }
|
|
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]) { 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
|
|
}
|