// SPDX-License-Identifier: Apache-2.0
; specs/widgets/basics-whole-numbers.t27 -- the infographic of lesson 5 of the t27 basics course (specs/course/t27-basics.t27)
; Source of truth for public/widgets/basics-whole-numbers/ (gHashTag/trinity): scripts/widget-pages-from-spec.mjs compiles
; this file, checks its constants, evaluates the tests below and writes the page. tool.js is one import of
; ../infographic.js, which draws SAY_TABLE_* as a real <table> and SAY_FLOW_* as an SVG diagram with a
; <title>, black and white, and holds no words of its own. ASCII only (L3), English only (LANG-EN).
; The lesson spec it illustrates: public/t27/files/specs/basics/05_whole_numbers.t27.
; phi^2 + 1/phi^2 = 3 | TRINITY

module widget_basics_whole_numbers;

pub const KIND : str = "widget-tool";
pub const ID : str = "basics-whole-numbers";
pub const TITLE : str = "t27 basics 5: integer widths and their ranges";
pub const DESCRIPTION : str = "u8, u16, u32 and i32 with their bit counts and ranges, and the error t27c gives a value too big for its type. Lesson 5 of the t27 basics course.";
pub const IMAGE_ALT : str = "A black and white table of t27 integer types: u8 is 8 bits from 0 to 255, u16 is 16 bits from 0 to 65535, u32 is 32 bits from 0 to 4294967295, i32 is 32 bits and signed; below it the compiler error for a u8 given the value 300.";
pub const HOOK : str = "Give a u8 the value 300 and t27c refuses the spec. The table shows why.";
pub const CATEGORY : str = "compiler";
pub const DATA_SOURCES : [2]str = ["The lesson spec public/t27/files/specs/basics/05_whole_numbers.t27, compiled clean on 7 backends by public/t27/t27_compiler.wasm, whose tests pass in the site test runner", "Compiler verdicts, error lines, code and counts quoted on this page are what the same wasm answered in node 22 when the course was authored; words without a run behind them are said to be read, not run"];
pub const READS_LOCAL_FILES : bool = false;
pub const SENDS_NOTHING : bool = true;

; --- The table -----------------------------------------------------------------------------
pub const SAY_TABLE_CAPTION : str = "Integer types";
pub const SAY_TABLE_HEAD : [4]str = ["Type", "Bits", "Smallest", "Largest"];
pub const SAY_TABLE_CELLS : [16]str = ["u8", "8", "0", "255", "u16", "16", "0", "65535", "u32", "32", "0", "4294967295", "i32", "32", "-2147483648", "2147483647"];
pub const K_TABLE_COLS : u8 = 4;
pub const K_TABLE_ROWS : u8 = 4;
pub const K_TABLE_CELLS : u16 = 16;

; --- The diagram and the note ----------------------------------------------------------------
pub const SAY_FLOW_TITLE : str = "pub const N : u8 = 300;";
pub const SAY_FLOW_STEPS : [2]str = ["t27c checks 300 against u8", "error: constant 'N' declares u8 but its value has 3 digits, which no u8 can hold"];
pub const K_FLOW_STEPS : u8 = 2;
pub const SAY_NOTE : str = "The error line is what t27_compiler.wasm answered for pub const N : u8 = 300;";

test the_cells_fill_whole_rows {
    assert K_TABLE_ROWS * K_TABLE_COLS == K_TABLE_CELLS;
}

test the_table_has_a_body {
    assert K_TABLE_ROWS > 0;
    assert K_TABLE_COLS > 0;
}

test the_diagram_has_every_step {
    assert K_FLOW_STEPS == 2;
    assert K_FLOW_STEPS > 1;
}
