import { describe, expect, it } from '@jest/globals'; import { toNOrd as $o, NOrd } from '../src/ord'; import { toBoolean as $b, fromBoolean as _b } from '../src/bool'; import { fromNumber as _n } from '../src/byte'; import { toChar as $c, fromChar as _c, cmp, eq, ge, gt, le, lt, show } from '../src/char'; import { toString as $s } from '../src/string'; describe('Char', () => { describe('toChar', () => { it('converts "0"', () => { expect($c(_n(48))).toBe('0'); }); it('converts "a"', () => { expect($c(_n(97))).toBe('a'); }); it('converts "Z"', () => { expect($c(_n(90))).toBe('Z'); }); it('converts "-"', () => { expect($c(_n(45))).toBe('-'); }); }); describe('fromChar', () => { it('converts "0"', () => { expect($c(_c('0'))).toBe('0'); }); it('converts "a"', () => { expect($c(_c('a'))).toBe('a'); }); it('converts "Z"', () => { expect($c(_c('Z'))).toBe('Z'); }); it('converts "-"', () => { expect($c(_c('-'))).toBe('-'); }); }); describe('cmp', () => { it('"0" cmp "0" is EQ', () => { expect($o(cmp(_c('0'))(_c('0')))).toBe(NOrd.EQ); }); it('"0" cmp "a" is LT', () => { expect($o(cmp(_c('0'))(_c('a')))).toBe(NOrd.LT); }); it('"a" cmp "0" is GT', () => { expect($o(cmp(_c('a'))(_c('0')))).toBe(NOrd.GT); }); it('"z" cmp "z" is EQ', () => { expect($o(cmp(_c('z'))(_c('z')))).toBe(NOrd.EQ); }); it('"z" cmp "-" is GT', () => { expect($o(cmp(_c('z'))(_c('-')))).toBe(NOrd.GT); }); it('"-" cmp "z" is LT', () => { expect($o(cmp(_c('-'))(_c('z')))).toBe(NOrd.LT); }); }); describe('lt', () => { it('"0" lt "0" is False', () => { expect($b(lt(_c('0'))(_c('0')))).toBe(false); }); it('"0" lt "a" is True', () => { expect($b(lt(_c('0'))(_c('a')))).toBe(true); }); it('"a" lt "0" is False', () => { expect($b(lt(_c('a'))(_c('0')))).toBe(false); }); it('"z" lt "z" is False', () => { expect($b(lt(_c('z'))(_c('z')))).toBe(false); }); it('"z" lt "-" is False', () => { expect($b(lt(_c('z'))(_c('-')))).toBe(false); }); it('"-" lt "z" is True', () => { expect($b(lt(_c('-'))(_c('z')))).toBe(true); }); }); describe('le', () => { it('"0" le "0" is True', () => { expect($b(le(_c('0'))(_c('0')))).toBe(true); }); it('"0" le "a" is True', () => { expect($b(le(_c('0'))(_c('a')))).toBe(true); }); it('"a" le "0" is False', () => { expect($b(le(_c('a'))(_c('0')))).toBe(false); }); it('"z" le "z" is True', () => { expect($b(le(_c('z'))(_c('z')))).toBe(true); }); it('"z" le "-" is False', () => { expect($b(le(_c('z'))(_c('-')))).toBe(false); }); it('"-" le "z" is True', () => { expect($b(le(_c('-'))(_c('z')))).toBe(true); }); }); describe('eq', () => { it('"0" eq "0" is True', () => { expect($b(eq(_c('0'))(_c('0')))).toBe(true); }); it('"0" eq "a" is False', () => { expect($b(eq(_c('0'))(_c('a')))).toBe(false); }); it('"a" eq "0" is False', () => { expect($b(eq(_c('a'))(_c('0')))).toBe(false); }); it('"z" eq "z" is True', () => { expect($b(eq(_c('z'))(_c('z')))).toBe(true); }); it('"z" eq "-" is False', () => { expect($b(eq(_c('z'))(_c('-')))).toBe(false); }); it('"-" eq "z" is False', () => { expect($b(eq(_c('-'))(_c('z')))).toBe(false); }); }); describe('ge', () => { it('"0" ge "0" is True', () => { expect($b(ge(_c('0'))(_c('0')))).toBe(true); }); it('"0" ge "a" is False', () => { expect($b(ge(_c('0'))(_c('a')))).toBe(false); }); it('"a" ge "0" is True', () => { expect($b(ge(_c('a'))(_c('0')))).toBe(true); }); it('"z" ge "z" is True', () => { expect($b(ge(_c('z'))(_c('z')))).toBe(true); }); it('"z" ge "-" is True', () => { expect($b(ge(_c('z'))(_c('-')))).toBe(true); }); it('"-" ge "z" is False', () => { expect($b(ge(_c('-'))(_c('z')))).toBe(false); }); }); describe('gt', () => { it('"0" gt "0" is False', () => { expect($b(gt(_c('0'))(_c('0')))).toBe(false); }); it('"0" gt "a" is False', () => { expect($b(gt(_c('0'))(_c('a')))).toBe(false); }); it('"a" gt "0" is True', () => { expect($b(gt(_c('a'))(_c('0')))).toBe(true); }); it('"z" gt "z" is False', () => { expect($b(gt(_c('z'))(_c('z')))).toBe(false); }); it('"z" gt "-" is True', () => { expect($b(gt(_c('z'))(_c('-')))).toBe(true); }); it('"-" gt "z" is False', () => { expect($b(gt(_c('-'))(_c('z')))).toBe(false); }); }); describe('show', () => { it('show "0" is "\'0\'"', () => { expect($s(show(_c('0')))).toBe('\'0\''); }); it('show "a" is "\'a\'"', () => { expect($s(show(_c('a')))).toBe('\'a\''); }); it('show "-" is "\'-\'"', () => { expect($s(show(_c('-')))).toBe('\'-\''); }); }); });